zold 0.17.3 → 0.17.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b180bc5d7ff240eafaa73f624652f2842cd576f3c43b87642e77d37716249a1
4
- data.tar.gz: '0279c65c274f3725bf91ab3ba0b93ed60aca6b9db2edf7ab2a4f546818104acb'
3
+ metadata.gz: 622a8738f318299d195dd0efbe8cdb8bc41aac3432a964b775a31a1b78cc592f
4
+ data.tar.gz: 06ed79ff0550b5e4f66eb28af66051b14b3d840caf4ea936cfd40b36e6693124
5
5
  SHA512:
6
- metadata.gz: d840735668e54a0d8c88f7161c273631de34c06a938f7232cecbe61e11fe74ebac60fd0f810fcb832ff3b26b73ceb37e4d45a7d9529d6e7f0dda18bce433ad69
7
- data.tar.gz: 9ebec3e75b50640543bf569f0957e1808af5f7bb5d82316bf21b58c7f98cec23961a40ed4297a73a52693c9054923c719a34b68bdf2f6e8cf586cad2256c013f
6
+ metadata.gz: d0e4e8282e87e826b31e3662f0139aa4e0634c4d5e7d2cdb13b48a8958bb48557c007605a4f07d79f50b678acf7beab1860ddb1283b2819b00b66f208ab3b850
7
+ data.tar.gz: 9a4fb162a36f9db69b3c5916ffca1658c75ea3450b975e05d29054a6b6da991e46e4bdb6c201394a724dcf1461284e1d1a101a000a09bdfebec2420a5c9957f5
@@ -251,8 +251,8 @@ module Zold
251
251
  ).start do |entrance|
252
252
  Front.set(:entrance, entrance)
253
253
  farmer = opts['no-spawn'] ? Farmers::Plain.new : Farmers::Fork.new(log: @log)
254
- Farm.new(invoice, File.join(home, 'farm'), log: @log, farmer: farmer)
255
- .start(host, opts[:port], threads: opts[:threads], strength: opts[:strength]) do |farm|
254
+ Farm.new(invoice, File.join(home, 'farm'), log: @log, farmer: farmer, strength: opts[:strength])
255
+ .start(host, opts[:port], threads: opts[:threads]) do |farm|
256
256
  Front.set(:farm, farm)
257
257
  metronome(farm, opts).start do |metronome|
258
258
  Front.set(:metronome, metronome)
@@ -58,7 +58,7 @@ module Zold
58
58
  # it's the entire day, since the Score expires in 24 hours; can be decreased for the
59
59
  # purpose of unit testing.
60
60
  def initialize(invoice, cache = File.join(Dir.pwd, 'farm'), log: Log::NULL,
61
- farmer: Farmers::Plain.new, lifetime: 24 * 60 * 60)
61
+ farmer: Farmers::Plain.new, lifetime: 24 * 60 * 60, strength: Score::STRENGTH)
62
62
  @log = log
63
63
  @cache = File.expand_path(cache)
64
64
  @invoice = invoice
@@ -66,6 +66,7 @@ module Zold
66
66
  @farmer = farmer
67
67
  @threads = []
68
68
  @lifetime = lifetime
69
+ @strength = strength
69
70
  end
70
71
 
71
72
  # Returns the list of best scores the farm managed to find up to now. The
@@ -112,7 +113,7 @@ module Zold
112
113
  #
113
114
  # The farm will stop all its threads and close all resources safely
114
115
  # right after the block provided exists.
115
- def start(host, port, strength: Score::STRENGTH, threads: Concurrent.processor_count)
116
+ def start(host, port, threads: Concurrent.processor_count)
116
117
  raise 'Block is required for the farm to start' unless block_given?
117
118
  @log.info('Zero-threads farm won\'t score anything!') if threads.zero?
118
119
  if best.empty?
@@ -124,7 +125,7 @@ module Zold
124
125
  Thread.new do
125
126
  Thread.current.thread_variable_set(:tid, t.to_s)
126
127
  Endless.new("f#{t}", log: @log).run do
127
- cycle(host, port, strength, threads)
128
+ cycle(host, port, threads)
128
129
  end
129
130
  end
130
131
  end
@@ -132,7 +133,7 @@ module Zold
132
133
  ready = false
133
134
  @threads << Thread.new do
134
135
  Endless.new('cleanup', log: @log).run do
135
- cleanup(host, port, strength, threads)
136
+ cleanup(host, port, threads)
136
137
  ready = true
137
138
  sleep(1)
138
139
  end
@@ -140,26 +141,26 @@ module Zold
140
141
  loop { break if ready }
141
142
  end
142
143
  if @threads.empty?
