Skip to content

Commit

Permalink
--die-on-orphan option to terminate the node when it receives an orph…
Browse files Browse the repository at this point in the history
…an block
  • Loading branch information
mhanne committed Mar 25, 2015
1 parent 5f508d3 commit 4af613e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/bitcoin_node
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ optparse = OptionParser.new do |opts|
end
end

opts.on("--die-on-orphan", "Terminate the node when an orphan block is received") do |d|
options[:die_on_orphan] = d
end

opts.on("--import DIR", "Import blk*.dat files from DIR") do |dir|
options[:import] = dir
end
Expand Down
7 changes: 6 additions & 1 deletion lib/bitcoin/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Node
epoll_limit: 10000,
epoll_user: nil,
addr_file: "~/.bitcoin-ruby/<network>/peers.json",
die_on_orphan: false,
log: {
network: :info,
storage: :info,
Expand Down Expand Up @@ -433,7 +434,11 @@ def work_queue
while obj = @queue.shift
begin
if obj[0].to_sym == :block
@store.new_block(obj[1])
height, chain = @store.new_block(obj[1])
if @config[:die_on_orphan] && chain == 2
puts "Orphan block received, terminating."
exit
end
else
drop = @unconfirmed.size - @config[:max][:unconfirmed] + 1
drop.times { @unconfirmed.shift } if drop > 0
Expand Down

0 comments on commit 4af613e

Please sign in to comment.