zold 0.19.1 → 0.19.2

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: 4a31487e8700a8c5b7c346e82df8f142931e471a37292df407067320a6a095e9
4
- data.tar.gz: ffb06dbf75783b9be9c7b02271bdb5a1a1a70a74b61909cb52f82b24d7ac6ab3
3
+ metadata.gz: 32709fc443bc01bdd90a978c9cc7204fd8d6758466a46dbecb5c811bd2a40a12
4
+ data.tar.gz: cd4fe030458935e3ec27db1673289d3b1dbdf63989b027ea50bf8f336fcab49f
5
5
  SHA512:
6
- metadata.gz: 78ded3b0ff00af5ccf51e31d68e5e8593f3a1c0ee5851a3b051ee77b29e9abad1b672f9daca870bcc6805f0089db89c12c92b791d6cdbecc393db0ac9dc607bc
7
- data.tar.gz: b7e0bcdf1b27eaefe1ddb141538f0b01a001cdfe3128056c1620c7f8201d6e72e21f0623a7d3c044a08bc1d8ec64e5a8ed067ef9d2267372ebd226d9fa86fd5b
6
+ metadata.gz: c7b3009e694c98f2dd296d888191b2060cd222e19d621bda1cb457941b5167257149d6c9e7c1ea9645cb221b1c8014fc8d7f44574fcbcecd9a731a204ec5c4ba
7
+ data.tar.gz: 30a9c25381547e573a6908412465311c7477314d085100d17fe3ca4baa4289e42196fc62bfdd6565998b36b6d773f3c17bd074c9e0dd2d74e4be83f1590ca9a9
data/heroku-run.sh CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/bin/sh
2
2
 
3
- ./bin/zold node --no-colors --trace --dump-errors \
3
+ ./bin/zold node --no-colors --trace --dump-errors --skip-oom \
4
4
  --bind-port=$PORT --port=80 --host=b1.zold.io --threads=0 \
5
5
  --invoice=ML5Ern7m@912ecc24b32dbe74 --never-reboot
@@ -99,6 +99,7 @@ Available options:"
99
99
  private
100
100
 
101
101
  def fetch(id, cps, opts)
102
+ raise "There are no remote nodes, run 'zold remote reset'" if @remotes.all.empty?
102
103
  start = Time.now
103
104
  total = Concurrent::AtomicFixnum.new
104
105
  nodes = Concurrent::AtomicFixnum.new
@@ -110,14 +111,14 @@ Available options:"
110
111
  masters.increment if r.master?
111
112
  done.increment
112
113
  end
113
- raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
114
114
  unless opts['quiet-if-absent']
115
115
  raise "No nodes out of #{nodes.value} have the wallet #{id}" if done.value.zero?
116
116
  if masters.value.zero? && !opts['tolerate-edges']
117
- raise EdgesOnly, "There are only edge nodes, run 'zold remote reset' or use --tolerate-edges"
117
+ raise EdgesOnly, "There are only edge nodes, run 'zold remote update' or use --tolerate-edges"
118
118
  end
119
119
  if nodes.value < opts['tolerate-quorum']
120
- raise NoQuorum, "There were not enough nodes, run 'zold remote reset' or use --tolerate-quorum=1"
120
+ raise NoQuorum, "There were not enough nodes, the required quorum is #{opts['tolerate-quorum']}; \
121
+ run 'zold remote update' or use --tolerate-quorum=1"
121
122
  end
122
123
  end
