diff --git a/core/blockchain.go b/core/blockchain.go index d0cd2687d1..c1024445f2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 { diff --git a/core/genesis.go b/core/genesis.go index 72db9955ee..87e28de41f 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -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 diff --git a/core/state/statedb.go b/core/state/statedb.go index 574eb114ba..105588f159 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -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-