aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-05-19 18:24:14 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-05-26 21:33:09 +0800
commit748d1c171d74fbf6b6051fd629d3c2204dd930e3 (patch)
treef3bc5352efadae61cb39afd33ceeaba7b824609c /core
parenta7434fd0085f55235acea5348db0c9247e9aac10 (diff)
downloadgo-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.tar
go-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.tar.gz
go-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.tar.bz2
go-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.tar.lz
go-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.tar.xz
go-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.tar.zst
go-tangerine-748d1c171d74fbf6b6051fd629d3c2204dd930e3.zip
core, core/state, trie: enterprise hand-tuned multi-level caching
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go7
-rw-r--r--core/state/statedb.go22
2 files changed, 28 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 171a49e53..bd84adfe9 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -819,6 +819,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
tstart = time.Now()
nonceChecked = make([]bool, len(chain))
+ statedb *state.StateDB
)
// Start the parallel nonce verifier.
@@ -885,7 +886,11 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// Create a new statedb using the parent block and report an
// error if it fails.
- statedb, err := state.New(self.GetBlock(block.ParentHash()).Root(), self.chainDb)
+ if statedb == nil {
+ statedb, err = state.New(self.GetBlock(block.ParentHash()).Root(), self.chainDb)
+ } else {
+ err = statedb.Reset(chain[i-1].Root())
+ }
if err != nil {
reportBlock(block, err)
return i, err
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 22ffa36a0..cfcb82d97 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -68,6 +68,28 @@ func New(root common.Hash, db ethdb.Database) (*StateDB, error) {
}, nil
}
+// Reset clears out all emphemeral state objects from the state db, but keeps
+// the underlying state trie to avoid reloading data for the next operations.
+func (self *StateDB) Reset(root common.Hash) error {
+ var (
+ err error
+ tr = self.trie
+ )
+ if self.trie.Hash() != root {
+ if tr, err = trie.NewSecure(root, self.db); err != nil {
+ return err
+ }
+ }
+ *self = StateDB{
+ db: self.db,
+ trie: tr,
+ stateObjects: make(map[string]*StateObject),
+ refund: new(big.Int),
+ logs: make(map[common.Hash]vm.Logs),
+ }
+ return nil
+}
+
func (self *StateDB) StartRecord(thash, bhash common.Hash, ti int) {
self.thash = thash
self.bhash = bhash