lib/zold/commands/fetch.rb in zold-0.19.0 vs lib/zold/commands/fetch.rb in zold-0.19.1
- old
+ new
@@ -47,10 +47,16 @@
module Zold
# FETCH pulling command
class Fetch
prepend ThreadBadge
+ # Raises when there are only edge nodes and not a single master one.
+ class EdgesOnly < StandardError; end
+
+ # Raises when there are not enough successful nodes.
+ class NoQuorum < StandardError; end
+
def initialize(wallets:, remotes:, copies:, log: Log::NULL)
@wallets = wallets
@remotes = remotes
@copies = copies
@log = log
@@ -67,10 +73,13 @@
'Ignore this node and don\'t fetch from it',
default: []
o.bool '--tolerate-edges',
'Don\'t fail if only "edge" (not "master" ones) nodes accepted the wallet',
default: false
+ o.integer '--tolerate-quorum',
+ 'The minimum number of nodes required for a successful fetch (default: 4)',
+ default: 4
o.bool '--quiet-if-absent',
'Don\'t fail if the wallet is absent in all remote nodes',
default: false
o.string '--network',
'The name of the network we work in',
@@ -103,10 +112,13 @@
end
raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
unless opts['quiet-if-absent']
raise "No nodes out of #{nodes.value} have the wallet #{id}" if done.value.zero?
if masters.value.zero? && !opts['tolerate-edges']
- raise "There are only edge nodes, run 'zold remote reset' or use --tolerate-edges"
+ raise EdgesOnly, "There are only edge nodes, run 'zold remote reset' or use --tolerate-edges"
+ end
+ if nodes.value < opts['tolerate-quorum']
+ raise NoQuorum, "There were not enough nodes, run 'zold remote reset' or use --tolerate-quorum=1"
end
end
@log.info("#{done.value} copies of #{id} fetched in #{Age.new(start)} with the total score of \
#{total.value} from #{nodes.value} nodes (#{masters.value} master nodes)")
list = cps.all.map do |c|