From 8fa7895c9d81dae8264fa262fbc1fdd5f205fdc1 Mon Sep 17 00:00:00 2001 From: flywukong <2229306838@qq.com> Date: Fri, 12 Jul 2024 13:38:04 +0800 Subject: [PATCH] remove double check --- badblock/badblock.go | 19 --------------- core/blockchain.go | 2 -- core/state/state_object.go | 48 ++++--------------------------------- core/state/statedb.go | 49 +++++++------------------------------- 4 files changed, 13 insertions(+), 105 deletions(-) delete mode 100644 badblock/badblock.go diff --git a/badblock/badblock.go b/badblock/badblock.go deleted file mode 100644 index 4dbe72f5d6..0000000000 --- a/badblock/badblock.go +++ /dev/null @@ -1,19 +0,0 @@ -package badblock - -var BadBlock = 0 - -func InitBadBlock() { - BadBlock = 0 -} - -func SetBadBlock() { - BadBlock = 1 -} - -func HasBadBlock() bool { - if BadBlock == 1 { - return true - } - - return false -} diff --git a/core/blockchain.go b/core/blockchain.go index b73519a318..90e290f2d1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -32,7 +32,6 @@ import ( exlru "github.com/hashicorp/golang-lru" "golang.org/x/crypto/sha3" - "github.com/ethereum/go-ethereum/badblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/lru" "github.com/ethereum/go-ethereum/common/mclock" @@ -3084,7 +3083,6 @@ func (bc *BlockChain) isCachedBadBlock(block *types.Block) bool { // bad block need not save receipts & sidecars. func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, err error) { rawdb.WriteBadBlock(bc.db, block) - badblock.SetBadBlock() log.Error(summarizeBadBlock(block, receipts, bc.Config(), err)) } diff --git a/core/state/state_object.go b/core/state/state_object.go index 06c85852f1..959a6c2d50 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -23,11 +23,9 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/badblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie/trienode" @@ -229,59 +227,23 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash { enc []byte err error value common.Hash + exist bool ) if s.db.snap != nil { start := time.Now() - existInCache := false storageKey := crypto.Keccak256Hash(key.Bytes()) - - // Try to get from cache among blocks if root is not nil + // Try to get from cache among blocks if the cache root is the pre-state root if s.db.cacheAmongBlocks != nil && s.db.cacheAmongBlocks.GetRoot() == s.db.originalRoot { - start1 := time.Now() - enc, existInCache = s.db.cacheAmongBlocks.GetStorage(s.addrHash, storageKey) - if existInCache { + enc, exist = s.db.cacheAmongBlocks.GetStorage(s.addrHash, storageKey) + if exist { SnapshotBlockCacheStorageHitMeter.Mark(1) - BlockCacheStorageTimer.Update(time.Since(start1)) - if badblock.HasBadBlock() { - acc, exist := s.db.cacheAmongBlocks.GetAccount(s.addrHash) - if exist == true { - if acc == nil { - log.Info("account is nil when storage hit", "account", s.addrHash, "enc", common.Bytes2Hex(enc)) - } - } - if exist == false { - log.Info("check bad block info", "account not exist in cache", 1) - } else if exist == true && acc != nil { - log.Info("check bad block info", "account is not nil", "nil") - } - enc2, err2 := s.db.snap.Storage(s.addrHash, storageKey) - if !existInCache { - log.Error("no cache in cache among blocks") - } - if err2 != nil { - log.Error("compare read err", "err", err2, "account", s.addrHash, - "key", storageKey, "enc1", common.Bytes2Hex(enc)) - } - if len(enc) == 0 && len(enc2) != 0 { - log.Error("compare cache and difflayer not same", "account", s.addrHash, - "key", storageKey, "enc1", "nil", "enc2", common.Bytes2Hex(enc2)) - } else if len(enc) != 0 && len(enc2) == 0 { - log.Error("compare cache and difflayer not same", "account", s.addrHash, - "key", storageKey, "enc1", common.Bytes2Hex(enc), "enc2", "nil") - } else if bytes.Compare(enc, enc2) != 0 { - log.Error("compare cache and difflayer not same", "account", s.addrHash, - "key", storageKey, "enc1", common.Bytes2Hex(enc), - "enc2", common.Bytes2Hex(enc2), "enc1 str", string(enc), "enc2 str", string(enc2)) - } - } } else { SnapshotBlockCacheStorageMissMeter.Mark(1) } } - - if !existInCache { + if !exist { enc, err = s.db.snap.Storage(s.addrHash, storageKey) if metrics.EnabledExpensive { s.db.SnapshotStorageReads += time.Since(start) diff --git a/core/state/statedb.go b/core/state/statedb.go index 16dd2424c9..741d6307fb 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -25,7 +25,6 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/badblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/gopool" "github.com/ethereum/go-ethereum/core/rawdb" @@ -735,56 +734,24 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { // If no live objects are available, attempt to use snapshots var data *types.StateAccount var err error + var exist bool if s.snap != nil { start := time.Now() - - existInCache := false var acc *types.SlimAccount - accounthash := crypto.HashData(s.hasher, addr.Bytes()) - // Try to get from cache among blocks if root is not nil + // Try to get from cache among blocks if the cache root is the pre-state root if s.cacheAmongBlocks != nil && s.cacheAmongBlocks.GetRoot() == s.originalRoot { - start1 := time.Now() - acc, existInCache = s.cacheAmongBlocks.GetAccount(accounthash) - if existInCache { - BlockCacheAccountTimer.Update(time.Since(start1)) + acc, exist = s.cacheAmongBlocks.GetAccount(accounthash) + if exist { SnapshotBlockCacheAccountHitMeter.Mark(1) - if badblock.HasBadBlock() { - log.Info("check bad block info") - acc2, err2 := s.snap.Account(accounthash) - if err2 == nil { - if acc == nil && acc2 != nil { - log.Info("compare cache and difflayer not same", "account", acc, - "acc", "nil", "acc2 info", acc2.Balance, "code", common.Bytes2Hex(acc2.CodeHash), "root", acc2.Root, - "Nonce", acc2.Nonce) - } else if acc2 == nil && acc != nil { - log.Info("compare cache and difflayer not same", "account", acc, - "acc1 info", acc.Balance, "code", common.Bytes2Hex(acc.CodeHash), "root", acc.Root, - "Nonce", acc.Nonce, "acc2", "nil") - } else if acc2 != nil && acc != nil { - if *acc.Balance != *acc2.Balance || string(acc.CodeHash) != string(acc2.CodeHash) || - acc.Nonce != acc2.Nonce || string(acc.Root) != string(acc2.Root) { - log.Info("compare cache and difflayer not same", "account", acc, - "acc1 info", acc.Balance, "code", common.Bytes2Hex(acc.CodeHash), "root", acc.Root, - "Nonce", acc.Nonce, "acc2 info", acc2.Balance, "code", common.Bytes2Hex(acc2.CodeHash), "root", acc2.Root, - "Nonce", acc2.Nonce) - } - } - } else { - log.Error("read compare err", "err", err2, "account", acc, - "acc1 info", acc.Balance, "code", acc.CodeHash, "root", acc.Root, - "Nonce", acc.Nonce) - } + if acc == nil { + return nil } } else { SnapshotBlockCacheAccountMissMeter.Mark(1) } - if existInCache && acc == nil { - return nil - } } - - if existInCache == false { + if exist == false { acc, err = s.snap.Account(accounthash) if metrics.EnabledExpensive { s.SnapshotAccountReads += time.Since(start) @@ -796,7 +763,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { } } - if err == nil || existInCache { + if err == nil || exist { data = &types.StateAccount{ Nonce: acc.Nonce, Balance: acc.Balance,