Skip to content

Commit

Permalink
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 6, 2023
1 parent eb52d84 commit 366b09e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 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 @@ -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 366b09e

Please sign in to comment.