zold 0.26.10 → 0.26.11

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: c0eb2f544daa848545dbc287811d8bf14a3d691dbcb63bdf947c53660be7c7f0
4
- data.tar.gz: 6126407c380aaf900613521f39feb4ae3af39e1badb6824aed3691fbcabbe800
3
+ metadata.gz: 1d0d8d5abb824adcb3222588744bd9f51b095b6a35d7de3401d6155867899bbd
4
+ data.tar.gz: 04e0597677b18e5f3e63b2492b5541352391522d3f92b092bddba7095dcd8c38
5
5
  SHA512:
6
- metadata.gz: 07e2cf7c0014c54bdacbf31b7efe09d71224e4305953f24282b8568e8b8a0b3dcb748fb3ff14dfe4a8b7152d150a44903b18976f4aff19bfebc011d043860d22
7
- data.tar.gz: 5a8f701777875c91cb072ff8d97eee4790365d0338a0c5760780d8d6e5e873681db6e78212b8ef07b990cca4b56b7c3f5b02f065d9045aa82f388aa242060749
6
+ metadata.gz: 9702cf51e271bbdad9ccb1a635e3274c49499e5070b3b18f20e239f97060c2f2edfc7b19b18f4af90c989eb33fb987c96312ccab8c172c26a131a4a0ebdc73f1
7
+ data.tar.gz: 96a39ed4f622342873430f0b9183ea1370f4520b3042d20fc5f3b40e313940f0fd844750ce6d5fcfbf12166b252c6c4408ef6fad446e3308c3d39e618c4e5f6a
@@ -56,6 +56,9 @@ Available options:"
56
56
  o.integer '--threads',
57
57
  'How many threads to use for cleaning copies (default: 1)',
58
58
  default: 1
59
+ o.integer '--max-age',
60
+ 'Maximum age for a copy to stay, in hours (default: 24)',
61
+ default: 24
59
62
  o.bool '--help', 'Print instructions'
60
63
  end
61
64
  mine = Args.new(opts, @log).take || return
@@ -65,9 +68,9 @@ Available options:"
65
68
  end
66
69
  end
67
70
 
68
- def clean(cps, _)
71
+ def clean(cps, opts)
69
72
  start = Time.now
70
- deleted = cps.clean
73
+ deleted = cps.clean(max: opts['max-age'])
71
74
  list = cps.all.map do |c|
72
75
  wallet = Wallet.new(c[:path])
73
76
  "#{c[:name]}: #{c[:score]} #{wallet.mnemo} \
@@ -156,15 +156,7 @@ run 'zold remote update' or use --tolerate-quorum=1"
156
156
  r.assert_valid_score(score)
157
157
  r.assert_score_ownership(score)
158
158
  r.assert_score_strength(score) unless opts['ignore-score-weakness']
159
- copy = nil
160
- cps.all.each do |c|
161
- next unless json['digest'] == OpenSSL::Digest::SHA256.file(c[:path]).hexdigest &&
162
- json['size'] == File.size(c[:path])
163
- copy = cps.add(IO.read(c[:path]), score.host, score.port, score.value, master: r.master?)
164
- @log.debug("No need to fetch #{id} from #{r}, it's the same content as copy ##{copy}")
165
- break
166
- end
167
- if copy.nil?
159
+ unless existing_copy_added(id, cps, score, r, json)
168
160
  Tempfile.open(['', Wallet::EXT]) do |f|
169
161
  r.http("/wallet/#{id}.bin").get_file(f)
170
162
  wallet = Wallet.new(f.path)
@@ -208,6 +200,17 @@ as copy ##{copy}/#{cps.all.count} in #{Age.new(start, limit: 4)}: \
208
200
  end
209
201
  end
210
202
 
