From ba13e5d7f98d9ec53f6b18cc2304dbadf3f10948 Mon Sep 17 00:00:00 2001 From: antonis19 Date: Tue, 3 Dec 2024 12:45:29 +0100 Subject: [PATCH] Remove duplicate import (#12974) Co-authored-by: antonis19 --- .../trie/flatdb_sub_trie_loader_test.go | 11 +- erigon-lib/trie/hack.go | 8 +- erigon-lib/trie/stream.go | 31 +++--- erigon-lib/trie/stream_test.go | 9 +- erigon-lib/trie/structural_test.go | 29 +++-- erigon-lib/trie/trie_test.go | 103 +++++++++--------- 6 files changed, 92 insertions(+), 99 deletions(-) diff --git a/erigon-lib/trie/flatdb_sub_trie_loader_test.go b/erigon-lib/trie/flatdb_sub_trie_loader_test.go index bb672135f16..21c0eb7a4d7 100644 --- a/erigon-lib/trie/flatdb_sub_trie_loader_test.go +++ b/erigon-lib/trie/flatdb_sub_trie_loader_test.go @@ -21,7 +21,6 @@ import ( "fmt" "testing" - libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/kv" "github.com/stretchr/testify/assert" @@ -32,7 +31,7 @@ import ( func TestCreateLoadingPrefixes(t *testing.T) { assert := assert.New(t) - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) kAcc1 := common.FromHex("0001cf1ce0664746d39af9f6db99dc3370282f1d9d48df7f804b7e6499558c83") kInc := make([]byte, 8) binary.BigEndian.PutUint64(kInc, uint64(1)) @@ -99,13 +98,13 @@ func TestIsBefore(t *testing.T) { assert.Equal(true, is) contract := fmt.Sprintf("2%063x", 0) - storageKey := libcommon.Hex2Bytes(contract + "ffffffff" + fmt.Sprintf("10%062x", 0)) - cacheKey := libcommon.Hex2Bytes(contract + "ffffffff" + "20") + storageKey := common.Hex2Bytes(contract + "ffffffff" + fmt.Sprintf("10%062x", 0)) + cacheKey := common.Hex2Bytes(contract + "ffffffff" + "20") is = keyIsBefore(cacheKey, storageKey) assert.False(is) - storageKey = libcommon.Hex2Bytes(contract + "ffffffffffffffff" + fmt.Sprintf("20%062x", 0)) - cacheKey = libcommon.Hex2Bytes(contract + "ffffffffffffffff" + "10") + storageKey = common.Hex2Bytes(contract + "ffffffffffffffff" + fmt.Sprintf("20%062x", 0)) + cacheKey = common.Hex2Bytes(contract + "ffffffffffffffff" + "10") is = keyIsBefore(cacheKey, storageKey) assert.True(is) } diff --git a/erigon-lib/trie/hack.go b/erigon-lib/trie/hack.go index fd59eab089c..17ab3ebc308 100644 --- a/erigon-lib/trie/hack.go +++ b/erigon-lib/trie/hack.go @@ -19,8 +19,6 @@ package trie import ( "fmt" - libcommon "github.com/erigontech/erigon-lib/common" - "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/rlp" ) @@ -47,7 +45,7 @@ func FullNode2() { func FullNode3() { f := &fullNode{} f.Children[0] = valueNode(nil) - h := libcommon.Hash{} + h := common.Hash{} f.Children[1] = hashNode{hash: h[:]} b, err := rlp.EncodeToBytes(f) if err != nil { @@ -58,7 +56,7 @@ func FullNode3() { func FullNode4() { f := &fullNode{} - h := libcommon.Hash{} + h := common.Hash{} for i := 0; i < 17; i++ { f.Children[i] = hashNode{hash: h[:]} } @@ -92,7 +90,7 @@ func hashRoot(n node, title string) { h1 := newHasher(true) defer returnHasherToPool(h) defer returnHasherToPool(h1) - var hash libcommon.Hash + var hash common.Hash hLen, _ := h.hash(n, true, hash[:]) if hLen < 32 { panic("expected hashNode") diff --git a/erigon-lib/trie/stream.go b/erigon-lib/trie/stream.go index 9d106f62c78..ce5bd1593ff 100644 --- a/erigon-lib/trie/stream.go +++ b/erigon-lib/trie/stream.go @@ -25,7 +25,6 @@ import ( "fmt" "os" - libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/common/length" "github.com/erigontech/erigon-lib/common" @@ -603,18 +602,18 @@ func (smi *StreamMergeIterator) Next() (itemType1 StreamItem, hex1 []byte, aValu } // StreamHash computes the hash of a stream, as if it was a trie -func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, trace bool) (libcommon.Hash, error) { +func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, trace bool) (common.Hash, error) { var succ bytes.Buffer var curr bytes.Buffer var succStorage bytes.Buffer var currStorage bytes.Buffer var value bytes.Buffer - var hashBuf libcommon.Hash - var hashBufStorage libcommon.Hash + var hashBuf common.Hash + var hashBufStorage common.Hash var hashRef []byte var hashRefStorage []byte var groups, hasTree, hasHash []uint16 // Separate groups slices for storage items and for accounts - var aRoot libcommon.Hash + var aRoot common.Hash var aEmptyRoot = true var isAccount bool var fieldSet uint32 @@ -653,14 +652,14 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, var err error groups, hasTree, hasHash, err = GenStructStep(retain, currStorage.Bytes(), succStorage.Bytes(), hb, nil /* hashCollector */, makeData(0, hashRefStorage), groups, hasTree, hasHash, trace) if err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } currStorage.Reset() fieldSet += AccountFieldStorageOnly } } else if itemType == AccountStreamItem && !aEmptyRoot { if err := hb.hash(aRoot[:]); err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } fieldSet += AccountFieldStorageOnly } @@ -676,7 +675,7 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, var err error groups, hasTree, hasHash, err = GenStructStep(retain, curr.Bytes(), succ.Bytes(), hb, nil /* hashCollector */, makeData(fieldSet, hashRef), groups, hasTree, hasHash, trace) if err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } } itemType = newItemType @@ -698,12 +697,12 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, if aCode != nil { fieldSet |= AccountFieldCodeOnly if err := hb.code(aCode); err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } } else if !a.IsEmptyCodeHash() { fieldSet |= AccountFieldCodeOnly if err := hb.hash(a.CodeHash[:]); err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } } hashRef = nil @@ -724,7 +723,7 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, var err error groups, hasTree, hasHash, err = GenStructStep(retain, currStorage.Bytes(), succStorage.Bytes(), hb, nil /* hashCollector */, makeData(0, hashRefStorage), groups, hasTree, hasHash, trace) if err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } } sItemType = newItemType @@ -749,14 +748,14 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, var err error _, _, _, err = GenStructStep(retain, currStorage.Bytes(), succStorage.Bytes(), hb, nil /* hashCollector */, makeData(0, hashRefStorage), groups, hasTree, hasHash, trace) if err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } currStorage.Reset() fieldSet |= AccountFieldStorageOnly } } else if itemType == AccountStreamItem && !aEmptyRoot { if err := hb.hash(aRoot[:]); err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } fieldSet |= AccountFieldStorageOnly } @@ -768,11 +767,11 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, var err error _, _, _, err = GenStructStep(retain, curr.Bytes(), succ.Bytes(), hb, nil /* hashCollector */, makeData(fieldSet, hashRef), groups, hasTree, hasHash, trace) if err != nil { - return libcommon.Hash{}, err + return common.Hash{}, err } } if trace { - tt := New(libcommon.Hash{}) + tt := New(common.Hash{}) tt.root = hb.root() filename := "root.txt" f, err1 := os.Create(filename) @@ -795,7 +794,7 @@ func HashWithModifications( newStream *Stream, // Streams that will be reused for old and new stream hb *HashBuilder, // HashBuilder will be reused trace bool, -) (libcommon.Hash, error) { +) (common.Hash, error) { keyCount := len(aKeys) + len(sKeys) var stream = Stream{ keyBytes: make([]byte, len(aKeys)*(2*length.Hash)+len(sKeys)*(4*length.Hash+2*length.Incarnation)), diff --git a/erigon-lib/trie/stream_test.go b/erigon-lib/trie/stream_test.go index 213859c4d07..2754268afe4 100644 --- a/erigon-lib/trie/stream_test.go +++ b/erigon-lib/trie/stream_test.go @@ -24,7 +24,6 @@ import ( "sort" "testing" - libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/crypto" "github.com/erigontech/erigon-lib/common" @@ -32,7 +31,7 @@ import ( ) func TestHashWithModificationsEmpty(t *testing.T) { - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) // Populate the trie // Build the root var stream Stream @@ -55,7 +54,7 @@ func TestHashWithModificationsEmpty(t *testing.T) { } func TestHashWithModificationsNoChanges(t *testing.T) { - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) // Populate the trie var preimage [4]byte var keys []string @@ -113,7 +112,7 @@ func TestHashWithModificationsNoChanges(t *testing.T) { } func TestHashWithModificationsChanges(t *testing.T) { - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) // Populate the trie var preimage [4]byte var keys []string @@ -152,7 +151,7 @@ func TestHashWithModificationsChanges(t *testing.T) { tr.Hash() // Generate account change binary.BigEndian.PutUint32(preimage[:], 5000000) - var insertKey libcommon.Hash + var insertKey common.Hash copy(insertKey[:], crypto.Keccak256(preimage[:])) var insertA accounts.Account insertA.Balance.SetUint64(300000) diff --git a/erigon-lib/trie/structural_test.go b/erigon-lib/trie/structural_test.go index 883dccda148..cda3ecaccb6 100644 --- a/erigon-lib/trie/structural_test.go +++ b/erigon-lib/trie/structural_test.go @@ -31,7 +31,6 @@ import ( "github.com/stretchr/testify/require" - libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/common/length" "github.com/erigontech/erigon-lib/crypto" @@ -53,7 +52,7 @@ func TestV2HashBuilding(t *testing.T) { fmt.Printf("Duplicate!\n") } } - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) valueLong := []byte("VALUE123985903485903489043859043859043859048590485904385903485940385439058934058439058439058439058940385904358904385438809348908345") valueShort := []byte("VAL") for i, key := range keys { @@ -115,7 +114,7 @@ func TestV2Resolution(t *testing.T) { keys = append(keys, string(key)) } slices.Sort(keys) - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) value := []byte("VALUE123985903485903489043859043859043859048590485904385903485940385439058934058439058439058439058940385904358904385438809348908345") for _, key := range keys { tr.Update([]byte(key), value) @@ -164,7 +163,7 @@ func TestV2Resolution(t *testing.T) { if _, _, _, err := GenStructStep(rl.Retain, curr.Bytes(), succ.Bytes(), hb, nil /* hashCollector */, &GenStructStepLeafData{rlphacks.RlpSerializableBytes(valueTape.Bytes())}, groups, hasTree, hasHash, false); err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) } - tr1 := New(libcommon.Hash{}) + tr1 := New(common.Hash{}) tr1.root = hb.root() builtHash := hb.rootHash() if trieHash != builtHash { @@ -194,19 +193,19 @@ func TestV2Resolution(t *testing.T) { // In order to prevent the branch node on top of the extension node, we will need to manipulate // the `groups` array and truncate it to the level of the accounts func TestEmbeddedStorage(t *testing.T) { - var accountAddress = libcommon.Address{3, 4, 5, 6} + var accountAddress = common.Address{3, 4, 5, 6} addrHash := crypto.Keccak256(accountAddress[:]) incarnation := make([]byte, 8) binary.BigEndian.PutUint64(incarnation, uint64(2)) - var location1 = libcommon.Hash{1} + var location1 = common.Hash{1} locationKey1 := append(append([]byte{}, addrHash...), crypto.Keccak256(location1[:])...) - var location2 = libcommon.Hash{2} + var location2 = common.Hash{2} locationKey2 := append(append([]byte{}, addrHash...), crypto.Keccak256(location2[:])...) - var location3 = libcommon.Hash{3} + var location3 = common.Hash{3} locationKey3 := append(append([]byte{}, addrHash...), crypto.Keccak256(location3[:])...) var keys = []string{string(locationKey1), string(locationKey2), string(locationKey3)} slices.Sort(keys) - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) valueShort := []byte("VAL") for _, key := range keys { tr.Update([]byte(key)[length.Hash:], valueShort) @@ -483,7 +482,7 @@ func TestBranchesOnly(t *testing.T) { succ.Reset() succ.Write(key.k) if curr.Len() > 0 { - groups, hasTree, hasHash, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), succ.Bytes(), hb, hc /* hashCollector */, &GenStructStepHashData{libcommon.Hash{}, key.hasTree}, groups, hasTree, hasHash, false) + groups, hasTree, hasHash, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), succ.Bytes(), hb, hc /* hashCollector */, &GenStructStepHashData{common.Hash{}, key.hasTree}, groups, hasTree, hasHash, false) if err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) } @@ -493,7 +492,7 @@ func TestBranchesOnly(t *testing.T) { curr.Write(succ.Bytes()) succ.Reset() // Produce the key which is specially modified version of `curr` (only different in the last nibble) - if _, _, _, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), []byte{}, hb, hc /* hashCollector */, &GenStructStepHashData{libcommon.Hash{}, false}, groups, hasTree, hasHash, false); err != nil { + if _, _, _, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), []byte{}, hb, hc /* hashCollector */, &GenStructStepHashData{common.Hash{}, false}, groups, hasTree, hasHash, false); err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) } require.Equal(t, 7, i) @@ -646,7 +645,7 @@ func TestStorageWithoutBranchNodeInRoot(t *testing.T) { currhasTree = succhasTree succhasTree = key.hasTree if curr.Len() > 0 { - v := &GenStructStepHashData{libcommon.Hash{}, currhasTree} + v := &GenStructStepHashData{common.Hash{}, currhasTree} groups, hasTree, hasHash, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), succ.Bytes(), hb, hc /* hashCollector */, v, groups, hasTree, hasHash, trace) if err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) @@ -657,7 +656,7 @@ func TestStorageWithoutBranchNodeInRoot(t *testing.T) { curr.Write(succ.Bytes()) succ.Reset() currhasTree = succhasTree - v := &GenStructStepHashData{libcommon.Hash{}, currhasTree} + v := &GenStructStepHashData{common.Hash{}, currhasTree} // Produce the key which is specially modified version of `curr` (only different in the last nibble) if _, _, _, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), []byte{}, hb, hc /* hashCollector */, v, groups, hasTree, hasHash, trace); err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) @@ -720,7 +719,7 @@ func Test2(t *testing.T) { curr.Bytes(), succ.Bytes(), hb, func(keyHex []byte, hasState, hasTree, hasHash uint16, hashes, rootHash []byte) error { return nil - }, /* hashCollector */ &GenStructStepHashData{Hash: libcommon.BytesToHash(key.v)}, groups, hasTree, hasHash, false) + }, /* hashCollector */ &GenStructStepHashData{Hash: common.BytesToHash(key.v)}, groups, hasTree, hasHash, false) if err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) } @@ -732,7 +731,7 @@ func Test2(t *testing.T) { // Produce the key which is specially modified version of `curr` (only different in the last nibble) if _, _, _, err = GenStructStep(func(_ []byte) bool { return false }, curr.Bytes(), succ.Bytes(), hb, func(keyHex []byte, hasState, hasTree, hasHash uint16, hashes, rootHash []byte) error { return nil - }, /* hashCollector */ &GenStructStepHashData{Hash: libcommon.BytesToHash(keys[len(keys)-1].v)}, groups, hasTree, hasHash, false); err != nil { + }, /* hashCollector */ &GenStructStepHashData{Hash: common.BytesToHash(keys[len(keys)-1].v)}, groups, hasTree, hasHash, false); err != nil { t.Errorf("Could not execute step of structGen algorithm: %v", err) } } diff --git a/erigon-lib/trie/trie_test.go b/erigon-lib/trie/trie_test.go index 4fe3b5d83e2..48ecfdebb76 100644 --- a/erigon-lib/trie/trie_test.go +++ b/erigon-lib/trie/trie_test.go @@ -32,7 +32,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/erigontech/erigon-lib/common" - libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/crypto" "github.com/erigontech/erigon-lib/rlp" "github.com/erigontech/erigon-lib/types/accounts" @@ -45,7 +44,7 @@ func init() { // Used for testing func newEmpty() *Trie { - trie := New(libcommon.Hash{}) + trie := New(common.Hash{}) return trie } @@ -79,31 +78,31 @@ func TestLargeValue(t *testing.T) { // TestRandomCases tests som cases that were found via random fuzzing func TestRandomCases(t *testing.T) { var rt = []randTestStep{ - {op: 6, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 0 - {op: 6, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 1 - {op: 0, key: libcommon.Hex2Bytes("d51b182b95d677e5f1c82508c0228de96b73092d78ce78b2230cd948674f66fd1483bd"), value: libcommon.Hex2Bytes("0000000000000002")}, // step 2 - {op: 2, key: libcommon.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: libcommon.Hex2Bytes("")}, // step 3 - {op: 3, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 4 - {op: 3, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 5 - {op: 6, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 6 - {op: 3, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 7 - {op: 0, key: libcommon.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: libcommon.Hex2Bytes("0000000000000008")}, // step 8 - {op: 0, key: libcommon.Hex2Bytes("d51b182b95d677e5f1c82508c0228de96b73092d78ce78b2230cd948674f66fd1483bd"), value: libcommon.Hex2Bytes("0000000000000009")}, // step 9 - {op: 2, key: libcommon.Hex2Bytes("fd"), value: libcommon.Hex2Bytes("")}, // step 10 - {op: 6, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 11 - {op: 6, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 12 - {op: 0, key: libcommon.Hex2Bytes("fd"), value: libcommon.Hex2Bytes("000000000000000d")}, // step 13 - {op: 6, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 14 - {op: 1, key: libcommon.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: libcommon.Hex2Bytes("")}, // step 15 - {op: 3, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 16 - {op: 0, key: libcommon.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: libcommon.Hex2Bytes("0000000000000011")}, // step 17 - {op: 5, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 18 - {op: 3, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 19 + {op: 6, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 0 + {op: 6, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 1 + {op: 0, key: common.Hex2Bytes("d51b182b95d677e5f1c82508c0228de96b73092d78ce78b2230cd948674f66fd1483bd"), value: common.Hex2Bytes("0000000000000002")}, // step 2 + {op: 2, key: common.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: common.Hex2Bytes("")}, // step 3 + {op: 3, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 4 + {op: 3, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 5 + {op: 6, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 6 + {op: 3, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 7 + {op: 0, key: common.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: common.Hex2Bytes("0000000000000008")}, // step 8 + {op: 0, key: common.Hex2Bytes("d51b182b95d677e5f1c82508c0228de96b73092d78ce78b2230cd948674f66fd1483bd"), value: common.Hex2Bytes("0000000000000009")}, // step 9 + {op: 2, key: common.Hex2Bytes("fd"), value: common.Hex2Bytes("")}, // step 10 + {op: 6, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 11 + {op: 6, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 12 + {op: 0, key: common.Hex2Bytes("fd"), value: common.Hex2Bytes("000000000000000d")}, // step 13 + {op: 6, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 14 + {op: 1, key: common.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: common.Hex2Bytes("")}, // step 15 + {op: 3, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 16 + {op: 0, key: common.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: common.Hex2Bytes("0000000000000011")}, // step 17 + {op: 5, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 18 + {op: 3, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 19 // FIXME: fix these testcases for Erigon //{op: 0, key: common.Hex2Bytes("d51b182b95d677e5f1c82508c0228de96b73092d78ce78b2230cd948674f66fd1483bd"), value: common.Hex2Bytes("0000000000000014")}, // step 20 //{op: 0, key: common.Hex2Bytes("d51b182b95d677e5f1c82508c0228de96b73092d78ce78b2230cd948674f66fd1483bd"), value: common.Hex2Bytes("0000000000000015")}, // step 21 //{op: 0, key: common.Hex2Bytes("c2a38512b83107d665c65235b0250002882ac2022eb00711552354832c5f1d030d0e408e"), value: common.Hex2Bytes("0000000000000016")}, // step 22 - {op: 5, key: libcommon.Hex2Bytes(""), value: libcommon.Hex2Bytes("")}, // step 23 + {op: 5, key: common.Hex2Bytes(""), value: common.Hex2Bytes("")}, // step 23 //{op: 1, key: common.Hex2Bytes("980c393656413a15c8da01978ed9f89feb80b502f58f2d640e3a2f5f7a99a7018f1b573befd92053ac6f78fca4a87268"), value: common.Hex2Bytes("")}, // step 24 //{op: 1, key: common.Hex2Bytes("fd"), value: common.Hex2Bytes("")}, // step 25 } @@ -165,7 +164,7 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value { } func runRandTest(rt randTest) bool { - tr := New(libcommon.Hash{}) + tr := New(common.Hash{}) values := make(map[string]string) // tracks content of the trie for i, step := range rt { @@ -194,7 +193,7 @@ func runRandTest(rt randTest) bool { case opItercheckhash: // FIXME: restore for Erigon /* - checktr := New(libcommon.Hash{}) + checktr := New(common.Hash{}) it := NewIterator(tr.NodeIterator(nil)) for it.Next() { checktr.Update(it.Key, it.Value) @@ -232,7 +231,7 @@ func BenchmarkHash(b *testing.B) { for i := 0; i < len(accounts); i++ { var ( nonce = uint64(random.Int63()) - balance = new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance = new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) root = EmptyRoot code = crypto.Keccak256(nil) ) @@ -262,13 +261,13 @@ func TestDeepHash(t *testing.T) { } for i, keyVals := range testdata { fmt.Println("Test", i) - trie := New(libcommon.Hash{}) + trie := New(common.Hash{}) for _, keyVal := range keyVals { trie.Update([]byte(keyVal.key), []byte(keyVal.value)) } hash1 := trie.Hash() - prefixTrie := New(libcommon.Hash{}) + prefixTrie := New(common.Hash{}) prefixTrie.UpdateAccount([]byte(prefix), &acc) for _, keyVal := range keyVals { // Add a prefix to every key @@ -313,8 +312,8 @@ func TestCodeNodeValid(t *testing.T) { codeValues := make([][]byte, len(addresses)) for i := 0; i < len(addresses); i++ { codeValues[i] = genRandomByteArrayOfLen(128) - codeHash := libcommon.BytesToHash(crypto.Keccak256(codeValues[i])) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + codeHash := common.BytesToHash(crypto.Keccak256(codeValues[i])) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) acc.Balance.SetFromBig(balance) @@ -341,8 +340,8 @@ func TestCodeNodeUpdateNotExisting(t *testing.T) { address := getAddressForIndex(0) codeValue := genRandomByteArrayOfLen(128) - codeHash := libcommon.BytesToHash(crypto.Keccak256(codeValue)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + codeHash := common.BytesToHash(crypto.Keccak256(codeValue)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -369,8 +368,8 @@ func TestCodeNodeGetNotExistingAccount(t *testing.T) { address := getAddressForIndex(0) codeValue := genRandomByteArrayOfLen(128) - codeHash := libcommon.BytesToHash(crypto.Keccak256(codeValue)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + codeHash := common.BytesToHash(crypto.Keccak256(codeValue)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -395,7 +394,7 @@ func TestCodeNodeGetHashedAccount(t *testing.T) { address := getAddressForIndex(0) fakeAccount := genRandomByteArrayOfLen(50) - fakeAccountHash := libcommon.BytesToHash(crypto.Keccak256(fakeAccount)) + fakeAccountHash := common.BytesToHash(crypto.Keccak256(fakeAccount)) hex := keybytesToHex(crypto.Keccak256(address[:])) @@ -414,8 +413,8 @@ func TestCodeNodeGetExistingAccountNoCodeNotEmpty(t *testing.T) { address := getAddressForIndex(0) codeValue := genRandomByteArrayOfLen(128) - codeHash := libcommon.BytesToHash(crypto.Keccak256(codeValue)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + codeHash := common.BytesToHash(crypto.Keccak256(codeValue)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -438,7 +437,7 @@ func TestCodeNodeGetExistingAccountEmptyCode(t *testing.T) { address := getAddressForIndex(0) codeHash := EmptyCodeHash - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -461,9 +460,9 @@ func TestCodeNodeWrongHash(t *testing.T) { address := getAddressForIndex(0) codeValue1 := genRandomByteArrayOfLen(128) - codeHash1 := libcommon.BytesToHash(crypto.Keccak256(codeValue1)) + codeHash1 := common.BytesToHash(crypto.Keccak256(codeValue1)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -486,9 +485,9 @@ func TestCodeNodeUpdateAccountAndCodeValidHash(t *testing.T) { address := getAddressForIndex(0) codeValue1 := genRandomByteArrayOfLen(128) - codeHash1 := libcommon.BytesToHash(crypto.Keccak256(codeValue1)) + codeHash1 := common.BytesToHash(crypto.Keccak256(codeValue1)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -501,7 +500,7 @@ func TestCodeNodeUpdateAccountAndCodeValidHash(t *testing.T) { assert.Nil(t, err, "should successfully insert code") codeValue2 := genRandomByteArrayOfLen(128) - codeHash2 := libcommon.BytesToHash(crypto.Keccak256(codeValue2)) + codeHash2 := common.BytesToHash(crypto.Keccak256(codeValue2)) acc.CodeHash = codeHash2 @@ -518,9 +517,9 @@ func TestCodeNodeUpdateAccountAndCodeInvalidHash(t *testing.T) { address := getAddressForIndex(0) codeValue1 := genRandomByteArrayOfLen(128) - codeHash1 := libcommon.BytesToHash(crypto.Keccak256(codeValue1)) + codeHash1 := common.BytesToHash(crypto.Keccak256(codeValue1)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -533,7 +532,7 @@ func TestCodeNodeUpdateAccountAndCodeInvalidHash(t *testing.T) { assert.Nil(t, err, "should successfully insert code") codeValue2 := genRandomByteArrayOfLen(128) - codeHash2 := libcommon.BytesToHash(crypto.Keccak256(codeValue2)) + codeHash2 := common.BytesToHash(crypto.Keccak256(codeValue2)) codeValue3 := genRandomByteArrayOfLen(128) @@ -552,9 +551,9 @@ func TestCodeNodeUpdateAccountChangeCodeHash(t *testing.T) { address := getAddressForIndex(0) codeValue1 := genRandomByteArrayOfLen(128) - codeHash1 := libcommon.BytesToHash(crypto.Keccak256(codeValue1)) + codeHash1 := common.BytesToHash(crypto.Keccak256(codeValue1)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -567,7 +566,7 @@ func TestCodeNodeUpdateAccountChangeCodeHash(t *testing.T) { assert.Nil(t, err, "should successfully insert code") codeValue2 := genRandomByteArrayOfLen(128) - codeHash2 := libcommon.BytesToHash(crypto.Keccak256(codeValue2)) + codeHash2 := common.BytesToHash(crypto.Keccak256(codeValue2)) acc.CodeHash = codeHash2 @@ -585,9 +584,9 @@ func TestCodeNodeUpdateAccountNoChangeCodeHash(t *testing.T) { address := getAddressForIndex(0) codeValue1 := genRandomByteArrayOfLen(128) - codeHash1 := libcommon.BytesToHash(crypto.Keccak256(codeValue1)) + codeHash1 := common.BytesToHash(crypto.Keccak256(codeValue1)) - balance := new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance := new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc := accounts.NewAccount() acc.Nonce = uint64(random.Int63()) @@ -600,7 +599,7 @@ func TestCodeNodeUpdateAccountNoChangeCodeHash(t *testing.T) { assert.Nil(t, err, "should successfully insert code") acc.Nonce = uint64(random.Int63()) - balance = new(big.Int).Rand(random, new(big.Int).Exp(libcommon.Big2, libcommon.Big256, nil)) + balance = new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) acc.Balance.SetFromBig(balance) trie.UpdateAccount(crypto.Keccak256(address[:]), &acc)