143
- cleanup(host, port, strength, threads)
144
+ cleanup(host, port, threads)
144
145
  @log.info("Farm started with no threads (there will be no score) at #{host}:#{port}")
145
146
  else
146
147
  @log.info("Farm started with #{@threads.count} threads (one for cleanup) \
147
- at #{host}:#{port}, strength is #{strength}")
148
+ at #{host}:#{port}, strength is #{@strength}")
148
149
  end
149
150
  begin
150
151
  yield(self)
151
152
  ensure
152
153
  @threads.each(&:kill)
153
- @log.info("Farm stopped (threads=#{threads}, strength=#{strength})")
154
+ @log.info("Farm stopped (threads=#{threads}, strength=#{@strength})")
154
155
  end
155
156
  end
156
157
 
157
158
  private
158
159
 
159
- def cleanup(host, port, strength, threads)
160
+ def cleanup(host, port, threads)
160
161
  scores = load
161
162
  before = scores.map(&:value).max.to_i
162
- save(threads, [Score.new(host: host, port: port, invoice: @invoice, strength: strength)])
163
+ save(threads, [Score.new(host: host, port: port, invoice: @invoice, strength: @strength)])
163
164
  scores = load
164
165
  free = scores.reject { |s| @threads.find { |t| t.name == s.to_mnemo } }
165
166
  @pipeline << free[0] if @pipeline.size.zero? && !free.empty?
@@ -168,7 +169,7 @@ at #{host}:#{port}, strength is #{strength}")
168
169
  @log.debug("#{Thread.current.name}: best score of #{scores.count} is #{scores[0]}")
169
170
  end
170
171
 
171
- def cycle(host, port, strength, threads)
172
+ def cycle(host, port, threads)
172
173
  s = []
173
174
  loop do
174
175
  begin
@@ -183,13 +184,13 @@ at #{host}:#{port}, strength is #{strength}")
183
184
  return unless s.valid?
184
185
  return unless s.host == host
185
186
  return unless s.port == port
186
- return unless s.strength >= strength
187
+ return unless s.strength >= @strength
187
188
  Thread.current.name = s.to_mnemo
188
189
  Thread.current.thread_variable_set(:start, Time.now.utc.iso8601)
189
190
  score = @farmer.up(s)
190
- @log.debug("New score discovered: #{score}") if strength > 4
191
+ @log.debug("New score discovered: #{score}") if @strength > 4
191
192
  save(threads, [score])
192
- cleanup(host, port, strength, threads)
193
+ cleanup(host, port, threads)
193
194
  end
194
195
 
195
196
  def save(threads, list = [])
@@ -200,6 +201,7 @@ at #{host}:#{port}, strength is #{strength}")
200
201
  f,
201
202
  scores.select(&:valid?)
202
203
  .reject(&:expired?)
204
+ .reject { |s| s.strength < @strength }
203
205
  .sort_by(&:value)
204
206
  .reverse
205
207
  .uniq(&:time)
data/lib/zold/version.rb CHANGED
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.17.3'
28
+ VERSION = '0.17.4'
29
29
  PROTOCOL = 2
30
30
  end
@@ -30,8 +30,8 @@ require_relative '../../lib/zold/node/farm'
30
30
  class FarmTest < Zold::Test
31
31
  def test_renders_in_json
32
32
  Dir.mktmpdir do |dir|
33
- farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
34
- farm.start('localhost', 80, threads: 2, strength: 2) do
33
+ farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 2)
34
+ farm.start('localhost', 80, threads: 2) do
35
35
  assert_wait { !farm.best.empty? && !farm.best[0].value.zero? }
36
36
  count = 0
37
37
  100.times { count += farm.to_json[:best].length }
@@ -42,8 +42,8 @@ class FarmTest < Zold::Test
42
42
 
43
43
  def test_renders_in_text
44
44
  Dir.mktmpdir do |dir|
45
- farm = Zold::Farm.new('NOPREFIX7@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
46
- farm.start('localhost', 80, threads: 2, strength: 1) do
45
+ farm = Zold::Farm.new('NOPREFIX7@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 1)
46
+ farm.start('localhost', 80, threads: 2) do
47
47
  assert(!farm.to_text.nil?)
48
48
  end
49
49
  end
@@ -52,8 +52,8 @@ class FarmTest < Zold::Test
52
52
  def test_makes_many_scores
53
53
  Dir.mktmpdir do |dir|
54
54
  farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'),
55
- log: test_log, lifetime: 10, farmer: Zold::Farmers::Plain.new)
56
- farm.start('localhost', 80, threads: 4, strength: 1) do
55
+ log: test_log, lifetime: 10, farmer: Zold::Farmers::Plain.new, strength: 1)
56
+ farm.start('localhost', 80, threads: 4) do
57
57
  assert_wait { farm.best.length == 4 }
