zold 0.18.9 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ad955cd4ed1c34ff735ca6684945186c29c07bf970f4bdc130ffdc0b3164922
4
- data.tar.gz: 9344af265b58567d3aa2afda28815c6efaaddf0235a379d85f1ae69433112cd0
3
+ metadata.gz: 2b6e5a80a2216feaeb4ac83bafc229c711bb981df2c1c7fa73a828f9620580c5
4
+ data.tar.gz: 9cb90c56a015453a5ababcabed994a119ae44b734d557bf00f3fabebe9a06660
5
5
  SHA512:
6
- metadata.gz: fba208cc63dc399eb24dd6c015f6eada0e22c9a3ca2b22d6a5612576b6ea264f2e3bc6cb57c0a69618694544928faa5f919d779c6e29d7da5137d40325e9b62e
7
- data.tar.gz: bbfd1eec62d4f29272c21273aef71d9d110bbe491237b264c18f571e687d724b606861141e2efacadc3551fafe7917b2d896ed88eccc39b80f86066e226d81ee
6
+ metadata.gz: cbd48e9a0ac951f438964c39e98d3e5942d41665b1bb8f61d7a5ef1942947566fd6be97eea8871a317a47004812ba56cccf4a7fafd2bd552112026189158aada
7
+ data.tar.gz: c661f88c9fe2de378dd2bb1107f5b7cd12ca0ab2cb2fd3465070da1b7be5105c0c3627257e0cb7eb4eb9e4680f58cb8d2044ae55069ef6deeaa8158ba17e335f
data/bin/zold CHANGED
@@ -177,7 +177,7 @@ remotes = Zold::Remotes.new(file: fremotes, network: opts['network'])
177
177
  if File.exist?(fremotes)
178
178
  log.debug("Remote nodes: #{remotes.all.count} total")
179
179
  else
180
- remotes.defaults
180
+ remotes.masters
181
181
  log.debug("Default remotes have been set: #{remotes.all.count} total")
182
182
  end
183
183
  copies = File.join(zoldata, 'copies')
@@ -67,7 +67,7 @@ Available options:"
67
67
  'Ignore this node and don\'t fetch from it',
68
68
  default: []
69
69
  o.bool '--tolerate-edges',
70
- 'Don\'t fail if only "edge" (not default ones) nodes accepted the wallet',
70
+ 'Don\'t fail if only "edge" (not "master" ones) nodes accepted the wallet',
71
71
  default: false
72
72
  o.bool '--quiet-if-absent',
73
73
  'Don\'t fail if the wallet is absent in all remote nodes',
@@ -94,22 +94,22 @@ Available options:"
94
94
  total = Concurrent::AtomicFixnum.new
95
95
  nodes = Concurrent::AtomicFixnum.new
96
96
  done = Concurrent::AtomicFixnum.new
97
- defaults = Concurrent::AtomicFixnum.new
97
+ masters = Concurrent::AtomicFixnum.new
98
98
  @remotes.iterate(@log) do |r|
99
99
  nodes.increment
100
100
  total.increment(fetch_one(id, r, cps, opts))
101
- defaults.increment if r.default?
101
+ masters.increment if r.master?
102
102
  done.increment
103
103
  end
104
104
  raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
105
105
  unless opts['quiet-if-absent']
106
106
  raise "No nodes out of #{nodes.value} have the wallet #{id}" if done.value.zero?
107
- if defaults.value.zero? && !opts['tolerate-edges']
107
+ if masters.value.zero? && !opts['tolerate-edges']
108
108
  raise "There are only edge nodes, run 'zold remote reset' or use --tolerate-edges"
109
109
  end
110
110
  end
