zold 0.17.9 → 0.17.10

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: 4567d45897491fe4282ba9fffc25102944150b1aeaa78faa404a559daeca9361
4
- data.tar.gz: 4c7ca7524761770cd82f7c21532965a5257240e2733d9bc9ea91bf6a88fcf1af
3
+ metadata.gz: 80212bbebddbc1807018d0ddaf9ce6af4e902b446840efa3976f2bf8aaf70e7f
4
+ data.tar.gz: 962892885f128f4841e36f7c75146ab695832e4a499822acf46fc07e5799934d
5
5
  SHA512:
6
- metadata.gz: d3d437b8b7131358a521be3e0ee49b1f0a81a0bb1c995686cbc22372670f581cc1d4f455b03a445c2ea0a65eb79b33c5706e8d2b3b8abfff197201c4af531cd4
7
- data.tar.gz: 13a80d37be609c96b5522d937848f900eb51a904a2059c4a00315e791948d0fdd421077dd9399644f316ac84e9fb12b99a5f4932887a091c008fc05af5921f9d
6
+ metadata.gz: bf58960e766640f2acf4e6d1665dcbb896ac8590994147e0e8a3819d753633d4d6fe8d126d11637a4c8e5ef702c061b0e21202c411fa5c4f7b2b59f26cfff38c
7
+ data.tar.gz: 300f10b27f536f837526f9d8464990fad14757152eb925096d863fed6e7f50a8c9b7005b3dfd6cd40926116611869f0849bac78ef54361d292a8326e955f27d7
@@ -130,6 +130,9 @@ module Zold
130
130
  o.bool '--skip-oom',
131
131
  'Skip Out Of Memory check and never exit, no matter how much RAM is consumed',
132
132
  default: false
133
+ o.integer '--oom-limit',
134
+ 'Maximum amount of memory we can consume, quit if we take more than that, in Mb (default: 512)',
135
+ default: 512
133
136
  o.integer '--queue-limit',
134
137
  'The maximum number of wallets to be accepted via PUSH and stored in the queue (default: 4096)',
135
138
  default: 4096
@@ -228,7 +231,7 @@ module Zold
228
231
  wallets: @wallets, remotes: @remotes, copies: @copies, log: @log
229
232
  ).run(['invoice', invoice, "--network=#{opts['network']}"])
230
233
  end
