aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-11-15 16:44:18 +0800
committerGitHub <noreply@github.com>2017-11-15 16:44:18 +0800
commit43c8a1914ce5014c3589c2de0613a06eb6ad3f69 (patch)
treec57c9b2bfa484a071b0e33b9b1b0f12972387151 /core
parentba62215d9ef8655743ce7b1380056755943e3d72 (diff)
parent54ce3887d84a56894904baaa90e44c2972a0107f (diff)
downloadgo-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.tar
go-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.tar.gz
go-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.tar.bz2
go-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.tar.lz
go-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.tar.xz
go-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.tar.zst
go-tangerine-43c8a1914ce5014c3589c2de0613a06eb6ad3f69.zip
Merge pull request #15470 from karalabe/clique-sametd-splitter
core: split same-td blocks on block height
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 57a881f38..325753c7a 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -818,7 +818,12 @@ func (bc *BlockChain) WriteBlockAndState(block *types.Block, receipts []*types.R
// 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
- if externTd.Cmp(localTd) > 0 || (externTd.Cmp(localTd) == 0 && mrand.Float64() < 0.5) {
+ reorg := externTd.Cmp(localTd) > 0
+ if !reorg && externTd.Cmp(localTd) == 0 {
+ // Split same-difficulty blocks by number, then at random
+ reorg = block.NumberU64() < bc.currentBlock.NumberU64() || (block.NumberU64() == bc.currentBlock.NumberU64() && mrand.Float64() < 0.5)
+ }
+ if reorg {
// Reorganise the chain if the parent is not the head block
if block.ParentHash() != bc.currentBlock.Hash() {
if err := bc.reorg(bc.currentBlock, block); err != nil {