Skip to content

Commit

Permalink
remove double check
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Jul 12, 2024
1 parent 74a7719 commit 8fa7895
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 105 deletions.
19 changes: 0 additions & 19 deletions badblock/badblock.go

This file was deleted.

2 changes: 0 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}

Expand Down
48 changes: 5 additions & 43 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Check failure on line 244 in core/state/state_object.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.21.x, ubuntu-latest)

unnecessary trailing newline (whitespace)
}

if !existInCache {
if !exist {
enc, err = s.db.snap.Storage(s.addrHash, storageKey)
if metrics.EnabledExpensive {
s.db.SnapshotStorageReads += time.Since(start)
Expand Down
49 changes: 8 additions & 41 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {

Check failure on line 754 in core/state/statedb.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.21.x, ubuntu-latest)

S1002: should omit comparison to bool constant, can be simplified to `!exist` (gosimple)
acc, err = s.snap.Account(accounthash)
if metrics.EnabledExpensive {
s.SnapshotAccountReads += time.Since(start)
Expand All @@ -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,
Expand Down

0 comments on commit 8fa7895

Please sign in to comment.