Skip to content

Commit

Permalink
handle empy ranges in snap client
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte committed Oct 3, 2023
1 parent 8381c58 commit 6475e4e
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,30 @@ public void commit(final FlatDatabaseUpdater flatDatabaseUpdater, final NodeUpda
proofsEntries.put(Hash.hash(proof), proof);
}

final InnerNodeDiscoveryManager<Bytes> snapStoredNodeFactory =
new InnerNodeDiscoveryManager<>(
(location, hash) -> Optional.ofNullable(proofsEntries.get(hash)),
Function.identity(),
Function.identity(),
startKeyHash,
keys.lastKey(),
true);

final MerkleTrie<Bytes, Bytes> trie =
new StoredMerklePatriciaTrie<>(
snapStoredNodeFactory, proofs.isEmpty() ? MerkleTrie.EMPTY_TRIE_NODE_HASH : rootHash);

for (Map.Entry<Bytes32, Bytes> entry : keys.entrySet()) {
trie.put(entry.getKey(), new SnapPutVisitor<>(snapStoredNodeFactory, entry.getValue()));
}

keys.forEach(flatDatabaseUpdater::update);

trie.commit(
nodeUpdater,
(new CommitVisitor<>(nodeUpdater) {
@Override
public void maybeStoreNode(final Bytes location, final Node<Bytes> node) {
if (!node.isHealNeeded()) {
super.maybeStoreNode(location, node);
}
if (keys.size() > 0) {
final InnerNodeDiscoveryManager<Bytes> snapStoredNodeFactory =
new InnerNodeDiscoveryManager<>(
(location, hash) -> Optional.ofNullable(proofsEntries.get(hash)),
Function.identity(), Function.identity(), startKeyHash, keys.lastKey(), true);

final MerkleTrie<Bytes, Bytes> trie = new StoredMerklePatriciaTrie<>(snapStoredNodeFactory,
proofs.isEmpty() ? MerkleTrie.EMPTY_TRIE_NODE_HASH : rootHash);

for (Map.Entry<Bytes32, Bytes> entry : keys.entrySet()) {
trie.put(entry.getKey(), new SnapPutVisitor<>(snapStoredNodeFactory, entry.getValue()));
}

keys.forEach(flatDatabaseUpdater::update);

trie.commit(nodeUpdater, (new CommitVisitor<>(nodeUpdater) {
@Override
public void maybeStoreNode(final Bytes location, final Node<Bytes> node) {
if (!node.isHealNeeded()) {
super.maybeStoreNode(location, node);
}
}));
}
}));
}
}
}

Expand Down

0 comments on commit 6475e4e

Please sign in to comment.