aboutsummaryrefslogtreecommitdiffstats
path: root/core/genesis.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/genesis.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/genesis.go')
-rw-r--r--core/genesis.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/core/genesis.go b/core/genesis.go
index b2346da65..bf97da2e2 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -69,7 +69,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
statedb.SetState(address, common.HexToHash(key), common.HexToHash(value))
}
}
- statedb.SyncObjects()
+ root, stateBatch := statedb.CommitBatch()
difficulty := common.String2Big(genesis.Difficulty)
block := types.NewBlock(&types.Header{
@@ -81,7 +81,7 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
Difficulty: difficulty,
MixDigest: common.HexToHash(genesis.Mixhash),
Coinbase: common.HexToAddress(genesis.Coinbase),
- Root: statedb.Root(),
+ Root: root,
}, nil, nil, nil)
if block := GetBlock(chainDb, block.Hash()); block != nil {
@@ -92,8 +92,10 @@ func WriteGenesisBlock(chainDb ethdb.Database, reader io.Reader) (*types.Block,
}
return block, nil
}
- statedb.Sync()
+ if err := stateBatch.Write(); err != nil {
+ return nil, fmt.Errorf("cannot write state: %v", err)
+ }
if err := WriteTd(chainDb, block.Hash(), difficulty); err != nil {
return nil, err
}
@@ -115,12 +117,14 @@ func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big
statedb := state.New(common.Hash{}, db)
obj := statedb.GetOrNewStateObject(addr)
obj.SetBalance(balance)
- statedb.SyncObjects()
- statedb.Sync()
+ root, err := statedb.Commit()
+ if err != nil {
+ panic(fmt.Sprintf("cannot write state: %v", err))
+ }
block := types.NewBlock(&types.Header{
Difficulty: params.GenesisDifficulty,
GasLimit: params.GenesisGasLimit,
- Root: statedb.Root(),
+ Root: root,
}, nil, nil, nil)
return block
}