mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 06:04:33 +00:00
parent
1f6bd2bae5
commit
0b13b19b55
4 changed files with 19 additions and 19 deletions
|
|
@ -162,7 +162,7 @@ func (n *cachedNode) rlp() []byte {
|
|||
// or by regenerating it from the rlp encoded blob.
|
||||
func (n *cachedNode) obj(hash common.Hash) node {
|
||||
if node, ok := n.node.(rawNode); ok {
|
||||
// The raw-blob format nodes are loaded from either from
|
||||
// The raw-blob format nodes are loaded either from the
|
||||
// clean cache or the database, they are all in their own
|
||||
// copy and safe to use unsafe decoder.
|
||||
return mustDecodeNodeUnsafe(hash[:], node)
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ func (h *hasher) hashData(data []byte) hashNode {
|
|||
}
|
||||
|
||||
// proofHash is used to construct trie proofs, and returns the 'collapsed'
|
||||
// Node (for later RLP encoding) aswell as the hashed Node -- unless the
|
||||
// Node (for later RLP encoding) as well as the hashed Node -- unless the
|
||||
// Node is smaller than 32 bytes, in which case it will be returned as is.
|
||||
// This method does not do anything on value- or hash-nodes.
|
||||
func (h *hasher) proofHash(original node) (collapsed, hashed node) {
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ func TestRangeProofWithNonExistentProof(t *testing.T) {
|
|||
proof := memorydb.New()
|
||||
|
||||
// Short circuit if the decreased key is same with the previous key
|
||||
first := decreseKey(common.CopyBytes(entries[start].k))
|
||||
first := decreaseKey(common.CopyBytes(entries[start].k))
|
||||
if start != 0 && bytes.Equal(first, entries[start-1].k) {
|
||||
continue
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ func TestRangeProofWithNonExistentProof(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
// Short circuit if the increased key is same with the next key
|
||||
last := increseKey(common.CopyBytes(entries[end-1].k))
|
||||
last := increaseKey(common.CopyBytes(entries[end-1].k))
|
||||
if end != len(entries) && bytes.Equal(last, entries[end].k) {
|
||||
continue
|
||||
}
|
||||
|
|
@ -269,7 +269,7 @@ func TestRangeProofWithInvalidNonExistentProof(t *testing.T) {
|
|||
|
||||
// Case 1
|
||||
start, end := 100, 200
|
||||
first := decreseKey(common.CopyBytes(entries[start].k))
|
||||
first := decreaseKey(common.CopyBytes(entries[start].k))
|
||||
|
||||
proof := memorydb.New()
|
||||
if err := trie.Prove(first, 0, proof); err != nil {
|
||||
|
|
@ -292,7 +292,7 @@ func TestRangeProofWithInvalidNonExistentProof(t *testing.T) {
|
|||
|
||||
// Case 2
|
||||
start, end = 100, 200
|
||||
last := increseKey(common.CopyBytes(entries[end-1].k))
|
||||
last := increaseKey(common.CopyBytes(entries[end-1].k))
|
||||
proof = memorydb.New()
|
||||
if err := trie.Prove(entries[start].k, 0, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
|
|
@ -338,7 +338,7 @@ func TestOneElementRangeProof(t *testing.T) {
|
|||
|
||||
// One element with left non-existent edge proof
|
||||
start = 1000
|
||||
first := decreseKey(common.CopyBytes(entries[start].k))
|
||||
first := decreaseKey(common.CopyBytes(entries[start].k))
|
||||
proof = memorydb.New()
|
||||
if err := trie.Prove(first, 0, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
|
|
@ -353,7 +353,7 @@ func TestOneElementRangeProof(t *testing.T) {
|
|||
|
||||
// One element with right non-existent edge proof
|
||||
start = 1000
|
||||
last := increseKey(common.CopyBytes(entries[start].k))
|
||||
last := increaseKey(common.CopyBytes(entries[start].k))
|
||||
proof = memorydb.New()
|
||||
if err := trie.Prove(entries[start].k, 0, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
|
|
@ -368,7 +368,7 @@ func TestOneElementRangeProof(t *testing.T) {
|
|||
|
||||
// One element with two non-existent edge proofs
|
||||
start = 1000
|
||||
first, last = decreseKey(common.CopyBytes(entries[start].k)), increseKey(common.CopyBytes(entries[start].k))
|
||||
first, last = decreaseKey(common.CopyBytes(entries[start].k)), increaseKey(common.CopyBytes(entries[start].k))
|
||||
proof = memorydb.New()
|
||||
if err := trie.Prove(first, 0, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
|
|
@ -636,9 +636,9 @@ func TestSameSideProofs(t *testing.T) {
|
|||
sort.Sort(entries)
|
||||
|
||||
pos := 1000
|
||||
first := decreseKey(common.CopyBytes(entries[pos].k))
|
||||
first = decreseKey(first)
|
||||
last := decreseKey(common.CopyBytes(entries[pos].k))
|
||||
first := decreaseKey(common.CopyBytes(entries[pos].k))
|
||||
first = decreaseKey(first)
|
||||
last := decreaseKey(common.CopyBytes(entries[pos].k))
|
||||
|
||||
proof := memorydb.New()
|
||||
if err := trie.Prove(first, 0, proof); err != nil {
|
||||
|
|
@ -652,9 +652,9 @@ func TestSameSideProofs(t *testing.T) {
|
|||
t.Fatalf("Expected error, got nil")
|
||||
}
|
||||
|
||||
first = increseKey(common.CopyBytes(entries[pos].k))
|
||||
last = increseKey(common.CopyBytes(entries[pos].k))
|
||||
last = increseKey(last)
|
||||
first = increaseKey(common.CopyBytes(entries[pos].k))
|
||||
last = increaseKey(common.CopyBytes(entries[pos].k))
|
||||
last = increaseKey(last)
|
||||
|
||||
proof = memorydb.New()
|
||||
if err := trie.Prove(first, 0, proof); err != nil {
|
||||
|
|
@ -760,7 +760,7 @@ func TestEmptyRangeProof(t *testing.T) {
|
|||
}
|
||||
for _, c := range cases {
|
||||
proof := memorydb.New()
|
||||
first := increseKey(common.CopyBytes(entries[c.pos].k))
|
||||
first := increaseKey(common.CopyBytes(entries[c.pos].k))
|
||||
if err := trie.Prove(first, 0, proof); err != nil {
|
||||
t.Fatalf("Failed to prove the first node %v", err)
|
||||
}
|
||||
|
|
@ -899,7 +899,7 @@ func mutateByte(b []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
func increseKey(key []byte) []byte {
|
||||
func increaseKey(key []byte) []byte {
|
||||
for i := len(key) - 1; i >= 0; i-- {
|
||||
key[i]++
|
||||
if key[i] != 0x0 {
|
||||
|
|
@ -909,7 +909,7 @@ func increseKey(key []byte) []byte {
|
|||
return key
|
||||
}
|
||||
|
||||
func decreseKey(key []byte) []byte {
|
||||
func decreaseKey(key []byte) []byte {
|
||||
for i := len(key) - 1; i >= 0; i-- {
|
||||
key[i]--
|
||||
if key[i] != 0xff {
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func TestStateTrieConcurrency(t *testing.T) {
|
|||
for i := 0; i < threads; i++ {
|
||||
tries[i] = trie.Copy()
|
||||
}
|
||||
// Start a batch of goroutines interactng with the trie
|
||||
// Start a batch of goroutines interacting with the trie
|
||||
pend := new(sync.WaitGroup)
|
||||
pend.Add(threads)
|
||||
for i := 0; i < threads; i++ {
|
||||
|
|
|
|||
Loading…
Reference in a new issue