aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-10-09 21:21:47 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-10-19 15:03:10 +0800
commita9d8dfc8e77330412b1f21e25a69b96d59567e36 (patch)
treeff4e6b4dbf34ba4b3aab0672adddbce764c855e4 /core/blockchain.go
parentb97e34a8e4d06b315cc495819ba6612f89dec54f (diff)
downloaddexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.tar
dexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.tar.gz
dexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.tar.bz2
dexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.tar.lz
dexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.tar.xz
dexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.tar.zst
dexon-a9d8dfc8e77330412b1f21e25a69b96d59567e36.zip
core, eth: roll back uncertain headers in failed fast syncs
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 3e7dfa9ee..490552ea0 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -245,7 +245,21 @@ func (bc *BlockChain) SetHead(head uint64) {
if bc.currentBlock == nil {
bc.currentBlock = bc.genesisBlock
}
- bc.insert(bc.currentBlock)
+ if bc.currentHeader == nil {
+ bc.currentHeader = bc.genesisBlock.Header()
+ }
+ if bc.currentFastBlock == nil {
+ bc.currentFastBlock = bc.genesisBlock
+ }
+ if err := WriteHeadBlockHash(bc.chainDb, bc.currentBlock.Hash()); err != nil {
+ glog.Fatalf("failed to reset head block hash: %v", err)
+ }
+ if err := WriteHeadHeaderHash(bc.chainDb, bc.currentHeader.Hash()); err != nil {
+ glog.Fatalf("failed to reset head header hash: %v", err)
+ }
+ if err := WriteHeadFastBlockHash(bc.chainDb, bc.currentFastBlock.Hash()); err != nil {
+ glog.Fatalf("failed to reset head fast block hash: %v", err)
+ }
bc.loadLastState()
}
@@ -790,6 +804,27 @@ func (self *BlockChain) InsertHeaderChain(chain []*types.Header, checkFreq int)
return 0, nil
}
+// Rollback is designed to remove a chain of links from the database that aren't
+// certain enough to be valid.
+func (self *BlockChain) Rollback(chain []common.Hash) {
+ for i := len(chain) - 1; i >= 0; i-- {
+ hash := chain[i]
+
+ if self.currentHeader.Hash() == hash {
+ self.currentHeader = self.GetHeader(self.currentHeader.ParentHash)
+ WriteHeadHeaderHash(self.chainDb, self.currentHeader.Hash())
+ }
+ if self.currentFastBlock.Hash() == hash {
+ self.currentFastBlock = self.GetBlock(self.currentFastBlock.ParentHash())
+ WriteHeadFastBlockHash(self.chainDb, self.currentFastBlock.Hash())
+ }
+ if self.currentBlock.Hash() == hash {
+ self.currentBlock = self.GetBlock(self.currentBlock.ParentHash())
+ WriteHeadBlockHash(self.chainDb, self.currentBlock.Hash())
+ }
+ }
+}
+
// InsertReceiptChain attempts to complete an already existing header chain with
// transaction and receipt data.
func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts) (int, error) {