zold 0.20.1 → 0.20.2

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bin/zold +23 -7
  3. data/fixtures/merge/into-no-wallet/copies/0123456789abcdef/scores.zc +1 -1
  4. data/fixtures/merge/random-expenses/copies/0123456789abcdef/scores.zc +5 -5
  5. data/fixtures/merge/simple-case/copies/0123456789abcdef/scores.zc +1 -1
  6. data/lib/zold/age.rb +2 -1
  7. data/lib/zold/amount.rb +3 -0
  8. data/lib/zold/cached_wallets.rb +2 -2
  9. data/lib/zold/commands/calculate.rb +1 -1
  10. data/lib/zold/commands/clean.rb +6 -1
  11. data/lib/zold/commands/fetch.rb +5 -4
  12. data/lib/zold/commands/merge.rb +2 -1
  13. data/lib/zold/commands/node.rb +46 -10
  14. data/lib/zold/commands/push.rb +4 -2
  15. data/lib/zold/commands/routines/audit.rb +53 -0
  16. data/lib/zold/commands/routines/gc.rb +1 -1
  17. data/lib/zold/copies.rb +15 -8
  18. data/lib/zold/head.rb +15 -14
  19. data/lib/zold/hungry_wallets.rb +2 -2
  20. data/lib/zold/id.rb +4 -8
  21. data/lib/zold/metronome.rb +4 -4
  22. data/lib/zold/node/async_entrance.rb +7 -3
  23. data/lib/zold/node/farm.rb +1 -1
  24. data/lib/zold/node/front.rb +8 -5
  25. data/lib/zold/node/sync_entrance.rb +4 -0
  26. data/lib/zold/remotes.rb +57 -55
  27. data/lib/zold/tax.rb +2 -2
  28. data/lib/zold/thread_pool.rb +18 -14
  29. data/lib/zold/tree_wallets.rb +1 -1
  30. data/lib/zold/txn.rb +32 -3
  31. data/lib/zold/txns.rb +14 -14
  32. data/lib/zold/verbose_thread.rb +7 -0
  33. data/lib/zold/version.rb +1 -1
  34. data/lib/zold/wallet.rb +2 -2
  35. data/test/commands/routines/test_audit.rb +41 -0
  36. data/test/commands/test_clean.rb +3 -3
  37. data/test/node/fake_node.rb +2 -1
  38. data/test/node/test_async_entrance.rb +3 -1
  39. data/test/node/test_front.rb +1 -0
  40. data/test/node/test_sync_entrance.rb +2 -2
  41. data/test/test_copies.rb +14 -5
  42. data/test/test_tree_wallets.rb +17 -7
  43. data/test/test_txn.rb +8 -0
  44. data/test/test_wallet.rb +17 -0
  45. data/zold.gemspec +1 -1
  46. metadata +8 -5
data/lib/zold/txns.rb CHANGED
@@ -46,23 +46,23 @@ module Zold
46
46
  .map { |line, i| Txn.parse(line, i + 6) }
47
47
  .sort
48
48
  end
49
+ end
49
50
 
50
- # Cached transactions.
51
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
52
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
53
- # License:: MIT
54
- class Cached
55
- def initialize(txns)
56
- @txns = txns
57
- end
51
+ # Cached transactions.
52
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
53
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
54
+ # License:: MIT
55
+ class CachedTxns
56
+ def initialize(txns)
57
+ @txns = txns
58
+ end
58
59
 
59
- def flush
60
- @fetch = nil
61
- end
60
+ def flush
61
+ @fetch = nil
62
+ end
62
63
 
63
- def fetch
64
- @fetch ||= @txns.fetch
65
- end
64
+ def fetch
65
+ @fetch ||= @txns.fetch
66
66
  end
67
67
  end
68
68
  end
@@ -21,7 +21,9 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'backtrace'
24
+ require 'get_process_mem'
24
25
  require_relative 'log'
26
+ require_relative 'size'
25
27
 
26
28
  # Verbose thread.
27
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -37,6 +39,11 @@ module Zold
37
39
  def run(safe = false)
38
40
  Thread.current.report_on_exception = false
39
41
  yield
