zold 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/lib/zold/commands/merge.rb +7 -7
- data/lib/zold/commands/node.rb +7 -6
- data/lib/zold/commands/routines/gc.rb +58 -0
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallets.rb +4 -1
- data/test/commands/routines/test_gc.rb +70 -0
- data/test/test_wallets.rb +6 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2544c7f82192df9838d17ce34db7e71f43bf354f74a4021a6567e015feb88c78
|
4
|
+
data.tar.gz: b7d465bedb331452972844bcd7808182633ff9eabf3c7e1da795dc6d64c1483b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ae9482cf55549e0c5e44063369b5dede47e9550c995fc2d5cdb83fd89b315cbcfb0e41a2381ded0fcb60d230c91c6ec0cf4e87ce0d3d397983e670de183c06d
|
7
|
+
data.tar.gz: 054a46f86e5538edd0aaf7bf0f0b9fc116b83fb86d1810d8dfb11b7e4d49bd7e042acc07a3a0d5be34b44e262a4967dd18ba7129a65b23a0890def81196761de
|
data/.rubocop.yml
CHANGED
data/lib/zold/commands/merge.rb
CHANGED
@@ -74,16 +74,10 @@ Available options:"
|
|
74
74
|
private
|
75
75
|
|
76
76
|
def merge(id, cps, opts)
|
77
|
+
start = Time.now
|
77
78
|
cps = cps.all.sort_by { |c| c[:score] }.reverse
|
78
79
|
patch = Patch.new(@wallets, log: @log)
|
79
80
|
score = 0
|
80
|
-
cps.each_with_index do |c, idx|
|
81
|
-
wallet = Wallet.new(c[:path])
|
82
|
-
name = "#{c[:name]}/#{idx}/#{c[:score]}"
|
83
|
-
merge_one(opts, patch, wallet, name)
|
84
|
-
score += c[:score]
|
85
|
-
end
|
86
|
-
start = Time.now
|
87
81
|
@wallets.acq(id) do |w|
|
88
82
|
if w.exists?
|
89
83
|
merge_one(opts, patch, w, 'localhost')
|
@@ -92,6 +86,12 @@ Available options:"
|
|
92
86
|
@log.debug("Local copy of #{id} is absent, nothing to merge")
|
93
87
|
end
|
94
88
|
end
|
89
|
+
cps.each_with_index do |c, idx|
|
90
|
+
wallet = Wallet.new(c[:path])
|
91
|
+
name = "#{c[:name]}/#{idx}/#{c[:score]}"
|
92
|
+
merge_one(opts, patch, wallet, name)
|
93
|
+
score += c[:score]
|
94
|
+
end
|
95
95
|
modified = @wallets.acq(id, exclusive: true) { |w| patch.save(w.path, overwrite: true) }
|
96
96
|
if modified
|
97
97
|
@log.info("#{cps.count} copies with the total score of #{score} successfully merged \
|
data/lib/zold/commands/node.rb
CHANGED
@@ -136,6 +136,9 @@ module Zold
|
|
136
136
|
o.integer '--queue-limit',
|
137
137
|
'The maximum number of wallets to be accepted via PUSH and stored in the queue (default: 4096)',
|
138
138
|
default: 4096
|
139
|
+
o.integer '--gc-age',
|
140
|
+
'Maximum time in seconds to keep an empty and unused wallet on the disk',
|
141
|
+
default: 60 * 60 * 24 * 10
|
139
142
|
o.string '--expose-version',
|
140
143
|
"The version of the software to expose in JSON (default: #{VERSION})",
|
141
144
|
default: VERSION
|
@@ -360,12 +363,10 @@ module Zold
|
|
360
363
|
@log.info('Metronome hasn\'t been started because of --no-metronome')
|
361
364
|
return metronome
|
362
365
|
end
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
# require_relative 'routines/spread'
|
368
|
-
# metronome.add(Routines::Spread.new(opts, @wallets, @remotes, log: @log))
|
366
|
+
require_relative 'routines/spread'
|
367
|
+
metronome.add(Routines::Spread.new(opts, @wallets, @remotes, log: @log))
|
368
|
+
require_relative 'routines/gc'
|
369
|
+
metronome.add(Routines::Gc.new(opts, @wallets, log: @log))
|
369
370
|
unless opts['standalone']
|
370
371
|
require_relative 'routines/reconnect'
|
371
372
|
metronome.add(Routines::Reconnect.new(opts, @remotes, farm, network: opts['network'], log: @log))
|
@@ -0,0 +1,58 @@
|
|
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_relative '../../log'
|
24
|
+
require_relative '../remove'
|
25
|
+
|
26
|
+
# Gargage collecting. It goes through the list of all wallets and removes
|
27
|
+
# those that are older than 10 days and don't have any transactions inside.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
module Zold
|
32
|
+
# Routines module
|
33
|
+
module Routines
|
34
|
+
# Garbage collector
|
35
|
+
class Gc
|
36
|
+
def initialize(opts, wallets, log: Log::NULL)
|
37
|
+
@opts = opts
|
38
|
+
@wallets = wallets
|
39
|
+
@log = log
|
40
|
+
end
|
41
|
+
|
42
|
+
def exec(_ = 0)
|
43
|
+
sleep(60) unless @opts['routine-immediately']
|
44
|
+
cmd = Remove.new(wallets: @wallets, log: @log)
|
45
|
+
args = ['remove']
|
46
|
+
seen = 0
|
47
|
+
removed = 0
|
48
|
+
@wallets.all.each do |id|
|
49
|
+
seen += 1
|
50
|
+
next unless @wallets.acq(id) { |w| w.txns.empty? && w.mtime < Time.now - @opts['gc-age'] }
|
51
|
+
cmd.run(args + [id.to_s])
|
52
|
+
removed += 1
|
53
|
+
end
|
54
|
+
@log.info("Removed #{removed} empty+old wallets out of #{seen} total")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallets.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
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_relative '../../test__helper'
|
25
|
+
require_relative '../../fake_home'
|
26
|
+
require_relative '../../../lib/zold/wallets'
|
27
|
+
require_relative '../../../lib/zold/commands/routines/gc.rb'
|
28
|
+
|
29
|
+
# Gc test.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class TestGc < Zold::Test
|
34
|
+
def test_collects_garbage
|
35
|
+
FakeHome.new(log: test_log).run do |home|
|
36
|
+
wallets = home.wallets
|
37
|
+
home.create_wallet
|
38
|
+
opts = { 'routine-immediately' => true, 'gc-age' => 0 }
|
39
|
+
assert_equal(1, wallets.count)
|
40
|
+
routine = Zold::Routines::Gc.new(opts, wallets, log: test_log)
|
41
|
+
routine.exec
|
42
|
+
assert_equal(0, wallets.count)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_doesnt_touch_non_empty_wallets
|
47
|
+
FakeHome.new(log: test_log).run do |home|
|
48
|
+
wallets = home.wallets
|
49
|
+
wallet = home.create_wallet
|
50
|
+
amount = Zold::Amount.new(zld: 39.99)
|
51
|
+
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
52
|
+
wallet.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
53
|
+
opts = { 'routine-immediately' => true, 'gc-age' => 0 }
|
54
|
+
routine = Zold::Routines::Gc.new(opts, wallets, log: test_log)
|
55
|
+
routine.exec
|
56
|
+
assert_equal(1, wallets.count)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_doesnt_touch_fresh_wallets
|
61
|
+
FakeHome.new(log: test_log).run do |home|
|
62
|
+
wallets = home.wallets
|
63
|
+
home.create_wallet
|
64
|
+
opts = { 'routine-immediately' => true, 'gc-age' => 60 * 60 }
|
65
|
+
routine = Zold::Routines::Gc.new(opts, wallets, log: test_log)
|
66
|
+
routine.exec
|
67
|
+
assert_equal(1, wallets.count)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/test/test_wallets.rb
CHANGED
@@ -71,10 +71,15 @@ class TestWallets < Zold::Test
|
|
71
71
|
def test_count_wallets
|
72
72
|
Dir.mktmpdir do |dir|
|
73
73
|
Dir.chdir(dir) do
|
74
|
-
5.times { |i| FileUtils.touch("wallet_#{i}") }
|
74
|
+
5.times { |i| FileUtils.touch("wallet_#{i}#{Zold::Wallet::EXT}") }
|
75
75
|
wallets = Zold::Wallets.new(Dir.pwd)
|
76
76
|
assert_equal(5, wallets.count)
|
77
77
|
end
|
78
78
|
end
|
79
|
+
FakeHome.new(log: test_log).run do |home|
|
80
|
+
wallets = home.wallets
|
81
|
+
home.create_wallet
|
82
|
+
assert_equal(1, wallets.count)
|
83
|
+
end
|
79
84
|
end
|
80
85
|
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.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -576,6 +576,7 @@ files:
|
|
576
576
|
- lib/zold/commands/push.rb
|
577
577
|
- lib/zold/commands/remote.rb
|
578
578
|
- lib/zold/commands/remove.rb
|
579
|
+
- lib/zold/commands/routines/gc.rb
|
579
580
|
- lib/zold/commands/routines/reconnect.rb
|
580
581
|
- lib/zold/commands/routines/spread.rb
|
581
582
|
- lib/zold/commands/show.rb
|
@@ -625,6 +626,7 @@ files:
|
|
625
626
|
- lib/zold/wallets.rb
|
626
627
|
- resources/remotes
|
627
628
|
- resources/root.pub
|
629
|
+
- test/commands/routines/test_gc.rb
|
628
630
|
- test/commands/routines/test_reconnect.rb
|
629
631
|
- test/commands/routines/test_spread.rb
|
630
632
|
- test/commands/test_alias.rb
|
@@ -701,7 +703,7 @@ licenses:
|
|
701
703
|
- MIT
|
702
704
|
metadata: {}
|
703
705
|
post_install_message: |-
|
704
|
-
Thanks for installing Zold 0.18.
|
706
|
+
Thanks for installing Zold 0.18.2!
|
705
707
|
Study our White Paper: https://papers.zold.io/wp.pdf
|
706
708
|
Read our blog posts: https://blog.zold.io
|
707
709
|
Try online wallet at: https://wts.zold.io
|
@@ -733,6 +735,7 @@ test_files:
|
|
733
735
|
- features/gem_package.feature
|
734
736
|
- features/step_definitions/steps.rb
|
735
737
|
- features/support/env.rb
|
738
|
+
- test/commands/routines/test_gc.rb
|
736
739
|
- test/commands/routines/test_reconnect.rb
|
737
740
|
- test/commands/routines/test_spread.rb
|
738
741
|
- test/commands/test_alias.rb
|