Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapserver GetTrieNodes request to handle short hash for storage #7264

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ MessageData constructGetTrieNodesResponse(final MessageData message) {
// otherwise the first element should be account hash, and subsequent paths
// are compact encoded account storage paths

final Bytes accountPrefix = triePath.get(0);
final Bytes accountPrefix = Bytes32.leftPad(triePath.getFirst());

List<Bytes> storagePaths = triePath.subList(1, triePath.size());
for (var path : storagePaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,24 @@ public void assertStorageTriePathRequest() {
assertThat(trieNodes.size()).isEqualTo(4);
}

@Test
public void assertStorageTrieShortAccountHashPathRequest() {
Bytes accountShortHash = Bytes.fromHexStringLenient("0x40");
Hash accountFullHash = Hash.wrap(Bytes32.leftPad(accountShortHash));
SnapTestAccount testAccount = createTestContractAccount(accountFullHash, inMemoryStorage);
insertTestAccounts(testAccount);
var pathToSlot11 = CompactEncoding.encode(Bytes.fromHexStringLenient("0x0101"));
var pathToSlot12 = CompactEncoding.encode(Bytes.fromHexStringLenient("0x0102"));
var trieNodeRequest =
requestTrieNodes(
storageTrie.getRootHash(),
List.of(List.of(accountShortHash, pathToSlot11, pathToSlot12)));
assertThat(trieNodeRequest).isNotNull();
List<Bytes> trieNodes = trieNodeRequest.nodes(false);
assertThat(trieNodes).isNotNull();
assertThat(trieNodes.size()).isEqualTo(2);
}

@Test
public void assertStorageTrieLimitRequest() {
insertTestAccounts(acct1, acct2, acct3, acct4);
Expand Down Expand Up @@ -671,7 +689,12 @@ static SnapTestAccount createTestAccount(final String hexAddr) {

static SnapTestAccount createTestContractAccount(
final String hexAddr, final BonsaiWorldStateKeyValueStorage storage) {
Hash acctHash = Hash.wrap(Bytes32.rightPad(Bytes.fromHexString(hexAddr)));
final Hash acctHash = Hash.wrap(Bytes32.rightPad(Bytes.fromHexString(hexAddr)));
return createTestContractAccount(acctHash, storage);
}

static SnapTestAccount createTestContractAccount(
final Hash acctHash, final BonsaiWorldStateKeyValueStorage storage) {
MerkleTrie<Bytes32, Bytes> trie =
new StoredMerklePatriciaTrie<>(
(loc, hash) -> storage.getAccountStorageTrieNode(acctHash, loc, hash),
Expand Down
Loading