111
111
  @log.info("#{done.value} copies of #{id} fetched in #{Age.new(start)} with the total score of \
112
- #{total.value} from #{nodes.value} nodes (#{defaults.value} defaults)")
112
+ #{total.value} from #{nodes.value} nodes (#{masters.value} master nodes)")
113
113
  list = cps.all.map do |c|
114
114
  " ##{c[:name]}: #{c[:score]} #{Wallet.new(c[:path]).mnemo} \
115
115
  #{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}"
@@ -52,7 +52,7 @@ Available options:"
52
52
  'The length of the invoice prefix (default: 8)',
53
53
  default: 8
54
54
  o.bool '--tolerate-edges',
55
- 'Don\'t fail if only "edge" (not default ones) nodes have the wallet',
55
+ 'Don\'t fail if only "edge" (not "master" ones) nodes have the wallet',
56
56
  default: false
57
57
  o.string '--network',
58
58
  'The name of the network we work in',
@@ -92,6 +92,7 @@ Available options:"
92
92
  @log.debug("Local copy of #{id} is absent, nothing to merge")
93
93
  end
94
94
  end
95
+ raise "There are no copies of #{id}, nothing to merge" if patch.empty?
95
96
  modified = @wallets.acq(id, exclusive: true) { |w| patch.save(w.path, overwrite: true) }
96
97
  if modified
97
98
  @log.info("#{cps.count} copies with the total score of #{score} successfully merged \
@@ -98,7 +98,7 @@ module Zold
98
98
  'Ignore score weakness of incoming requests and register those nodes anyway',
99
99
  default: false
100
100
  o.bool '--tolerate-edges',
101
- 'Don\'t fail if only "edge" (not default ones) nodes accepted/have the wallet',
101
+ 'Don\'t fail if only "edge" (not "master" ones) nodes accepted/have the wallet',
102
102
  default: false
103
103
  o.boolean '--nohup',
104
104
  'Run it in background, rebooting when a higher version is available in the network',
@@ -59,7 +59,7 @@ Available options:"
59
59
  'Don\'t complain when their score is too weak',
60
60
  default: false
61
61
  o.bool '--tolerate-edges',
62
- 'Don\'t fail if only "edge" (not default ones) nodes accepted the wallet',
62
+ 'Don\'t fail if only "edge" (not "master" ones) nodes accepted the wallet',
63
63
  default: false
64
64
  o.bool '--quiet-if-missed',
65
65
  'Don\'t fail if the wallet wasn\'t delivered to any remotes',
@@ -85,22 +85,22 @@ Available options:"
85
85
  total = Concurrent::AtomicFixnum.new
86
86
  nodes = Concurrent::AtomicFixnum.new
87
87
  done = Concurrent::AtomicFixnum.new
88
- defaults = Concurrent::AtomicFixnum.new
88
+ masters = Concurrent::AtomicFixnum.new
89
89
  start = Time.now
90
90
  @remotes.iterate(@log) do |r|
91
91
  nodes.increment
92
92
  total.increment(push_one(id, r, opts))
93
- defaults.increment if r.default?
93
+ masters.increment if r.master?
94
94
  done.increment
95
95
  end
96
96
  raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
97
97
  unless opts['quiet-if-missed']
98
98
  raise "No nodes out of #{nodes} accepted the wallet #{id}" if done.value.zero?
99
- if defaults.value.zero? && !opts['tolerate-edges']
99
+ if masters.value.zero? && !opts['tolerate-edges']
100
100
  raise "There are only edge nodes, run 'zold remote reset' or use --tolerate-edges"
101
101
  end
102
102
  end
103
- @log.info("Push finished to #{done.value} nodes (#{defaults.value} defaults) \
103
+ @log.info("Push finished to #{done.value} nodes (#{masters.value} master nodes) \
104
104
  out of #{nodes.value} in #{Age.new(start)}, total score for #{id} is #{total.value}")
105
105
  end
106
106
 
@@ -63,8 +63,8 @@ Available commands:
63
63
  Remove all registered remote nodes
64
64
  #{Rainbow('remote reset').green}
65
65
  Restore it back to the default list of nodes
66
- #{Rainbow('remote defaults').green}
67
- Add all default nodes to the list
66
+ #{Rainbow('remote masters').green}
67
+ Add all \"master\" nodes to the list
68
68
  #{Rainbow('remote add').green} host [port]
69
69
  Add a new remote node
70
70
  #{Rainbow('remote remove').green} host [port]
@@ -139,8 +139,8 @@ Available options:"
139
139
  clean
140
140
  when 'reset'
141
141
  reset(opts)
142
- when 'defaults'
143
- defaults(opts)
142
+ when 'masters'
143
+ masters(opts)
144
144
  when 'add'
145
145
  add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
146
146
  when 'remove'
@@ -175,14 +175,14 @@ Available options:"
175
175
 
176
176
  def reset(opts)
177
177
  clean
178
- defaults(opts)
178
+ masters(opts)
179
179
  end
180
180
 
181
- def defaults(opts)
182
- @remotes.defaults do |host, port|
181
+ def masters(opts)
182
+ @remotes.masters do |host, port|
183
183
  !opts['ignore-node'].include?("#{host}:#{port}")
184
184
  end
185
- @log.debug("Default remote nodes were added to the list, #{@remotes.all.count} total")
185
+ @log.debug("Masters nodes were added to the list, #{@remotes.all.count} total")
186
186
  end
187
187
 
188
188
  def add(host, port, opts)
@@ -44,6 +44,9 @@ module Zold
44
44
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
45
45
  o.banner = "Usage: zold remove [ID...] [options]
46
46
  Available options:"
47
+ o.bool '--force',
48
+ 'Don\'t report any errors if the wallet doesn\'t exist',
49
+ default: false
47
50
  o.bool '--help', 'Print instructions'
48
51
  end
49
52
  mine = Args.new(opts, @log).take || return
@@ -52,10 +55,14 @@ Available options:"
52
55
  end
53
56
  end
54
57
 
55
- def remove(id, _)
58
+ def remove(id, opts)
56
59
  @wallets.acq(id, exclusive: true) do |w|
57
- raise "Wallet #{id} doesn't exist in #{w.path}" unless w.exists?
58
- File.delete(w.path)
60
+ if w.exists?
61
+ File.delete(w.path)
62
+ else
63
+ raise "Wallet #{id} doesn't exist in #{w.path}" unless opts['force']
64
+ @log.info("Wallet #{id} file not found in #{w.path}")
65
+ end
59
66
  end
60
67
  @log.info("Wallet #{id} removed")
61
68
  end
@@ -46,7 +46,7 @@ module Zold
46
46
  args = ['remote', "--network=#{@opts['network']}", '--ignore-ping']
47
47
  score = @farm.best[0]
48
48
  args << "--ignore-node=#{score.host}:#{score.port}" if score
49
- cmd.run(args + ['defaults']) unless @opts['routine-immediately']
49
+ cmd.run(args + ['masters']) unless @opts['routine-immediately']
50
50
  return if @opts['routine-immediately'] && @remotes.all.empty?
51
51
  cmd.run(args + ['update'] + (@opts['never-reboot'] ? [] : ['--reboot']))
52
52
  cmd.run(args + ['trim'])
@@ -84,6 +84,7 @@ module Zold
84
84
  before do
85
85
  Thread.current.name = "#{request.request_method}:#{request.url}"
86
86
  Thread.current.thread_variable_set(:uri, request.url)
87
+ error(400, 'Can\'t detect your IP') if request.ip.nil? || request.ip.empty?
87
88
  Thread.current.thread_variable_set(:ip, request.ip)
88
89
  @start = Time.now
89
90
  if !settings.opts['halt-code'].empty? && params[:halt] && params[:halt] == settings.opts['halt-code']
data/lib/zold/patch.rb CHANGED
@@ -104,7 +104,8 @@ module Zold
104
104
  next
105
105
  end
106
106
  unless @wallets.acq(txn.bnf) { |p| p.includes_negative?(txn.id, wallet.id) }
107
- @log.error("The beneficiary of #{@id} doesn't have this transaction: \"#{txn.to_text}\"")
107
+ @log.error("The beneficiary #{@wallets.acq(txn.bnf, &:mnemo)} of #{@id} \
108
+ doesn't have this transaction: \"#{txn.to_text}\"")
108
109
  next
109
110
  end
110
111
  end
@@ -113,9 +114,13 @@ module Zold
113
114
  end
114
115
  end
115
116
 
117
+ def empty?
118
+ @id.nil?
119
+ end
120
+
116
121
  # Returns TRUE if the file was actually modified
117
122
  def save(file, overwrite: false)
118
- raise 'You have to join at least one wallet in' if @id.nil?
123
+ raise 'You have to join at least one wallet in' if empty?
119
124
  before = ''
120
125
  before = IO.read(file) if File.exist?(file)
121
126
  wallet = Wallet.new(file)
data/lib/zold/remotes.rb CHANGED
@@ -51,8 +51,8 @@ module Zold
51
51
  MAX_NODES = 16
52
52
 
53
53
  # Default nodes and their ports
54
- DEFS = CSV.read(File.expand_path(File.join(File.dirname(__FILE__), '../../resources/remotes')))
55
- private_constant :DEFS
54
+ MASTERS = CSV.read(File.expand_path(File.join(File.dirname(__FILE__), '../../resources/masters')))
55
+ private_constant :MASTERS
56
56
 
57
57
  # Empty, for standalone mode
58
58
  class Empty
@@ -88,8 +88,8 @@ module Zold
88
88
  Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network)
89
89
  end
90
90
 
91
- def default?
92
- !DEFS.find { |r| r[0] == @host && r[1].to_i == @port }.nil?
91
+ def master?
92
+ !MASTERS.find { |r| r[0] == @host && r[1].to_i == @port }.nil?
93
93
  end
94
94
 
95
95
  def to_s
@@ -148,8 +148,8 @@ module Zold
148
148
  modify { [] }
149
149
  end
150
150
 
151
- def defaults
152
- DEFS.each do |r|
151
+ def masters
152
+ MASTERS.each do |r|
153
153
  if block_given?
154
154
  next unless yield(r[0], r[1].to_i)
155
155
  end
@@ -235,8 +235,8 @@ module Zold
235
235
  File.exist?(@file) ? File.mtime(@file) : Time.now
236
236
  end
237
237
 
238
- def default?(host, port)
239
- !DEFS.find { |r| r[0] == host && r[1].to_i == port }.nil?
238
+ def master?(host, port)
239
+ !MASTERS.find { |r| r[0] == host && r[1].to_i == port }.nil?
240
240
  end
241
241
 
242
242
  private
@@ -276,7 +276,7 @@ module Zold
276
276
  port: row[1].to_i,
277
277
  score: row[2].to_i,
278
278
  errors: row[3].to_i,
279
- default: default?(row[0], row[1].to_i)
279
+ master: master?(row[0], row[1].to_i)
280
280
  }
281
281
  end
282
282
  raw.reject { |r| !r[:host] || r[:port].zero? }.map do |r|
@@ -125,7 +125,7 @@ it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}
125
125
  name: t.name,
126
126
  status: t.status,
127
127
  alive: t.alive?,
128
- vars: t.thread_variables.map { |v| { v.to_s => t.thread_variable_get(v) } }
128
+ vars: Hash[t.thread_variables.map { |v| [v.to_s, t.thread_variable_get(v)] }]
129
129
  }
130
130
  end
131
131
  end
data/lib/zold/version.rb CHANGED
@@ -25,7 +25,7 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.18.9'
28
+ VERSION = '0.19.0'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
File without changes
@@ -193,7 +193,7 @@ class TestRemote < Zold::Test
193
193
  def test_select_respects_max_nodes_option
194
194
  Dir.mktmpdir do |dir|
195
195
  remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
196
- remotes.defaults
196
+ remotes.masters
197
197
  zero = Zold::Score::ZERO
198
198
  cmd = Zold::Remote.new(remotes: remotes, log: test_log)
199
199
  (5000..5010).each do |port|
@@ -215,17 +215,17 @@ class TestRemote < Zold::Test
215
215
  )
