Skip to content

Commit

Permalink
Remove duplicate import (#12974)
Browse files Browse the repository at this point in the history
Co-authored-by: antonis19 <[email protected]>
  • Loading branch information
antonis19 and antonis19 authored Dec 3, 2024
1 parent 4e40c9f commit ba13e5d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 99 deletions.
11 changes: 5 additions & 6 deletions erigon-lib/trie/flatdb_sub_trie_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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))
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 3 additions & 5 deletions erigon-lib/trie/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand All @@ -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[:]}
}
Expand Down Expand Up @@ -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")
Expand Down
31 changes: 15 additions & 16 deletions erigon-lib/trie/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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)),
Expand Down
9 changes: 4 additions & 5 deletions erigon-lib/trie/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import (
"sort"
"testing"

libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/crypto"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/types/accounts"
)

func TestHashWithModificationsEmpty(t *testing.T) {
tr := New(libcommon.Hash{})
tr := New(common.Hash{})
// Populate the trie
// Build the root
var stream Stream
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 14 additions & 15 deletions erigon-lib/trie/structural_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
}
Loading

0 comments on commit ba13e5d

Please sign in to comment.