zold 0.10.10 → 0.10.11

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
  SHA1:
3
- metadata.gz: f1a0df814aaa040edb72486cce4b9512ef380baa
4
- data.tar.gz: c1596a6c12527583ed59d1fa9ec864afb1beb5de
3
+ metadata.gz: 1e2236b7567d7ba2d5c403278d42ec9e9385ab36
4
+ data.tar.gz: a379df9335dcd1d79266e1393f2a38f8c4e93f95
5
5
  SHA512:
6
- metadata.gz: 0fb149dbfbecb7ee537148ced5272b364ca54ecde594261893c9a54018d7e5c4e44895bd88e41f9b0c244d6162c0f6d6c01c04f8c30059f7cd3094bfd5997c42
7
- data.tar.gz: 4195273f638acafef7f21bed1c9e4b35da9d9556c97686ffb66ecc93ef9dcf4bccedd2fbaa6e0d651186b1981c9972414a3953b265116b036bde8f121a43c8ee
6
+ metadata.gz: 94ed101de88e700fcfd8bd785d73b8c999dacc4e0d802ead0309e318f59f315754245b5ef23779e8ccb6f46bc660ef52e014f4365062310f544310713aaf6e1a
7
+ data.tar.gz: edf18e39339f221a86d7d7a368ba45190fa8dab3dda99be33e2bd36e340a149466531f3387ded9b09f04d02e43ee0095e31afa8d9348b9d37707a6478fc3d84e
@@ -22,6 +22,7 @@ require 'slop'
22
22
  require_relative '../score'
23
23
  require_relative '../wallets'
24
24
  require_relative '../remotes'
25
+ require_relative '../verbose_thread'
25
26
  require_relative '../node/entrance'
26
27
  require_relative '../node/front'
27
28
  require_relative '../node/farm'
@@ -71,34 +72,34 @@ module Zold
71
72
  return
72
73
  end
73
74
  raise '--invoice is mandatory' unless opts[:invoice]
74
- Zold::Front.set(:log, @log)
75
- Zold::Front.set(:logging, @log.debug?)
75
+ Front.set(:log, @log)
76
+ Front.set(:logging, @log.debug?)
76
77
  FileUtils.mkdir_p(opts[:home])
