Skip to content

Commit

Permalink
fix some errors:
Browse files Browse the repository at this point in the history
 * couple segment mapping errors
 * wrap segmented storage transactions in a validating decorator (useless but necessary for unit test suite)
 * fix a few tests that were using mock segment id's

Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Jul 23, 2023
1 parent b428ba5 commit aaba707
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
import org.hyperledger.besu.plugin.data.PropagatedBlockContext;
import org.hyperledger.besu.plugin.data.SyncStatus;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import org.hyperledger.besu.plugin.data.Transaction;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import org.hyperledger.besu.testutil.TestClock;

import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public BonsaiUpdater putAccountStateTrieNode(

@Override
public BonsaiUpdater removeAccountStateTrieNode(final Bytes location, final Bytes32 nodeHash) {
composedWorldStateTransaction.remove(ACCOUNT_INFO_STATE, location.toArrayUnsafe());
composedWorldStateTransaction.remove(TRIE_BRANCH_STORAGE, location.toArrayUnsafe());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_STORAGE_STORAGE;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.CODE_STORAGE;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE;

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.StorageSlotKey;
Expand Down Expand Up @@ -112,7 +111,7 @@ public Optional<Bytes> getCode(
return Optional.of(Bytes.EMPTY);
} else {
return storage
.get(TRIE_BRANCH_STORAGE, accountHash.toArrayUnsafe())
.get(CODE_STORAGE, accountHash.toArrayUnsafe())
.map(Bytes::wrap)
.filter(b -> Hash.hash(b).equals(codeHash));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.hyperledger.besu.ethereum.bonsai.BonsaiAccount.fromRLP;
import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY;
import static org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.ACCOUNT_INFO_STATE;
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.TRIE_BRANCH_STORAGE;

import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -187,7 +186,7 @@ private Hash calculateRootHash(
accountTrie.commit(
(location, hash, value) ->
writeTrieNode(
ACCOUNT_INFO_STATE,
TRIE_BRANCH_STORAGE,
bonsaiUpdater.getWorldStateTransaction(),
location,
value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.plugin.services.storage.rocksdb;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.plugin.services.storage.rocksdb.segmented.RocksDBColumnarKeyValueStorageTest.TestSegment;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.metrics.ObservableMetricsSystem;
Expand Down Expand Up @@ -43,8 +44,8 @@ public class RocksDBKeyValuePrivacyStorageFactoryTest {
@Mock private BesuConfiguration commonConfiguration;
@TempDir private Path temporaryFolder;
private final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem();
private final List<SegmentIdentifier> segments = List.of();
@Mock private SegmentIdentifier segment;
private final SegmentIdentifier segment = TestSegment.BAR;
private final List<SegmentIdentifier> segments = List.of(segment);

@Test
public void shouldDetectVersion1DatabaseIfNoMetadataFileFound() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.DatabaseMetadata;
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration;
import org.hyperledger.besu.plugin.services.storage.rocksdb.segmented.RocksDBColumnarKeyValueStorageTest.TestSegment;

import java.nio.charset.Charset;
import java.nio.file.Files;
Expand All @@ -48,8 +49,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Mock private BesuConfiguration commonConfiguration;
@TempDir public Path temporaryFolder;
private final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem();
private final List<SegmentIdentifier> segments = List.of();
@Mock private SegmentIdentifier segment;
private final SegmentIdentifier segment = TestSegment.FOO;
private final List<SegmentIdentifier> segments = List.of(segment);

@Test
public void shouldCreateCorrectMetadataFileForLatestVersion() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public void close() {}

@Override
public SegmentedKeyValueStorageTransaction startTransaction() {
return new SegmentedInMemoryTransaction();
return new SegmentedKeyValueStorageTransactionValidatorDecorator(
new SegmentedInMemoryTransaction(), this::isClosed);
}

@Override
Expand Down

0 comments on commit aaba707

Please sign in to comment.