zold 0.16.29 → 0.16.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/commands/clean.rb +1 -1
- data/lib/zold/commands/node.rb +12 -1
- data/lib/zold/commands/remote.rb +3 -1
- data/lib/zold/http.rb +2 -2
- data/lib/zold/node/async_entrance.rb +4 -2
- data/lib/zold/node/front.rb +7 -5
- data/lib/zold/remotes.rb +20 -19
- data/lib/zold/version.rb +1 -1
- data/test/node/test_front.rb +2 -2
- data/test/test__helper.rb +1 -0
- data/test/test_remotes.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290d87dc57f2e51e44dffc3f55ca05fbcb9903988070583a5c074bd8482ee261
|
4
|
+
data.tar.gz: 59842e6f21d7c959b1e03900d971d7f1d193e2e16cb6eddb0e58d909bef06e9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '086dcfc48660670347ae67d832b3a915e96c67dc870abea06589e0d4a5156aca5adcf5abd028a123500ad6962a410abbd489fac6674c21b9de942fa292b4921c'
|
7
|
+
data.tar.gz: 48eeebe1591746a0d48f9ba65c644c83f5a621a6426500544e80f789bca0ac33895f67ae62d97e28ae117618956c24aa29971111c0daa86133c5485547811a58
|
data/lib/zold/commands/clean.rb
CHANGED
@@ -64,7 +64,7 @@ Available options:"
|
|
64
64
|
deleted = cps.clean
|
65
65
|
list = cps.all.map do |c|
|
66
66
|
wallet = Wallet.new(c[:path])
|
67
|
-
"
|
67
|
+
"#{c[:name]}: #{c[:score]} #{wallet.mnemo} \
|
68
68
|
#{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}"
|
69
69
|
end
|
70
70
|
@log.debug(
|
data/lib/zold/commands/node.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'open3'
|
24
24
|
require 'slop'
|
25
25
|
require 'backtrace'
|
26
|
+
require 'zache'
|
26
27
|
require 'concurrent'
|
27
28
|
require 'zold/score'
|
28
29
|
require_relative 'thread_badge'
|
@@ -119,6 +120,12 @@ module Zold
|
|
119
120
|
o.bool '--routine-immediately',
|
120
121
|
'Run all routines immediately, without waiting between executions (for testing mostly)',
|
121
122
|
default: false
|
123
|
+
o.bool '--no-cache',
|
124
|
+
'Skip caching of front JSON pages (will seriously slow down, mostly useful for testing)',
|
125
|
+
default: false
|
126
|
+
o.integer '--queue-limit',
|
127
|
+
'The maximum number of wallets to be accepted via PUSH and stored in the queue (default: 4096)',
|
128
|
+
default: 4096
|
122
129
|
o.string '--expose-version',
|
123
130
|
"The version of the software to expose in JSON (default: #{VERSION})",
|
124
131
|
default: VERSION
|
@@ -177,6 +184,7 @@ module Zold
|
|
177
184
|
@log.info("Zold gem version: #{Zold::VERSION}")
|
178
185
|
@log.info("Zold protocol version: #{Zold::PROTOCOL}")
|
179
186
|
@log.info("Network ID: #{opts['network']}")
|
187
|
+
@log.info('Front caching is disabled via --no-cache') if opts['no-cache']
|
180
188
|
host = opts[:host] || ip
|
181
189
|
port = opts[:port]
|
182
190
|
address = "#{host}:#{port}".downcase
|
@@ -192,6 +200,7 @@ module Zold
|
|
192
200
|
Zold::Remote.new(remotes: @remotes).run(['remote', 'remove', host, port.to_s])
|
193
201
|
@log.info("Removed current node (#{address}) from list of remotes")
|
194
202
|
end
|
203
|
+
Front.set(:zache, Zache.new)
|
195
204
|
Front.set(:wallets, @wallets)
|
196
205
|
Front.set(:remotes, @remotes)
|
197
206
|
Front.set(:copies, @copies)
|
@@ -229,7 +238,9 @@ module Zold
|
|
229
238
|
log: @log,
|
230
239
|
ignore_score_weakeness: opts['ignore-score-weakness']
|
231
240
|
),
|
232
|
-
File.join(home, '.zoldata/async-entrance'),
|
241
|
+
File.join(home, '.zoldata/async-entrance'),
|
242
|
+
log: @log,
|
243
|
+
queue_limit: opts['queue-limit']
|
233
244
|
),
|
234
245
|
@wallets
|
235
246
|
),
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -176,7 +176,9 @@ Available options:"
|
|
176
176
|
end
|
177
177
|
|
178
178
|
def defaults
|
179
|
-
@remotes.defaults
|
179
|
+
@remotes.defaults do |host, port|
|
180
|
+
!opts['ignore-node'].include?("#{host}:#{port}")
|
181
|
+
end
|
180
182
|
@log.debug("Default remote nodes were added to the list, #{@remotes.all.count} total")
|
181
183
|
end
|
182
184
|
|
data/lib/zold/http.rb
CHANGED
@@ -54,11 +54,11 @@ module Zold
|
|
54
54
|
PROTOCOL_HEADER = 'X-Zold-Protocol'
|
55
55
|
|
56
56
|
# Read timeout in seconds
|
57
|
-
READ_TIMEOUT =
|
57
|
+
READ_TIMEOUT = 2
|
58
58
|
private_constant :READ_TIMEOUT
|
59
59
|
|
60
60
|
# Connect timeout in seconds
|
61
|
-
CONNECT_TIMEOUT = 0.
|
61
|
+
CONNECT_TIMEOUT = 0.8
|
62
62
|
private_constant :CONNECT_TIMEOUT
|
63
63
|
|
64
64
|
def initialize(uri:, score: Score::ZERO, network: 'test')
|
@@ -36,12 +36,14 @@ require_relative '../dir_items'
|
|
36
36
|
module Zold
|
37
37
|
# The entrance
|
38
38
|
class AsyncEntrance
|
39
|
-
def initialize(entrance, dir, log: Log::NULL,
|
39
|
+
def initialize(entrance, dir, log: Log::NULL,
|
40
|
+
threads: [Concurrent.processor_count, 8].max, queue_limit: 8)
|
40
41
|
@entrance = entrance
|
41
42
|
@dir = File.expand_path(dir)
|
42
43
|
@log = log
|
43
44
|
@total = threads
|
44
45
|
@queue = Queue.new
|
46
|
+
@queue_limit = queue_limit
|
45
47
|
end
|
46
48
|
|
47
49
|
def to_json
|
@@ -78,7 +80,7 @@ module Zold
|
|
78
80
|
|
79
81
|
# Always returns an array with a single ID of the pushed wallet
|
80
82
|
def push(id, body)
|
81
|
-
raise "Queue is too long (#{@queue.size} wallets), try again later" if @queue.size >
|
83
|
+
raise "Queue is too long (#{@queue.size} wallets), try again later" if @queue.size > @queue_limit
|
82
84
|
start = Time.now
|
83
85
|
loop do
|
84
86
|
uuid = SecureRandom.uuid
|
data/lib/zold/node/front.rb
CHANGED
@@ -72,7 +72,7 @@ module Zold
|
|
72
72
|
set :remotes, nil # to be injected at node.rb
|
73
73
|
set :copies, nil # to be injected at node.rb
|
74
74
|
set :node_alias, nil # to be injected at node.rb
|
75
|
-
set :zache,
|
75
|
+
set :zache, nil # to be injected at node.rb
|
76
76
|
end
|
77
77
|
use Rack::Deflater
|
78
78
|
|
@@ -435,17 +435,19 @@ in #{Age.new(@start, limit: 1)}")
|
|
435
435
|
# we must find a way to count them somehow faster.
|
436
436
|
def total_wallets
|
437
437
|
return 256 if settings.opts['network'] == Wallet::MAINET
|
438
|
-
settings.wallets.
|
438
|
+
settings.zache.get(:wallets, lifetime: settings.opts['no-cache'] ? 0 : 60) do
|
439
|
+
settings.wallets.all.count
|
440
|
+
end
|
439
441
|
end
|
440
442
|
|
441
443
|
def all_remotes
|
442
|
-
settings.zache.get(:remotes, lifetime: settings.opts['
|
444
|
+
settings.zache.get(:remotes, lifetime: settings.opts['no-cache'] ? 0 : 60) do
|
443
445
|
settings.remotes.all
|
444
446
|
end
|
445
447
|
end
|
446
448
|
|
447
449
|
def processes_count
|
448
|
-
settings.zache.get(:processes, lifetime: settings.opts['
|
450
|
+
settings.zache.get(:processes, lifetime: settings.opts['no-cache'] ? 0 : 60) do
|
449
451
|
processes.count
|
450
452
|
end
|
451
453
|
end
|
@@ -459,7 +461,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
459
461
|
end
|
460
462
|
|
461
463
|
def score
|
462
|
-
settings.zache.get(:score, lifetime: settings.opts['
|
464
|
+
settings.zache.get(:score, lifetime: settings.opts['no-cache'] ? 0 : 60) do
|
463
465
|
b = settings.farm.best
|
464
466
|
raise 'Score is empty, there is something wrong with the Farm!' if b.empty?
|
465
467
|
b[0]
|
data/lib/zold/remotes.rb
CHANGED
@@ -128,7 +128,7 @@ module Zold
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def all
|
131
|
-
list = load
|
131
|
+
list = Futex.new(@file).open(false) { load }
|
132
132
|
max_score = list.map { |r| r[:score] }.max || 0
|
133
133
|
max_score = 1 if max_score.zero?
|
134
134
|
max_errors = list.map { |r| r[:errors] }.max || 0
|
@@ -144,6 +144,9 @@ module Zold
|
|
144
144
|
|
145
145
|
def defaults
|
146
146
|
DEFS.each do |r|
|
147
|
+
if block_given?
|
148
|
+
next unless yield(r[0], r[1].to_i)
|
149
|
+
end
|
147
150
|
add(r[0], r[1].to_i)
|
148
151
|
end
|
149
152
|
end
|
@@ -152,7 +155,8 @@ module Zold
|
|
152
155
|
raise 'Port has to be of type Integer' unless port.is_a?(Integer)
|
153
156
|
raise 'Host can\'t be nil' if host.nil?
|
154
157
|
raise 'Port can\'t be nil' if port.nil?
|
155
|
-
|
158
|
+
list = Futex.new(@file).open(false) { load }
|
159
|
+
!list.find { |r| r[:host] == host.downcase && r[:port] == port }.nil?
|
156
160
|
end
|
157
161
|
|
158
162
|
def add(host, port = PORT)
|
@@ -240,8 +244,20 @@ module Zold
|
|
240
244
|
private
|
241
245
|
|
242
246
|
def modify
|
243
|
-
|
244
|
-
|
247
|
+
FileUtils.mkdir_p(File.dirname(@file))
|
248
|
+
Futex.new(@file).open(true) do
|
249
|
+
list = yield(load)
|
250
|
+
IO.write(
|
251
|
+
@file,
|
252
|
+
list.uniq { |r| "#{r[:host]}:#{r[:port]}" }.map do |r|
|
253
|
+
[
|
254
|
+
r[:host],
|
255
|
+
r[:port],
|
256
|
+
r[:score],
|
257
|
+
r[:errors]
|
258
|
+
].join(',')
|
259
|
+
end.join("\n")
|
260
|
+
)
|
245
261
|
end
|
246
262
|
end
|
247
263
|
|
@@ -273,20 +289,5 @@ module Zold
|
|
273
289
|
[]
|
274
290
|
end
|
275
291
|
end
|
276
|
-
|
277
|
-
def save(list)
|
278
|
-
FileUtils.mkdir_p(File.dirname(@file))
|
279
|
-
IO.write(
|
280
|
-
@file,
|
281
|
-
list.uniq { |r| "#{r[:host]}:#{r[:port]}" }.map do |r|
|
282
|
-
[
|
283
|
-
r[:host],
|
284
|
-
r[:port],
|
285
|
-
r[:score],
|
286
|
-
r[:errors]
|
287
|
-
].join(',')
|
288
|
-
end.join("\n")
|
289
|
-
)
|
290
|
-
end
|
291
292
|
end
|
292
293
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/node/test_front.rb
CHANGED
@@ -112,7 +112,7 @@ class FrontTest < Zold::Test
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_updates_list_of_remotes
|
115
|
-
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
115
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--no-cache']) do |port|
|
116
116
|
score = Zold::Score.new(
|
117
117
|
host: 'localhost', port: port, invoice: 'NOPREFIX@ffffffffffffffff', strength: 1
|
118
118
|
).next.next.next.next
|
@@ -128,7 +128,7 @@ class FrontTest < Zold::Test
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def test_increments_score
|
131
|
-
FakeNode.new(log: test_log).run(['--threads=1', '--strength=1', '--no-metronome']) do |port|
|
131
|
+
FakeNode.new(log: test_log).run(['--threads=1', '--strength=1', '--no-metronome', '--no-cache']) do |port|
|
132
132
|
3.times do |i|
|
133
133
|
assert_equal_wait(true) do
|
134
134
|
response = Zold::Http.new(uri: "http://localhost:#{port}/").get
|
data/test/test__helper.rb
CHANGED
data/test/test_remotes.rb
CHANGED
@@ -200,8 +200,12 @@ class TestRemotes < Zold::Test
|
|
200
200
|
Dir.mktmpdir do |dir|
|
201
201
|
remotes = Zold::Remotes.new(file: File.join(dir, 'xx.csv'))
|
202
202
|
remotes.clean
|
203
|
-
|
204
|
-
|
203
|
+
host = '127.0.0.1'
|
204
|
+
Threads.new(2).assert(100) do |_, r|
|
205
|
+
port = 8080 + r
|
206
|
+
remotes.add(host, port)
|
207
|
+
remotes.error(host, port)
|
208
|
+
assert(remotes.all.find { |x| x[:port] == port })
|
205
209
|
end
|
206
210
|
assert_equal(100, remotes.all.count)
|
207
211
|
end
|
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.16.
|
4
|
+
version: 0.16.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -697,7 +697,7 @@ licenses:
|
|
697
697
|
- MIT
|
698
698
|
metadata: {}
|
699
699
|
post_install_message: |-
|
700
|
-
Thanks for installing Zold 0.16.
|
700
|
+
Thanks for installing Zold 0.16.30!
|
701
701
|
Study our White Paper: https://papers.zold.io/wp.pdf
|
702
702
|
Read our blog posts: https://blog.zold.io
|
703
703
|
Try online wallet at: https://wts.zold.io
|