zold 0.19.1 → 0.19.2
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/heroku-run.sh +1 -1
- data/lib/zold/commands/fetch.rb +4 -3
- data/lib/zold/commands/push.rb +5 -4
- data/lib/zold/commands/remote.rb +1 -1
- data/lib/zold/commands/show.rb +14 -3
- data/lib/zold/hungry_wallets.rb +29 -14
- data/lib/zold/thread_pool.rb +16 -11
- data/lib/zold/version.rb +1 -1
- data/test/test_hungry_wallets.rb +1 -1
- data/test/test_thread_pool.rb +5 -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: 32709fc443bc01bdd90a978c9cc7204fd8d6758466a46dbecb5c811bd2a40a12
|
4
|
+
data.tar.gz: cd4fe030458935e3ec27db1673289d3b1dbdf63989b027ea50bf8f336fcab49f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7b3009e694c98f2dd296d888191b2060cd222e19d621bda1cb457941b5167257149d6c9e7c1ea9645cb221b1c8014fc8d7f44574fcbcecd9a731a204ec5c4ba
|
7
|
+
data.tar.gz: 30a9c25381547e573a6908412465311c7477314d085100d17fe3ca4baa4289e42196fc62bfdd6565998b36b6d773f3c17bd074c9e0dd2d74e4be83f1590ca9a9
|
data/heroku-run.sh
CHANGED
data/lib/zold/commands/fetch.rb
CHANGED
@@ -99,6 +99,7 @@ Available options:"
|
|
99
99
|
private
|
100
100
|
|
101
101
|
def fetch(id, cps, opts)
|
102
|
+
raise "There are no remote nodes, run 'zold remote reset'" if @remotes.all.empty?
|
102
103
|
start = Time.now
|
103
104
|
total = Concurrent::AtomicFixnum.new
|
104
105
|
nodes = Concurrent::AtomicFixnum.new
|
@@ -110,14 +111,14 @@ Available options:"
|
|
110
111
|
masters.increment if r.master?
|
111
112
|
done.increment
|
112
113
|
end
|
113
|
-
raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
|
114
114
|
unless opts['quiet-if-absent']
|
115
115
|
raise "No nodes out of #{nodes.value} have the wallet #{id}" if done.value.zero?
|
116
116
|
if masters.value.zero? && !opts['tolerate-edges']
|
117
|
-
raise EdgesOnly, "There are only edge nodes, run 'zold remote
|
117
|
+
raise EdgesOnly, "There are only edge nodes, run 'zold remote update' or use --tolerate-edges"
|
118
118
|
end
|
119
119
|
if nodes.value < opts['tolerate-quorum']
|
120
|
-
raise NoQuorum, "There were not enough nodes,
|
120
|
+
raise NoQuorum, "There were not enough nodes, the required quorum is #{opts['tolerate-quorum']}; \
|
121
|
+
run 'zold remote update' or use --tolerate-quorum=1"
|
121
122
|
end
|
122
123
|
end
|
123
124
|
@log.info("#{done.value} copies of #{id} fetched in #{Age.new(start)} with the total score of \
|
data/lib/zold/commands/push.rb
CHANGED
@@ -91,25 +91,26 @@ Available options:"
|
|
91
91
|
private
|
92
92
|
|
93
93
|
def push(id, opts)
|
94
|
+
raise "There are no remote nodes, run 'zold remote reset'" if @remotes.all.empty?
|
95
|
+
start = Time.now
|
94
96
|
total = Concurrent::AtomicFixnum.new
|
95
97
|
nodes = Concurrent::AtomicFixnum.new
|
96
98
|
done = Concurrent::AtomicFixnum.new
|
97
99
|
masters = Concurrent::AtomicFixnum.new
|
98
|
-
start = Time.now
|
99
100
|
@remotes.iterate(@log) do |r|
|
100
101
|
nodes.increment
|
101
102
|
total.increment(push_one(id, r, opts))
|
102
103
|
masters.increment if r.master?
|
103
104
|
done.increment
|
104
105
|
end
|
105
|
-
raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
|
106
106
|
unless opts['quiet-if-missed']
|
107
107
|
raise "No nodes out of #{nodes} accepted the wallet #{id}" if done.value.zero?
|
108
108
|
if masters.value.zero? && !opts['tolerate-edges']
|
109
|
-
raise EdgesOnly, "There are only edge nodes, run 'zold remote
|
109
|
+
raise EdgesOnly, "There are only edge nodes, run 'zold remote update' or use --tolerate-edges"
|
110
110
|
end
|
111
111
|
if nodes.value < opts['tolerate-quorum']
|
112
|
-
raise NoQuorum, "There were not enough nodes,
|
112
|
+
raise NoQuorum, "There were not enough nodes, the required quorum is #{opts['tolerate-quorum']}; \
|
113
|
+
run 'zold remote update' or use --tolerate-quorum=1"
|
113
114
|
end
|
114
115
|
end
|
115
116
|
@log.info("Push finished to #{done.value} nodes (#{masters.value} master nodes) \
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -107,7 +107,7 @@ Available options:"
|
|
107
107
|
default: false
|
108
108
|
o.integer '--depth',
|
109
109
|
'The amount of update cycles to run, in order to fetch as many nodes as possible (default: 2)',
|
110
|
-
default:
|
110
|
+
default: 3
|
111
111
|
o.string '--network',
|
112
112
|
"The name of the network we work in (default: #{Wallet::MAINET}",
|
113
113
|
required: true,
|
data/lib/zold/commands/show.rb
CHANGED
@@ -28,6 +28,9 @@ require_relative '../log'
|
|
28
28
|
require_relative '../id'
|
29
29
|
require_relative '../amount'
|
30
30
|
require_relative '../wallet'
|
31
|
+
require_relative '../tax'
|
32
|
+
require_relative '../size'
|
33
|
+
require_relative '../age'
|
31
34
|
|
32
35
|
# SHOW command.
|
33
36
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -72,9 +75,17 @@ Available options:"
|
|
72
75
|
wallet.txns.each do |t|
|
73
76
|
@log.info(t.to_text)
|
74
77
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
@log.info(
|
79
|
+
[
|
80
|
+
"The balance of #{wallet}: #{balance} (#{balance.to_i} zents)",
|
81
|
+
"Network: #{wallet.network}",
|
82
|
+
"Transactions: #{wallet.txns.count}",
|
83
|
+
"Taxes: #{Tax.new(wallet).paid} paid, the debt is #{Tax.new(wallet).debt}",
|
84
|
+
"File size: #{Size.new(wallet.size)}, #{Copies.new(File.join(@copies, wallet.id)).all.count} copies",
|
85
|
+
"Modified: #{wallet.mtime.utc.iso8601} (#{Age.new(wallet.mtime.utc.iso8601)} ago)",
|
86
|
+
"Digest: #{wallet.digest}"
|
87
|
+
].join("\n")
|
88
|
+
)
|
78
89
|
balance
|
79
90
|
end
|
80
91
|
end
|
data/lib/zold/hungry_wallets.rb
CHANGED
@@ -24,6 +24,7 @@ require 'delegate'
|
|
24
24
|
require_relative 'log'
|
25
25
|
require_relative 'thread_pool'
|
26
26
|
require_relative 'commands/pull'
|
27
|
+
require_relative 'commands/fetch'
|
27
28
|
|
28
29
|
# Wallets that PULL what's missing, in the background.
|
29
30
|
#
|
@@ -41,31 +42,45 @@ module Zold
|
|
41
42
|
@log = log
|
42
43
|
@network = network
|
43
44
|
@pool = pool
|
44
|
-
@queue =
|
45
|
+
@queue = []
|
46
|
+
@mutex = Mutex.new
|
45
47
|
@pool.add do
|
46
|
-
Endless.new('hungry', log: log).run
|
47
|
-
id = @queue.pop
|
48
|
-
Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
|
49
|
-
['pull', id.to_s, "--network=#{@network}"]
|
50
|
-
)
|
51
|
-
rescue Pull::EdgesOnly => e
|
52
|
-
@log.error("Can't hungry-pull #{id}: #{e.message}")
|
53
|
-
end
|
48
|
+
Endless.new('hungry', log: log).run { pull }
|
54
49
|
end
|
55
50
|
super(wallets)
|
56
51
|
end
|
57
52
|
|
58
53
|
def acq(id, exclusive: false)
|
59
54
|
@wallets.acq(id, exclusive: exclusive) do |wallet|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
@queue
|
55
|
+
if @queue.size > 256
|
56
|
+
@log.error("Hungry queue is full with #{@queue.size} wallets, can't add #{id}")
|
57
|
+
else
|
58
|
+
@mutex.synchronize do
|
59
|
+
unless @queue.include?(id)
|
60
|
+
@queue << id
|
61
|
+
@log.debug("Hungry queue got #{id}, at the pos no.#{@queue.size}")
|
62
|
+
end
|
65
63
|
end
|
66
64
|
end
|
67
65
|
yield wallet
|
68
66
|
end
|
69
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def pull
|
72
|
+
id = @mutex.synchronize { @queue.pop }
|
73
|
+
if id.nil?
|
74
|
+
sleep 1
|
75
|
+
return
|
76
|
+
end
|
77
|
+
begin
|
78
|
+
Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
|
79
|
+
['pull', id.to_s, "--network=#{@network}"]
|
80
|
+
)
|
81
|
+
rescue Fetch::EdgesOnly => e
|
82
|
+
@log.error("Can't hungry-pull #{id}: #{e.message}")
|
83
|
+
end
|
84
|
+
end
|
70
85
|
end
|
71
86
|
end
|
data/lib/zold/thread_pool.rb
CHANGED
@@ -94,18 +94,23 @@ module Zold
|
|
94
94
|
@log.debug("Stopping \"#{@title}\" thread pool with #{@threads.count} threads: \
|
95
95
|
#{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}...")
|
96
96
|
start = Time.new
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
(
|
104
|
-
|
105
|
-
|
106
|
-
|
97
|
+
begin
|
98
|
+
@threads.each do |t|
|
99
|
+
t.join(0.1)
|
100
|
+
end
|
101
|
+
ensure
|
102
|
+
@threads.each do |t|
|
103
|
+
(t.thread_variable_get(:kids) || []).each(&:kill)
|
104
|
+
t.kill
|
105
|
+
Thread.current.thread_variable_set(
|
106
|
+
:kids,
|
107
|
+
(Thread.current.thread_variable_get(:kids) || []) - [t]
|
108
|
+
)
|
109
|
+
end
|
110
|
+
@log.debug("Thread pool \"#{@title}\" terminated all threads in #{Age.new(start)}, \
|
107
111
|
it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}")
|
108
|
-
|
112
|
+
@threads.clear
|
113
|
+
end
|
109
114
|
end
|
110
115
|
|
111
116
|
# How many threads are in there
|
data/lib/zold/version.rb
CHANGED
data/test/test_hungry_wallets.rb
CHANGED
data/test/test_thread_pool.rb
CHANGED
@@ -71,8 +71,11 @@ class TestThreadPool < Zold::Test
|
|
71
71
|
|
72
72
|
def test_runs_with_exceptions
|
73
73
|
assert_raises do
|
74
|
-
Zold::ThreadPool.new('test', log: test_log).run(
|
75
|
-
|
74
|
+
Zold::ThreadPool.new('test', log: test_log).run(5) do |i|
|
75
|
+
if i == 4
|
76
|
+
sleep 0.1
|
77
|
+
raise 'intended'
|
78
|
+
end
|
76
79
|
end
|
77
80
|
end
|
78
81
|
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.19.
|
4
|
+
version: 0.19.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -690,7 +690,7 @@ licenses:
|
|
690
690
|
- MIT
|
691
691
|
metadata: {}
|
692
692
|
post_install_message: |-
|
693
|
-
Thanks for installing Zold 0.19.
|
693
|
+
Thanks for installing Zold 0.19.2!
|
694
694
|
Study our White Paper: https://papers.zold.io/wp.pdf
|
695
695
|
Read our blog posts: https://blog.zold.io
|
696
696
|
Try online wallet at: https://wts.zold.io
|