216
216
  cmd.run(%W[remote add localhost #{port}])
217
217
  end
218
- assert_equal(11 + File.readlines('resources/remotes').count, remotes.all.count)
218
+ assert_equal(11 + File.readlines('resources/masters').count, remotes.all.count)
219
219
  cmd.run(%w[remote select --max-nodes=5])
220
220
  assert_equal(5, remotes.all.count)
221
221
  end
222
222
  end
223
223
 
224
- def test_sets_defaults
224
+ def test_sets_masters
225
225
  Dir.mktmpdir do |dir|
226
226
  remotes = Zold::Remotes.new(file: File.join(dir, 'remotes.txt'))
227
227
  cmd = Zold::Remote.new(remotes: remotes, log: test_log)
228
- cmd.run(%w[remote defaults])
228
+ cmd.run(%w[remote masters])
229
229
  assert(!remotes.all.empty?)
230
230
  end
231
231
  end
@@ -54,4 +54,13 @@ class TestRemove < Zold::Test
54
54
  assert(home.wallets.all.empty?)
55
55
  end
56
56
  end
57
+
58
+ def test_removes_absent_wallets
59
+ FakeHome.new(log: test_log).run do |home|
60
+ Zold::Remove.new(wallets: home.wallets, log: test_log).run(
61
+ ['remove', '7654321076543210', '--force']
62
+ )
63
+ assert(home.wallets.all.empty?)
64
+ end
65
+ end
57
66
  end
data/test/test_remotes.rb CHANGED
@@ -45,12 +45,12 @@ class TestRemotes < Zold::Test
45
45
  end
46
46
  end
47
47
 
48
- def test_finds_defaults
48
+ def test_finds_masters
49
49
  Dir.mktmpdir do |dir|
50
50
  file = File.join(dir, 'remotes')
51
51
  FileUtils.touch(file)
52
52
  remotes = Zold::Remotes.new(file: file)
53
- assert(remotes.default?('b1.zold.io', 80))
53
+ assert(remotes.master?('b1.zold.io', 80))
54
54
  end
55
55
  end
56
56
 
@@ -166,8 +166,8 @@ class TestRemotes < Zold::Test
166
166
  Dir.mktmpdir do |dir|
167
167
  remotes = Zold::Remotes.new(file: File.join(dir, 'remotes'))
168
168
  remotes.clean
169
- remotes.defaults
170
- remotes.defaults
169
+ remotes.masters
170
+ remotes.masters
171
171
  assert(!remotes.all.empty?)
172
172
  end
173
173
  end
@@ -102,7 +102,18 @@ class TestThreadPool < Zold::Test
102
102
 
103
103
  def test_prints_to_json
104
104
  pool = Zold::ThreadPool.new('test', log: test_log)
105
+ pool.add do
106
+ Thread.current.thread_variable_set(:foo, 1)
107
+ loop do
108
+ # forever
109
+ end
110
+ end
105
111
  assert(pool.to_json.is_a?(Array))
112
+ assert_equal('test', pool.to_json[0][:name])
113
+ assert_equal('run', pool.to_json[0][:status])
114
+ assert_equal(true, pool.to_json[0][:alive])
115
+ assert_equal(1, pool.to_json[0][:vars]['foo'])
116
+ pool.kill
106
117
  end
107
118
 
108
119
  def test_prints_to_text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.9
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -610,7 +610,7 @@ files:
610
610
  - lib/zold/version_file.rb
611
611
  - lib/zold/wallet.rb
612
612
  - lib/zold/wallets.rb
613
- - resources/remotes
613
+ - resources/masters
614
614
  - resources/root.pub
615
615
  - test/commands/routines/test_gc.rb
616
616
  - test/commands/routines/test_reconnect.rb
@@ -690,7 +690,7 @@ licenses:
690
690
  - MIT
691
691
  metadata: {}
692
692
  post_install_message: |-
693
- Thanks for installing Zold 0.18.9!
693
+ Thanks for installing Zold 0.19.0!
694
694
  Study our White Paper: https://papers.zold.io/wp.pdf
695
695
  Read our blog posts: https://blog.zold.io
696
696
  Try online wallet at: https://wts.zold.io