zold 0.13.17 → 0.13.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/zold/commands/node.rb +9 -12
- data/lib/zold/commands/push.rb +1 -1
- data/lib/zold/node/farm.rb +33 -25
- data/lib/zold/score.rb +3 -1
- data/lib/zold/version.rb +1 -1
- data/test/node/test_farm.rb +39 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 803822a36daa76dbf38f3ee899fac369268b6f4c
|
4
|
+
data.tar.gz: 5a5a326d4b076e6906dc15e7930291d9cb8e9d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37506ab72e6affb6f9b8b46786608fae5726ad70f390bd309954b3f495d78e00b7f88b3d12a7a08ad9c81f1ff6bad268c4fe729e0db9d9e90adb832b4be64254
|
7
|
+
data.tar.gz: d516c13ac21efa8a51daffa5cae34009f5716886a77f4c96959f0af9dbcc9b7bb53036eb51cb5aa91f7518fc01c62abb4ee132470923d55db48ce72f8d57194f
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
|
7
7
|
|
8
8
|
[![Build Status](https://travis-ci.org/zold-io/zold.svg)](https://travis-ci.org/zold-io/zold)
|
9
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/
|
9
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/15ola3lb03opv14m?svg=true)](https://ci.appveyor.com/project/yegor256/zold-wcn4o)
|
10
10
|
[![PDD status](http://www.0pdd.com/svg?name=zold-io/zold)](http://www.0pdd.com/p?name=zold-io/zold)
|
11
11
|
[![Gem Version](https://badge.fury.io/rb/zold.svg)](http://badge.fury.io/rb/zold)
|
12
12
|
[![Test Coverage](https://img.shields.io/codecov/c/github/zold-io/zold.svg)](https://codecov.io/github/zold-io/zold?branch=master)
|
@@ -201,6 +201,10 @@ network. You can see the full list of nodes at `/remotes` URL of your node.
|
|
201
201
|
|
202
202
|
* `best` is ... something not important to you.
|
203
203
|
|
204
|
+
* `history` is the amount of scores currently saved on the disc. The
|
205
|
+
farm keeps them there in case the node gets restarted. It will load
|
206
|
+
them back and reuse.
|
207
|
+
|
204
208
|
`entrance` is the place where all new wallets arive and get merged and pushed
|
205
209
|
further. The health of this point is critical to the entire node. Some
|
206
210
|
numbers it includes must be watched carefully.
|
data/lib/zold/commands/node.rb
CHANGED
@@ -155,18 +155,15 @@ module Zold
|
|
155
155
|
invoice = Invoice.new(wallets: @wallets, log: @log).run(['invoice', invoice])
|
156
156
|
end
|
157
157
|
farm = Farm.new(invoice, File.join(Dir.pwd, 'farm'), log: @log)
|
158
|
-
farm.start(
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
ensure
|
168
|
-
farm.stop
|
169
|
-
metronome.stop
|
158
|
+
farm.start(opts[:host], opts[:port], threads: opts[:threads], strength: opts[:strength]) do
|
159
|
+
Front.set(:farm, farm)
|
160
|
+
metronome = metronome(farm, entrance, opts)
|
161
|
+
begin
|
162
|
+
@log.info("Starting up the web front at http://#{host}:#{opts[:port]}...")
|
163
|
+
Front.run!
|
164
|
+
ensure
|
165
|
+
metronome.stop
|
166
|
+
end
|
170
167
|
end
|
171
168
|
end
|
172
169
|
|
data/lib/zold/commands/push.rb
CHANGED
@@ -83,7 +83,7 @@ Available options:"
|
|
83
83
|
content = AtomicFile.new(wallet.path).read
|
84
84
|
response = r.http("/wallet/#{wallet.id}#{opts['sync'] ? '?sync=true' : ''}").put(content)
|
85
85
|
if response.code == '304'
|
86
|
-
@log.info("#{r}: same version of #{wallet.id} there")
|
86
|
+
@log.info("#{r}: same version of #{wallet.id} there, in #{(Time.now - start).round(2)}s")
|
87
87
|
return 0
|
88
88
|
end
|
89
89
|
r.assert_code(200, response)
|
data/lib/zold/node/farm.rb
CHANGED
@@ -53,7 +53,8 @@ module Zold
|
|
53
53
|
{
|
54
54
|
threads: @threads.count,
|
55
55
|
scores: @scores.size,
|
56
|
-
best: @best.count
|
56
|
+
best: @best.count,
|
57
|
+
history: history.count
|
57
58
|
}
|
58
59
|
end
|
59
60
|
|
@@ -68,33 +69,17 @@ module Zold
|
|
68
69
|
Thread.new do
|
69
70
|
VerboseThread.new(@log).run do
|
70
71
|
Thread.current.name = "farm-#{t}"
|
71
|
-
loop
|
72
|
-
if @scores.length < threads
|
73
|
-
@scores << Score.new(
|
74
|
-
Time.now, host, port, @invoice,
|
75
|
-
strength: strength
|
76
|
-
)
|
77
|
-
end
|
78
|
-
s = @scores.pop
|
79
|
-
next unless s.valid?
|
80
|
-
next unless s.host == host
|
81
|
-
next unless s.port == port
|
82
|
-
next unless s.strength >= strength
|
83
|
-
n = s.next
|
84
|
-
@semaphore.synchronize do
|
85
|
-
before = @best.map(&:value).max
|
86
|
-
save(n)
|
87
|
-
@best << n
|
88
|
-
after = @best.map(&:value).max
|
89
|
-
@best = @best.reject(&:expired?).sort_by(&:value).reverse.take(threads)
|
90
|
-
@log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
|
91
|
-
end
|
92
|
-
@scores << n
|
93
|
-
end
|
72
|
+
loop { cycle(host, port, strength, threads) }
|
94
73
|
end
|
95
74
|
end
|
96
75
|
end
|
97
76
|
@log.info("Farm started with #{threads} threads at #{host}:#{port}, strength is #{strength}")
|
77
|
+
return unless block_given?
|
78
|
+
begin
|
79
|
+
yield
|
80
|
+
ensure
|
81
|
+
stop
|
82
|
+
end
|
98
83
|
end
|
99
84
|
|
100
85
|
def stop
|
@@ -110,8 +95,31 @@ module Zold
|
|
110
95
|
|
111
96
|
private
|
112
97
|
|
98
|
+
def cycle(host, port, strength, threads)
|
99
|
+
if @scores.length < threads
|
100
|
+
zero = Score.new(Time.now, host, port, @invoice, strength: strength)
|
101
|
+
@scores << zero
|
102
|
+
@best << zero
|
103
|
+
end
|
104
|
+
s = @scores.pop
|
105
|
+
return unless s.valid?
|
106
|
+
return unless s.host == host
|
107
|
+
return unless s.port == port
|
108
|
+
return unless s.strength >= strength
|
109
|
+
n = s.next
|
110
|
+
@semaphore.synchronize do
|
111
|
+
before = @best.map(&:value).max
|
112
|
+
save(n)
|
113
|
+
@best << n
|
114
|
+
after = @best.map(&:value).max
|
115
|
+
@best = @best.reject(&:expired?).sort_by(&:value).reverse.take(threads)
|
116
|
+
@log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
|
117
|
+
end
|
118
|
+
@scores << n
|
119
|
+
end
|
120
|
+
|
113
121
|
def save(score)
|
114
|
-
AtomicFile.new(@cache).write((history + [score]).map(&:to_s).join("\n"))
|
122
|
+
AtomicFile.new(@cache).write((history + [score]).map(&:to_s).uniq.join("\n"))
|
115
123
|
end
|
116
124
|
|
117
125
|
def history(max = 16)
|
data/lib/zold/score.rb
CHANGED
@@ -46,6 +46,7 @@ module Zold
|
|
46
46
|
@invoice = invoice
|
47
47
|
@suffixes = suffixes
|
48
48
|
@strength = strength
|
49
|
+
@created = Time.now
|
49
50
|
end
|
50
51
|
|
51
52
|
# The default no-value score.
|
@@ -140,7 +141,8 @@ module Zold
|
|
140
141
|
hash: value.zero? ? nil : hash,
|
141
142
|
expired: expired?,
|
142
143
|
valid: valid?,
|
143
|
-
minutes: ((Time.now - @time) / 60).to_i
|
144
|
+
minutes: ((Time.now - @time) / 60).to_i,
|
145
|
+
created: @created.utc.iso8601
|
144
146
|
}
|
145
147
|
end
|
146
148
|
|
data/lib/zold/version.rb
CHANGED
data/test/node/test_farm.rb
CHANGED
@@ -26,25 +26,40 @@ require_relative '../../lib/zold/log'
|
|
26
26
|
require_relative '../../lib/zold/node/farm'
|
27
27
|
|
28
28
|
class FarmTest < Minitest::Test
|
29
|
+
def test_renders_in_json
|
30
|
+
Dir.mktmpdir 'test' do |dir|
|
31
|
+
farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
|
32
|
+
farm.start('localhost', 80, threads: 4, strength: 2) do
|
33
|
+
sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
|
34
|
+
count = 0
|
35
|
+
100.times { count += farm.to_json[:history] }
|
36
|
+
assert(count > 0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
29
41
|
def test_makes_best_score_in_background
|
30
42
|
Dir.mktmpdir 'test' do |dir|
|
31
43
|
farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
|
32
|
-
farm.start('localhost', 80, threads: 4, strength: 2)
|
33
|
-
|
34
|
-
|
35
|
-
|
44
|
+
farm.start('localhost', 80, threads: 4, strength: 2) do
|
45
|
+
sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
|
46
|
+
score = farm.best[0]
|
47
|
+
assert(!score.expired?)
|
48
|
+
assert(score.value > 0)
|
49
|
+
end
|
36
50
|
end
|
37
51
|
end
|
38
52
|
|
39
53
|
def test_correct_score_from_empty_farm
|
40
54
|
Dir.mktmpdir 'test' do |dir|
|
41
55
|
farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log: test_log)
|
42
|
-
farm.start('example.com', 8080, threads: 0, strength: 1)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
farm.start('example.com', 8080, threads: 0, strength: 1) do
|
57
|
+
score = farm.best[0]
|
58
|
+
assert(!score.expired?)
|
59
|
+
assert_equal(0, score.value)
|
60
|
+
assert_equal('example.com', score.host)
|
61
|
+
assert_equal(8080, score.port)
|
62
|
+
end
|
48
63
|
end
|
49
64
|
end
|
50
65
|
|
@@ -52,12 +67,13 @@ class FarmTest < Minitest::Test
|
|
52
67
|
Dir.mktmpdir 'test' do |dir|
|
53
68
|
cache = File.join(dir, 'cache')
|
54
69
|
farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', cache, log: test_log)
|
55
|
-
farm.start('example.com', 8080, threads: 0, strength: 1)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
farm.start('example.com', 8080, threads: 0, strength: 1) do
|
71
|
+
score = farm.best[0]
|
72
|
+
assert_equal(0, score.value)
|
73
|
+
assert(!score.expired?)
|
74
|
+
assert_equal('example.com', score.host)
|
75
|
+
assert_equal(8080, score.port)
|
76
|
+
end
|
61
77
|
end
|
62
78
|
end
|
63
79
|
|
@@ -66,18 +82,18 @@ class FarmTest < Minitest::Test
|
|
66
82
|
cache = File.join(dir, 'cache')
|
67
83
|
score = Zold::Score.new(
|
68
84
|
Time.parse('2017-07-19T21:24:51Z'),
|
69
|
-
'some-host', 9999, 'NOPREFIX@ffffffffffffffff', [
|
85
|
+
'some-host', 9999, 'NOPREFIX@ffffffffffffffff', %w[13f7f01 b2b32b 4ade7e],
|
70
86
|
strength: 6
|
71
87
|
)
|
72
88
|
File.write(cache, score.to_s)
|
73
89
|
farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', cache, log: test_log)
|
74
|
-
farm.start(score.host, score.port, threads: 1, strength: score.strength)
|
75
|
-
|
76
|
-
|
77
|
-
|
90
|
+
farm.start(score.host, score.port, threads: 1, strength: score.strength) do
|
91
|
+
100.times do
|
92
|
+
sleep(0.1)
|
93
|
+
break if farm.best[0].value.zero?
|
94
|
+
end
|
95
|
+
assert_equal(0, farm.best[0].value)
|
78
96
|
end
|
79
|
-
assert_equal(0, farm.best[0].value)
|
80
|
-
farm.stop
|
81
97
|
end
|
82
98
|
end
|
83
99
|
end
|
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.13.
|
4
|
+
version: 0.13.18
|
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-06-
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|