zold 0.14.37 → 0.14.38
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/.gitignore +1 -0
- data/fixtures/merge/into-no-wallet/copies/0123456789abcdef/{1.z → 1.zc} +0 -0
- data/fixtures/merge/into-no-wallet/copies/0123456789abcdef/{scores.z → scores.zc} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{1.z → 1.zc} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{2.z → 2.zc} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{3.z → 3.zc} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{4.z → 4.zc} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{5.z → 5.zc} +0 -0
- data/fixtures/merge/random-expenses/copies/0123456789abcdef/{scores.z → scores.zc} +0 -0
- data/fixtures/merge/simple-case/copies/0123456789abcdef/{1.z → 1.zc} +0 -0
- data/fixtures/merge/simple-case/copies/0123456789abcdef/{scores.z → scores.zc} +0 -0
- data/fixtures/scripts/redeploy-on-upgrade.sh +1 -1
- data/lib/zold/commands/node.rb +33 -4
- data/lib/zold/copies.rb +10 -7
- data/lib/zold/node/farm.rb +9 -6
- data/lib/zold/node/front.rb +9 -0
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_merge.rb +1 -1
- data/test/test_copies.rb +2 -2
- data/test/test_zold.rb +1 -1
- data/zold.log +12 -0
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3fc39017077100e9934e90a71f121139e4a1432
|
4
|
+
data.tar.gz: da8496c1bdfa6398785e5a7ab464eff0a45e02a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2a9f4c3b526399c34bf84c05a66c90db67e39649ea6347abd74bf2428b848128991a73810ff06d9a421e2967140de674fa177b52bfa3f82d5e8bdf69fa4f25e
|
7
|
+
data.tar.gz: 85720186b77dec3343a10968310d0001a94940722490e2041b55c593ee7b230f8ebb6a5f9112622e10b78e717abd9778cc24f1b0b142d7d79dec485717638c48
|
data/.gitignore
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -4,7 +4,7 @@ function start_node {
|
|
4
4
|
mkdir $1
|
5
5
|
cd $1
|
6
6
|
zold remote clean
|
7
|
-
zold node $3 --nohup --nohup-command='touch restarted' --nohup-log=log --nohup-max-cycles=0 \
|
7
|
+
zold node $3 --nohup --nohup-command='touch restarted' --nohup-log=log --nohup-max-cycles=0 --nohup-log-truncate=10240 \
|
8
8
|
--expose-version=$2 --save-pid=pid --routine-immediately \
|
9
9
|
--verbose --trace --invoice=REDEPLOY@ffffffffffffffff \
|
10
10
|
--host=localhost --port=$1 --bind-port=$1 --threads=0 > /dev/null 2>&1
|
data/lib/zold/commands/node.rb
CHANGED
@@ -96,6 +96,9 @@ module Zold
|
|
96
96
|
o.string '--nohup-log',
|
97
97
|
'The file to log output into (default: zold.log)',
|
98
98
|
default: 'zold.log'
|
99
|
+
o.integer '--nohup-log-truncate',
|
100
|
+
'The maximum amount of bytes to keep in the file, and truncate it in half if it grows bigger',
|
101
|
+
default: 1024 * 1024
|
99
102
|
o.string '--halt-code',
|
100
103
|
'The value of HTTP query parameter "halt," which will cause the front-end immediate termination',
|
101
104
|
default: ''
|
@@ -138,7 +141,7 @@ module Zold
|
|
138
141
|
return
|
139
142
|
end
|
140
143
|
raise '--invoice is mandatory' unless opts['invoice']
|
141
|
-
if opts[
|
144
|
+
if opts['nohup']
|
142
145
|
pid = nohup(opts)
|
143
146
|
File.write(opts['save-pid'], pid) if opts['save-pid']
|
144
147
|
@log.debug("Process ID #{pid} saved into \"#{opts['save-pid']}\"")
|
@@ -148,6 +151,7 @@ module Zold
|
|
148
151
|
@log = Trace.new(@log, opts['trace-length'])
|
149
152
|
Front.set(:log, @log)
|
150
153
|
Front.set(:trace, @log)
|
154
|
+
Front.set(:nohup_log, opts['nohup-log']) if opts['nohup-log']
|
151
155
|
Front.set(:version, opts['expose-version'])
|
152
156
|
Front.set(:protocol, Zold::PROTOCOL)
|
153
157
|
Front.set(:logging, @log.debug?)
|
@@ -264,7 +268,7 @@ module Zold
|
|
264
268
|
|
265
269
|
def nohup(opts)
|
266
270
|
pid = fork do
|
267
|
-
nohup_log = NohupLog.new(opts['nohup-log'])
|
271
|
+
nohup_log = NohupLog.new(opts['nohup-log'], opts['nohup-log-truncate'])
|
268
272
|
Signal.trap('HUP') do
|
269
273
|
nohup_log.print("Received HUP, ignoring...\n")
|
270
274
|
end
|
@@ -273,7 +277,7 @@ module Zold
|
|
273
277
|
exit(-1)
|
274
278
|
end
|
275
279
|
myself = File.expand_path($PROGRAM_NAME)
|
276
|
-
args = ARGV.delete_if { |a| a.start_with?('--
|
280
|
+
args = ARGV.delete_if { |a| a.start_with?('--home') || a == '--nohup' }
|
277
281
|
cycle = 0
|
278
282
|
loop do
|
279
283
|
begin
|
@@ -326,12 +330,37 @@ module Zold
|
|
326
330
|
|
327
331
|
# Log facility for nohup
|
328
332
|
class NohupLog
|
329
|
-
def initialize(file)
|
333
|
+
def initialize(file, max)
|
330
334
|
@file = file
|
335
|
+
raise "Truncation size is too small (#{max}), should be over 10Kb" if max < 10 * 1024
|
336
|
+
@max = max
|
331
337
|
end
|
332
338
|
|
333
339
|
def print(data)
|
334
340
|
File.open(@file, 'a') { |f| f.print(data) }
|
341
|
+
return if File.size(@file) < @max
|
342
|
+
temp = Tempfile.new
|
343
|
+
total = copy(@file, temp)
|
344
|
+
unit = File.size(@file) / total
|
345
|
+
tail = total - @max / (2 * unit)
|
346
|
+
copy(temp, @file, tail)
|
347
|
+
File.delete(temp)
|
348
|
+
File.open(@file, 'a') do |f|
|
349
|
+
f.print("The file was truncated, because it was over the quota of #{@max} bytes, \
|
350
|
+
#{tail} lines left out of #{total}, average line length was #{unit} bytes\n\n")
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
def copy(source, target, start = 0)
|
355
|
+
total = 0
|
356
|
+
File.open(target, 'w') do |t|
|
357
|
+
File.open(source, 'r').each do |line|
|
358
|
+
next unless total >= start
|
359
|
+
t.print(line)
|
360
|
+
total += 1
|
361
|
+
end
|
362
|
+
end
|
363
|
+
total
|
335
364
|
end
|
336
365
|
end
|
337
366
|
|
data/lib/zold/copies.rb
CHANGED
@@ -34,6 +34,9 @@ require_relative 'backtrace'
|
|
34
34
|
module Zold
|
35
35
|
# All copies
|
36
36
|
class Copies
|
37
|
+
# Extension for copy files
|
38
|
+
EXT = '.zc'
|
39
|
+
|
37
40
|
def initialize(dir, log: Log::Quiet.new)
|
38
41
|
raise 'Dir can\'t be nil' if dir.nil?
|
39
42
|
@dir = dir
|
@@ -57,7 +60,7 @@ module Zold
|
|
57
60
|
save(list)
|
58
61
|
deleted = 0
|
59
62
|
files.each do |f|
|
60
|
-
next unless list.find { |s| s[:name] == File.basename(f,
|
63
|
+
next unless list.find { |s| s[:name] == File.basename(f, Copies::EXT) }.nil?
|
61
64
|
file = File.join(@dir, f)
|
62
65
|
size = File.size(file)
|
63
66
|
File.delete(file)
|
@@ -99,17 +102,17 @@ module Zold
|
|
99
102
|
FileUtils.mkdir_p(@dir)
|
100
103
|
list = load
|
101
104
|
target = list.find do |s|
|
102
|
-
f = File.join(@dir, "#{s[:name]}#{
|
105
|
+
f = File.join(@dir, "#{s[:name]}#{Copies::EXT}")
|
103
106
|
File.exist?(f) && AtomicFile.new(f).read == content
|
104
107
|
end
|
105
108
|
if target.nil?
|
106
109
|
max = Dir.new(@dir)
|
107
|
-
.select { |f| File.basename(f,
|
110
|
+
.select { |f| File.basename(f, Copies::EXT) =~ /^[0-9]+$/ }
|
108
111
|
.map(&:to_i)
|
109
112
|
.max
|
110
113
|
max = 0 if max.nil?
|
111
114
|
name = (max + 1).to_s
|
112
|
-
AtomicFile.new(File.join(@dir, "#{name}#{
|
115
|
+
AtomicFile.new(File.join(@dir, "#{name}#{Copies::EXT}")).write(content)
|
113
116
|
else
|
114
117
|
name = target[:name]
|
115
118
|
end
|
@@ -131,7 +134,7 @@ module Zold
|
|
131
134
|
load.group_by { |s| s[:name] }.map do |name, scores|
|
132
135
|
{
|
133
136
|
name: name,
|
134
|
-
path: File.join(@dir, "#{name}#{
|
137
|
+
path: File.join(@dir, "#{name}#{Copies::EXT}"),
|
135
138
|
score: scores.select { |s| s[:time] > Time.now - 24 * 60 * 60 }
|
136
139
|
.map { |s| s[:score] }
|
137
140
|
.inject(&:+) || 0
|
@@ -169,11 +172,11 @@ module Zold
|
|
169
172
|
end
|
170
173
|
|
171
174
|
def files
|
172
|
-
Dir.new(@dir).select { |f| File.basename(f,
|
175
|
+
Dir.new(@dir).select { |f| File.basename(f, Copies::EXT) =~ /^[0-9]+$/ }
|
173
176
|
end
|
174
177
|
|
175
178
|
def file
|
176
|
-
File.join(@dir, "scores#{
|
179
|
+
File.join(@dir, "scores#{Copies::EXT}")
|
177
180
|
end
|
178
181
|
end
|
179
182
|
end
|
data/lib/zold/node/farm.rb
CHANGED
@@ -77,6 +77,7 @@ module Zold
|
|
77
77
|
@log.info('Zero-threads farm won\'t score anything!') if threads.zero?
|
78
78
|
cleanup(host, port, strength, threads)
|
79
79
|
@log.info("#{@pipeline.size} scores pre-loaded, the best is: #{best[0]}")
|
80
|
+
@alive = true
|
80
81
|
@threads = (1..threads).map do |t|
|
81
82
|
Thread.new do
|
82
83
|
Thread.current.abort_on_exception = true
|
@@ -89,17 +90,17 @@ module Zold
|
|
89
90
|
end
|
90
91
|
end
|
91
92
|
end
|
92
|
-
@alive = true
|
93
93
|
@cleanup = Thread.new do
|
94
94
|
Thread.current.abort_on_exception = true
|
95
95
|
Thread.current.name = 'cleanup'
|
96
96
|
loop do
|
97
|
-
|
97
|
+
max = 600
|
98
|
+
a = (0..max).take_while do
|
98
99
|
sleep 0.1
|
99
100
|
@alive
|
100
101
|
end
|
101
|
-
unless a.count ==
|
102
|
-
@log.info("It's time to stop the cleanup thread...")
|
102
|
+
unless a.count == max
|
103
|
+
@log.info("It's time to stop the cleanup thread (#{a.count} != #{max}, alive=#{@alive})...")
|
103
104
|
break
|
104
105
|
end
|
105
106
|
VerboseThread.new(@log).run do
|
@@ -181,8 +182,10 @@ module Zold
|
|
181
182
|
loop do
|
182
183
|
begin
|
183
184
|
buffer << stdout.read_nonblock(1024)
|
184
|
-
|
185
|
-
|
185
|
+
# rubocop:disable Lint/HandleExceptions
|
186
|
+
rescue IO::WaitReadable => _
|
187
|
+
# rubocop:enable Lint/HandleExceptions
|
188
|
+
# nothing to do here
|
186
189
|
end
|
187
190
|
if buffer.end_with?("\n") && thr.value.to_i.zero?
|
188
191
|
score = Score.parse(buffer.strip)
|
data/lib/zold/node/front.rb
CHANGED
@@ -62,6 +62,7 @@ module Zold
|
|
62
62
|
set :protocol, PROTOCOL # to be injected at node.rb
|
63
63
|
set :ignore_score_weakness, false # to be injected at node.rb
|
64
64
|
set :reboot, false # to be injected at node.rb
|
65
|
+
set :nohup_log, false # to be injected at node.rb
|
65
66
|
set :home, nil? # to be injected at node.rb
|
66
67
|
set :logging, true # to be injected at node.rb
|
67
68
|
set :address, nil? # to be injected at node.rb
|
@@ -144,6 +145,14 @@ while #{settings.address} is in '#{settings.network}'"
|
|
144
145
|
settings.trace.to_s
|
145
146
|
end
|
146
147
|
|
148
|
+
get '/nohup_log' do
|
149
|
+
raise 'Run it with --nohup in order to see this log' if settings.nohup_log.nil?
|
150
|
+
raise "Log not found at #{settings.nohup_log}" unless File.exist?(settings.nohup_log)
|
151
|
+
response.headers['Content-Type'] = 'text/plain'
|
152
|
+
response.headers['Content-Disposition'] = "attachment; filename='#{File.basename(settings.nohup_log)}'"
|
153
|
+
File.read(settings.nohup_log)
|
154
|
+
end
|
155
|
+
|
147
156
|
get '/favicon.ico' do
|
148
157
|
if score.value >= 16
|
149
158
|
redirect 'https://www.zold.io/images/logo-green.png'
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_merge.rb
CHANGED
@@ -142,7 +142,7 @@ class TestMerge < Minitest::Test
|
|
142
142
|
Dir.new(base).select { |f| File.directory?(File.join(base, f)) && !f.start_with?('.') }.each do |f|
|
143
143
|
Dir.mktmpdir do |dir|
|
144
144
|
FileUtils.cp_r(File.join('fixtures/merge', "#{f}/."), dir)
|
145
|
-
scores = File.join(dir,
|
145
|
+
scores = File.join(dir, "copies/0123456789abcdef/scores#{Zold::Copies::EXT}")
|
146
146
|
File.write(scores, File.read(scores).gsub(/NOW/, Time.now.utc.iso8601))
|
147
147
|
FileUtils.cp('fixtures/merge/asserts.rb', dir)
|
148
148
|
wallets = Zold::Wallets.new(dir)
|
data/test/test_copies.rb
CHANGED
@@ -73,10 +73,10 @@ class TestCopies < Minitest::Test
|
|
73
73
|
copies = Zold::Copies.new(dir, log: test_log)
|
74
74
|
copies.add(content('h1'), 'zold.io', 4096, 10, Time.now - 25 * 60 * 60)
|
75
75
|
copies.add(content('h1'), 'zold.io', 4097, 20, Time.now - 26 * 60 * 60)
|
76
|
-
assert(File.exist?(File.join(dir, "1#{Zold::
|
76
|
+
assert(File.exist?(File.join(dir, "1#{Zold::Copies::EXT}")))
|
77
77
|
copies.clean
|
78
78
|
assert(copies.all.empty?, "#{copies.all.count} is not empty")
|
79
|
-
assert(!File.exist?(File.join(dir, "1#{Zold::
|
79
|
+
assert(!File.exist?(File.join(dir, "1#{Zold::Copies::EXT}")))
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
data/test/test_zold.rb
CHANGED
@@ -34,7 +34,7 @@ require_relative '../lib/zold/version'
|
|
34
34
|
class TestZold < Minitest::Test
|
35
35
|
def test_all_scripts
|
36
36
|
Dir.new('fixtures/scripts').select { |f| f =~ /\.sh$/ && !f.start_with?('_') }.each do |f|
|
37
|
-
# next unless f == '
|
37
|
+
# next unless f == 'redeploy-on-upgrade.sh'
|
38
38
|
Dir.mktmpdir do |dir|
|
39
39
|
FileUtils.cp('fixtures/id_rsa.pub', dir)
|
40
40
|
FileUtils.cp('fixtures/id_rsa', dir)
|
data/zold.log
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
The file was truncated, because it was over the quota of 1024 bytes, 9 lines left out of 16, average line length was 66 bytes
|
2
|
+
|
3
|
+
94.103.80.24:4096 found at 109.234.37.76:4096/0 and added
|
4
|
+
178.128.41.66:4096 added to the list, 21 total
|
5
|
+
178.128.41.66:4096 found at 109.234.37.76:4096/0 and added
|
6
|
+
109.234.37.76:4096: The node 62.113.238.234:4096 is not responding (code is 599) in 27s
|
7
|
+
RuntimeError: The node 62.113.238.234:4096 is not responding (code is 599)
|
8
|
+
/Volumes/ssd2/code/zold/zold/lib/zold/commands/remote.rb:170:in `add'
|
9
|
+
/Volumes/ssd2/code/zold/zold/lib/zold/commands/remote.rb:237:in `block (2 levels) in update'
|
10
|
+
/Volumes/ssd2/code/zold/zold/lib/zold/commands/remote.rb:236:in `each'
|
11
|
+
/Volumes/ssd2/code/zold/zold/lib/zold/commands/remote.rb:236:in `block in update'
|
12
|
+
/Volumes/ssd2/code/zold/zold/lib/zold/remotes.rb:193:in `block (2 levels) in iterate'
|
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.14.
|
4
|
+
version: 0.14.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -430,22 +430,22 @@ files:
|
|
430
430
|
- fixtures/merge/id_rsa
|
431
431
|
- fixtures/merge/id_rsa.pub
|
432
432
|
- fixtures/merge/into-no-wallet/assert.rb
|
433
|
-
- fixtures/merge/into-no-wallet/copies/0123456789abcdef/1.
|
434
|
-
- fixtures/merge/into-no-wallet/copies/0123456789abcdef/scores.
|
433
|
+
- fixtures/merge/into-no-wallet/copies/0123456789abcdef/1.zc
|
434
|
+
- fixtures/merge/into-no-wallet/copies/0123456789abcdef/scores.zc
|
435
435
|
- fixtures/merge/random-expenses/0000000000000000.z
|
436
436
|
- fixtures/merge/random-expenses/0123456789abcdef.z
|
437
437
|
- fixtures/merge/random-expenses/assert.rb
|
438
|
-
- fixtures/merge/random-expenses/copies/0123456789abcdef/1.
|
439
|
-
- fixtures/merge/random-expenses/copies/0123456789abcdef/2.
|
440
|
-
- fixtures/merge/random-expenses/copies/0123456789abcdef/3.
|
441
|
-
- fixtures/merge/random-expenses/copies/0123456789abcdef/4.
|
442
|
-
- fixtures/merge/random-expenses/copies/0123456789abcdef/5.
|
443
|
-
- fixtures/merge/random-expenses/copies/0123456789abcdef/scores.
|
438
|
+
- fixtures/merge/random-expenses/copies/0123456789abcdef/1.zc
|
439
|
+
- fixtures/merge/random-expenses/copies/0123456789abcdef/2.zc
|
440
|
+
- fixtures/merge/random-expenses/copies/0123456789abcdef/3.zc
|
441
|
+
- fixtures/merge/random-expenses/copies/0123456789abcdef/4.zc
|
442
|
+
- fixtures/merge/random-expenses/copies/0123456789abcdef/5.zc
|
443
|
+
- fixtures/merge/random-expenses/copies/0123456789abcdef/scores.zc
|
444
444
|
- fixtures/merge/simple-case/0000000000000000.z
|
445
445
|
- fixtures/merge/simple-case/0123456789abcdef.z
|
446
446
|
- fixtures/merge/simple-case/assert.rb
|
447
|
-
- fixtures/merge/simple-case/copies/0123456789abcdef/1.
|
448
|
-
- fixtures/merge/simple-case/copies/0123456789abcdef/scores.
|
447
|
+
- fixtures/merge/simple-case/copies/0123456789abcdef/1.zc
|
448
|
+
- fixtures/merge/simple-case/copies/0123456789abcdef/scores.zc
|
449
449
|
- fixtures/scripts/_head.sh
|
450
450
|
- fixtures/scripts/calculate-scores.sh
|
451
451
|
- fixtures/scripts/distribute-wallet.sh
|
@@ -582,6 +582,7 @@ files:
|
|
582
582
|
- upgrades/protocol_up.rb
|
583
583
|
- upgrades/rename_foreign_wallets.rb
|
584
584
|
- zold.gemspec
|
585
|
+
- zold.log
|
585
586
|
homepage: http://github.com/zold-io/zold
|
586
587
|
licenses:
|
587
588
|
- MIT
|