forked from cerc-io/plugeth
eth/protocols/snap: fix snap sync failure on empty storage range (#28306)
This change addresses an issue in snap sync, specifically when the entire sync process can be halted due to an encountered empty storage range.
Currently, on the snap sync client side, the response to an empty (partial) storage range is discarded as a non-delivery. However, this response can be a valid response, when the particular range requested does not contain any slots.
For instance, consider a large contract where the entire key space is divided into 16 chunks, and there are no available slots in the last chunk [0xf] -> [end]. When the node receives a request for this particular range, the response includes:
The proof with origin [0xf]
A nil storage slot set
If we simply discard this response, the finalization of the last range will be skipped, halting the entire sync process indefinitely. The test case TestSyncWithUnevenStorage can reproduce the scenario described above.
In addition, this change also defines the common variables MaxAddress and MaxHash.
This commit is contained in:
+4
-4
@@ -250,7 +250,7 @@ func TestRangeProofWithNonExistentProof(t *testing.T) {
|
||||
// Special case, two edge proofs for two edge key.
|
||||
proof := memorydb.New()
|
||||
first := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000").Bytes()
|
||||
last := common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").Bytes()
|
||||
last := common.MaxHash.Bytes()
|
||||
if err := trie.Prove(first, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
}
|
||||
@@ -451,7 +451,7 @@ func TestAllElementsProof(t *testing.T) {
|
||||
// Even with non-existent edge proofs, it should still work.
|
||||
proof = memorydb.New()
|
||||
first := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000").Bytes()
|
||||
last := common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").Bytes()
|
||||
last := common.MaxHash.Bytes()
|
||||
if err := trie.Prove(first, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
}
|
||||
@@ -517,7 +517,7 @@ func TestReverseSingleSideRangeProof(t *testing.T) {
|
||||
if err := trie.Prove(entries[pos].k, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
}
|
||||
last := common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
|
||||
last := common.MaxHash
|
||||
if err := trie.Prove(last.Bytes(), proof); err != nil {
|
||||
t.Fatalf("Failed to prove the last node %v", err)
|
||||
}
|
||||
@@ -728,7 +728,7 @@ func TestHasRightElement(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if c.end == -1 {
|
||||
lastKey, end = common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").Bytes(), len(entries)
|
||||
lastKey, end = common.MaxHash.Bytes(), len(entries)
|
||||
if err := trie.Prove(lastKey, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user