From bb127178f0f5e1f7dd31cf40c1182a70fb1e6a5c Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 20 Jun 2024 09:46:09 +0800 Subject: [PATCH] eth/protocols/snap, trie/trienode: polish the code --- eth/protocols/snap/handler.go | 6 ++---- eth/protocols/snap/sync_test.go | 12 ++++-------- trie/trienode/proof.go | 6 +++--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/eth/protocols/snap/handler.go b/eth/protocols/snap/handler.go index 1411d86982..5cbe9d1270 100644 --- a/eth/protocols/snap/handler.go +++ b/eth/protocols/snap/handler.go @@ -332,7 +332,7 @@ func ServiceGetAccountRangeQuery(chain *core.BlockChain, req *GetAccountRangePac return nil, nil } } - return accounts, proof.ByteList() + return accounts, proof.List() } func ServiceGetStorageRangesQuery(chain *core.BlockChain, req *GetStorageRangesPacket) ([][]*StorageData, [][]byte) { @@ -434,9 +434,7 @@ func ServiceGetStorageRangesQuery(chain *core.BlockChain, req *GetStorageRangesP return nil, nil } } - for _, blob := range proof.ByteList() { - proofs = append(proofs, blob) - } + proofs = append(proofs, proof.List()...) // Proof terminates the reply as proofs are only added if a node // refuses to serve more data (exception when a contract fetch is // finishing, but that's that). diff --git a/eth/protocols/snap/sync_test.go b/eth/protocols/snap/sync_test.go index cc2303959a..c97c3b99b3 100644 --- a/eth/protocols/snap/sync_test.go +++ b/eth/protocols/snap/sync_test.go @@ -286,7 +286,7 @@ func createAccountRequestResponse(t *testPeer, root common.Hash, origin common.H t.logger.Error("Could not prove last item", "error", err) } } - return keys, vals, proof.ByteList() + return keys, vals, proof.List() } // defaultStorageRequestHandler is a well-behaving storage request handler @@ -368,9 +368,7 @@ func createStorageRequestResponse(t *testPeer, root common.Hash, accounts []comm t.logger.Error("Could not prove last item", "error", err) } } - for _, blob := range proof.ByteList() { - proofs = append(proofs, blob) - } + proofs = append(proofs, proof.List()...) break } } @@ -427,9 +425,7 @@ func createStorageRequestResponseAlwaysProve(t *testPeer, root common.Hash, acco t.logger.Error("Could not prove last item", "error", err) } } - for _, blob := range proof.ByteList() { - proofs = append(proofs, blob) - } + proofs = append(proofs, proof.List()...) break } } @@ -614,7 +610,7 @@ func testSyncBloatedProof(t *testing.T, scheme string) { keys = append(keys[:1], keys[2:]...) vals = append(vals[:1], vals[2:]...) } - if err := t.remote.OnAccounts(t, requestId, keys, vals, proof.ByteList()); err != nil { + if err := t.remote.OnAccounts(t, requestId, keys, vals, proof.List()); err != nil { t.logger.Info("remote error on delivery (as expected)", "error", err) t.term() // This is actually correct, signal to exit the test successfully diff --git a/trie/trienode/proof.go b/trie/trienode/proof.go index 6f9c35f7a0..d3075ecccf 100644 --- a/trie/trienode/proof.go +++ b/trie/trienode/proof.go @@ -102,12 +102,12 @@ func (db *ProofSet) DataSize() int { return db.dataSize } -// ByteList converts the node set to a [][]byte -func (db *ProofSet) ByteList() [][]byte { +// List converts the node set to a slice of bytes. +func (db *ProofSet) List() [][]byte { db.lock.RLock() defer db.lock.RUnlock() - var values = make([][]byte, len(db.order)) + values := make([][]byte, len(db.order)) for i, key := range db.order { values[i] = db.nodes[key] }