aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-10-06 00:37:56 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-10-19 15:03:09 +0800
commitab27bee25a845be90bd60e774ff68d2ea1501772 (patch)
tree44d6a980fabd4cb065abe333e93a1088a3502466 /core/blockchain.go
parent832b37c8221e330896c36eb419d92af6b1fdc9dd (diff)
downloaddexon-ab27bee25a845be90bd60e774ff68d2ea1501772.tar
dexon-ab27bee25a845be90bd60e774ff68d2ea1501772.tar.gz
dexon-ab27bee25a845be90bd60e774ff68d2ea1501772.tar.bz2
dexon-ab27bee25a845be90bd60e774ff68d2ea1501772.tar.lz
dexon-ab27bee25a845be90bd60e774ff68d2ea1501772.tar.xz
dexon-ab27bee25a845be90bd60e774ff68d2ea1501772.tar.zst
dexon-ab27bee25a845be90bd60e774ff68d2ea1501772.zip
core, eth, trie: direct state trie synchronization
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index b68e7d3ae..6c8a24751 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
+ "github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru"
)
@@ -246,6 +247,26 @@ func (bc *BlockChain) SetHead(head uint64) {
bc.loadLastState()
}
+// FastSyncCommitHead sets the current head block to the one defined by the hash
+// irrelevant what the chain contents were prior.
+func (self *BlockChain) FastSyncCommitHead(hash common.Hash) error {
+ // Make sure that both the block as well at it's state trie exists
+ block := self.GetBlock(hash)
+ if block == nil {
+ return fmt.Errorf("non existent block [%x…]", hash[:4])
+ }
+ if _, err := trie.NewSecure(block.Root(), self.chainDb); err != nil {
+ return err
+ }
+ // If all checks out, manually set the head block
+ self.mu.Lock()
+ self.currentBlock = block
+ self.mu.Unlock()
+
+ glog.V(logger.Info).Infof("committed block #%d [%x…] as new head", block.Number(), hash[:4])
+ return nil
+}
+
func (self *BlockChain) GasLimit() *big.Int {
self.mu.RLock()
defer self.mu.RUnlock()
@@ -721,10 +742,6 @@ func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain
self.wg.Add(1)
defer self.wg.Done()
- // Make sure only one thread manipulates the chain at once
- self.chainmu.Lock()
- defer self.chainmu.Unlock()
-
// Collect some import statistics to report on
stats := struct{ processed, ignored int }{}
start := time.Now()