42
+ rescue Errno::ENOMEM => e
43
+ @log.error(Backtrace.new(e).to_s)
44
+ @log.error("We are too big in memory (#{Size.new(GetProcessMem.new.bytes.to_i)}), quitting; \
45
+ this is not a normal behavior, you may want to report a bug to our GitHub repository")
46
+ abort
40
47
  rescue StandardError => e
41
48
  @log.error(Backtrace.new(e).to_s)
42
49
  raise e unless safe
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.20.1'
28
+ VERSION = '0.20.2'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
data/lib/zold/wallet.rb CHANGED
@@ -59,8 +59,8 @@ module Zold
59
59
  raise "Wallet file must end with #{Wallet::EXT} or #{Copies::EXT}: #{file}"
60
60
  end
61
61
  @file = File.absolute_path(file)
62
- @txns = Txns::Cached.new(Txns.new(@file))
63
- @head = Head::Cached.new(Head.new(@file))
62
+ @txns = CachedTxns.new(Txns.new(@file))
63
+ @head = CachedHead.new(Head.new(@file))
64
64
  end
65
65
 
66
66
  def ==(other)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require 'tmpdir'
25
+ require 'webmock/minitest'
26
+ require_relative '../../test__helper'
27
+ require_relative '../../../lib/zold/commands/routines/audit.rb'
28
+
29
+ # Audit test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestAudit < Zold::Test
34
+ def test_audits
35
+ FakeHome.new(log: test_log).run do |home|
36
+ opts = { 'routine-immediately' => true }
37
+ routine = Zold::Routines::Audit.new(opts, home.wallets, log: test_log)
38
+ routine.exec
39
+ end
40
+ end
41
+ end
@@ -37,8 +37,8 @@ class TestClean < Zold::Test
37
37
  FakeHome.new(log: test_log).run do |home|
38
38
  wallet = home.create_wallet
39
39
  copies = home.copies(wallet)
40
- copies.add('a1', 'host-1', 80, 1, Time.now - 26 * 60 * 60)
41
- copies.add('a2', 'host-2', 80, 2, Time.now - 26 * 60 * 60)
40
+ copies.add('a1', 'host-1', 80, 1, time: Time.now - 26 * 60 * 60)
41
+ copies.add('a2', 'host-2', 80, 2, time: Time.now - 26 * 60 * 60)
42
42
  Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean', wallet.id.to_s])
43
43
  assert(copies.all.empty?)
44
44
  end
@@ -63,7 +63,7 @@ class TestClean < Zold::Test
63
63
  FakeHome.new(log: test_log).run do |home|
64
64
  wallet = home.create_wallet
65
65
  copies = home.copies(wallet)
66
- copies.add(IO.read(wallet.path), 'host-2', 80, 2, Time.now)
66
+ copies.add(IO.read(wallet.path), 'host-2', 80, 2, time: Time.now)
67
67
  Threads.new(20).assert do
68
68
  Zold::Clean.new(wallets: home.wallets, copies: copies.root, log: test_log).run(['clean'])
69
69
  end
@@ -57,6 +57,7 @@ class FakeNode
57
57
  '--threads=1',
58
58
  '--dump-errors',
59
59
  '--strength=2',
60
+ '--halt-code=test',
60
61
  '--routine-immediately',
61
62
  '--invoice=NOPREFIX@ffffffffffffffff'
62
63
  ] + args
@@ -77,7 +78,7 @@ class FakeNode
77
78
  begin
78
79
  yield port
79
80
  ensure
80
- Zold::Front.stop!
81
+ Zold::Http.new(uri: uri + '?halt=test').get
81
82
  node.join
82
83
  end
83
84
  end
@@ -74,8 +74,10 @@ class TestAsyncEntrance < Zold::Test
74
74
  def test_handles_broken_entrance_gracefully
75
75
  FakeHome.new(log: test_log).run do |home|
76
76
  wallet = home.create_wallet
77
+ id = wallet.id
78
+ body = IO.read(wallet.path)
77
79
  Zold::AsyncEntrance.new(BrokenEntrance.new, home.dir, log: test_log).start do |e|
78
- e.push(wallet.id, IO.read(wallet.path))
80
+ e.push(id, body)
79
81
  end
80
82
  end
81
83
  end
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'eventmachine'
23
24
  require 'minitest/autorun'
24
25
  require 'json'
25
26
  require 'time'
@@ -32,8 +32,8 @@ require_relative 'fake_entrance'
32
32
  # License:: MIT
33
33
  class TestSyncEntrance < Zold::Test
34
34
  def test_renders_json
35
- FakeHome.new(log: test_log).run do
36
- Zold::SyncEntrance.new(FakeEntrance.new, log: test_log).start do |e|
35
+ FakeHome.new(log: test_log).run do |home|
36
+ Zold::SyncEntrance.new(FakeEntrance.new, File.join(home.dir, 'x'), log: test_log).start do |e|
37
37
  assert(!e.to_json.nil?)
38
38
  end
39
39
  end
data/test/test_copies.rb CHANGED
@@ -70,11 +70,20 @@ class TestCopies < Zold::Test
70
70
  end
71
71
  end
72
72
 