231
- SafeEntrance.new(
234
+ entrance = SafeEntrance.new(
232
235
  NoSpamEntrance.new(
233
236
  NoDupEntrance.new(
234
237
  AsyncEntrance.new(
@@ -257,12 +260,13 @@ module Zold
257
260
  log: @log
258
261
  ),
259
262
  network: opts['network']
260
- ).start do |entrance|
261
- Front.set(:entrance, entrance)
262
- Farm.new(invoice, File.join(home, 'farm'), log: @log, farmer: farmer(opts), strength: opts[:strength])
263
- .start(host, opts[:port], threads: opts[:threads]) do |farm|
264
- Front.set(:farm, farm)
265
- metronome(farm, opts).start do |metronome|
263
+ )
264
+ entrance.start do |ent|
265
+ Front.set(:entrance, ent)
266
+ farm = Farm.new(invoice, File.join(home, 'farm'), log: @log, farmer: farmer(opts), strength: opts[:strength])
267
+ farm.start(host, opts[:port], threads: opts[:threads]) do |f|
268
+ Front.set(:farm, f)
269
+ metronome(f, opts).start do |metronome|
266
270
  Front.set(:metronome, metronome)
267
271
  @log.info("Starting up the web front at http://#{host}:#{opts[:port]}...")
268
272
  Front.run!
@@ -84,7 +84,7 @@ Available options:"
84
84
  end
85
85
  next if target.includes_positive?(t.id, id)
86
86
  unless target.prefix?(t.prefix)
87
- @log.error("#{t.amount * -1} to #{t.bnf}: wrong prefix")
87
+ @log.error("#{t.amount * -1} from #{id} to #{t.bnf}: wrong prefix \"#{t.prefix}\" in \"#{t}\"")
88
88
  next
89
89
  end
90
90
  target.add(t.inverse(id))
@@ -187,7 +187,7 @@ Available options:"
187
187
 
188
188
  def add(host, port, opts)
189
189
  if opts['ignore-node'].include?("#{host}:#{port}")
190
- @log.info("#{host}:#{port} won't be added since it's in the --ignore-node list")
190
+ @log.debug("#{host}:#{port} won't be added since it's in the --ignore-node list")
191
191
  return
192
192
  end
193
193
  if opts['ignore-if-exists'] && @remotes.exists?(host, port)
@@ -286,7 +286,8 @@ it's recommended to reboot, but I don't do it because of --never-reboot")
286
286
  if total.zero?
287
287
  @log.info("The list of remotes is #{Rainbow('empty').red}, run 'zold remote reset'!")
288
288
  else
289
- @log.info("There are #{total} known remotes after update in #{Age.new(st)}")
289
+ @log.info("There are #{total} known remotes with the overall score of \
290
+ #{@remotes.all.map { |r| r[:score] }.inject(&:+)}, after update in #{Age.new(st)}")
290
291
  end
291
292
  end
292
293
 
@@ -52,7 +52,7 @@ module Zold
52
52
  cmd.run(args + ['trim'])
53
53
  cmd.run(args + ['select'])
54
54
  @log.info("Reconnected, there are #{@remotes.all.count} remote notes: \
55
- #{@remotes.all.map { |r| "#{r[:host]}:#{r[:port]}" }.join(', ')}")
55
+ #{@remotes.all.map { |r| "#{r[:host]}:#{r[:port]}/#{r[:score]}/#{r[:errors]}" }.join(', ')}")
56
56
  end
57
57
  end
58
58
  end
@@ -39,7 +39,7 @@ module Zold
39
39
  end
40
40
 
41
41
  def fetch(recursive: true)
42
- `find #{([@dir, '-type', 'f', '-print'] + (recursive ? [] : ['-maxdepth', '1'])).join(' ')}`
42
+ `find #{([@dir] + (recursive ? [] : ['-maxdepth', '1']) + ['-type', 'f', '-print']).join(' ')}`
43
43
  .strip
44
44
  .split(' ')
45
45
  .select { |f| f.start_with?(@dir) && f.length > @dir.length }
@@ -62,17 +62,16 @@ module Zold
62
62
  end
63
63
 
64
64
  def start
65
- alive = true
66
65
  @routines.each_with_index do |r, idx|
67
66
  @threads << Thread.start do
68
67
  Thread.current.abort_on_exception = true
69
68
  Thread.current.name = "#{r.class.name}-#{idx}"
70
69
  step = 0
71
- while alive
70
+ loop do
72
71
  @starts[Thread.current] = Time.now
73
72
  begin
74
73
  r.exec(step)
75
- @log.info("Routine #{r.class.name} ##{step} done in #{Age.new(@starts[Thread.current])}")
74
+ @log.debug("Routine #{r.class.name} ##{step} done in #{Age.new(@starts[Thread.current])}")
76
75
  rescue StandardError => e
77
76
  @failures[r.class.name] = Time.now.utc.iso8601 + "\n" + Backtrace.new(e).to_s
78
77
  @log.error("Routine #{r.class.name} ##{step} failed in #{Age.new(@starts[Thread.current])}")
@@ -88,16 +87,10 @@ module Zold
88
87
  ensure
89
88
  start = Time.now
90
89
  unless @threads.empty?
91
- alive = false
92
90
  @log.info("Stopping the metronome with #{@threads.count} threads: #{@threads.map(&:name).join(', ')}")
93
91
  @threads.each do |t|
94
- tstart = Time.now
95
- if t.join(60)
96
- @log.info("Thread #{t.name} finished in #{Age.new(tstart)}")
97
- else
98
- t.exit
99
- @log.info("Thread #{t.name} killed in #{Age.new(tstart)}")
100
- end
92
+ t.kill
93
+ t.join
101
94
  end
102
95
  end
103
96
  @log.info("Metronome stopped in #{Age.new(start)}, #{@failures.count} failures")
@@ -23,6 +23,7 @@
23
23
  STDOUT.sync = true
24
24
 
25
25
  require 'eventmachine'
26
+ require 'get_process_mem'
26
27
  require 'thin'
27
28
  require 'json'
28
29
  require 'sinatra/base'
@@ -135,8 +136,8 @@ while #{settings.address} is in '#{settings.opts['network']}'")
135
136
  headers['X-Zold-Thread'] = Thread.current.object_id.to_s
136
137
  unless @start.nil?
137
138
  if Time.now - @start > 1
138
- settings.log.info("Slow response to #{request.request_method} #{request.url} \
139
- in #{Age.new(@start, limit: 1)}")
139
+ settings.log.info("Slow response to #{request.request_method} #{request.url}
140
+ from #{request.ip} in #{Age.new(@start, limit: 1)}")
140
141
  end
141
142
  headers['X-Zold-Milliseconds'] = ((Time.now - @start) * 1000).round.to_s
142
143
  end
@@ -204,9 +205,8 @@ in #{Age.new(@start, limit: 1)}")
204
205
  Concurrent.processor_count
205
206
  end,
206
207
  memory: settings.zache.get(:memory, lifetime: 5 * 60) do
207
- require 'get_process_mem'
208
208
  mem = GetProcessMem.new.bytes.to_i
209
- if mem > 1024 * 1024 * 1024 && !settings.opts['skip-oom']
209
+ if mem > settings.opts['oom-limit'] * 1024 * 1024 && !settings.opts['skip-oom']
210
210
  settings.log.error("We are too big in memory (#{Size.new(mem)}), quitting; use --skip-oom to never quit")
211
211
  Front.stop!
212
212
  end
@@ -429,6 +429,11 @@ in #{Age.new(@start, limit: 1)}")
429
429
  content_type 'text/plain'
430
430
  headers['X-Zold-Error'] = e.message
431
431
  settings.log.error(Backtrace.new(e).to_s) unless e.is_a?(SoftError)
432
+ if e.is_a?(Errno::ENOMEM) && !settings.opts['skip-oom']
433
+ settings.log.error("We are running out of memory (#{Size.new(GetProcessMem.new.bytes.to_i)}), \
434
+ time to stop; use --skip-oom to never quit")
435
+ Front.stop!
436
+ end
432
437
  Backtrace.new(e).to_s
433
438
  end
434
439
 
@@ -23,6 +23,7 @@
23
23
  require 'concurrent'
24
24
  require 'tempfile'
25
25
  require_relative 'emission'
26
+ require_relative 'soft_error'
26
27
  require_relative '../log'
27
28
  require_relative '../remotes'
28
29
  require_relative '../copies'
@@ -64,19 +65,19 @@ module Zold
64
65
  wallet = Wallet.new(f.path)
65
66
  wallet.refurbish
66
67
  unless wallet.protocol == Zold::PROTOCOL
67
- raise "Protocol mismatch, #{wallet.id} is in '#{wallet.protocol}', we are in '#{Zold::PROTOCOL}'"
68
+ raise SoftError, "Protocol mismatch, #{wallet.id} is in '#{wallet.protocol}', we are in '#{Zold::PROTOCOL}'"
68
69
  end
69
70
  unless wallet.network == @network
70
- raise "Network name mismatch, #{wallet.id} is in '#{wallet.network}', we are in '#{@network}'"
71
+ raise SoftError, "Network name mismatch, #{wallet.id} is in '#{wallet.network}', we are in '#{@network}'"
71
72
  end
72
73
  balance = wallet.balance
73
74
  if balance.negative? && !wallet.root?
74
- raise "The balance #{balance} of #{wallet.id} is negative and it's not a root wallet"
75
+ raise SoftError, "The balance #{balance} of #{wallet.id} is negative and it's not a root wallet"
75
76
  end
76
77
  Emission.new(wallet).check
77
78
  tax = Tax.new(wallet)
78
79
  if tax.in_debt?
79
- raise "Taxes are not paid, can't accept the wallet #{wallet.mnemo}; the debt is #{tax.debt} \
80
+ raise SoftError, "Taxes are not paid, can't accept the wallet #{wallet.mnemo}; the debt is #{tax.debt} \
80
81
  (#{tax.debt.to_i} zents); formula ingredients are #{tax.to_text}"
81
82
  end
82
83
  @entrance.push(id, body)
@@ -66,7 +66,9 @@ module Zold
66
66
  Endless.new('push', log: @log).run do
67
67
  id = @modified.pop
68
68
  if @remotes.all.empty?
69
- @log.info("There are no remotes, won\'t spread #{id}")
69
+ @log.info("There are no remotes, won't spread #{id}")
70
+ elsif @wallets.acq(id) { |w| Tax.new(w).in_debt? }
71
+ @log.info("The wallet #{id} is in debt, won't spread")
70
72
  else
71
73
  Thread.current.thread_variable_set(:wallet, id.to_s)
72
74
  Push.new(wallets: @wallets, remotes: @remotes, log: @log).run(
@@ -82,7 +84,8 @@ module Zold
82
84
  ensure
83
85
  @log.info('Waiting for spread entrance to finish...')
84
86
  @modified.clear
85
- @push.exit
87
+ @push.kill
88
+ @push.join
86
89
  @log.info('Spread entrance finished, thread killed')
87
90
  end
88
91
  end
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.9'
28
+ VERSION = '0.17.10'
29
29
  PROTOCOL = 2
30
30
  end
@@ -284,14 +284,13 @@ class FrontTest < Zold::Test
284
284
  # out those that are too weak.
285
285
  def test_score_is_reduced
286
286
  FakeNode.new(log: test_log).run(['--threads=1', '--strength=1', '--no-metronome', '--farmer=plain']) do |port|
287
- res = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
288
- assert_wait(max: 60) do
289
- Zold::Score.parse(res.headers[Zold::Http::SCORE_HEADER]).value > Zold::Front::MIN_SCORE - 1
290
- end
291
- sleep(3)
292
- assert_equal_wait(Zold::Front::MIN_SCORE, max: 60) do
293
- Zold::Score.parse(res.headers[Zold::Http::SCORE_HEADER]).value
287
+ scores = []
288
+ 50.times do
289
+ res = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
290
+ scores << Zold::Score.parse(res.headers[Zold::Http::SCORE_HEADER]).value
291
+ sleep(0.1)
294
292
  end
293
+ assert(scores.uniq.sort.reverse[0] <= Zold::Front::MIN_SCORE)
295
294
  end
296
295
  end
297
296
 
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.17.9
4
+ version: 0.17.10
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-12-04 00:00:00.000000000 Z
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -700,7 +700,7 @@ licenses:
700
700
  - MIT
701
701
  metadata: {}
702
702
  post_install_message: |-
703
- Thanks for installing Zold 0.17.9!
703
+ Thanks for installing Zold 0.17.10!
704
704
  Study our White Paper: https://papers.zold.io/wp.pdf
705
705
  Read our blog posts: https://blog.zold.io
706
706
  Try online wallet at: https://wts.zold.io