zold 0.26.10 → 0.26.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/zold/commands/clean.rb +5 -2
- data/lib/zold/commands/fetch.rb +12 -9
- data/lib/zold/commands/node.rb +3 -1
- data/lib/zold/commands/propagate.rb +3 -0
- data/lib/zold/commands/routines/reconnect.rb +1 -2
- data/lib/zold/commands/routines/spread.rb +56 -0
- data/lib/zold/copies.rb +3 -2
- data/lib/zold/id.rb +8 -1
- data/lib/zold/node/entrance.rb +7 -4
- data/lib/zold/node/front.rb +3 -2
- data/lib/zold/patch.rb +2 -3
- data/lib/zold/version.rb +1 -1
- data/test/fake_home.rb +1 -3
- data/test/test_id.rb +4 -0
- data/test/upgrades/test_delete_banned_wallets.rb +1 -1
- data/upgrades/delete_banned_wallets.rb +2 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d0d8d5abb824adcb3222588744bd9f51b095b6a35d7de3401d6155867899bbd
|
4
|
+
data.tar.gz: 04e0597677b18e5f3e63b2492b5541352391522d3f92b092bddba7095dcd8c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9702cf51e271bbdad9ccb1a635e3274c49499e5070b3b18f20e239f97060c2f2edfc7b19b18f4af90c989eb33fb987c96312ccab8c172c26a131a4a0ebdc73f1
|
7
|
+
data.tar.gz: 96a39ed4f622342873430f0b9183ea1370f4520b3042d20fc5f3b40e313940f0fd844750ce6d5fcfbf12166b252c6c4408ef6fad446e3308c3d39e618c4e5f6a
|
data/lib/zold/commands/clean.rb
CHANGED
@@ -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} \
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -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
|
-
|
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?
|
data/lib/zold/commands/node.rb
CHANGED
@@ -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,
|
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,
|
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
|
data/lib/zold/copies.rb
CHANGED
@@ -53,10 +53,11 @@ module Zold
|
|
53
53
|
File.basename(@dir)
|
54
54
|
end
|
55
55
|
|
56
|
-
|
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 -
|
60
|
+
list.reject! { |s| s[:time] < Time.now - max }
|
60
61
|
save(list)
|
61
62
|
deleted = 0
|
62
63
|
files.each do |f|
|
data/lib/zold/id.rb
CHANGED
@@ -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
|
44
|
+
next if Id::BANNED.include?(id)
|
38
45
|
return id
|
39
46
|
end
|
40
47
|
end
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -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
|
-
|
78
|
-
copies.add(body,
|
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(
|
86
|
-
|
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
|
data/lib/zold/node/front.rb
CHANGED
@@ -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)}
|
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
|
527
|
+
return unless Id::BANNED.include?(id.to_s)
|
527
528
|
error(404, "The wallet #{id} is banned")
|
528
529
|
end
|
529
530
|
|
data/lib/zold/patch.rb
CHANGED
@@ -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
|
-
|
175
|
-
before != after
|
174
|
+
before != wallet.digest
|
176
175
|
end
|
177
176
|
end
|
178
177
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/fake_home.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/test/test_id.rb
CHANGED
@@ -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(
|
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
|
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.
|
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-
|
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.
|
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
|