73
+ def test_master_first
74
+ Dir.mktmpdir do |dir|
75
+ copies = Zold::Copies.new(File.join(dir, 'my/a/copies-2'), log: test_log)
76
+ copies.add(content('z1'), 'master', 80, 100, master: false)
77
+ copies.add(content('z2'), 'edge', 80, 1, master: true)
78
+ assert(copies.all[0][:master])
79
+ end
80
+ end
81
+
73
82
  def test_cleans_copies
74
83
  Dir.mktmpdir do |dir|
75
84
  copies = Zold::Copies.new(dir, log: test_log)
76
- copies.add(content('h1'), 'zold.io', 4096, 10, Time.now - 25 * 60 * 60)
77
- copies.add(content('h1'), 'zold.io', 4097, 20, Time.now - 26 * 60 * 60)
85
+ copies.add(content('h1'), 'zold.io', 4096, 10, time: Time.now - 25 * 60 * 60)
86
+ copies.add(content('h1'), 'zold.io', 4097, 20, time: Time.now - 26 * 60 * 60)
78
87
  assert(File.exist?(File.join(dir, "1#{Zold::Copies::EXT}")))
79
88
  copies.clean
80
89
  assert(copies.all.empty?, "#{copies.all.count} is not empty")
@@ -85,7 +94,7 @@ class TestCopies < Zold::Test
85
94
  def test_cleans_broken_copies
86
95
  Dir.mktmpdir do |dir|
87
96
  copies = Zold::Copies.new(dir, log: test_log)
88
- copies.add('broken wallet content', 'zold.io', 4096, 10, Time.now)
97
+ copies.add('broken wallet content', 'zold.io', 4096, 10, time: Time.now)
89
98
  copies.clean
90
99
  assert(copies.all.empty?, "#{copies.all.count} is not empty")
91
100
  end
@@ -94,7 +103,7 @@ class TestCopies < Zold::Test
94
103
  def test_ignores_garbage
95
104
  Dir.mktmpdir do |dir|
96
105
  copies = Zold::Copies.new(dir, log: test_log)
97
- copies.add(content('h1'), 'zold.io', 50, 80, Time.now - 25 * 60 * 60)
106
+ copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - 25 * 60 * 60)
98
107
  FileUtils.mkdir(File.join(dir, '55'))
99
108
  assert_equal(1, copies.all.count)
100
109
  end
@@ -114,7 +123,7 @@ class TestCopies < Zold::Test
114
123
  def test_ignores_too_old_scores
115
124
  Dir.mktmpdir do |dir|
116
125
  copies = Zold::Copies.new(dir, log: test_log)
117
- copies.add(content('h1'), 'zold.io', 50, 80, Time.now - 1000 * 60 * 60)
126
+ copies.add(content('h1'), 'zold.io', 50, 80, time: Time.now - 1000 * 60 * 60)
118
127
  assert_equal(0, copies.all[0][:score])
119
128
  end
120
129
  end
@@ -23,6 +23,7 @@
23
23
  require 'minitest/autorun'
24
24
  require 'tmpdir'
25
25
  require_relative 'test__helper'
26
+ require_relative '../lib/zold/wallet'
26
27
  require_relative '../lib/zold/key'
27
28
  require_relative '../lib/zold/id'
28
29
  require_relative '../lib/zold/tree_wallets'
@@ -59,15 +60,24 @@ class TestTreeWallets < Zold::Test
59
60
  end
60
61
 
61
62
  def test_count_tree_wallets
63
+ files = [
64
+ "0000111122223333#{Zold::Wallet::EXT}",
65
+ "a/b/d/e/0000111122223333#{Zold::Wallet::EXT}",
66
+ "a/b/0000111122223333#{Zold::Wallet::EXT}"
67
+ ]
68
+ garbage = [
69
+ '0000111122223333',
70
+ '0000111122223333.lock',
71
+ 'a/b/c-0000111122223333'
72
+ ]
62
73
  Dir.mktmpdir do |dir|
63
- Dir.chdir(dir) do
64
- 5.times { |i| FileUtils.touch("wallet_#{i}.z") }
65
- Dir.mktmpdir(nil, dir) do |subdir|
66
- 5.times { |i| FileUtils.touch("#{subdir}/wallet_#{i}.z") }
67
- wallets = Zold::TreeWallets.new(Dir.pwd)
68
- assert_equal(10, wallets.count)
69
- end
74
+ (files + garbage).each do |f|
75
+ path = File.join(dir, f)
76
+ FileUtils.mkdir_p(File.dirname(path))
77
+ FileUtils.touch(path)
70
78
  end
79
+ wallets = Zold::TreeWallets.new(dir)
80
+ assert_equal(files.count, wallets.count)
71
81
  end
