aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 950804d40..888c98dce 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -778,6 +778,14 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64())
externTd := new(big.Int).Add(block.Difficulty(), ptd)
+ // Irrelevant of the canonical status, write the block itself to the database
+ if err := self.hc.WriteTd(block.Hash(), block.NumberU64(), externTd); err != nil {
+ glog.Fatalf("failed to write block total difficulty: %v", err)
+ }
+ if err := WriteBlock(self.chainDb, block); err != nil {
+ glog.Fatalf("failed to write block contents: %v", err)
+ }
+
// If the total difficulty is higher than our known, add it to the canonical chain
// Second clause in the if statement reduces the vulnerability to selfish mining.
// Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf
@@ -788,19 +796,11 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
return NonStatTy, err
}
}
- // Insert the block as the new head of the chain
- self.insert(block)
+ self.insert(block) // Insert the block as the new head of the chain
status = CanonStatTy
} else {
status = SideStatTy
}
- // Irrelevant of the canonical status, write the block itself to the database
- if err := self.hc.WriteTd(block.Hash(), block.NumberU64(), externTd); err != nil {
- glog.Fatalf("failed to write block total difficulty: %v", err)
- }
- if err := WriteBlock(self.chainDb, block); err != nil {
- glog.Fatalf("failed to write block contents: %v", err)
- }
self.futureBlocks.Remove(block.Hash())