zold 0.31.4 → 0.31.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codecov.yml +20 -0
- data/.github/workflows/pdd.yml +11 -0
- data/.github/workflows/rake.yml +23 -0
- data/.github/workflows/xcop.yml +11 -0
- data/.rubocop.yml +9 -5
- data/.ruby-version +1 -1
- data/.rultor.yml +4 -5
- data/.simplecov +15 -19
- data/Dockerfile +1 -1
- data/Gemfile +18 -1
- data/Guardfile +1 -1
- data/README.md +0 -5
- data/Rakefile +1 -1
- data/bin/zold +1 -1
- data/features/step_definitions/steps.rb +5 -5
- data/features/support/env.rb +1 -1
- data/fixtures/merge/asserts.rb +1 -1
- data/fixtures/merge/into_no_wallet/assert.rb +1 -1
- data/fixtures/merge/legacy_negatives_stay/assert.rb +2 -2
- data/fixtures/merge/missed_wallets/assert.rb +2 -2
- data/fixtures/merge/negative_overwriting/assert.rb +1 -1
- data/fixtures/merge/negatives_in_between/assert.rb +2 -2
- data/fixtures/merge/random_expenses/assert.rb +2 -2
- data/fixtures/merge/simple_case/assert.rb +1 -1
- data/fixtures/merge/unconfirmed_income/assert.rb +1 -1
- data/lib/zold/age.rb +1 -1
- data/lib/zold/amount.rb +3 -3
- data/lib/zold/cached_wallets.rb +1 -1
- data/lib/zold/commands/args.rb +1 -1
- data/lib/zold/commands/calculate.rb +2 -2
- data/lib/zold/commands/clean.rb +1 -1
- data/lib/zold/commands/create.rb +6 -2
- data/lib/zold/commands/diff.rb +3 -3
- data/lib/zold/commands/fetch.rb +3 -3
- data/lib/zold/commands/invoice.rb +1 -1
- data/lib/zold/commands/list.rb +1 -1
- data/lib/zold/commands/merge.rb +4 -4
- data/lib/zold/commands/next.rb +1 -1
- data/lib/zold/commands/node.rb +3 -3
- data/lib/zold/commands/pay.rb +6 -2
- data/lib/zold/commands/propagate.rb +2 -2
- data/lib/zold/commands/pull.rb +1 -1
- data/lib/zold/commands/push.rb +1 -1
- data/lib/zold/commands/remote.rb +1 -1
- data/lib/zold/commands/remove.rb +1 -1
- data/lib/zold/commands/routines/audit.rb +7 -8
- data/lib/zold/commands/routines/gc.rb +1 -1
- data/lib/zold/commands/routines/reconcile.rb +1 -1
- data/lib/zold/commands/routines/reconnect.rb +1 -1
- data/lib/zold/commands/routines/retire.rb +1 -1
- data/lib/zold/commands/routines.rb +1 -1
- data/lib/zold/commands/show.rb +5 -6
- data/lib/zold/commands/taxes.rb +2 -2
- data/lib/zold/commands/thread_badge.rb +1 -1
- data/lib/zold/copies.rb +4 -4
- data/lib/zold/dir_items.rb +2 -2
- data/lib/zold/endless.rb +3 -5
- data/lib/zold/gem.rb +1 -1
- data/lib/zold/hands.rb +4 -4
- data/lib/zold/head.rb +1 -1
- data/lib/zold/hexnum.rb +1 -1
- data/lib/zold/http.rb +5 -4
- data/lib/zold/hungry_wallets.rb +2 -2
- data/lib/zold/id.rb +3 -5
- data/lib/zold/json_page.rb +2 -2
- data/lib/zold/key.rb +5 -5
- data/lib/zold/log.rb +7 -7
- data/lib/zold/metronome.rb +2 -2
- data/lib/zold/node/async_entrance.rb +9 -9
- data/lib/zold/node/entrance.rb +5 -5
- data/lib/zold/node/farm.rb +4 -4
- data/lib/zold/node/farmers.rb +2 -4
- data/lib/zold/node/front.rb +23 -19
- data/lib/zold/node/journaled_pipeline.rb +6 -6
- data/lib/zold/node/nodup_entrance.rb +1 -1
- data/lib/zold/node/nospam_entrance.rb +2 -2
- data/lib/zold/node/pipeline.rb +6 -6
- data/lib/zold/node/safe_entrance.rb +2 -2
- data/lib/zold/node/soft_error.rb +1 -1
- data/lib/zold/node/spread_entrance.rb +3 -3
- data/lib/zold/node/sync_entrance.rb +1 -1
- data/lib/zold/node/trace.rb +1 -1
- data/lib/zold/patch.rb +14 -15
- data/lib/zold/prefixes.rb +1 -1
- data/lib/zold/remotes.rb +4 -6
- data/lib/zold/signature.rb +1 -1
- data/lib/zold/size.rb +1 -1
- data/lib/zold/sync_wallets.rb +1 -1
- data/lib/zold/tax.rb +6 -4
- data/lib/zold/thread_pool.rb +3 -3
- data/lib/zold/tree_wallets.rb +1 -1
- data/lib/zold/txn.rb +26 -19
- data/lib/zold/txns.rb +1 -1
- data/lib/zold/upgrades.rb +2 -2
- data/lib/zold/verbose_thread.rb +2 -2
- data/lib/zold/version.rb +2 -2
- data/lib/zold/version_file.rb +1 -1
- data/lib/zold/wallet.rb +3 -3
- data/lib/zold/wallets.rb +6 -1
- data/lib/zold.rb +1 -1
- data/renovate.json +6 -0
- data/test/commands/routines/test_audit.rb +2 -2
- data/test/commands/routines/test_gc.rb +2 -2
- data/test/commands/routines/test_reconcile.rb +2 -2
- data/test/commands/routines/test_reconnect.rb +2 -2
- data/test/commands/routines/test_retire.rb +2 -2
- data/test/commands/test_alias.rb +1 -1
- data/test/commands/test_calculate.rb +1 -1
- data/test/commands/test_clean.rb +4 -4
- data/test/commands/test_create.rb +1 -1
- data/test/commands/test_diff.rb +5 -5
- data/test/commands/test_fetch.rb +21 -21
- data/test/commands/test_invoice.rb +1 -1
- data/test/commands/test_list.rb +1 -1
- data/test/commands/test_merge.rb +11 -11
- data/test/commands/test_node.rb +1 -1
- data/test/commands/test_pay.rb +4 -4
- data/test/commands/test_propagate.rb +1 -1
- data/test/commands/test_pull.rb +1 -1
- data/test/commands/test_push.rb +1 -1
- data/test/commands/test_remote.rb +2 -2
- data/test/commands/test_remove.rb +1 -1
- data/test/commands/test_show.rb +1 -1
- data/test/commands/test_taxes.rb +2 -2
- data/test/fake_home.rb +4 -3
- data/test/node/fake_entrance.rb +1 -1
- data/test/node/fake_node.rb +2 -2
- data/test/node/test_async_entrance.rb +6 -4
- data/test/node/test_entrance.rb +4 -4
- data/test/node/test_farm.rb +2 -2
- data/test/node/test_farmers.rb +1 -1
- data/test/node/test_front.rb +4 -4
- data/test/node/test_nodup_entrance.rb +2 -2
- data/test/node/test_nospam_entrance.rb +1 -1
- data/test/node/test_safe_entrance.rb +3 -3
- data/test/node/test_spread_entrance.rb +2 -2
- data/test/node/test_sync_entrance.rb +1 -1
- data/test/node/test_trace.rb +1 -1
- data/test/test__helper.rb +5 -8
- data/test/test_age.rb +2 -2
- data/test/test_amount.rb +1 -1
- data/test/test_cached_wallets.rb +3 -3
- data/test/test_copies.rb +6 -6
- data/test/test_dir_items.rb +2 -4
- data/test/test_gem.rb +1 -1
- data/test/test_hands.rb +1 -1
- data/test/test_hexnum.rb +1 -1
- data/test/test_http.rb +5 -5
- data/test/test_hungry_wallets.rb +1 -1
- data/test/test_id.rb +1 -1
- data/test/test_json_page.rb +1 -1
- data/test/test_key.rb +5 -5
- data/test/test_log.rb +1 -1
- data/test/test_metronome.rb +2 -1
- data/test/test_patch.rb +9 -9
- data/test/test_prefixes.rb +1 -1
- data/test/test_remotes.rb +2 -2
- data/test/test_signature.rb +1 -1
- data/test/test_size.rb +1 -1
- data/test/test_sync_wallets.rb +1 -1
- data/test/test_tax.rb +4 -4
- data/test/test_thread_pool.rb +1 -1
- data/test/test_tree_wallets.rb +1 -1
- data/test/test_txn.rb +2 -2
- data/test/test_upgrades.rb +4 -4
- data/test/test_verbose_thread.rb +1 -1
- data/test/test_wallet.rb +14 -14
- data/test/test_wallets.rb +1 -1
- data/test/test_zold.rb +2 -2
- data/test/upgrades/test_delete_banned_wallets.rb +1 -1
- data/test/upgrades/test_protocol_up.rb +1 -1
- data/upgrades/2.rb +1 -1
- data/upgrades/delete_banned_wallets.rb +2 -2
- data/upgrades/move_wallets_into_tree.rb +1 -1
- data/upgrades/protocol_up.rb +3 -3
- data/upgrades/rename_foreign_wallets.rb +2 -2
- data/zold.gemspec +21 -40
- metadata +40 -341
- data/.github/CODE_OF_CONDUCT.md +0 -76
- data/.github/CONTRIBUTING.md +0 -11
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -51,9 +51,9 @@ module Zold
|
|
51
51
|
|
52
52
|
def to_json
|
53
53
|
@entrance.to_json.merge(
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
queue: @queue.size,
|
55
|
+
threads: @pool.count,
|
56
|
+
queue_limit: @queue_limit
|
57
57
|
)
|
58
58
|
end
|
59
59
|
|
@@ -69,7 +69,7 @@ module Zold
|
|
69
69
|
File.delete(file)
|
70
70
|
end
|
71
71
|
end
|
72
|
-
@log.info("#{@queue.size} wallets pre-loaded into async_entrace from #{@dir}") unless @queue.
|
72
|
+
@log.info("#{@queue.size} wallets pre-loaded into async_entrace from #{@dir}") unless @queue.empty?
|
73
73
|
@entrance.start do
|
74
74
|
(0..@threads).map do |i|
|
75
75
|
@pool.add do
|
@@ -100,7 +100,7 @@ module Zold
|
|
100
100
|
uuid = SecureRandom.uuid
|
101
101
|
file = File.join(@dir, "#{id}-#{uuid}#{Wallet::EXT}")
|
102
102
|
next if File.exist?(file)
|
103
|
-
|
103
|
+
File.write(file, body)
|
104
104
|
@queue << { id: id, file: file }
|
105
105
|
@log.debug("Added #{id}/#{Size.new(body.length)} to the queue at pos.#{@queue.size} \
|
106
106
|
in #{Age.new(start, limit: 0.05)}")
|
@@ -122,7 +122,7 @@ module Zold
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def safe_read(file)
|
125
|
-
|
125
|
+
File.read(file)
|
126
126
|
rescue Errno::ENOENT
|
127
127
|
''
|
128
128
|
end
|
@@ -131,11 +131,11 @@ module Zold
|
|
131
131
|
start = Time.now
|
132
132
|
item = @queue.pop
|
133
133
|
Thread.current.thread_variable_set(:wallet, item[:id].to_s)
|
134
|
-
body =
|
134
|
+
body = File.read(item[:file])
|
135
135
|
FileUtils.rm_f(item[:file])
|
136
136
|
@entrance.push(item[:id], body)
|
137
137
|
@log.debug("Pushed #{item[:id]}/#{Size.new(body.length)} to #{@entrance.class.name} \
|
138
|
-
in #{Age.new(start, limit: 0.1)}#{@queue.
|
138
|
+
in #{Age.new(start, limit: 0.1)}#{@queue.empty? ? '' : "(#{@queue.size} still in the queue)"}")
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -47,10 +47,10 @@ module Zold
|
|
47
47
|
|
48
48
|
def to_json
|
49
49
|
{
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
history: @history.join(', '),
|
51
|
+
history_size: @history.count,
|
52
|
+
speed: @speed.empty? ? 0 : (@speed.inject(&:+) / @speed.count),
|
53
|
+
pipeline: @pipeline.to_json
|
54
54
|
}
|
55
55
|
end
|
56
56
|
|
data/lib/zold/node/farm.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -156,7 +156,7 @@ at #{host}:#{port}, strength is #{@strength}")
|
|
156
156
|
save(host, port, threads, [Score.new(host: host, port: port, invoice: @invoice, strength: @strength)])
|
157
157
|
scores = load
|
158
158
|
free = scores.reject { |s| @threads.exists?(s.to_mnemo) }
|
159
|
-
@pipeline << free[0] if @pipeline.
|
159
|
+
@pipeline << free[0] if @pipeline.empty? && !free.empty?
|
160
160
|
after = scores.map(&:value).max.to_i
|
161
161
|
return unless before != after && !after.zero?
|
162
162
|
@log.debug("#{Thread.current.name}: best score of #{scores.count} is #{scores[0].reduced(4)}")
|
@@ -202,12 +202,12 @@ at #{host}:#{port}, strength is #{@strength}")
|
|
202
202
|
.map(&:to_s)
|
203
203
|
.uniq
|
204
204
|
.join("\n")
|
205
|
-
Futex.new(@cache).open { |f|
|
205
|
+
Futex.new(@cache).open { |f| File.write(f, body) }
|
206
206
|
end
|
207
207
|
|
208
208
|
def load
|
209
209
|
return [] unless File.exist?(@cache)
|
210
|
-
Futex.new(@cache).open(false) { |f|
|
210
|
+
Futex.new(@cache).open(false) { |f| File.readlines(f, "\n") }.reject(&:empty?).map do |t|
|
211
211
|
Score.parse(t)
|
212
212
|
rescue StandardError => e
|
213
213
|
@log.error(Backtrace.new(e).to_s)
|
data/lib/zold/node/farmers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -110,10 +110,8 @@ for #{score.value}/#{score.strength} at #{score.host}:#{score.port}")
|
|
110
110
|
loop do
|
111
111
|
begin
|
112
112
|
buffer << stdout.read_nonblock(16 * 1024)
|
113
|
-
# rubocop:disable Lint/HandleExceptions
|
114
113
|
rescue IO::WaitReadable
|
115
|
-
|
116
|
-
# nothing to do here
|
114
|
+
# nothing to do here
|
117
115
|
rescue StandardError => e
|
118
116
|
@log.error(buffer)
|
119
117
|
raise e
|
data/lib/zold/node/front.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -20,7 +20,7 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
|
23
|
+
$stdout.sync = true
|
24
24
|
|
25
25
|
require 'get_process_mem'
|
26
26
|
require 'thin'
|
@@ -187,7 +187,7 @@ from #{request.ip} in #{Age.new(@start, limit: 1)}")
|
|
187
187
|
error(400, "Log not found at #{settings.nohup_log}") unless File.exist?(settings.nohup_log)
|
188
188
|
response.headers['Content-Type'] = 'text/plain'
|
189
189
|
response.headers['Content-Disposition'] = "attachment; filename='#{File.basename(settings.nohup_log)}'"
|
190
|
-
|
190
|
+
File.read(settings.nohup_log)
|
191
191
|
end
|
192
192
|
|
193
193
|
get '/favicon.ico' do
|
@@ -228,8 +228,10 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
228
228
|
end,
|
229
229
|
platform: RUBY_PLATFORM,
|
230
230
|
load: settings.zache.get(:load, lifetime: settings.opts['no-cache'] ? 0 : 60) do
|
231
|
-
|
232
|
-
|
231
|
+
# doesn't work with Ruby 3.0+
|
232
|
+
# require 'usagewatch_ext'
|
233
|
+
# Object.const_defined?('Usagewatch') ? Usagewatch.uw_load.to_f : 0.0
|
234
|
+
0.0
|
233
235
|
end,
|
234
236
|
total_mem: total_mem,
|
235
237
|
threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
|
@@ -349,15 +351,17 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
349
351
|
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/copies} do
|
350
352
|
fetch do |wallet|
|
351
353
|
copies = Copies.new(File.join(settings.copies, wallet.id))
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
354
|
+
[
|
355
|
+
copies.load.map do |c|
|
356
|
+
"#{c[:name]}: #{c[:host]}:#{c[:port]} #{c[:score]} #{c[:time].utc.iso8601}"
|
357
|
+
end.join("\n"),
|
358
|
+
"\n\n",
|
359
|
+
copies.all.map do |c|
|
360
|
+
w = Wallet.new(c[:path])
|
361
|
+
"#{c[:name]}: #{c[:score]} #{w.mnemo} \
|
359
362
|
#{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}"
|
360
|
-
|
363
|
+
end.join("\n")
|
364
|
+
].join
|
361
365
|
end
|
362
366
|
end
|
363
367
|
|
@@ -366,7 +370,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
366
370
|
name = params[:name]
|
367
371
|
copy = Copies.new(File.join(settings.copies, wallet.id)).all.find { |c| c[:name] == name }
|
368
372
|
error 404 if copy.nil?
|
369
|
-
|
373
|
+
File.read(copy[:path])
|
370
374
|
end
|
371
375
|
end
|
372
376
|
|
@@ -407,13 +411,13 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
407
411
|
|
408
412
|
get '/ledger' do
|
409
413
|
content_type('text/plain')
|
410
|
-
File.exist?(settings.ledger) ?
|
414
|
+
File.exist?(settings.ledger) ? File.read(settings.ledger) : ''
|
411
415
|
end
|
412
416
|
|
413
417
|
get '/ledger.json' do
|
414
418
|
content_type('application/json')
|
415
419
|
pretty(
|
416
|
-
(File.exist?(settings.ledger) ?
|
420
|
+
(File.exist?(settings.ledger) ? File.read(settings.ledger).split("\n") : []).map do |t|
|
417
421
|
parts = t.split(';')
|
418
422
|
{
|
419
423
|
found: parts[0],
|
@@ -446,7 +450,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
446
450
|
Thread.list.map do |t|
|
447
451
|
[
|
448
452
|
"#{t.name}: status=#{t.status}; alive=#{t.alive?}",
|
449
|
-
|
453
|
+
"Vars: #{t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; ')}",
|
450
454
|
t.backtrace.nil? ? 'NO BACKTRACE' : " #{t.backtrace.join("\n ")}"
|
451
455
|
].join("\n")
|
452
456
|
end
|
@@ -460,7 +464,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
460
464
|
|
461
465
|
get '/queue' do
|
462
466
|
content_type('text/plain')
|
463
|
-
DirItems.new(settings.async_dir).fetch.
|
467
|
+
DirItems.new(settings.async_dir).fetch.grep(/^[0-9a-f]{16}-/).map do |f|
|
464
468
|
Wallet.new(File.join(settings.async_dir, f)).mnemo
|
465
469
|
rescue Errno::ENOENT
|
466
470
|
f
|
@@ -488,7 +492,7 @@ this is not a normal behavior, you may want to report a bug to our GitHub reposi
|
|
488
492
|
content_type('text/plain')
|
489
493
|
file = File.join(settings.journal_dir, params[:id])
|
490
494
|
error(404, "Journal item not found at #{file}") unless File.exist?(file)
|
491
|
-
|
495
|
+
File.read(file)
|
492
496
|
end
|
493
497
|
|
494
498
|
not_found do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -45,9 +45,9 @@ module Zold
|
|
45
45
|
def acq(id, exclusive: false)
|
46
46
|
@wallets.acq(id, exclusive: exclusive) do |wallet|
|
47
47
|
return yield wallet unless exclusive
|
48
|
-
before = wallet.exists? ?
|
48
|
+
before = wallet.exists? ? File.read(wallet.path) : ''
|
49
49
|
res = yield wallet
|
50
|
-
after = wallet.exists? ?
|
50
|
+
after = wallet.exists? ? File.read(wallet.path) : ''
|
51
51
|
unless before == after
|
52
52
|
diff = Diffy::Diff.new(before, after, context: 0).to_s
|
53
53
|
@log.info("The wallet #{id} was modified:\n #{diff.gsub("\n", "\n ")}")
|
@@ -70,7 +70,7 @@ module Zold
|
|
70
70
|
|
71
71
|
def to_json
|
72
72
|
@pipeline.to_json.merge(
|
73
|
-
|
73
|
+
dir: @dir
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
@@ -78,7 +78,7 @@ module Zold
|
|
78
78
|
def push(id, body, wallets, log, lifetime: 6)
|
79
79
|
DirItems.new(@dir).fetch.each do |f|
|
80
80
|
f = File.join(@dir, f)
|
81
|
-
File.delete(f) if File.mtime(f) < Time.now - lifetime * 60 * 60
|
81
|
+
File.delete(f) if File.mtime(f) < Time.now - (lifetime * 60 * 60)
|
82
82
|
end
|
83
83
|
journal = File.join(@dir, "#{Time.now.utc.iso8601.gsub(/[^0-9]/, '-')}-#{id}")
|
84
84
|
jlog = Logger.new(journal)
|
@@ -89,7 +89,7 @@ module Zold
|
|
89
89
|
jlog.info("Zold gem version: #{Zold::VERSION}")
|
90
90
|
modified = @pipeline.push(id, body, JournaledPipeline::Wallets.new(wallets, jlog), Log::Tee.new(log, jlog))
|
91
91
|
jlog.info("push(#{id}): done")
|
92
|
-
FileUtils.mv(journal, journal
|
92
|
+
FileUtils.mv(journal, "#{journal}-done")
|
93
93
|
modified
|
94
94
|
end
|
95
95
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -66,7 +66,7 @@ and '#{after[0..8]}' hash has already been seen #{Age.new(@zache.mtime(id.to_s))
|
|
66
66
|
private
|
67
67
|
|
68
68
|
def hash(id, body)
|
69
|
-
OpenSSL::Digest
|
69
|
+
OpenSSL::Digest.new('SHA256', "#{id} #{body}").hexdigest
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
data/lib/zold/node/pipeline.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -53,7 +53,7 @@ module Zold
|
|
53
53
|
# Show its internals.
|
54
54
|
def to_json
|
55
55
|
{
|
56
|
-
|
56
|
+
ledger: File.exist?(@ledger) ? File.read(@ledger).split("\n").count : 0
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
@@ -96,13 +96,13 @@ module Zold
|
|
96
96
|
)
|
97
97
|
end
|
98
98
|
@mutex.synchronize do
|
99
|
-
txns = File.exist?(@ledger) ?
|
100
|
-
txns +=
|
101
|
-
|
99
|
+
txns = File.exist?(@ledger) ? File.read(@ledger).strip.split("\n") : []
|
100
|
+
txns += File.read(f.path).strip.split("\n")
|
101
|
+
File.write(
|
102
102
|
@ledger,
|
103
103
|
txns.map { |t| t.split(';') }
|
104
104
|
.uniq { |t| "#{t[1]}-#{t[3]}" }
|
105
|
-
.reject { |t| Txn.parse_time(t[0]) < Time.now - 24 * 60 * 60 }
|
105
|
+
.reject { |t| Txn.parse_time(t[0]) < Time.now - (24 * 60 * 60) }
|
106
106
|
.map { |t| t.join(';') }
|
107
107
|
.join("\n")
|
108
108
|
.strip
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -60,7 +60,7 @@ module Zold
|
|
60
60
|
raise 'Id must be of type Id' unless id.is_a?(Id)
|
61
61
|
raise 'Body can\'t be nil' if body.nil?
|
62
62
|
Tempfile.open(['', Wallet::EXT]) do |f|
|
63
|
-
|
63
|
+
File.write(f, body)
|
64
64
|
wallet = Wallet.new(f.path)
|
65
65
|
wallet.refurbish
|
66
66
|
unless wallet.protocol == Zold::PROTOCOL
|
data/lib/zold/node/soft_error.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -56,8 +56,8 @@ module Zold
|
|
56
56
|
|
57
57
|
def to_json
|
58
58
|
@entrance.to_json.merge(
|
59
|
-
|
60
|
-
|
59
|
+
modified: @modified.size,
|
60
|
+
push: @push.to_json
|
61
61
|
)
|
62
62
|
end
|
63
63
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/zold/node/trace.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/zold/patch.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -51,7 +51,7 @@ module Zold
|
|
51
51
|
def legacy(wallet, hours: 24)
|
52
52
|
raise 'You can\'t add legacy to a non-empty patch' unless @id.nil?
|
53
53
|
wallet.txns.each do |txn|
|
54
|
-
@txns << txn if txn.amount.negative? && txn.date < Time.now - hours * 60 * 60
|
54
|
+
@txns << txn if txn.amount.negative? && txn.date < Time.now - (hours * 60 * 60)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -170,18 +170,17 @@ doesn't have this transaction: #{txn.to_text.inspect}")
|
|
170
170
|
added += 1
|
171
171
|
next unless txn.amount.negative?
|
172
172
|
File.open(ledger, 'a') do |f|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
)
|
173
|
+
msg = [
|
174
|
+
Time.now.utc.iso8601,
|
175
|
+
txn.id,
|
176
|
+
txn.date.utc.iso8601,
|
177
|
+
wallet.id,
|
178
|
+
txn.bnf,
|
179
|
+
txn.amount.to_i * -1,
|
180
|
+
txn.prefix,
|
181
|
+
txn.details
|
182
|
+
].map(&:to_s).join(';')
|
183
|
+
f.puts("#{msg}\n")
|
185
184
|
end
|
186
185
|
end
|
187
186
|
end
|
@@ -214,7 +213,7 @@ doesn't have this transaction: #{txn.to_text.inspect}")
|
|
214
213
|
end
|
215
214
|
else
|
216
215
|
FileUtils.mkdir_p(File.dirname(file))
|
217
|
-
|
216
|
+
File.write(file, File.read(f.path))
|
218
217
|
end
|
219
218
|
end
|
220
219
|
before != wallet.digest
|
data/lib/zold/prefixes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/zold/remotes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -166,7 +166,7 @@ at #{response.headers['X-Zold-Path']}"
|
|
166
166
|
max_errors = list.empty? ? 0 : list.max_by { |r| r[:errors] }[:errors]
|
167
167
|
max_errors = 1 if max_errors.zero?
|
168
168
|
list.sort_by do |r|
|
169
|
-
(1 - r[:errors] / max_errors) * 5 + (r[:score] / max_score)
|
169
|
+
((1 - (r[:errors] / max_errors)) * 5) + (r[:score] / max_score)
|
170
170
|
end.reverse
|
171
171
|
end
|
172
172
|
|
@@ -176,9 +176,7 @@ at #{response.headers['X-Zold-Path']}"
|
|
176
176
|
|
177
177
|
def masters
|
178
178
|
MASTERS.each do |r|
|
179
|
-
if block_given?
|
180
|
-
next unless yield(r[:host], r[:port])
|
181
|
-
end
|
179
|
+
next if block_given? && !yield(r[:host], r[:port])
|
182
180
|
add(r[:host], r[:port])
|
183
181
|
end
|
184
182
|
end
|
@@ -273,7 +271,7 @@ at #{response.headers['X-Zold-Path']}"
|
|
273
271
|
FileUtils.mkdir_p(File.dirname(@file))
|
274
272
|
Futex.new(@file).open do
|
275
273
|
list = yield(load)
|
276
|
-
|
274
|
+
File.write(
|
277
275
|
@file,
|
278
276
|
list.uniq { |r| "#{r[:host]}:#{r[:port]}" }.map do |r|
|
279
277
|
[
|
data/lib/zold/signature.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/zold/size.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/zold/sync_wallets.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/zold/tax.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -94,7 +94,7 @@ module Zold
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def debt
|
97
|
-
FEE * @wallet.txns.count * @wallet.age - paid
|
97
|
+
(FEE * @wallet.txns.count * @wallet.age) - paid
|
98
98
|
end
|
99
99
|
|
100
100
|
def paid
|
@@ -106,8 +106,10 @@ module Zold
|
|
106
106
|
score = Score.parse(body)
|
107
107
|
next unless score.valid?
|
108
108
|
next unless score.value == EXACT_SCORE || @ignore_score_weakness
|
109
|
-
if score.strength < @strength && !@ignore_score_weakness
|
110
|
-
|
109
|
+
if score.strength < @strength && !@ignore_score_weakness && !MILESTONES.find do |d, s|
|
110
|
+
t.date < d && score.strength >= s
|
111
|
+
end
|
112
|
+
next
|
111
113
|
end
|
112
114
|
next if t.amount * -1 > MAX_PAYMENT
|
113
115
|
t
|
data/lib/zold/thread_pool.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -110,7 +110,7 @@ it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}
|
|
110
110
|
name: t.name,
|
111
111
|
status: t.status,
|
112
112
|
alive: t.alive?,
|
113
|
-
vars:
|
113
|
+
vars: t.thread_variables.map { |v| [v.to_s, t.thread_variable_get(v)] }.to_h
|
114
114
|
}
|
115
115
|
end
|
116
116
|
end
|
@@ -120,7 +120,7 @@ it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}
|
|
120
120
|
@threads.map do |t|
|
121
121
|
[
|
122
122
|
"#{t.name}: status=#{t.status}; alive=#{t.alive?}",
|
123
|
-
|
123
|
+
"Vars: #{t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; ')}",
|
124
124
|
t.backtrace.nil? ? 'NO BACKTRACE' : " #{t.backtrace.join("\n ")}"
|
125
125
|
].join("\n")
|
126
126
|
end
|
data/lib/zold/tree_wallets.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
3
|
+
# Copyright (c) 2018-2023 Zerocracy
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|