72
82
  end
73
83
  end
data/test/test_txn.rb CHANGED
@@ -73,4 +73,12 @@ class TestTxn < Zold::Test
73
73
  )
74
74
  assert_equal(details, txn.details)
75
75
  end
76
+
77
+ def test_prints_and_parses_time
78
+ 10.times do |i|
79
+ time = Time.now + i * 12_345
80
+ iso = time.utc.iso8601
81
+ assert_equal(time.to_s, Zold::Txn.parse_time(iso).to_s)
82
+ end
83
+ end
76
84
  end
data/test/test_wallet.rb CHANGED
@@ -280,4 +280,21 @@ class TestWallet < Zold::Test
280
280
  end
281
281
  end
282
282
  end
283
+
284
+ def test_collects_memory_garbage
285
+ require 'get_process_mem'
286
+ start = GetProcessMem.new.bytes.to_i
287
+ 40.times do |i|
288
+ wallet = Zold::Wallet.new('fixtures/448b451bc62e8e16.z')
289
+ GC.start
290
+ wallet.id
291
+ wallet.txns.count
292
+ test_log.debug("Memory: #{GetProcessMem.new.bytes.to_i}") if (i % 5).zero?
293
+ end
294
+ GC.stress = true
295
+ diff = GetProcessMem.new.bytes.to_i - start
296
+ GC.stress = false
297
+ test_log.debug("Memory diff is #{diff}")
298
+ assert(diff < 20_000_000)
299
+ end
283
300
  end
data/zold.gemspec CHANGED
@@ -83,7 +83,7 @@ and suggests a different architecture for digital wallet maintenance.'
83
83
  s.add_runtime_dependency 'typhoeus', '1.3.1'
84
84
  s.add_runtime_dependency 'usagewatch_ext', '0.2.1'
85
85
  s.add_runtime_dependency 'xcop', '>=0.6'
86
- s.add_runtime_dependency 'zache', '>=0.5.3'
86
+ s.add_runtime_dependency 'zache', '>=0.7.0'
87
87
  s.add_runtime_dependency 'zold-score', '0.4.4'
88
88
  s.add_development_dependency 'codecov', '0.1.13'
89
89
  s.add_development_dependency 'minitest', '5.11.3'
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.20.1
4
+ version: 0.20.2
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-19 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -324,14 +324,14 @@ dependencies:
324
324
  requirements:
325
325
  - - ">="
326
326
  - !ruby/object:Gem::Version
327
- version: 0.5.3
327
+ version: 0.7.0
328
328
  type: :runtime
329
329
  prerelease: false
330
330
  version_requirements: !ruby/object:Gem::Requirement
331
331
  requirements:
332
332
  - - ">="
333
333
  - !ruby/object:Gem::Version
334
- version: 0.5.3
334
+ version: 0.7.0
335
335
  - !ruby/object:Gem::Dependency
336
336
  name: zold-score
337
337
  requirement: !ruby/object:Gem::Requirement
@@ -562,6 +562,7 @@ files:
562
562
  - lib/zold/commands/push.rb
563
563
  - lib/zold/commands/remote.rb
564
564
  - lib/zold/commands/remove.rb
565
+ - lib/zold/commands/routines/audit.rb
565
566
  - lib/zold/commands/routines/gc.rb
566
567
  - lib/zold/commands/routines/reconnect.rb
567
568
  - lib/zold/commands/show.rb
@@ -612,6 +613,7 @@ files:
612
613
  - lib/zold/wallets.rb
613
614
  - resources/masters
614
615
  - resources/root.pub
616
+ - test/commands/routines/test_audit.rb
615
617
  - test/commands/routines/test_gc.rb
616
618
  - test/commands/routines/test_reconnect.rb
617
619
  - test/commands/test_alias.rb
@@ -690,7 +692,7 @@ licenses:
690
692
  - MIT
691
693
  metadata: {}
692
694
  post_install_message: |-
693
- Thanks for installing Zold 0.20.1!
695
+ Thanks for installing Zold 0.20.2!
694
696
  Study our White Paper: https://papers.zold.io/wp.pdf
695
697
  Read our blog posts: https://blog.zold.io
696
698
  Try online wallet at: https://wts.zold.io
@@ -722,6 +724,7 @@ test_files:
722
724
  - features/gem_package.feature
723
725
  - features/step_definitions/steps.rb
724
726
  - features/support/env.rb
727
+ - test/commands/routines/test_audit.rb
725
728
  - test/commands/routines/test_gc.rb
726
729
  - test/commands/routines/test_reconnect.rb
727
730
  - test/commands/test_alias.rb