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 60df2fa commit 11f9fa8
Show file tree
Hide file tree
Showing 3 changed files with 35 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 @@ -2278,6 +2278,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
1 change: 1 addition & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func flushAlloc(ga *types.GenesisAlloc, db ethdb.Database, triedb *triedb.Databa
}
}
statedb.IntermediateRoot(false)
statedb.DebugPrint(0, false)
root, _, err := statedb.Commit(0, nil)
if err != nil {
return err
Expand Down
32 changes: 32 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,38 @@ 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)
for addr := range s.stateObjectsDirty {
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 11f9fa8

Please sign in to comment.