diff --git a/core/blockchain.go b/core/blockchain.go index 51387a13f0..65c929d2b2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 { diff --git a/core/genesis.go b/core/genesis.go index 71787ce2bf..309db4968c 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -169,6 +169,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 525da23b0f..52f50303e1 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1475,6 +1475,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-