Skip to content

Commit

Permalink
Merge pull request #90 from akroma-project/reorg_error_vs_warning
Browse files Browse the repository at this point in the history
feat(blockchain): prevent reorg greater then 64 blocks)
  • Loading branch information
detroitpro committed Feb 21, 2019
2 parents 8bfbdb4 + 98d020b commit daf198a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions core/blockchain.go
Expand Up @@ -1555,11 +1555,10 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
}
// Ensure the user sees large reorgs
if len(oldChain) > 0 && len(newChain) > 0 {
logFn := log.Debug
if len(oldChain) > 63 {
logFn = log.Warn
if len(oldChain) > 64 {
return fmt.Errorf("Chain is too long for reorg")
}
logFn("Chain split detected", "number", commonBlock.Number(), "hash", commonBlock.Hash(),
log.Debug("Chain split detected", "number", commonBlock.Number(), "hash", commonBlock.Hash(),
"drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash())
} else {
log.Error("Impossible reorg, please file an issue", "oldnum", oldBlock.Number(), "oldhash", oldBlock.Hash(), "newnum", newBlock.Number(), "newhash", newBlock.Hash())
Expand Down
4 changes: 2 additions & 2 deletions core/blockchain_test.go
Expand Up @@ -374,8 +374,8 @@ func TestReorgShortBlocks(t *testing.T) { testReorgShort(t, true) }
func testReorgShort(t *testing.T, full bool) {
// Create a long easy chain vs. a short heavy one. Due to difficulty adjustment
// we need a fairly long chain of blocks with different difficulties for a short
// one to become heavyer than a long one. The 96 is an empirical value.
easy := make([]int64, 96)
// one to become heavyer than a long one. The 64 is an empirical value.
easy := make([]int64, 64)
for i := 0; i < len(easy); i++ {
easy[i] = 60
}
Expand Down

0 comments on commit daf198a

Please sign in to comment.