aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_makers.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-08-18 20:14:45 +0800
committerFelix Lange <fjl@twurst.com>2015-09-23 04:57:37 +0800
commita2d5a60418e70ce56112381dffdd121cc678a1b6 (patch)
treec9733cb16b7ca5bac98d6ae11254def5a48aafb8 /core/chain_makers.go
parent565d9f2306d19f63be6a6e1b8fc480af8dca9617 (diff)
downloaddexon-a2d5a60418e70ce56112381dffdd121cc678a1b6.tar.gz
dexon-a2d5a60418e70ce56112381dffdd121cc678a1b6.tar.zst
dexon-a2d5a60418e70ce56112381dffdd121cc678a1b6.zip
core, core/state: batch-based state sync
Diffstat (limited to 'core/chain_makers.go')
-rw-r--r--core/chain_makers.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 70233438d..3af9b0b89 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -17,6 +17,7 @@
package core
import (
+ "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
@@ -94,9 +95,9 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
if err != nil {
panic(err)
}
- b.statedb.SyncIntermediate()
+ root := b.statedb.IntermediateRoot()
b.header.GasUsed.Add(b.header.GasUsed, gas)
- receipt := types.NewReceipt(b.statedb.Root().Bytes(), b.header.GasUsed)
+ receipt := types.NewReceipt(root.Bytes(), b.header.GasUsed)
logs := b.statedb.GetLogs(tx.Hash())
receipt.SetLogs(logs)
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
@@ -163,8 +164,11 @@ func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int,
gen(i, b)
}
AccumulateRewards(statedb, h, b.uncles)
- statedb.SyncIntermediate()
- h.Root = statedb.Root()
+ root, err := statedb.Commit()
+ if err != nil {
+ panic(fmt.Sprintf("state write error: %v", err))
+ }
+ h.Root = root
return types.NewBlock(h, b.txs, b.uncles, b.receipts)
}
for i := 0; i < n; i++ {
@@ -184,7 +188,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.Root(),
+ Root: state.IntermediateRoot(),
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
Difficulty: CalcDifficulty(time.Uint64(), new(big.Int).Sub(time, big.NewInt(10)).Uint64(), parent.Number(), parent.Difficulty()),