diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-01 18:07:14 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-04 08:51:36 +0800 |
commit | ab16ce70fc68d9ab1b7d8cda57c180b4785cab6a (patch) | |
tree | b6d294b8fbe8ba7f34a9f78f676ca99758a58bf5 | |
parent | 08caeedd842526373d30a929e63101a5fe7fda55 (diff) | |
download | go-tangerine-ab16ce70fc68d9ab1b7d8cda57c180b4785cab6a.tar.gz go-tangerine-ab16ce70fc68d9ab1b7d8cda57c180b4785cab6a.tar.zst go-tangerine-ab16ce70fc68d9ab1b7d8cda57c180b4785cab6a.zip |
core, miner, tests: renamed state methods
* Update => SyncIntermediate
* Added SyncObjects
SyncIntermediate only updates whatever has changed, but, as a side
effect, requires much more disk space.
SyncObjects will only sync whatever is required for a block and will not
save intermediate state to disk. As drawback this requires more time
when more txs come in.
-rw-r--r-- | core/block_processor.go | 4 | ||||
-rw-r--r-- | core/chain_makers.go | 4 | ||||
-rw-r--r-- | core/genesis.go | 2 | ||||
-rw-r--r-- | core/state/state_test.go | 2 | ||||
-rw-r--r-- | core/state/statedb.go | 6 | ||||
-rw-r--r-- | miner/worker.go | 2 | ||||
-rw-r--r-- | tests/block_test_util.go | 2 | ||||
-rw-r--r-- | tests/state_test_util.go | 2 |
8 files changed, 13 insertions, 11 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index 5f745e491..e7ad059c3 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -77,7 +77,7 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated } // Update the state with pending changes - statedb.Update() + statedb.SyncIntermediate() usedGas.Add(usedGas, gas) receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas) @@ -243,7 +243,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st // Commit state objects/accounts to a temporary trie (does not save) // used to calculate the state root. - state.CleanUpdate() + state.SyncObjects() if header.Root != state.Root() { err = fmt.Errorf("invalid merkle root. received=%x got=%x", header.Root, state.Root()) return diff --git a/core/chain_makers.go b/core/chain_makers.go index 37475e0ae..c46f627f8 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -77,7 +77,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) { if err != nil { panic(err) } - b.statedb.Update() + b.statedb.SyncIntermediate() b.header.GasUsed.Add(b.header.GasUsed, gas) receipt := types.NewReceipt(b.statedb.Root().Bytes(), b.header.GasUsed) logs := b.statedb.GetLogs(tx.Hash()) @@ -135,7 +135,7 @@ func GenerateChain(parent *types.Block, db common.Database, n int, gen func(int, gen(i, b) } AccumulateRewards(statedb, h, b.uncles) - statedb.Update() + statedb.SyncIntermediate() h.Root = statedb.Root() return types.NewBlock(h, b.txs, b.uncles, b.receipts) } diff --git a/core/genesis.go b/core/genesis.go index df13466ec..d27e7097b 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -64,7 +64,7 @@ func GenesisBlockForTesting(db common.Database, addr common.Address, balance *bi statedb := state.New(common.Hash{}, db) obj := statedb.GetOrNewStateObject(addr) obj.SetBalance(balance) - statedb.Update() + statedb.SyncObjects() statedb.Sync() block := types.NewBlock(&types.Header{ Difficulty: params.GenesisDifficulty, diff --git a/core/state/state_test.go b/core/state/state_test.go index 00e133dab..b63b8ae9b 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -72,7 +72,7 @@ func TestNull(t *testing.T) { //value := common.FromHex("0x823140710bf13990e4500136726d8b55") var value common.Hash state.SetState(address, common.Hash{}, value) - state.Update() + state.SyncIntermediate() state.Sync() value = state.GetState(address, common.Hash{}) if !common.EmptyHash(value) { diff --git a/core/state/statedb.go b/core/state/statedb.go index bd4ff6ff3..4ccda1fc7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -324,7 +324,8 @@ func (self *StateDB) Refunds() *big.Int { return self.refund } -func (self *StateDB) Update() { +// SyncIntermediate updates the intermediate state and all mid steps +func (self *StateDB) SyncIntermediate() { self.refund = new(big.Int) for _, stateObject := range self.stateObjects { @@ -341,7 +342,8 @@ func (self *StateDB) Update() { } } -func (self *StateDB) CleanUpdate() { +// SyncObjects syncs the changed objects to the trie +func (self *StateDB) SyncObjects() { self.trie = trie.NewSecure(self.root[:], self.db) self.refund = new(big.Int) diff --git a/miner/worker.go b/miner/worker.go index dd004da6e..1615ff84b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -453,7 +453,7 @@ func (self *worker) commitNewWork() { if atomic.LoadInt32(&self.mining) == 1 { // commit state root after all state transitions. core.AccumulateRewards(self.current.state, header, uncles) - current.state.Update() + current.state.SyncObjects() self.current.state.Sync() header.Root = current.state.Root() } diff --git a/tests/block_test_util.go b/tests/block_test_util.go index 67f6a1d18..3b20da492 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -215,7 +215,7 @@ func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, erro } } // sync objects to trie - statedb.Update() + statedb.SyncObjects() // sync trie to disk statedb.Sync() diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 2f3d497be..7f1a22ac0 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -175,7 +175,7 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state. if core.IsNonceErr(err) || core.IsInvalidTxErr(err) || state.IsGasLimitErr(err) { statedb.Set(snapshot) } - statedb.Update() + statedb.SyncObjects() return ret, vmenv.state.Logs(), vmenv.Gas, err } |