zold 0.13.21 → 0.13.22
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/lib/zold/commands/node.rb +1 -1
- data/lib/zold/node/farm.rb +9 -13
- data/lib/zold/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2e4d4e5e627137b421211b093b25dd2930423d7
|
4
|
+
data.tar.gz: e78835ebe8c5ead373287def6500d3d17a9ab648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d902fe84aa485c17b9785d83a832ca212c001db35bedd520026d1f4bc41e162006b3aecc3459192a9d5d24e6bfdbcd7a157edb871695b34fe663c816f35f6c
|
7
|
+
data.tar.gz: 176e92ee884fb86e0ef764bf05478cebb940183b07082f6f8ade8cec1162648cdcc319ace98fdd6776e9f2506afa9f2794163e483a0493445a252f97d9b619e2
|
data/lib/zold/commands/node.rb
CHANGED
@@ -155,7 +155,7 @@ 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(
|
158
|
+
farm.start(host, opts[:port], threads: opts[:threads], strength: opts[:strength]) do
|
159
159
|
Front.set(:farm, farm)
|
160
160
|
metronome = metronome(farm, entrance, opts)
|
161
161
|
begin
|
data/lib/zold/node/farm.rb
CHANGED
@@ -63,7 +63,7 @@ module Zold
|
|
63
63
|
def to_json
|
64
64
|
{
|
65
65
|
threads: @threads.map do |t|
|
66
|
-
"#{t.name}/#{t.status}
|
66
|
+
"#{t.name}/#{t.status}/#{t.alive? ? 'A' : 'D'}"
|
67
67
|
end.join(', '),
|
68
68
|
scores: @scores.size,
|
69
69
|
best: @best.map(&:value).join(', '),
|
@@ -74,9 +74,8 @@ module Zold
|
|
74
74
|
def start(host, port, strength: 8, threads: 8)
|
75
75
|
@log.debug('Zero-threads farm won\'t score anything!') if threads.zero?
|
76
76
|
@scores = Queue.new
|
77
|
-
|
78
|
-
|
79
|
-
@best << (h[0] || Score.new(Time.now, host, port, @invoice, strength: strength))
|
77
|
+
@best = history
|
78
|
+
clean(host, port, strength, threads)
|
80
79
|
@log.info("#{@scores.size} scores pre-loaded, the best is: #{@best[0]}")
|
81
80
|
@threads = (1..threads).map do |t|
|
82
81
|
Thread.new do
|
@@ -121,21 +120,19 @@ module Zold
|
|
121
120
|
|
122
121
|
def clean(host, port, strength, threads)
|
123
122
|
@mutex.synchronize do
|
124
|
-
before = @best.map(&:value).max
|
125
|
-
@best = @best.reject(&:expired?).sort_by(&:value).reverse
|
123
|
+
before = @best.map(&:value).max.to_i
|
124
|
+
@best = @best.select(&:valid?).reject(&:expired?).sort_by(&:value).reverse
|
126
125
|
@best = @best.take(threads) unless threads.zero?
|
127
|
-
if @
|
128
|
-
|
129
|
-
@scores << zero
|
130
|
-
@best << zero
|
126
|
+
if @best.empty? || !threads.zero? && @best.map(&:age_hours).min > 24 / threads
|
127
|
+
@best << Score.new(Time.now, host, port, @invoice, strength: strength)
|
131
128
|
end
|
129
|
+
@best.sort_by(&:age_hours).each { |b| @scores << b }
|
132
130
|
after = @best.map(&:value).max
|
133
131
|
@log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
|
134
132
|
end
|
135
133
|
end
|
136
134
|
|
137
135
|
def cycle(host, port, strength, threads)
|
138
|
-
clean(host, port, strength, threads)
|
139
136
|
s = @scores.pop
|
140
137
|
return unless s.valid?
|
141
138
|
return unless s.host == host
|
@@ -154,7 +151,7 @@ module Zold
|
|
154
151
|
AtomicFile.new(@cache).write((history + [score]).map(&:to_s).uniq.join("\n"))
|
155
152
|
end
|
156
153
|
|
157
|
-
def history
|
154
|
+
def history
|
158
155
|
if File.exist?(@cache)
|
159
156
|
AtomicFile.new(@cache).read
|
160
157
|
.split(/\n/)
|
@@ -162,7 +159,6 @@ module Zold
|
|
162
159
|
.select(&:valid?)
|
163
160
|
.sort_by(&:value)
|
164
161
|
.reverse
|
165
|
-
.take(max)
|
166
162
|
else
|
167
163
|
[]
|
168
164
|
end
|
data/lib/zold/version.rb
CHANGED