203
+ def existing_copy_added(id, cps, score, r, json)
204
+ cps.all.each do |c|
205
+ next unless json['digest'] == OpenSSL::Digest::SHA256.file(c[:path]).hexdigest &&
206
+ json['size'] == File.size(c[:path])
207
+ copy = cps.add(IO.read(c[:path]), score.host, score.port, score.value, master: r.master?)
208
+ @log.debug("No need to fetch #{id} from #{r}, it's the same content as copy ##{copy}")
209
+ return true
210
+ end
211
+ false
212
+ end
213
+
211
214
  def digest(json)
212
215
  hash = json['digest']
213
216
  return '?' if hash.nil?
@@ -438,9 +438,11 @@ the node won\'t connect to the network like that; try to do "zold remote reset"
438
438
  @log.info('Reconnect is disabled because of --skip-reconnect')
439
439
  else
440
440
  require_relative 'routines/reconnect'
441
- metronome.add(Routines::Reconnect.new(opts, @remotes, farm, network: opts['network'], log: @log))
441
+ metronome.add(Routines::Reconnect.new(opts, @remotes, farm, log: @log))
442
442
  end
443
443
  end
444
+ require_relative 'routines/spread'
445
+ metronome.add(Routines::Spread.new(opts, @wallets, @remotes, @copies, log: @log))
444
446
  @log.info('Metronome started (use --no-metronome to disable it)')
445
447
  metronome
446
448
  end
@@ -95,6 +95,9 @@ Available options:"
95
95
  modified.uniq!
