Skip to content

Commit b48c5d1

Browse files
committed
chore: add debug print statedb
1 parent 83a9b13 commit b48c5d1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

core/blockchain.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
22702270
}
22712271
ptime := time.Since(pstart)
22722272

2273+
statedb.DebugPrint(block.NumberU64(), true)
2274+
22732275
// Validate the state using the default validator
22742276
vstart := time.Now()
22752277
if err := bc.validator.ValidateState(block, statedb, receipts, usedGas); err != nil {

core/genesis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func flushAlloc(ga *types.GenesisAlloc, db ethdb.Database, triedb *triedb.Databa
169169
}
170170
}
171171
statedb.IntermediateRoot(false)
172+
statedb.DebugPrint(0, false)
172173
root, _, err := statedb.Commit(0, nil)
173174
if err != nil {
174175
return err

core/state/statedb.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,38 @@ func (s *StateDB) handleDestruction(nodes *trienode.MergedNodeSet) (map[common.A
14751475
return incomplete, nil
14761476
}
14771477

1478+
func (s *StateDB) DebugPrint(block uint64, deleteEmptyObjects bool) {
1479+
log.Info("================== block start ===============", "number", block)
1480+
hash := s.IntermediateRoot(deleteEmptyObjects)
1481+
log.Info("mpt root", "hash", hash)
1482+
for addr := range s.stateObjectsDirty {
1483+
if obj := s.stateObjects[addr]; !obj.deleted {
1484+
log.Info("state object", "address", obj.address)
1485+
log.Info("state object", "addrHash", obj.addrHash)
1486+
log.Info("state object", "dirtyCode", obj.dirtyCode)
1487+
log.Info("state object", "selfDestructed", obj.selfDestructed)
1488+
log.Info("state object", "deleted", obj.deleted)
1489+
log.Info("state object", "created", obj.created)
1490+
if obj.origin != nil {
1491+
log.Info("state object origin", "Nonce", obj.origin.Nonce)
1492+
log.Info("state object origin", "Balance", obj.origin.Balance)
1493+
log.Info("state object origin", "Root", obj.origin.Root)
1494+
log.Info("state object origin", "CodeHash", common.Bytes2Hex(obj.origin.CodeHash))
1495+
} else {
1496+
log.Info("state object origin is nil")
1497+
}
1498+
log.Info("state object new", "Nonce", obj.data.Nonce)
1499+
log.Info("state object new", "Balance", obj.data.Balance)
1500+
log.Info("state object new", "Root", obj.data.Root)
1501+
log.Info("state object new", "CodeHash", common.Bytes2Hex(obj.data.CodeHash))
1502+
}
1503+
}
1504+
log.Info("================== block end ================", "number", block)
1505+
if block == 1 {
1506+
log.Crit("exit....")
1507+
}
1508+
}
1509+
14781510
// Once the state is committed, tries cached in stateDB (including account
14791511
// trie, storage tries) will no longer be functional. A new state instance
14801512
// must be created with new root and updated database for accessing post-

0 commit comments

Comments
 (0)