From 366b09ee9c682c06282399e77d63e825eaefb59e Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 31 Aug 2023 22:48:35 -0700 Subject: [PATCH] javadoc and a bit of cleanup Signed-off-by: garyschulte --- .../bonsai/storage/BonsaiPreImageProxy.java | 32 ++++--------------- .../segmented/RocksDBSnapshotTransaction.java | 21 +++++++++++- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java index 42a86ce36b2..248e5d895fd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.java @@ -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 getStorageTrieKeyPreimage(final Bytes32 trieKey) { - return Optional.empty(); - } - - @Override - public Optional
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 preImageCache = HashBiMap.create(); @Override @@ -82,5 +58,11 @@ public Optional getStorageTrieKeyPreimage(final Bytes32 trieKey) { public Optional
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"); + } } } diff --git a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBSnapshotTransaction.java b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBSnapshotTransaction.java index 5d058bbaddb..0897493eb19 100644 --- a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBSnapshotTransaction.java +++ b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBSnapshotTransaction.java @@ -166,7 +166,15 @@ public Stream 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> streamFromKey( final SegmentIdentifier segment, final byte[] startKey) { throwIfClosed(); @@ -177,6 +185,17 @@ public Stream> 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> streamFromKey( final SegmentIdentifier segment, final byte[] startKey, final byte[] endKey) { throwIfClosed();