Skip to content

Commit

Permalink
for a new block to extend the main chain, make sure the prev block is…
Browse files Browse the repository at this point in the history
… the current head

and not just some old block in the main chain; in that case the new block becomes side branch
  • Loading branch information
mhanne committed Sep 13, 2012
1 parent 0295bb0 commit c737be3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/bitcoin/storage/storage.rb
Expand Up @@ -78,14 +78,13 @@ def store_block blk
end
depth = prev_block.depth + 1
if prev_block.chain == MAIN
next_block = prev_block.get_next_block
if next_block && next_block.chain == MAIN
log.debug { "=> side (#{depth})" }
return persist_block(blk, SIDE, depth)
else
if prev_block == get_head
log.debug { "=> main (#{depth})" }
validator.validate(rules: [:context], raise_errors: true)
return persist_block(blk, MAIN, depth)
else
log.debug { "=> side (#{depth})" }
return persist_block(blk, SIDE, depth)
end
else
head = get_head
Expand Down

0 comments on commit c737be3

Please sign in to comment.