123
124
  @log.info("#{done.value} copies of #{id} fetched in #{Age.new(start)} with the total score of \
@@ -91,25 +91,26 @@ Available options:"
91
91
  private
92
92
 
93
93
  def push(id, opts)
94
+ raise "There are no remote nodes, run 'zold remote reset'" if @remotes.all.empty?
95
+ start = Time.now
94
96
  total = Concurrent::AtomicFixnum.new
95
97
  nodes = Concurrent::AtomicFixnum.new
96
98
  done = Concurrent::AtomicFixnum.new
97
99
  masters = Concurrent::AtomicFixnum.new
98
- start = Time.now
99
100
  @remotes.iterate(@log) do |r|
100
101
  nodes.increment
101
102
  total.increment(push_one(id, r, opts))
102
103
  masters.increment if r.master?
103
104
  done.increment
104
105
  end
105
- raise "There are no remote nodes, run 'zold remote reset'" if nodes.value.zero?
106
106
  unless opts['quiet-if-missed']
107
107
  raise "No nodes out of #{nodes} accepted the wallet #{id}" if done.value.zero?
108
108
  if masters.value.zero? && !opts['tolerate-edges']
109
- raise EdgesOnly, "There are only edge nodes, run 'zold remote reset' or use --tolerate-edges"
109
+ raise EdgesOnly, "There are only edge nodes, run 'zold remote update' or use --tolerate-edges"
110
110
  end
111
111
  if nodes.value < opts['tolerate-quorum']
112
- raise NoQuorum, "There were not enough nodes, run 'zold remote reset' or use --tolerate-quorum=1"
112
+ raise NoQuorum, "There were not enough nodes, the required quorum is #{opts['tolerate-quorum']}; \
113
+ run 'zold remote update' or use --tolerate-quorum=1"
113
114
  end
114
115
  end
115
116
  @log.info("Push finished to #{done.value} nodes (#{masters.value} master nodes) \
@@ -107,7 +107,7 @@ Available options:"
107
107
  default: false
108
108
  o.integer '--depth',
109
109
  'The amount of update cycles to run, in order to fetch as many nodes as possible (default: 2)',
110
- default: 2
110
+ default: 3
111
111
  o.string '--network',
112
112
  "The name of the network we work in (default: #{Wallet::MAINET}",
113
113
  required: true,
@@ -28,6 +28,9 @@ require_relative '../log'
28
28
  require_relative '../id'
29
29
  require_relative '../amount'
30
30
  require_relative '../wallet'
31
+ require_relative '../tax'
32
+ require_relative '../size'
33
+ require_relative '../age'
31
34
 
32
35
  # SHOW command.
33
36
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -72,9 +75,17 @@ Available options:"
72
75
  wallet.txns.each do |t|
73
76
  @log.info(t.to_text)
74
77
  end
75
- msg = "The balance of #{wallet}: #{balance}"
76
- msg += " (net:#{wallet.network})" if wallet.network != Wallet::MAINET
77
- @log.info(msg)
78
+ @log.info(
79
+ [
80
+ "The balance of #{wallet}: #{balance} (#{balance.to_i} zents)",
81
+ "Network: #{wallet.network}",
82
+ "Transactions: #{wallet.txns.count}",
83
+ "Taxes: #{Tax.new(wallet).paid} paid, the debt is #{Tax.new(wallet).debt}",
84
+ "File size: #{Size.new(wallet.size)}, #{Copies.new(File.join(@copies, wallet.id)).all.count} copies",
85
+ "Modified: #{wallet.mtime.utc.iso8601} (#{Age.new(wallet.mtime.utc.iso8601)} ago)",
86
+ "Digest: #{wallet.digest}"
87
+ ].join("\n")
88
+ )
78
89
  balance
79
90
  end
80
91
  end
@@ -24,6 +24,7 @@ require 'delegate'
24
24
  require_relative 'log'
25
25
  require_relative 'thread_pool'
26
26
  require_relative 'commands/pull'
27
+ require_relative 'commands/fetch'
27
28
 
28
29
  # Wallets that PULL what's missing, in the background.
29
30
  #
@@ -41,31 +42,45 @@ module Zold
41
42
  @log = log
42
43
  @network = network
43
44
  @pool = pool
44
- @queue = Queue.new
45
+ @queue = []
46
+ @mutex = Mutex.new
45
47
  @pool.add do
46
- Endless.new('hungry', log: log).run do
47
- id = @queue.pop
48
- Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
49
- ['pull', id.to_s, "--network=#{@network}"]
50
- )
51
- rescue Pull::EdgesOnly => e
52
- @log.error("Can't hungry-pull #{id}: #{e.message}")
53
- end
48
+ Endless.new('hungry', log: log).run { pull }
54
49
  end
55
50
  super(wallets)
56
51
  end
57
52
 
58
53
  def acq(id, exclusive: false)
59
54
  @wallets.acq(id, exclusive: exclusive) do |wallet|
60
- unless wallet.exists?
61
- if @queue.size > 256
62
- @log.error("Hungry queue is full with #{@queue.size} wallets, can't add #{id}")
63
- else
64
- @queue << id
55
+ if @queue.size > 256
56
+ @log.error("Hungry queue is full with #{@queue.size} wallets, can't add #{id}")
57
+ else
58
+ @mutex.synchronize do
59
+ unless @queue.include?(id)
60
+ @queue << id
61
+ @log.debug("Hungry queue got #{id}, at the pos no.#{@queue.size}")
62
+ end
65
63
  end
66
64
  end
67
65
  yield wallet
68
66
  end
69
67
  end
68
+
69
+ private
70
+
71
+ def pull
72
+ id = @mutex.synchronize { @queue.pop }
73
+ if id.nil?
74
+ sleep 1
75
+ return
76
+ end
77
+ begin
78
+ Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
79
+ ['pull', id.to_s, "--network=#{@network}"]
80
+ )
81
+ rescue Fetch::EdgesOnly => e
82
+ @log.error("Can't hungry-pull #{id}: #{e.message}")
83
+ end
84
+ end
70
85
  end