58
58
  end
59
59
  end
@@ -67,8 +67,8 @@ class FarmTest < Zold::Test
67
67
  # that it's usually a few microseconds, but sometimes over 200ms.
68
68
  def test_reads_scores_at_high_speed
69
69
  Dir.mktmpdir do |dir|
70
- farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
71
- farm.start('localhost', 80, threads: 4, strength: 4) do
70
+ farm = Zold::Farm.new('NOPREFIX6@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 4)
71
+ farm.start('localhost', 80, threads: 4) do
72
72
  assert_wait { !farm.best.empty? && !farm.best[0].value.zero? }
73
73
  cycles = 100
74
74
  speed = (0..cycles - 1).map do
@@ -83,8 +83,8 @@ class FarmTest < Zold::Test
83
83
 
84
84
  def test_makes_best_score_in_background
85
85
  Dir.mktmpdir do |dir|
86
- farm = Zold::Farm.new('NOPREFIX1@ffffffffffffffff', File.join(dir, 'f'), log: test_log)
87
- farm.start('localhost', 80, threads: 1, strength: 3) do
86
+ farm = Zold::Farm.new('NOPREFIX1@ffffffffffffffff', File.join(dir, 'f'), log: test_log, strength: 3)
87
+ farm.start('localhost', 80, threads: 1) do
88
88
  assert_wait { !farm.best.empty? && farm.best[0].value >= 3 }
89
89
  score = farm.best[0]
90
90
  assert(!score.expired?)
@@ -95,8 +95,8 @@ class FarmTest < Zold::Test
95
95
 
96
96
  def test_correct_score_from_empty_farm
97
97
  Dir.mktmpdir do |dir|
98
- farm = Zold::Farm.new('NOPREFIX2@cccccccccccccccc', File.join(dir, 'f'), log: test_log)
99
- farm.start('example.com', 8080, threads: 0, strength: 1) do
98
+ farm = Zold::Farm.new('NOPREFIX2@cccccccccccccccc', File.join(dir, 'f'), log: test_log, strength: 1)
99
+ farm.start('example.com', 8080, threads: 0) do
100
100
  score = farm.best[0]
101
101
  assert(!score.expired?)
102
102
  assert_equal(0, score.value)
@@ -109,8 +109,8 @@ class FarmTest < Zold::Test
109
109
  def test_pre_loads_history
110
110
  Dir.mktmpdir do |dir|
111
111
  cache = File.join(dir, 'a/b/c/cache')
112
- farm = Zold::Farm.new('NOPREFIX3@cccccccccccccccc', cache, log: test_log)
113
- farm.start('example.com', 8080, threads: 0, strength: 1) do
112
+ farm = Zold::Farm.new('NOPREFIX3@cccccccccccccccc', cache, log: test_log, strength: 1)
113
+ farm.start('example.com', 8080, threads: 0) do
114
114
  score = farm.best[0]
115
115
  assert(!score.nil?, 'The list of best scores can\'t be empty!')
116
116
  assert(File.exist?(cache), 'The cache file has to be created!')
@@ -132,8 +132,8 @@ class FarmTest < Zold::Test
132
132
  strength: 6
133
133
  )
134
134
  IO.write(cache, score.to_s)
135
- farm = Zold::Farm.new('NOPREFIX4@ffffffffffffffff', cache, log: test_log)
136
- farm.start(score.host, score.port, threads: 1, strength: score.strength) do
135
+ farm = Zold::Farm.new('NOPREFIX4@ffffffffffffffff', cache, log: test_log, strength: score.strength)
136
+ farm.start(score.host, score.port, threads: 1) do
137
137
  100.times do
138
138
  sleep(0.1)
139
139
  b = farm.best[0]
@@ -170,7 +170,7 @@ class FarmTest < Zold::Test
170
170
  end
171
171
 
172
172
  def test_terminates_farm_entirely
173
- Zold::Farm.new('NOPREFIX4@ffffffffffffffff', log: test_log).start('localhost', 4096, threads: 1, strength: 10) do
173
+ Zold::Farm.new('NOPREFIX4@ffffffffffffffff', log: test_log, strength: 10).start('localhost', 4096, threads: 1) do
174
174
  sleep 1
175
175
  end
176
176
  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.17.3
4
+ version: 0.17.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -711,7 +711,7 @@ licenses:
711
711
  - MIT
712
712
  metadata: {}
713
713
  post_install_message: |-
714
- Thanks for installing Zold 0.17.3!
714
+ Thanks for installing Zold 0.17.4!
715
715
  Study our White Paper: https://papers.zold.io/wp.pdf
716
716
  Read our blog posts: https://blog.zold.io
717
717
  Try online wallet at: https://wts.zold.io