zold 0.14.23 → 0.14.24
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/.rultor.yml +1 -0
- data/.travis.yml +1 -0
- data/fixtures/scripts/_head.sh +17 -13
- data/fixtures/scripts/distribute-wallet.sh +6 -4
- data/fixtures/scripts/spread-wallets.sh +2 -1
- data/lib/zold/commands/remote.rb +6 -3
- data/lib/zold/node/async_entrance.rb +7 -1
- data/lib/zold/node/front.rb +6 -3
- data/lib/zold/remotes.rb +0 -1
- data/lib/zold/score.rb +1 -1
- data/lib/zold/version.rb +1 -1
- data/test/node/test_front.rb +39 -0
- data/zold.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8d71880e2c5c0b0d18b9af54c062dc5782bdca4
|
4
|
+
data.tar.gz: b25ac38601d91489b7da16813a96784edd57bcb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd62a234221ae8733f83d090637c66730fb694743a63bd126604f92384986d6db36d1cd865cc6002ff384fb68411e4cfcae929abe478a3a7932b3687c193ca3d
|
7
|
+
data.tar.gz: 89f71e08e1dfa5ca33cd63f2274c78f2441098053d5145dfdbf01cb0b9f0dc19a5179b58bbe317476a70eb7eaaa62cadaf19e2d130da7bb4880eeaf56079c516
|
data/.rultor.yml
CHANGED
data/.travis.yml
CHANGED
data/fixtures/scripts/_head.sh
CHANGED
@@ -12,10 +12,11 @@ function reserve_port {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
function wait_for_url {
|
15
|
+
i=0
|
15
16
|
while ! curl --silent --fail $1 > /dev/null; do
|
16
|
-
((
|
17
|
-
if ((
|
18
|
-
echo "URL $1 is not available after $
|
17
|
+
((i++)) || sleep 0
|
18
|
+
if ((i==30)); then
|
19
|
+
echo "URL $1 is not available after ${i} attempts"
|
19
20
|
exit 12
|
20
21
|
fi
|
21
22
|
sleep 5
|
@@ -23,10 +24,11 @@ function wait_for_url {
|
|
23
24
|
}
|
24
25
|
|
25
26
|
function wait_for_port {
|
27
|
+
i=0
|
26
28
|
while ! nc -z localhost $1; do
|
27
|
-
((
|
28
|
-
if ((
|
29
|
-
echo "Port $1 is not available after $
|
29
|
+
((i++)) || sleep 0
|
30
|
+
if ((i==30)); then
|
31
|
+
echo "Port $1 is not available after ${i} attempts"
|
30
32
|
exit 13
|
31
33
|
fi
|
32
34
|
sleep 5
|
@@ -34,10 +36,11 @@ function wait_for_port {
|
|
34
36
|
}
|
35
37
|
|
36
38
|
function wait_for_file {
|
39
|
+
i=0
|
37
40
|
while [ ! -f $1 ]; do
|
38
|
-
((
|
39
|
-
if ((
|
40
|
-
echo "File $1 not found, giving up after $
|
41
|
+
((i++)) || sleep 0
|
42
|
+
if ((i==30)); then
|
43
|
+
echo "File $1 not found, giving up after ${i} attempts"
|
41
44
|
exit 14
|
42
45
|
fi
|
43
46
|
sleep 5
|
@@ -48,13 +51,14 @@ function halt_nodes {
|
|
48
51
|
for p in "$@"; do
|
49
52
|
pid=$(curl --silent "http://localhost:$p/pid?halt=test" || echo 'absent')
|
50
53
|
if [[ "${pid}" =~ ^[0-9]+$ ]]; then
|
54
|
+
i=0
|
51
55
|
while kill -0 ${pid}; do
|
52
|
-
((
|
53
|
-
if ((
|
54
|
-
echo "
|
56
|
+
((i++)) || sleep 0
|
57
|
+
if ((i==30)); then
|
58
|
+
echo "Process ${pid} didn't die, it's a bug"
|
55
59
|
exit 15
|
56
60
|
fi
|
57
|
-
echo "Still waiting for process ${pid} to die,
|
61
|
+
echo "Still waiting for process ${pid} to die, attempt no.${i}"
|
58
62
|
sleep 5
|
59
63
|
done
|
60
64
|
echo "Process ${pid} is dead!"
|
@@ -44,15 +44,16 @@ zold remote add localhost ${second}
|
|
44
44
|
# to be visible there. We are doing a number of attempts with a small
|
45
45
|
# delay between them, in order to give the first node a chance to distribute
|
46
46
|
# the wallet.
|
47
|
+
i=0
|
47
48
|
until zold fetch 0000000000000000 --ignore-score-weakness; do
|
48
49
|
echo 'Failed to fetch, let us try again'
|
49
|
-
((i++)) || sleep
|
50
|
+
((i++)) || sleep 0
|
50
51
|
if ((i==5)); then
|
51
52
|
cat ${first}/log.txt
|
52
53
|
echo "The wallet has not been distributed, after ${i} attempts"
|
53
54
|
exit 9
|
54
55
|
fi
|
55
|
-
sleep
|
56
|
+
sleep 5
|
56
57
|
done
|
57
58
|
|
58
59
|
# Here we check the JSON of the first node to make sure all status
|
@@ -74,14 +75,15 @@ fi
|
|
74
75
|
# Now, we remove the wallet from the second node and expect the first
|
75
76
|
# one to "spread" it again, almost immediately.
|
76
77
|
rm ${second}/0000000000000000.z
|
78
|
+
i=0
|
77
79
|
until zold fetch 0000000000000000 --ignore-score-weakness; do
|
78
80
|
echo 'Failed to fetch, let us try again'
|
79
|
-
((i++)) || sleep
|
81
|
+
((i++)) || sleep 0
|
80
82
|
if ((i==5)); then
|
81
83
|
cat ${first}/log.txt
|
82
84
|
echo "The wallet 0000000000000000 has not been spread, after ${i} attempts"
|
83
85
|
exit 8
|
84
86
|
fi
|
85
|
-
sleep
|
87
|
+
sleep 5
|
86
88
|
done
|
87
89
|
|
@@ -30,9 +30,10 @@ zold push 0000000000000000
|
|
30
30
|
zold remote clean
|
31
31
|
zold remote add localhost ${second}
|
32
32
|
|
33
|
+
i=0
|
33
34
|
until zold fetch 0000000000000000 --ignore-score-weakness; do
|
34
35
|
echo 'Failed to fetch, let us try again'
|
35
|
-
((i++)) || sleep
|
36
|
+
((i++)) || sleep 0
|
36
37
|
if ((i==5)); then
|
37
38
|
cat ${first}/log.txt
|
38
39
|
echo "The wallet has not been distributed, after ${i} attempts"
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -83,6 +83,9 @@ Available options:"
|
|
83
83
|
o.integer '--min-score',
|
84
84
|
"The minimum score required for winning the election (default: #{Tax::EXACT_SCORE})",
|
85
85
|
default: Tax::EXACT_SCORE
|
86
|
+
o.integer '--max-winners',
|
87
|
+
'The maximum amount of election winners the election (default: 1)',
|
88
|
+
default: 1
|
86
89
|
o.bool '--force',
|
87
90
|
'Add/remove if if this operation is not possible',
|
88
91
|
default: false
|
@@ -197,11 +200,11 @@ Available options:"
|
|
197
200
|
r.assert_score_value(score, opts['min-score']) unless opts['ignore-score-value']
|
198
201
|
scores << score
|
199
202
|
end
|
200
|
-
scores = scores.sample(
|
203
|
+
scores = scores.sample(opts['max-winners'])
|
201
204
|
if scores.empty?
|
202
205
|
@log.info("No winners elected out of #{@remotes.all.count} remotes")
|
203
206
|
else
|
204
|
-
@log.info("Elected: #{
|
207
|
+
scores.each { |s| @log.info("Elected: #{s}") }
|
205
208
|
end
|
206
209
|
scores
|
207
210
|
end
|
@@ -239,7 +242,7 @@ it's recommended to reboot, but I don't do it because of --never-reboot")
|
|
239
242
|
end
|
240
243
|
if deep
|
241
244
|
json['all'].each do |s|
|
242
|
-
|
245
|
+
@remotes.add(s['host'], s['port'])
|
243
246
|
end
|
244
247
|
end
|
245
248
|
capacity << { host: score.host, port: score.port, count: json['all'].count }
|
@@ -32,7 +32,12 @@ require_relative '../verbose_thread'
|
|
32
32
|
module Zold
|
33
33
|
# The entrance
|
34
34
|
class AsyncEntrance
|
35
|
-
|
35
|
+
# How many threads to use for processing
|
36
|
+
THREADS = Concurrent.processor_count * 8
|
37
|
+
|
38
|
+
# Max items in the queue. If there will be more, push() requests
|
39
|
+
# will be rejected.
|
40
|
+
MAX_QUEUE = 128
|
36
41
|
|
37
42
|
def initialize(entrance, dir, log: Log::Quiet.new)
|
38
43
|
raise 'Entrance can\'t be nil' if entrance.nil?
|
@@ -90,6 +95,7 @@ module Zold
|
|
90
95
|
|
91
96
|
# Always returns an array with a single ID of the pushed wallet
|
92
97
|
def push(id, body)
|
98
|
+
raise 'Queue is too long, try again later' if Dir.new(@dir).count > AsyncEntrance::MAX_QUEUE
|
93
99
|
@mutex.synchronize do
|
94
100
|
AtomicFile.new(File.join(@dir, id.to_s)).write(body)
|
95
101
|
end
|
data/lib/zold/node/front.rb
CHANGED
@@ -25,6 +25,7 @@ STDOUT.sync = true
|
|
25
25
|
require 'json'
|
26
26
|
require 'sinatra/base'
|
27
27
|
require 'webrick'
|
28
|
+
require 'get_process_mem'
|
28
29
|
require 'diffy'
|
29
30
|
require 'concurrent'
|
30
31
|
require_relative '../backtrace'
|
@@ -94,9 +95,10 @@ while #{settings.address} is in '#{settings.network}'"
|
|
94
95
|
error(400, 'The score is weak') if s.strength < Score::STRENGTH && !settings.ignore_score_weakness
|
95
96
|
if s.value > 3
|
96
97
|
require_relative '../commands/remote'
|
97
|
-
Remote.new(remotes: settings.remotes, log: settings.log)
|
98
|
-
|
99
|
-
)
|
98
|
+
cmd = Remote.new(remotes: settings.remotes, log: settings.log)
|
99
|
+
cmd.run(['remote', 'add', s.host, s.port.to_s, '--force', "--network=#{settings.network}"])
|
100
|
+
cmd.run(%w[remote trim])
|
101
|
+
cmd.run(%w[remote select])
|
100
102
|
else
|
101
103
|
settings.log.debug("#{request.url}: the score is too weak: #{s}")
|
102
104
|
end
|
@@ -153,6 +155,7 @@ while #{settings.address} is in '#{settings.network}'"
|
|
153
155
|
score: score.to_h,
|
154
156
|
pid: Process.pid,
|
155
157
|
cpus: Concurrent.processor_count,
|
158
|
+
memory: GetProcessMem.new.inspect.bytes,
|
156
159
|
platform: RUBY_PLATFORM,
|
157
160
|
uptime: `uptime`.strip,
|
158
161
|
threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
|
data/lib/zold/remotes.rb
CHANGED
@@ -149,7 +149,6 @@ module Zold
|
|
149
149
|
raise 'Port can\'t be zero' if port.zero?
|
150
150
|
raise 'Port can\'t be negative' if port.negative?
|
151
151
|
raise 'Port can\'t be over 65536' if port > 0xffff
|
152
|
-
raise "#{host}:#{port} already exists" if exists?(host, port)
|
153
152
|
modify do |list|
|
154
153
|
list + [{ host: host.downcase, port: port, score: 0 }]
|
155
154
|
end
|
data/lib/zold/score.rb
CHANGED
data/lib/zold/version.rb
CHANGED
data/test/node/test_front.rb
CHANGED
@@ -178,4 +178,43 @@ class FrontTest < Minitest::Test
|
|
178
178
|
sec = (Time.now - start) / total
|
179
179
|
test_log.info("Average response time is #{sec.round(2)}s")
|
180
180
|
end
|
181
|
+
|
182
|
+
def app
|
183
|
+
Zold::Front
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_headers_are_being_set_correctly
|
187
|
+
Time.stub :now, Time.at(0) do
|
188
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
189
|
+
response = Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
|
190
|
+
assert_equal(
|
191
|
+
'no-cache',
|
192
|
+
response.header['Cache-Control']
|
193
|
+
)
|
194
|
+
assert_equal(
|
195
|
+
'close',
|
196
|
+
response.header['Connection']
|
197
|
+
)
|
198
|
+
assert_equal(
|
199
|
+
app.settings.version,
|
200
|
+
response.header['X-Zold-Version']
|
201
|
+
)
|
202
|
+
assert_equal(
|
203
|
+
app.settings.protocol.to_s,
|
204
|
+
response.header[Zold::Http::PROTOCOL_HEADER]
|
205
|
+
)
|
206
|
+
assert_equal(
|
207
|
+
'*',
|
208
|
+
response.header['Access-Control-Allow-Origin']
|
209
|
+
)
|
210
|
+
score = Zold::Score.new(
|
211
|
+
time: Time.now, host: 'localhost', port: port, invoice: 'NOPREFIX@ffffffffffffffff', strength: 2
|
212
|
+
)
|
213
|
+
assert_equal(
|
214
|
+
score.to_s,
|
215
|
+
response.header[Zold::Http::SCORE_HEADER]
|
216
|
+
)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
181
220
|
end
|
data/zold.gemspec
CHANGED
@@ -59,6 +59,7 @@ and suggests a different architecture for digital wallet maintenance.'
|
|
59
59
|
s.add_runtime_dependency 'diffy', '~>3.2'
|
60
60
|
s.add_runtime_dependency 'dry-struct', '~>0.5.0'
|
61
61
|
s.add_runtime_dependency 'dry-types', '~>0.13.2'
|
62
|
+
s.add_runtime_dependency 'get_process_mem', '0.2.2'
|
62
63
|
s.add_runtime_dependency 'json', '~>1.8'
|
63
64
|
s.add_runtime_dependency 'openssl', '~>2.1'
|
64
65
|
s.add_runtime_dependency 'rainbow', '~>3.0'
|
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.14.
|
4
|
+
version: 0.14.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.13.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: get_process_mem
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.2.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.2.2
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: json
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|