diff --git a/core/block_validator.go b/core/block_validator.go index e5bc6178b9..9455306e5b 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -128,7 +128,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat } // Validate the state root against the received state root and throw // an error if they don't match. - if root := statedb.IntermediateRoot(); header.Root != root { + if root := state.IntermediateRoot(statedb); header.Root != root { return fmt.Errorf("invalid merkle root: header=%x computed=%x", header.Root, root) } return nil diff --git a/core/chain_makers.go b/core/chain_makers.go index cfcb12b3ef..591096e7c7 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -225,7 +225,7 @@ func GenerateChain(config *ChainConfig, parent *types.Block, db ethdb.Database, return blocks, receipts } -func makeHeader(parent *types.Block, state *state.StateDB) *types.Header { +func makeHeader(parent *types.Block, st *state.StateDB) *types.Header { var time *big.Int if parent.Time() == nil { time = big.NewInt(10) @@ -233,7 +233,7 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header { time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds } return &types.Header{ - Root: state.IntermediateRoot(), + Root: state.IntermediateRoot(st), ParentHash: parent.Hash(), Coinbase: parent.Coinbase(), Difficulty: CalcDifficulty(MakeChainConfig(), time.Uint64(), new(big.Int).Sub(time, big.NewInt(10)).Uint64(), parent.Number(), parent.Difficulty()), diff --git a/core/state_processor.go b/core/state_processor.go index 6cba104bbf..11cc7fbe6b 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -64,15 +64,17 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg header = block.Header() allLogs vm.Logs gp = new(GasPool).AddGas(block.GasLimit()) - forkState = state.Fork(statedb) ) // Mutate the the block and state according to any hard-fork specs if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 { ApplyDAOHardFork(statedb) } + + forkState := state.Fork(statedb) // Iterate over and process the individual transactions for i, tx := range block.Transactions() { forkState.TransitionState(tx.Hash(), block.Hash(), i) + txPostState, receipt, logs, _, err := ApplyTransaction(p.config, p.bc, gp, forkState, header, tx, totalUsedGas, cfg) if err != nil { return nil, nil, totalUsedGas, err @@ -82,7 +84,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg forkState = state.Fork(txPostState) } - AccumulateRewards(statedb, header, block.Uncles()) + AccumulateRewards(forkState, header, block.Uncles()) statedb.Set(state.Reduce(forkState))