From 4d4d45b553fe830105b2a074ee183dd4bf7d51a0 Mon Sep 17 00:00:00 2001 From: GalaIO Date: Mon, 8 May 2023 12:20:59 +0800 Subject: [PATCH] eth/protocols/snap: fix flaky test, don't include empty snapshot slot slice; --- eth/protocols/snap/handler.go | 6 ++++-- eth/protocols/snap/sync_test.go | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/eth/protocols/snap/handler.go b/eth/protocols/snap/handler.go index 314776dffe..23638ef888 100644 --- a/eth/protocols/snap/handler.go +++ b/eth/protocols/snap/handler.go @@ -404,13 +404,15 @@ func ServiceGetStorageRangesQuery(chain *core.BlockChain, req *GetStorageRangesP break } } - slots = append(slots, storage) + if len(storage) > 0 { + slots = append(slots, storage) + } it.Release() // Generate the Merkle proofs for the first and last storage slot, but // only if the response was capped. If the entire storage trie included // in the response, no need for any proofs. - if origin != (common.Hash{}) || abort { + if origin != (common.Hash{}) || (abort && len(storage) > 0) { // Request started at a non-zero hash or was capped prematurely, add // the endpoint Merkle proofs accTrie, err := trie.New(req.Root, chain.StateCache().TrieDB()) diff --git a/eth/protocols/snap/sync_test.go b/eth/protocols/snap/sync_test.go index 1dfba03c86..8e33364c33 100644 --- a/eth/protocols/snap/sync_test.go +++ b/eth/protocols/snap/sync_test.go @@ -334,13 +334,14 @@ func createStorageRequestResponse(t *testPeer, root common.Hash, accounts []comm break } } - hashes = append(hashes, keys) - slots = append(slots, vals) - + if len(keys) > 0 { + hashes = append(hashes, keys) + slots = append(slots, vals) + } // Generate the Merkle proofs for the first and last storage slot, but // only if the response was capped. If the entire storage trie included // in the response, no need for any proofs. - if originHash != (common.Hash{}) || abort { + if originHash != (common.Hash{}) || (abort && len(keys) > 0) { // If we're aborting, we need to prove the first and last item // This terminates the response (and thus the loop) proof := light.NewNodeSet()