Skip to content

Commit

Permalink
chore: add debug print statedb
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Aug 13, 2024
1 parent 83a9b13 commit 5153e69
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}
ptime := time.Since(pstart)

statedb.DebugPrint(block.NumberU64(), true)

// Validate the state using the default validator
vstart := time.Now()
if err := bc.validator.ValidateState(block, statedb, receipts, usedGas); err != nil {
Expand Down
43 changes: 43 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,49 @@ func (s *StateDB) handleDestruction(nodes *trienode.MergedNodeSet) (map[common.A
return incomplete, nil
}

func (s *StateDB) DebugPrint(block uint64, deleteEmptyObjects bool) {
log.Info("================== block start ===============", "number", block)
hash := s.IntermediateRoot(deleteEmptyObjects)
log.Info("mpt root", "hash", hash)

addrs := make([]common.Address, 0)
for addr := range s.stateObjectsDirty {
if obj := s.stateObjects[addr]; !obj.deleted {
addrs = append(addrs, addr)
}
}
sort.SliceStable(addrs, func(i, j int) bool {
return addrs[i].Cmp(addrs[j]) < 0
})

for _, addr := range addrs {
if obj := s.stateObjects[addr]; !obj.deleted {
log.Info("state object", "address", obj.address)
log.Info("state object", "addrHash", obj.addrHash)
log.Info("state object", "dirtyCode", obj.dirtyCode)
log.Info("state object", "selfDestructed", obj.selfDestructed)
log.Info("state object", "deleted", obj.deleted)
log.Info("state object", "created", obj.created)
if obj.origin != nil {
log.Info("state object origin", "Nonce", obj.origin.Nonce)
log.Info("state object origin", "Balance", obj.origin.Balance)
log.Info("state object origin", "Root", obj.origin.Root)
log.Info("state object origin", "CodeHash", common.Bytes2Hex(obj.origin.CodeHash))
} else {
log.Info("state object origin is nil")
}
log.Info("state object new", "Nonce", obj.data.Nonce)
log.Info("state object new", "Balance", obj.data.Balance)
log.Info("state object new", "Root", obj.data.Root)
log.Info("state object new", "CodeHash", common.Bytes2Hex(obj.data.CodeHash))
}
}
log.Info("================== block end ================", "number", block)
if block == 1 {
log.Crit("exit....")
}
}

// Once the state is committed, tries cached in stateDB (including account
// trie, storage tries) will no longer be functional. A new state instance
// must be created with new root and updated database for accessing post-
Expand Down

0 comments on commit 5153e69

Please sign in to comment.