96
96
  @log.debug("Wallet #{id} propagated successfully, #{total} txns \
97
97
  in #{Age.new(start, limit: 20 + total * 0.005)}, #{modified.count} wallets affected")
98
+ modified.each do |w|
99
+ @wallets.acq(w, &:refurbish)
100
+ end
98
101
  modified
99
102
  end
100
103
  end
@@ -32,11 +32,10 @@ module Zold
32
32
  module Routines
33
33
  # Reconnect to the network
34
34
  class Reconnect
35
- def initialize(opts, remotes, farm = Farm::Empty.new, network: 'test', log: Log::NULL)
35
+ def initialize(opts, remotes, farm = Farm::Empty.new, log: Log::NULL)
36
36
  @opts = opts
37
37
  @remotes = remotes
38
38
  @farm = farm
39
- @network = network
40
39
  @log = log
41
40
  end
42
41
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require_relative '../../log'
24
+ require_relative '../../id'
25
+ require_relative '../../copies'
26
+ require_relative '../push'
27
+
28
+ # Spread random wallets to the network.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
31
+ # License:: MIT
32
+ module Zold
33
+ # Routines module
34
+ module Routines
35
+ # Spread them
36
+ class Spread
37
+ def initialize(opts, wallets, remotes, copies, log: Log::NULL)
38
+ @opts = opts
39
+ @wallets = wallets
40
+ @remotes = remotes
41
+ @copies = copies
42
+ @log = log
43
+ end
44
+
45
+ def exec(_ = 0)
46
+ sleep(60) unless @opts['routine-immediately']
47
+ @wallets.all.sample(100).each do |id|
48
+ next if Copies.new(File.join(@copies, id)).all.count < 2
49
+ Push.new(wallets: @wallets, remotes: @remotes, log: @log).run(
50
+ ['push', "--network=#{@opts['network']}", id.to_s]
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -53,10 +53,11 @@ module Zold
53
53
  File.basename(@dir)
54
54
  end
55
55
 
56
- def clean
56
+ # Delete all copies that are older than the "max" age provided, in seconds.
57
+ def clean(max: 24 * 60 * 60)
57
58
  Futex.new(file, log: @log).open do
58
59
  list = load
59
- list.reject! { |s| s[:time] < Time.now - 24 * 60 * 60 }
60
+ list.reject! { |s| s[:time] < Time.now - max }
60
61
  save(list)
61
62
  deleted = 0
62
63
  files.each do |f|
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'csv'
24
+
23
25
  # The ID of the wallet.
24
26
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
27
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
@@ -31,10 +33,15 @@ module Zold
31
33
  PTN = Regexp.new('^[0-9a-fA-F]{16}$')
32
34
  private_constant :PTN
33
35
 
36
+ # Returns a list of banned IDs, as strings
37
+ BANNED = begin
38
+ CSV.read(File.join(__dir__, '../../resources/banned-wallets.csv')).map { |r| r[0] }
39
+ end
40
+
34
41
  def self.generate_id
35
42
  loop do
36
43
  id = format('%016x', rand(2**32..2**64 - 1))
37
- next if IO.read(File.join(__dir__, '../../resources/banned-wallets.csv')).include?("\"#{id}\"")
44
+ next if Id::BANNED.include?(id)
38
45
  return id
39
46
  end
40
47
  end
@@ -74,22 +74,25 @@ module Zold
74
74
  raise 'Body can\'t be nil' if body.nil?
75
75
  start = Time.now
76
76
  copies = Copies.new(File.join(@copies, id.to_s))
77
- localhost = '0.0.0.0'
78
- copies.add(body, localhost, Remotes::PORT, 0)
77
+ host = '0.0.0.0'
78
+ copies.add(body, host, Remotes::PORT, 0)
79
79
  unless @remotes.all.empty?
80
80
  Fetch.new(
81
81
  wallets: @wallets, remotes: @remotes, copies: copies.root, log: @log
82
82
  ).run(['fetch', id.to_s, "--ignore-node=#{@address}", "--network=#{@network}", '--quiet-if-absent'])
83
83
  end
84
84
  modified = merge(id, copies)
85
- Clean.new(wallets: @wallets, copies: copies.root, log: @log).run(['clean', id.to_s])
86
- copies.remove(localhost, Remotes::PORT)
85
+ Clean.new(wallets: @wallets, copies: copies.root, log: @log).run(
86
+ ['clean', id.to_s, '--max-age=1']
87
+ )
88
+ copies.remove(host, Remotes::PORT)
87
89
  modified += Rebase.new(wallets: @wallets, log: @log).run(['rebase', id.to_s])
88
90
  if modified.empty?
89
91
  @log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and not modified anything")
90
92
  else
91
93
  @log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and modified #{modified.join(', ')}")
92
94
  end
95
+ modified << id if copies.all.count > 1
93
96
  sec = (Time.now - start).round(2)
94
97
  @mutex.synchronize do
95
98
  @history.shift if @history.length >= 16
@@ -313,7 +313,8 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
313
313
  "Balance: #{wallet.balance.to_zld(8)} ZLD (#{wallet.balance.to_i} zents)",
314
314
  "Transactions: #{wallet.txns.count}",
315
315
  "Taxes: #{Tax.new(wallet).paid} paid, the debt is #{Tax.new(wallet).debt}",
316
- "File size: #{Size.new(wallet.size)}, #{Copies.new(File.join(settings.copies, wallet.id)).all.count} copies",
316
+ "File size: #{Size.new(wallet.size)}/#{wallet.size}, \
317
+ #{Copies.new(File.join(settings.copies, wallet.id)).all.count} copies",
317
318
  "Modified: #{wallet.mtime.utc.iso8601} (#{Age.new(wallet.mtime.utc.iso8601)} ago)",
318
319
  "Digest: #{wallet.digest}"
319
320
  ].join("\n")
@@ -523,7 +524,7 @@ time to stop; use --skip-oom to never quit")
523
524
  end
524
525
 
525
526
  def ban(id)
526
- return unless IO.read(File.join(__dir__, '../../../resources/banned-wallets.csv')).include?("\"#{id}\"")
527
+ return unless Id::BANNED.include?(id.to_s)
527
528
  error(404, "The wallet #{id} is banned")
528
529
  end
529
530
 
@@ -162,8 +162,8 @@ doesn't have this transaction: \"#{txn.to_text}\"")
162
162
  def save(file, overwrite: false)
163
163
  raise 'You have to join at least one wallet in' if empty?
164
164
  before = ''
165
- before = OpenSSL::Digest::SHA256.file(file).hexdigest if File.exist?(file)
166
165
  wallet = Wallet.new(file)
166
+ before = wallet.digest if wallet.exists?
167
167
  wallet.init(@id, @key, overwrite: overwrite, network: @network)
168
168
  File.open(file, 'a') do |f|
169
169
  @txns.each do |txn|
@@ -171,8 +171,7 @@ doesn't have this transaction: \"#{txn.to_text}\"")
171
171
  end
172
172
  end
173
173
  wallet.refurbish
174
- after = OpenSSL::Digest::SHA256.file(file).hexdigest
175
- before != after
174
+ before != wallet.digest
176
175
  end
177
176
  end
178
177
  end
@@ -25,7 +25,7 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.26.10'
28
+ VERSION = '0.26.11'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
@@ -45,9 +45,7 @@ class FakeHome
45
45
  def run
46
46
  Dir.mktmpdir do |dir|
47
47
  FileUtils.copy(File.expand_path(File.join(__dir__, '../fixtures/id_rsa')), File.join(dir, 'id_rsa'))
48
- result = yield FakeHome.new(dir, log: @log)
49
- sleep 0.5 # It's a workaround against a bug (without it tests fail sporadically)
50
- result
48
+ yield FakeHome.new(dir, log: @log)
51
49
  end
52
50
  end
53
51
 
@@ -37,6 +37,10 @@ class TestId < Zold::Test
37
37
  end
38
38
  end
39
39
 
40
+ def test_list_of_banned_ids_is_not_empty
41
+ assert(!Zold::Id::BANNED.empty?)
42
+ end
43
+
40
44
  def test_checks_for_root
41
45
  assert(Zold::Id::ROOT.root?)
42
46
  end
@@ -32,7 +32,7 @@ require_relative '../fake_home'
32
32
  # License:: MIT
33
33
  class TestDeleteBannedWallets < Zold::Test
34
34
  def test_delete_them
35
- id = Zold::Id.new(CSV.read(File.join(__dir__, '../../resources/banned-wallets.csv'))[0][0])
35
+ id = Zold::Id.new(Zold::Id::BANNED[0])
36
36
  FakeHome.new(log: test_log).run do |home|
37
37
  home.create_wallet(id)
38
38
  FileUtils.mkdir_p(File.join(home.dir, 'a/b/c'))
@@ -33,12 +33,11 @@ module Zold
33
33
  end
34
34
 
35
35
  def exec
36
- banned = IO.read(File.join(__dir__, '../resources/banned-wallets.csv'))
37
36
  DirItems.new(@home).fetch.each do |path|
38
37
  name = File.basename(path)
39
38
  next unless name =~ /^[a-f0-9]{16}#{Wallet::EXT}$/
40
- id = name[0..15]
41
- next unless banned.include?("\"#{id}\"")
39
+ id = Id.new(name[0..15])
40
+ next unless Id::BANNED.include?(id.to_s)
42
41
  path = File.join(@home, path)
43
42
  File.rename(path, path + '-banned')
44
43
  @log.info("Wallet file #{path} renamed, since wallet #{id} is banned")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.10
4
+ version: 0.26.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-08 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -641,6 +641,7 @@ files:
641
641
  - lib/zold/commands/routines/audit.rb
642
642
  - lib/zold/commands/routines/gc.rb
643
643
  - lib/zold/commands/routines/reconnect.rb
644
+ - lib/zold/commands/routines/spread.rb
644
645
  - lib/zold/commands/show.rb
645
646
  - lib/zold/commands/taxes.rb
646
647
  - lib/zold/commands/thread_badge.rb
@@ -772,7 +773,7 @@ licenses:
772
773
  - MIT
773
774
  metadata: {}
774
775
  post_install_message: |-
775
- Thanks for installing Zold 0.26.10!
776
+ Thanks for installing Zold 0.26.11!
776
777
  Study our White Paper: https://papers.zold.io/wp.pdf
777
778
  Read our blog posts: https://blog.zold.io
778
779
  Try ZLD online wallet at: https://wts.zold.io