diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index 2f176d14fd..cb54c7694d 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -429,6 +429,9 @@ func inspectTrie(ctx *cli.Context) error { return err } theInspect, err := trie.NewInspector(trieDB, theTrie, blockNumber, jobnum) + if err != nil { + return err + } theInspect.Run() theInspect.DisplayResult() } diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index 40866d2d95..65310f6e69 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -21,12 +21,13 @@ import ( "encoding/json" "errors" "fmt" - "github.com/ethereum/go-ethereum/core" "os" "path/filepath" "strings" "time" + "github.com/ethereum/go-ethereum/core" + "github.com/prometheus/tsdb/fileutil" "github.com/ethereum/go-ethereum/cmd/utils" diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c147f4de4d..65ec1aeb5e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -23,8 +23,6 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" "math" "math/big" "net" @@ -37,6 +35,9 @@ import ( "strings" "time" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/fatih/structs" pcsclite "github.com/gballet/go-libpcsclite" gopsutil "github.com/shirou/gopsutil/mem" diff --git a/core/rawdb/accessors_trie.go b/core/rawdb/accessors_trie.go index d179185b8d..bab4ca7e11 100644 --- a/core/rawdb/accessors_trie.go +++ b/core/rawdb/accessors_trie.go @@ -18,9 +18,10 @@ package rawdb import ( "fmt" - "github.com/ethereum/go-ethereum/core/types" "sync" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index bf91553c3a..7550e4743b 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -22,8 +22,6 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/ethereum/go-ethereum/params" - bloomfilter "github.com/holiman/bloomfilter/v2" "math" "math/big" "os" @@ -32,6 +30,9 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum/params" + bloomfilter "github.com/holiman/bloomfilter/v2" + "github.com/prometheus/tsdb/fileutil" "github.com/ethereum/go-ethereum/common" @@ -683,7 +684,7 @@ func (p *Pruner) Prune(root common.Hash) error { // find target header header := p.chainHeader - for header != nil && header.Number.Uint64() >= 0 && header.Root != root { + for header != nil && header.Root != root { header = rawdb.ReadHeader(p.db, header.ParentHash, header.Number.Uint64()-1) } if header == nil || header.Root != root { diff --git a/core/state/snapshot/conversion.go b/core/state/snapshot/conversion.go index 9e272a4d98..0c61e168d6 100644 --- a/core/state/snapshot/conversion.go +++ b/core/state/snapshot/conversion.go @@ -142,7 +142,7 @@ func TraverseContractTrie(snaptree *Tree, root common.Hash, pruneExpiredTrieCh c // Start to feed leaves for acctIt.Next() { // Fetch the next account and process it concurrently - account, err = types.FullAccount(acctIt.(AccountIterator).Account()) + account, err = types.FullAccount(acctIt.Account()) if err != nil { break } diff --git a/core/state/snapshot/generate_test.go b/core/state/snapshot/generate_test.go index dc86636488..40a73f5bd8 100644 --- a/core/state/snapshot/generate_test.go +++ b/core/state/snapshot/generate_test.go @@ -582,7 +582,6 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) { rawdb.WriteStorageSnapshot(helper.diskdb, key, hashData([]byte("b-key-2")), val) val, _ = rlp.EncodeToBytes([]byte("b-val-3")) rawdb.WriteStorageSnapshot(helper.diskdb, key, hashData([]byte("b-key-3")), val) - } root := helper.Commit() diff --git a/core/state/snapshot/snapshot_expire_test.go b/core/state/snapshot/snapshot_expire_test.go index ac20e9c90f..0bb2dd762c 100644 --- a/core/state/snapshot/snapshot_expire_test.go +++ b/core/state/snapshot/snapshot_expire_test.go @@ -1,20 +1,18 @@ package snapshot import ( + "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb/memorydb" "github.com/stretchr/testify/assert" - "testing" ) var ( - accountHash = common.HexToHash("0x31b67165f56d0ac50814cafa06748fb3b8fccd3c611a8117350e7a49b44ce130") - storageHash1 = common.HexToHash("0x0bb2f3e66816c6fd12513f053d5ee034b1fa2d448a1dc8ee7f56e4c87d6c53fe") - storageHash2 = common.HexToHash("0x0bb2f3e66816c93e142cd336c411ebd5576a90739bad7ec1ec0d4a63ea0ec1dc") - storageShrink1 = common.FromHex("0x0bb2f3e66816c") - storageNodeHash1 = common.HexToHash("0xcf0e24cb9417a38ff61d11def23fb0ec041257c81c04dec6156d5e6b30f4ec28") + accountHash = common.HexToHash("0x31b67165f56d0ac50814cafa06748fb3b8fccd3c611a8117350e7a49b44ce130") + storageHash1 = common.HexToHash("0x0bb2f3e66816c6fd12513f053d5ee034b1fa2d448a1dc8ee7f56e4c87d6c53fe") ) func TestShrinkExpiredLeaf(t *testing.T) { diff --git a/core/state/snapshot/snapshot_value.go b/core/state/snapshot/snapshot_value.go index e487889b70..b9086476d2 100644 --- a/core/state/snapshot/snapshot_value.go +++ b/core/state/snapshot/snapshot_value.go @@ -3,6 +3,7 @@ package snapshot import ( "bytes" "errors" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" ) diff --git a/core/state/snapshot/snapshot_value_test.go b/core/state/snapshot/snapshot_value_test.go index d316c95fbb..cb5088b20b 100644 --- a/core/state/snapshot/snapshot_value_test.go +++ b/core/state/snapshot/snapshot_value_test.go @@ -2,16 +2,16 @@ package snapshot import ( "encoding/hex" + "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/assert" - "testing" ) var ( - val, _ = hex.DecodeString("0000f9eef0150e074b32e3b3b6d34d2534222292e3953019a41d714d135763a6") - hash, _ = hex.DecodeString("2b6fad2e1335b0b4debd3de01c91f3f45d2b88465ff42ae2c53900f2f702101d") + val, _ = hex.DecodeString("0000f9eef0150e074b32e3b3b6d34d2534222292e3953019a41d714d135763a6") ) func TestRawValueEncode(t *testing.T) { diff --git a/core/state/state_expiry.go b/core/state/state_expiry.go index 2779e13e41..203ed2fa2e 100644 --- a/core/state/state_expiry.go +++ b/core/state/state_expiry.go @@ -3,13 +3,14 @@ package state import ( "bytes" "fmt" + "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/trie" - "time" ) var ( @@ -103,7 +104,6 @@ func batchFetchExpiredFromRemote(expiryMeta *stateExpiryMeta, addr common.Addres for i, key := range expiredKeys { keysStr[i] = common.Bytes2Hex(key[:]) } - } else { for i, prefix := range prefixKeys { prefixKeysStr[i] = common.Bytes2Hex(prefix) diff --git a/core/state/state_object.go b/core/state/state_object.go index 80f8432d80..565d3aa785 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -337,22 +337,6 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash { return value } -// needLoadFromTrie If not found in snap when EnableExpire(), need check insert duplication from trie. -func (s *stateObject) needLoadFromTrie(err error, sv snapshot.SnapValue) bool { - if s.db.snap == nil { - return true - } - if !s.db.EnableExpire() { - return err != nil - } - - if err != nil || sv == nil { - return true - } - - return false -} - // SetState updates a value in account storage. func (s *stateObject) SetState(key, value common.Hash) { // If the new value is the same as old, don't set diff --git a/core/state/statedb.go b/core/state/statedb.go index eb027cd61d..e4f9b568be 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -18,16 +18,16 @@ package state import ( - "bytes" "errors" "fmt" - "github.com/ethereum/go-ethereum/ethdb" "math/big" "runtime" "sort" "sync" "time" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/gopool" "github.com/ethereum/go-ethereum/core/rawdb" @@ -1899,16 +1899,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc return root, diffLayer, nil } -func stringfyEpochMeta(meta map[common.Hash]map[string][]byte) string { - buf := bytes.NewBuffer(nil) - for hash, m := range meta { - for k, v := range m { - buf.WriteString(fmt.Sprintf("%v: %v|%v, ", hash, []byte(k), common.Bytes2Hex(v))) - } - } - return buf.String() -} - func (s *StateDB) SnapToDiffLayer() ([]common.Address, []types.DiffAccount, []types.DiffStorage) { destructs := make([]common.Address, 0, len(s.stateObjectsDestruct)) for account := range s.stateObjectsDestruct { diff --git a/core/txpool/blobpool/interface.go b/core/txpool/blobpool/interface.go index f3c0658fc2..a1852a5bd8 100644 --- a/core/txpool/blobpool/interface.go +++ b/core/txpool/blobpool/interface.go @@ -17,11 +17,12 @@ package blobpool import ( + "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" - "math/big" ) // BlockChain defines the minimal set of methods needed to back a blob pool with diff --git a/core/types/gen_account_rlp.go b/core/types/gen_account_rlp.go index 5181d88411..9d07200e33 100644 --- a/core/types/gen_account_rlp.go +++ b/core/types/gen_account_rlp.go @@ -5,8 +5,11 @@ package types -import "github.com/ethereum/go-ethereum/rlp" -import "io" +import ( + "io" + + "github.com/ethereum/go-ethereum/rlp" +) func (obj *StateAccount) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index a5ed5cd150..e05bde09f6 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -5,8 +5,11 @@ package types -import "github.com/ethereum/go-ethereum/rlp" -import "io" +import ( + "io" + + "github.com/ethereum/go-ethereum/rlp" +) func (obj *Header) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/gen_log_rlp.go b/core/types/gen_log_rlp.go index 4a6c6b0094..78fa783cee 100644 --- a/core/types/gen_log_rlp.go +++ b/core/types/gen_log_rlp.go @@ -5,8 +5,11 @@ package types -import "github.com/ethereum/go-ethereum/rlp" -import "io" +import ( + "io" + + "github.com/ethereum/go-ethereum/rlp" +) func (obj *rlpLog) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/gen_withdrawal_rlp.go b/core/types/gen_withdrawal_rlp.go index d0b4e0147a..e3fa001eb6 100644 --- a/core/types/gen_withdrawal_rlp.go +++ b/core/types/gen_withdrawal_rlp.go @@ -5,8 +5,11 @@ package types -import "github.com/ethereum/go-ethereum/rlp" -import "io" +import ( + "io" + + "github.com/ethereum/go-ethereum/rlp" +) func (obj *Withdrawal) EncodeRLP(_w io.Writer) error { w := rlp.NewEncoderBuffer(_w) diff --git a/core/types/meta_test.go b/core/types/meta_test.go index e03a5b5097..ac03a5595f 100644 --- a/core/types/meta_test.go +++ b/core/types/meta_test.go @@ -2,8 +2,9 @@ package types import ( "encoding/hex" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestMetaEncodeDecode(t *testing.T) { diff --git a/core/types/state_expiry.go b/core/types/state_expiry.go index ed2bb18e43..bb83a31f2c 100644 --- a/core/types/state_expiry.go +++ b/core/types/state_expiry.go @@ -3,8 +3,9 @@ package types import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/log" "strings" + + "github.com/ethereum/go-ethereum/log" ) const ( diff --git a/core/types/typed_trie_node.go b/core/types/typed_trie_node.go index 01eb120edf..dedb94eddd 100644 --- a/core/types/typed_trie_node.go +++ b/core/types/typed_trie_node.go @@ -3,8 +3,9 @@ package types import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/rlp" "io" + + "github.com/ethereum/go-ethereum/rlp" ) const ( diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 9d44ff25b8..704fa82a86 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -19,9 +19,10 @@ package ethconfig import ( "errors" - "github.com/ethereum/go-ethereum/core/types" "time" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/beacon" diff --git a/ethclient/gethclient/gethclient.go b/ethclient/gethclient/gethclient.go index 87f93d1625..b219d0a9bc 100644 --- a/ethclient/gethclient/gethclient.go +++ b/ethclient/gethclient/gethclient.go @@ -130,7 +130,7 @@ func (ec *Client) GetProof(ctx context.Context, account common.Address, keys []s func (ec *Client) GetStorageReviveProof(ctx context.Context, stateRoot common.Hash, account common.Address, root common.Hash, keys []string, prefixKeys []string) (*types.ReviveResult, error) { type reviveResult struct { StorageProof []types.ReviveStorageProof `json:"storageProof"` - BlockNum hexutil.Uint64 `json:"blockNum"` + BlockNum uint64 `json:"blockNum"` } var err error @@ -140,7 +140,7 @@ func (ec *Client) GetStorageReviveProof(ctx context.Context, stateRoot common.Ha return &types.ReviveResult{ StorageProof: res.StorageProof, - BlockNum: uint64(res.BlockNum), + BlockNum: res.BlockNum, }, err } diff --git a/ethdb/fullstatedb.go b/ethdb/fullstatedb.go index 500beac1fb..367351f5e4 100644 --- a/ethdb/fullstatedb.go +++ b/ethdb/fullstatedb.go @@ -5,14 +5,15 @@ import ( "context" "errors" "fmt" + "strings" + "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/rpc" lru "github.com/hashicorp/golang-lru" - "strings" - "time" ) var ( diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index d5ec11b59e..5d12798f69 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -21,11 +21,12 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/ethereum/go-ethereum/metrics" "math/big" "strings" "time" + "github.com/ethereum/go-ethereum/metrics" + "github.com/davecgh/go-spew/spew" "github.com/ethereum/go-ethereum/accounts" diff --git a/miner/worker.go b/miner/worker.go index d641eb899a..6892da7d35 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -19,12 +19,13 @@ package miner import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/metrics" "math/big" "sync" "sync/atomic" "time" + "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" diff --git a/trie/committer.go b/trie/committer.go index 2ad8d9f4f5..f43f58419b 100644 --- a/trie/committer.go +++ b/trie/committer.go @@ -18,6 +18,7 @@ package trie import ( "fmt" + "github.com/ethereum/go-ethereum/trie/epochmeta" "github.com/ethereum/go-ethereum/common" diff --git a/trie/database.go b/trie/database.go index e8084300a8..ae7d919646 100644 --- a/trie/database.go +++ b/trie/database.go @@ -18,6 +18,7 @@ package trie import ( "errors" + "fmt" "math/big" "strings" diff --git a/trie/epochmeta/database.go b/trie/epochmeta/database.go index 8feb858991..566c33915c 100644 --- a/trie/epochmeta/database.go +++ b/trie/epochmeta/database.go @@ -3,9 +3,10 @@ package epochmeta import ( "bytes" "fmt" + "math/big" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" - "math/big" "github.com/ethereum/go-ethereum/rlp" @@ -91,9 +92,5 @@ func AccountMeta2Bytes(meta types.StateMeta) ([]byte, error) { // IsEpochMetaPath add some skip hash check rule func IsEpochMetaPath(path []byte) bool { - if bytes.Equal(AccountMetadataPath, path) { - return true - } - - return false + return bytes.Equal(AccountMetadataPath, path) } diff --git a/trie/epochmeta/difflayer.go b/trie/epochmeta/difflayer.go index 2838e8a9d0..2e2f73050a 100644 --- a/trie/epochmeta/difflayer.go +++ b/trie/epochmeta/difflayer.go @@ -4,13 +4,14 @@ import ( "bytes" "encoding/binary" "errors" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/rlp" - bloomfilter "github.com/holiman/bloomfilter/v2" "math" "math/big" "math/rand" "sync" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/rlp" + bloomfilter "github.com/holiman/bloomfilter/v2" ) const ( diff --git a/trie/epochmeta/difflayer_test.go b/trie/epochmeta/difflayer_test.go index 54cea5f3c3..ebe1c99818 100644 --- a/trie/epochmeta/difflayer_test.go +++ b/trie/epochmeta/difflayer_test.go @@ -1,9 +1,10 @@ package epochmeta import ( - "github.com/ethereum/go-ethereum/core/types" "testing" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb/memorydb" "github.com/stretchr/testify/assert" @@ -12,17 +13,12 @@ import ( const hashLen = len(common.Hash{}) var ( - blockRoot0 = makeHash("b0") - blockRoot1 = makeHash("b1") - blockRoot2 = makeHash("b2") - blockRoot3 = makeHash("b3") - storageRoot0 = makeHash("s0") - storageRoot1 = makeHash("s1") - storageRoot2 = makeHash("s2") - storageRoot3 = makeHash("s3") - contract1 = makeHash("c1") - contract2 = makeHash("c2") - contract3 = makeHash("c3") + blockRoot0 = makeHash("b0") + blockRoot1 = makeHash("b1") + blockRoot2 = makeHash("b2") + contract1 = makeHash("c1") + contract2 = makeHash("c2") + contract3 = makeHash("c3") ) func TestEpochMetaDiffLayer_whenGenesis(t *testing.T) { diff --git a/trie/epochmeta/disklayer.go b/trie/epochmeta/disklayer.go index cc7894736c..4d71de4c3b 100644 --- a/trie/epochmeta/disklayer.go +++ b/trie/epochmeta/disklayer.go @@ -3,14 +3,15 @@ package epochmeta import ( "bytes" "errors" + "math/big" + "sync" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" lru "github.com/hashicorp/golang-lru" - "math/big" - "sync" ) const ( diff --git a/trie/epochmeta/snapshot.go b/trie/epochmeta/snapshot.go index 71201f961d..decbdaaf87 100644 --- a/trie/epochmeta/snapshot.go +++ b/trie/epochmeta/snapshot.go @@ -4,15 +4,16 @@ import ( "bytes" "errors" "fmt" + "io" + "math/big" + "sync" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" - "io" - "math/big" - "sync" ) // snapshot record diff layer and disk layer of shadow nodes, support mini reorg diff --git a/trie/epochmeta/snapshot_test.go b/trie/epochmeta/snapshot_test.go index 35099d5ba2..0cc4145eee 100644 --- a/trie/epochmeta/snapshot_test.go +++ b/trie/epochmeta/snapshot_test.go @@ -1,11 +1,12 @@ package epochmeta import ( - "github.com/ethereum/go-ethereum/ethdb/memorydb" - "github.com/stretchr/testify/assert" "math/big" "strconv" "testing" + + "github.com/ethereum/go-ethereum/ethdb/memorydb" + "github.com/stretchr/testify/assert" ) func TestEpochMetaDiffLayer_capDiffLayers(t *testing.T) { diff --git a/trie/inspect_trie.go b/trie/inspect_trie.go index a6a9df7b7d..5d4cc00d04 100644 --- a/trie/inspect_trie.go +++ b/trie/inspect_trie.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "github.com/ethereum/go-ethereum/core/types" "math/big" "os" "runtime" @@ -14,6 +13,8 @@ import ( "sync/atomic" "time" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -32,7 +33,6 @@ type Inspector struct { trie *Trie // traverse trie blocknum uint64 root node // root of triedb - num uint64 // block number result *TotalTrieTreeStat // inspector result totalNum uint64 concurrentQueue chan struct{} @@ -206,7 +206,6 @@ func (inspect *Inspector) SubConcurrentTraversal(theTrie *Trie, theTrieTreeStat inspect.ConcurrentTraversal(theTrie, theTrieTreeStat, theNode, height, path) <-inspect.concurrentQueue inspect.wg.Done() - return } func (inspect *Inspector) ConcurrentTraversal(theTrie *Trie, theTrieTreeStat *TrieTreeStat, theNode node, height uint32, path []byte) { @@ -274,7 +273,6 @@ func (inspect *Inspector) ConcurrentTraversal(theTrie *Trie, theTrieTreeStat *Tr panic(errors.New("Invalid node type to traverse.")) } theTrieTreeStat.AtomicAdd(theNode, height) - return } func (inspect *Inspector) DisplayResult() { @@ -312,6 +310,5 @@ func (inspect *Inspector) DisplayResult() { } stat, _ := inspect.result.theTrieTreeStats.Get(cntHash[1]) stat.Display(cntHash[1], "ContractTrie") - i++ } } diff --git a/trie/node.go b/trie/node.go index 235344bcca..1ec7f00855 100644 --- a/trie/node.go +++ b/trie/node.go @@ -89,14 +89,6 @@ func (n *shortNode) setEpoch(epoch types.StateEpoch) { n.epoch = epoch } -func (n *fullNode) getEpoch() types.StateEpoch { - return n.epoch -} - -func (n *shortNode) getEpoch() types.StateEpoch { - return n.epoch -} - func (n *fullNode) GetChildEpoch(index int) types.StateEpoch { if index < 16 { return n.EpochMap[index] diff --git a/trie/proof.go b/trie/proof.go index cc19b84e37..5abee92cf9 100644 --- a/trie/proof.go +++ b/trie/proof.go @@ -21,6 +21,7 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/common" @@ -37,7 +38,6 @@ import ( // nodes of the longest existing prefix of the key (at least the root node), ending // with the node that proves the absence of the key. func (t *Trie) Prove(key []byte, proofDb ethdb.KeyValueWriter) error { - var nodeEpoch types.StateEpoch // Short circuit if the trie is already committed and not usable. @@ -201,7 +201,6 @@ func (t *Trie) traverseNodes(tn node, prefixKey, suffixKey []byte, nodes *[]node } func (t *Trie) ProveByPath(key []byte, prefixKeyHex []byte, proofDb ethdb.KeyValueWriter) error { - if t.committed { return ErrCommitted } diff --git a/trie/tracer.go b/trie/tracer.go index fc37f70698..a4321e5345 100644 --- a/trie/tracer.go +++ b/trie/tracer.go @@ -18,6 +18,7 @@ package trie import ( "bytes" + "github.com/ethereum/go-ethereum/common" ) @@ -95,9 +96,7 @@ func (t *tracer) onExpandToBranchNode(path []byte) { if !t.tagEpochMeta { return } - if _, present := t.deleteEpochMetas[string(path)]; present { - delete(t.deleteEpochMetas, string(path)) - } + delete(t.deleteEpochMetas, string(path)) } // onDelete tracks the newly deleted trie node. If it's already diff --git a/trie/trie.go b/trie/trie.go index e555fdffb6..063dd3edc3 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -21,16 +21,17 @@ import ( "bytes" "errors" "fmt" + "runtime" + "sync" + "sync/atomic" + "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/trie/epochmeta" "github.com/ethereum/go-ethereum/trie/trienode" - "runtime" - "sync" - "sync/atomic" - "time" ) var ( @@ -997,7 +998,6 @@ func (t *Trie) deleteWithEpoch(n node, prefix, key []byte, epoch types.StateEpoc default: panic(fmt.Sprintf("%T: invalid node: %v (%v)", n, n, key)) } - } func concat(s1 []byte, s2 ...byte) []byte { @@ -1292,7 +1292,6 @@ func (t *Trie) TryRevive(key []byte, proof []*MPTProofNub) ([]*MPTProofNub, erro // tryRevive it just revive from targetPrefixKey func (t *Trie) tryRevive(n node, key []byte, targetPrefixKey []byte, nub MPTProofNub, pos int, epoch types.StateEpoch, isExpired bool) (node, bool, error) { - if pos > len(targetPrefixKey) { return nil, false, fmt.Errorf("target revive node not found") } @@ -1578,7 +1577,6 @@ func (st *ScanTask) MoreThread() bool { // ScanForPrune traverses the storage trie and prunes all expired or unexpired nodes. func (t *Trie) ScanForPrune(st *ScanTask) error { - if !t.enableExpiry { return nil } diff --git a/trie/trie_expiry.go b/trie/trie_expiry.go index 4a31086574..8c7c8e32f4 100644 --- a/trie/trie_expiry.go +++ b/trie/trie_expiry.go @@ -3,6 +3,7 @@ package trie import ( "bytes" "fmt" + "github.com/ethereum/go-ethereum/core/types" ) diff --git a/trie/trie_reader.go b/trie/trie_reader.go index 4ec9ca27d0..3cad34c8de 100644 --- a/trie/trie_reader.go +++ b/trie/trie_reader.go @@ -19,14 +19,15 @@ package trie import ( "errors" "fmt" + "math/big" + "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/trie/epochmeta" "github.com/ethereum/go-ethereum/trie/triestate" - "math/big" - "time" ) var ( diff --git a/trie/trie_test.go b/trie/trie_test.go index aa704f8166..cb80fa8af2 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -1038,7 +1038,6 @@ func TestRevive(t *testing.T) { } func TestReviveCustom(t *testing.T) { - data := map[string]string{ "abcd": "A", "abce": "B", "abde": "C", "abdf": "D", "defg": "E", "defh": "F", "degh": "G", "degi": "H", @@ -1083,7 +1082,6 @@ func TestReviveCustom(t *testing.T) { // TestReviveBadProof tests that a trie cannot be revived from a bad proof func TestReviveBadProof(t *testing.T) { - dataA := map[string]string{ "abcd": "A", "abce": "B", "abde": "C", "abdf": "D", "defg": "E", "defh": "F", "degh": "G", "degi": "H", diff --git a/trie/triedb/pathdb/difflayer.go b/trie/triedb/pathdb/difflayer.go index c597cf1d55..a58d2d7c3f 100644 --- a/trie/triedb/pathdb/difflayer.go +++ b/trie/triedb/pathdb/difflayer.go @@ -18,9 +18,10 @@ package pathdb import ( "fmt" - "github.com/ethereum/go-ethereum/trie/epochmeta" "sync" + "github.com/ethereum/go-ethereum/trie/epochmeta" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/trie/trienode" diff --git a/trie/triedb/pathdb/disklayer.go b/trie/triedb/pathdb/disklayer.go index aa8dfd2d81..2f14f6823f 100644 --- a/trie/triedb/pathdb/disklayer.go +++ b/trie/triedb/pathdb/disklayer.go @@ -19,9 +19,10 @@ package pathdb import ( "errors" "fmt" + "sync" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/trie/epochmeta" - "sync" "github.com/VictoriaMetrics/fastcache" "github.com/ethereum/go-ethereum/common" diff --git a/trie/triedb/pathdb/layertree.go b/trie/triedb/pathdb/layertree.go index ad19ef5e7c..934ece2758 100644 --- a/trie/triedb/pathdb/layertree.go +++ b/trie/triedb/pathdb/layertree.go @@ -19,12 +19,12 @@ package pathdb import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/log" "sync" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/trie/trienode" "github.com/ethereum/go-ethereum/trie/triestate" ) diff --git a/trie/triedb/pathdb/nodebuffer.go b/trie/triedb/pathdb/nodebuffer.go index 8f6ed59345..cc908c9676 100644 --- a/trie/triedb/pathdb/nodebuffer.go +++ b/trie/triedb/pathdb/nodebuffer.go @@ -18,9 +18,10 @@ package pathdb import ( "fmt" - "github.com/ethereum/go-ethereum/trie/epochmeta" "time" + "github.com/ethereum/go-ethereum/trie/epochmeta" + "github.com/VictoriaMetrics/fastcache" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" diff --git a/trie/triedb/pathdb/testutils.go b/trie/triedb/pathdb/testutils.go index d6fdacb421..070e13dea3 100644 --- a/trie/triedb/pathdb/testutils.go +++ b/trie/triedb/pathdb/testutils.go @@ -20,6 +20,8 @@ import ( "bytes" "fmt" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" @@ -130,6 +132,7 @@ func hash(states map[common.Hash][]byte) (common.Hash, []byte) { if len(input) == 0 { return types.EmptyRootHash, nil } + input, _ = rlp.EncodeToBytes(input) return crypto.Keccak256Hash(input), input } diff --git a/trie/trienode/node.go b/trie/trienode/node.go index 6c1660ff79..38bd67cfe5 100644 --- a/trie/trienode/node.go +++ b/trie/trienode/node.go @@ -18,10 +18,11 @@ package trienode import ( "fmt" - "github.com/ethereum/go-ethereum/trie/epochmeta" "sort" "strings" + "github.com/ethereum/go-ethereum/trie/epochmeta" + "github.com/ethereum/go-ethereum/common" ) diff --git a/trie/typed_trie_node_test.go b/trie/typed_trie_node_test.go index dc88be1958..490b101c4d 100644 --- a/trie/typed_trie_node_test.go +++ b/trie/typed_trie_node_test.go @@ -1,11 +1,12 @@ package trie import ( + "math/rand" + "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/assert" - "math/rand" - "testing" ) var (