77
- Zold::Front.set(:home, opts[:home])
78
- Zold::Front.set(
78
+ Front.set(:home, opts[:home])
79
+ Front.set(
79
80
  :server_settings,
80
81
  Logger: WebrickLog.new(@log),
81
82
  AccessLog: []
82
83
  )
83
84
  if opts['standalone']
84
85
  remotes = Remotes::Empty.new
85
- @log.debug('Running in standalone mode!')
86
+ @log.debug('Running in standalone mode! (will never talk to other remotes)')
86
87
  else
87
88
  remotes = Remotes.new(File.join(opts[:home], 'zold-remotes'))
88
89
  end
89
90
  wallets = Wallets.new(File.join(opts[:home], 'zold-wallets'))
90
- Zold::Front.set(:wallets, wallets)
91
- Zold::Front.set(:remotes, remotes)
91
+ Front.set(:wallets, wallets)
92
+ Front.set(:remotes, remotes)
92
93
  copies = File.join(opts[:home], 'zold-copies')
93
- Zold::Front.set(:copies, copies)
94
+ Front.set(:copies, copies)
94
95
  address = "#{opts[:host]}:#{opts[:port]}".downcase
95
- Zold::Front.set(:address, address)
96
- Zold::Front.set(
96
+ Front.set(:address, address)
97
+ Front.set(
97
98
  :entrance, Entrance.new(wallets, remotes, copies, address, log: @log)
98
99
  )
99
- Zold::Front.set(:root, Dir.pwd)
100
- Zold::Front.set(:port, opts['bind-port'])
101
- Zold::Front.set(:reboot, !opts['never-reboot'])
100
+ Front.set(:root, Dir.pwd)
101
+ Front.set(:port, opts['bind-port'])
102
+ Front.set(:reboot, !opts['never-reboot'])
102
103
  invoice = opts[:invoice]
103
104
  unless invoice.include?('@')
104
105
  require_relative 'pull'
@@ -112,17 +113,19 @@ module Zold
112
113
  opts[:port],
113
114
  threads: opts[:threads], strength: opts[:strength]
114
115
  )
115
- Zold::Front.set(:farm, farm)
116
+ Front.set(:farm, farm)
116
117
  update = Thread.start do
117
- loop do
118
- sleep(60)
119
- Zold::Remote.new(remotes: remotes, log: @log).run(%w[remote update --reboot])
120
- @log.debug('Regular update of remote nodes succeeded')
118
+ VerboseThread.new(@log).run do
119
+ loop do
120
+ sleep(60)
121
+ Remote.new(remotes: remotes, log: @log).run(%w[remote update --reboot])
122
+ @log.debug('Regular update of remote nodes succeeded')
123
+ end
121
124
  end
122
125
  end
123
126
  @log.debug('Starting up the web front...')
124
127
  begin
125
- Zold::Front.run!
128
+ Front.run!
126
129
  ensure
127
130
  farm.stop
128
131
  update.exit
@@ -21,6 +21,7 @@
21
21
  require 'time'
22
22
  require_relative '../log'
23
23
  require_relative '../score'
24
+ require_relative '../verbose_thread'
24
25
 
25
26
  # The farm of scores.
26
27
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -63,24 +64,26 @@ module Zold
63
64
  @scores << first
64
65
  @threads = (1..threads).map do |t|
65
66
  Thread.new do
66
- Thread.current.name = "farm-#{t}"
67
- loop do
68
- s = @scores.pop
69
- next unless s.valid?
70
- @semaphore.synchronize do
71
- before = @best.map(&:value).max
72
- @best << s
73
- after = @best.map(&:value).max
74
- @best.reject! { |b| b.value < after }
75
- @log.debug("#{Thread.current.name}: best is #{@best[0]}") if before != after
67
+ VerboseThread.new(@log).run do
68
+ Thread.current.name = "farm-#{t}"
69
+ loop do
70
+ s = @scores.pop
71
+ next unless s.valid?
72
+ @semaphore.synchronize do
73
+ before = @best.map(&:value).max
74
+ @best << s
75
+ after = @best.map(&:value).max
76
+ @best.reject! { |b| b.value < after }
77
+ @log.debug("#{Thread.current.name}: best is #{@best[0]}") if before != after
78
+ end
79
+ if @scores.length < 4
80
+ @scores << Score.new(
81
+ Time.now, host, port, @invoice,
82
+ strength: strength
83
+ )
84
+ end
85
+ @scores << s.next
76
86
  end
77
- if @scores.length < 4
78
- @scores << Score.new(
79
- Time.now, host, port, @invoice,
80
- strength: strength
81
- )
82
- end
83
- @scores << s.next
84
87
  end
85
88
  end
86
89
  end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2018 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'log'
22
+
23
+ # Verbose thread.
24
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
+ # License:: MIT
27
+ module Zold
28
+ # Verbose thread
29
+ class VerboseThread
30
+ def initialize(log = Log::Quiet.new)
31
+ @log = log
32
+ end
33
+
34
+ def run
35
+ yield
36
+ rescue StandardError => e
37
+ @log.error("#{e.class.name}: #{e.message} #{e.backtrace.join("\n\t")}")
38
+ raise e
39
+ end
40
+ end
41
+ end
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.10.10'.freeze
26
+ VERSION = '0.10.11'.freeze
27
27
  end
@@ -22,6 +22,7 @@ require 'tmpdir'
22
22
  require 'webmock/minitest'
23
23
  require_relative '../../lib/zold/log'
24
24
  require_relative '../../lib/zold/http'
25
+ require_relative '../../lib/zold/verbose_thread'
25
26
 
26
27
  # Fake node.
27
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -39,7 +40,7 @@ class FakeNode
39
40
  port = server.addr[1]
40
41
  server.close
41
42
  node = Thread.new do
42
- begin
43
+ Zold::VerboseThread.new(@log).run do
43
44
  Thread.current.abort_on_exception = true
44
45
  home = File.join(dir, 'node-home')
45
46
  require_relative '../../lib/zold/commands/node'
@@ -54,8 +55,6 @@ class FakeNode
54
55
  '--home', home
55
56
  ]
56
57
  )
57
- rescue StandardError => e
58
- @log.error(e.message + "\n" + e.backtrace.join("\n\t"))
59
58
  end
60
59
  end
61
60
  home = URI("http://localhost:#{port}/")
@@ -28,7 +28,7 @@ class FarmTest < Minitest::Test
28
28
  def test_makes_best_score_in_background
29
29
  farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff')
30
30
  farm.start('localhost', 80, threads: 4, strength: 2)
31
- sleep 1 while farm.best.empty? || farm.best[0].value.zero?
31
+ sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
32
32
  assert(farm.best[0].value > 0)
33
33
  farm.stop
34
34
  end
data/test/test_tax.rb CHANGED
@@ -47,7 +47,7 @@ class TestTax < Minitest::Test
47
47
  )
48
48
  )
49
49
  tax = Zold::Tax.new(wallet)
50
- assert(tax.debt > Zold::Amount.new(coins: 1_006_524_000))
50
+ assert(tax.debt > Zold::Amount.new(coins: 1_006_523_000))
51
51
  assert(tax.debt < Zold::Amount.new(coins: 1_006_524_999))
52
52
  end
53
53
  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.10.10
4
+ version: 0.10.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -327,6 +327,7 @@ files:
327
327
  - lib/zold/signature.rb
328
328
  - lib/zold/tax.rb
329
329
  - lib/zold/txn.rb
330
+ - lib/zold/verbose_thread.rb
330
331
  - lib/zold/version.rb
331
332
  - lib/zold/wallet.rb
332
333
  - lib/zold/wallets.rb