Skip to content

Commit

Permalink
rebase, javadoc and a bit of cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Sep 14, 2023
1 parent 27d1e74 commit a407318
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,11 @@ public interface BonsaiPreImageProxy extends WorldStatePreimageStorage {
*/
Hash hashAndSavePreImage(Bytes value);

/** PreImageProxy which does not store or cache preImages and only implements hashing. */
class NoOpPreImageProxy implements BonsaiPreImageProxy {

@Override
public Hash hashAndSavePreImage(final Bytes value) {
return Hash.hash(value);
}

@Override
public Optional<UInt256> getStorageTrieKeyPreimage(final Bytes32 trieKey) {
return Optional.empty();
}

@Override
public Optional<Address> getAccountTrieKeyPreimage(final Bytes32 trieKey) {
return Optional.empty();
}

@Override
public Updater updater() {
throw new UnsupportedOperationException("NoOpPreImageProxy does not implement an updater");
}
}

/**
* A caching PreImageProxy suitable for ReferenceTestWorldState which saves hashes in an unbounded
* BiMap.
*/
class BonsaiReferenceTestPreImageProxy extends NoOpPreImageProxy {
class BonsaiReferenceTestPreImageProxy implements BonsaiPreImageProxy {
BiMap<Hash, Bytes> preImageCache = HashBiMap.create();

@Override
Expand All @@ -82,5 +58,11 @@ public Optional<UInt256> getStorageTrieKeyPreimage(final Bytes32 trieKey) {
public Optional<Address> getAccountTrieKeyPreimage(final Bytes32 trieKey) {
return Optional.ofNullable(preImageCache.get(trieKey)).map(Address::wrap);
}

@Override
public Updater updater() {
throw new UnsupportedOperationException(
"BonsaiReferenceTestPreImageProxy does not implement an updater");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public MutableAccount createAccount(final Address address, final long nonce, fin
accountsToUpdate.put(address, bonsaiValue);
} else if (bonsaiValue.getUpdated() != null) {
if (bonsaiValue.getUpdated().isEmpty()) {
return new WrappedEvmAccount(track(new UpdateTrackingAccount<>(bonsaiValue.getUpdated())));
return track(new UpdateTrackingAccount<>(bonsaiValue.getUpdated()));
} else {
throw new IllegalStateException("Cannot create an account when one already exists");
}
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'A44Xsq60UEFaeGmScHw+MVOgqWvJanMmEAqDtiaDA8k='
knownHash = 'tpSnjt4HgqSiOTJhBbYdB0r1nFX4QZbicjfloI71Wf0='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ public Stream<byte[]> streamKeys(final SegmentIdentifier segmentId) {
rocksIterator.seekToFirst();
return RocksDbIterator.create(rocksIterator).toStreamKeys();
}

/**
* Returns a stream of key-value pairs starting from the specified key. This method is used to
* retrieve a stream of data reading through the transaction, starting from the given key. If no
* data is available from the specified key onwards, an empty stream is returned.
*
* @param segment The segment identifier whose keys we want to stream.
* @param startKey The key from which the stream should start.
* @return A stream of key-value pairs starting from the specified key.
*/
public Stream<Pair<byte[], byte[]>> streamFromKey(
final SegmentIdentifier segment, final byte[] startKey) {
throwIfClosed();
Expand All @@ -177,6 +185,17 @@ public Stream<Pair<byte[], byte[]>> streamFromKey(
return RocksDbIterator.create(rocksIterator).toStream();
}

/**
* Returns a stream of key-value pairs starting from the specified key, ending at the specified
* key. This method is used to retrieve a stream of data reading through the transaction, starting
* from the given key. If no data is available from the specified key onwards, an empty stream is
* returned.
*
* @param segment The segment identifier whose keys we want to stream.
* @param startKey The key from which the stream should start.
* @param endKey The key at which the stream should stop.
* @return A stream of key-value pairs starting from the specified key.
*/
public Stream<Pair<byte[], byte[]>> streamFromKey(
final SegmentIdentifier segment, final byte[] startKey, final byte[] endKey) {
throwIfClosed();
Expand Down

0 comments on commit a407318

Please sign in to comment.