71
86
  end
@@ -94,18 +94,23 @@ module Zold
94
94
  @log.debug("Stopping \"#{@title}\" thread pool with #{@threads.count} threads: \
95
95
  #{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}...")
96
96
  start = Time.new
97
- @threads.each do |t|
98
- (t.thread_variable_get(:kids) || []).each(&:kill)
99
- t.kill
100
- raise "Failed to join the thread \"#{t.name}\" in \"#{@title}\" pool" unless t.join(0.1)
101
- Thread.current.thread_variable_set(
102
- :kids,
103
- (Thread.current.thread_variable_get(:kids) || []) - [t]
104
- )
105
- end
106
- @log.debug("Thread pool \"#{@title}\" terminated all threads in #{Age.new(start)}, \
97
+ begin
98
+ @threads.each do |t|
99
+ t.join(0.1)
100
+ end
101
+ ensure
102
+ @threads.each do |t|
103
+ (t.thread_variable_get(:kids) || []).each(&:kill)
104
+ t.kill
105
+ Thread.current.thread_variable_set(
106
+ :kids,
107
+ (Thread.current.thread_variable_get(:kids) || []) - [t]
108
+ )
109
+ end
110
+ @log.debug("Thread pool \"#{@title}\" terminated all threads in #{Age.new(start)}, \
107
111
  it was alive for #{Age.new(@start)}: #{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}")
108
- @threads.clear
112
+ @threads.clear
113
+ end
109
114
  end
110
115
 
111
116
  # How many threads are in there
data/lib/zold/version.rb CHANGED
@@ -25,7 +25,7 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.19.1'
28
+ VERSION = '0.19.2'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
@@ -46,7 +46,7 @@ class TestHungryWallets < Zold::Test
46
46
  pool, log: test_log
47
47
  )
48
48
  wallets.acq(id) { |w| assert(!w.exists?) }
49
- pool.join(1)
49
+ pool.join(2)
50
50
  assert_requested(get)
51
51
  end
52
52
  end
@@ -71,8 +71,11 @@ class TestThreadPool < Zold::Test
71
71
 
72
72
  def test_runs_with_exceptions
73
73
  assert_raises do
74
- Zold::ThreadPool.new('test', log: test_log).run(1) do
75
- raise 'intended'
74
+ Zold::ThreadPool.new('test', log: test_log).run(5) do |i|
75
+ if i == 4
76
+ sleep 0.1
77
+ raise 'intended'
78
+ end
76
79
  end
77
80
  end
78
81
  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.19.1
4
+ version: 0.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -690,7 +690,7 @@ licenses:
690
690
  - MIT
691
691
  metadata: {}
692
692
  post_install_message: |-
693
- Thanks for installing Zold 0.19.1!
693
+ Thanks for installing Zold 0.19.2!
694
694
  Study our White Paper: https://papers.zold.io/wp.pdf
695
695
  Read our blog posts: https://blog.zold.io
696
696
  Try online wallet at: https://wts.zold.io