zold 0.14.4 → 0.14.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8506b67f7b833f450efcf81d313c1598cc8a8dc
4
- data.tar.gz: bbb006a82c64e5647c975d116543ebc1412b237e
3
+ metadata.gz: 02756005fb2c93a0d5f761508fd96a03ced75595
4
+ data.tar.gz: eca849a45be0c29b8e5e11b7579ab16f15429388
5
5
  SHA512:
6
- metadata.gz: 6c93783eea87d06905b377242838684e8e9d58e653cd3dcfeb1c384ceaec4ddc5f70ba29cb8a6089c8c0b03f03f6162a225fcb70c1f31da6b65a7a568fa987e9
7
- data.tar.gz: b4dc313ac468f1484d5288c180876878150a4d9628f9a7905fb1851509aa34d54d6ad5361a1c6a203a47c142407e39fdf66b762938f8cb3b711892063fe2943a
6
+ metadata.gz: 77f888f0178cf42099ed921f9de20843cedcbc2adb9ea313f42236ee90f20497ad515f9a9055809ee19ffa291bf2986f0daaab522ababca288be60a0f3bacd18
7
+ data.tar.gz: 211a846efc40001fce2ba874e874b9cb5d312873719b379a4aae14e93bae4ab86a90b9d828f1440acae2f16faf0b874c17461d078c48bdc973b5a54797154833
data/.rultor.yml CHANGED
@@ -2,7 +2,6 @@ assets:
2
2
  rubygems.yml: zerocracy/home#assets/rubygems.yml
3
3
  id_rsa: zerocracy/home#assets/heroku-key
4
4
  id_rsa.pub: zerocracy/home#assets/heroku-key.pub
5
- bonus.key: zerocracy/home#assets/zold/bonus.key
6
5
  install: |
7
6
  sudo apt-get -y update
8
7
  sudo gem install pdd
@@ -30,7 +29,6 @@ release:
30
29
  git add Gemfile.lock
31
30
  git add .gitignore
32
31
  git fetch
33
- cp ../bonus.key . && git add bonus.key
34
32
  git commit -m 'config' && git push -f heroku $(git symbolic-ref --short HEAD):master
35
33
  curl -f --connect-timeout 15 --retry 5 --retry-delay 30 http://b1.zold.io > /dev/null
36
34
  architect:
@@ -29,8 +29,10 @@ zold taxes debt 0000000000000000
29
29
 
30
30
  zold remote show
31
31
  zold push 0000000000000000
32
- sleep 2
33
- zold fetch 0000000000000000 --ignore-score-weakness || echo 'Failed'
32
+ until zold fetch 0000000000000000 --ignore-score-weakness; do
33
+ echo 'Failed to fetch, let us try again'
34
+ sleep 1
35
+ done
34
36
  zold diff 0000000000000000
35
37
  zold merge 0000000000000000
36
38
  zold clean 0000000000000000
data/heroku-run.sh CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  ./bin/zold node --no-colors --trace \
4
4
  --bind-port=$PORT --port=80 --host=b1.zold.io --threads=0 \
5
- --invoice=ML5Ern7m@912ecc24b32dbe74 --never-reboot \
6
- --bonus-wallet=81c9c25789b03876 --private-key=bonus.key --bonus-amount=1 --bonus-time=60
5
+ --invoice=ML5Ern7m@912ecc24b32dbe74 --never-reboot
@@ -107,7 +107,7 @@ Available options:"
107
107
  raise "Protocol #{wallet.protocol} doesn't match #{Zold::PROTOCOL} in #{id}"
108
108
  end
109
109
  if wallet.network != opts['network']
110
- raise "The wallet #{id} is in network #{wallet.network}, while we are in #{opts['network']}"
110
+ raise "The wallet #{id} is in network '#{wallet.network}', while we are in '#{opts['network']}'"
111
111
  end
112
112
  if wallet.balance.negative? && !wallet.root?
113
113
  raise "The balance of #{id} is #{wallet.balance} and it's not a root wallet"
@@ -98,14 +98,6 @@ module Zold
98
98
  o.string '--expose-version',
99
99
  "The version of the software to expose in JSON (default: #{VERSION})",
100
100
  default: VERSION
101
- o.string '--bonus-wallet',
102
- 'The ID of the wallet to regularly send bonuses from (for nodes online)'
103
- o.integer '--bonus-time',
104
- 'The amount of minutes to wait between bonus awards (default: 60)',
105
- default: 60
106
- o.string '--bonus-amount',
107
- 'The amount of ZLD to pay to each remote as a bonus',
108
- default: '1'
109
101
  o.string '--private-key',
110
102
  'The location of RSA private key (default: ~/.ssh/id_rsa)',
111
103
  default: '~/.ssh/id_rsa'
@@ -173,7 +165,7 @@ module Zold
173
165
  SafeEntrance.new(
174
166
  AsyncEntrance.new(
175
167
  SpreadEntrance.new(
176
- Entrance.new(@wallets, @remotes, @copies, address, log: @log),
168
+ Entrance.new(@wallets, @remotes, @copies, address, log: @log, network: opts['network']),
177
169
  @wallets, @remotes, address,
178
170
  log: @log,
179
171
  ignore_score_weakeness: opts['ignore-score-weakness']
@@ -256,11 +248,7 @@ module Zold
256
248
  metronome.add(Routines::Spread.new(opts, @wallets, entrance, log: @log))
257
249
  unless opts['standalone']
258
250
  require_relative 'routines/reconnect'
259
- metronome.add(Routines::Reconnect.new(opts, @remotes, farm, log: @log))
260
- end
261
- if opts['bonus-wallet']
262
- require_relative 'routines/bonuses'
263
- metronome.add(Routines::Bonuses.new(opts, @wallets, @remotes, @copies, farm, log: @log))
251
+ metronome.add(Routines::Reconnect.new(opts, @remotes, farm, log: Log::Quiet.new))
264
252
  end
265
253
  @log.info('Metronome created')
266
254
  metronome
@@ -41,10 +41,13 @@ module Zold
41
41
 
42
42
  def exec(_ = 0)
43
43
  sleep(60) unless @opts['routine-immediately']
44
+ pushed = []
44
45
  @wallets.all.sample(10).map do |w|
45
46
  id = Id.new(w)
46
47
  @entrance.push(id, File.read(@wallets.find(id).path))
48
+ pushed << id
47
49
  end
50
+ @log.info("Spread #{pushed.count} random wallets out of #{@wallets.all.count}: #{pushed.join}")
48
51
  end
49
52
  end
50
53
  end
@@ -35,7 +35,7 @@ require_relative '../commands/push'
35
35
  module Zold
36
36
  # The entrance
37
37
  class Entrance
38
- def initialize(wallets, remotes, copies, address, log: Log::Quiet.new)
38
+ def initialize(wallets, remotes, copies, address, log: Log::Quiet.new, network: 'test')
39
39
  raise 'Wallets can\'t be nil' if wallets.nil?
40
40
  raise 'Wallets must implement the contract of Wallets: method #find is required' unless wallets.respond_to?(:find)
41
41
  @wallets = wallets
@@ -48,6 +48,8 @@ module Zold
48
48
  @address = address
49
49
  raise 'Log can\'t be nil' if log.nil?
50
50
  @log = log
51
+ raise 'Network can\'t be nil' if network.nil?
52
+ @network = network
51
53
  @history = []
52
54
  @mutex = Mutex.new
53
55
  end
@@ -74,7 +76,7 @@ module Zold
74
76
  unless @remotes.all.empty?
75
77
  Fetch.new(
76
78
  wallets: @wallets, remotes: @remotes, copies: copies.root, log: @log
77
- ).run(['fetch', id.to_s, "--ignore-node=#{@address}"])
79
+ ).run(['fetch', id.to_s, "--ignore-node=#{@address}", "--network=#{@network}"])
78
80
  end
79
81
  modified = Merge.new(
80
82
  wallets: @wallets, copies: copies.root, log: @log
data/lib/zold/version.rb CHANGED
@@ -23,6 +23,6 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.14.4'.freeze
26
+ VERSION = '0.14.5'.freeze
27
27
  PROTOCOL = 2
28
28
  end
@@ -48,11 +48,16 @@ class TestNode < Minitest::Test
48
48
  ['push', '--ignore-score-weakness']
49
49
  )
50
50
  copies = home.copies(wallet)
51
- sleep 2
52
- Zold::Fetch.new(
53
- wallets: wallets, copies: copies.root,
54
- remotes: remotes, log: test_log
55
- ).run(['fetch', '--ignore-score-weakness'])
51
+ begin
52
+ retries ||= 0
53
+ Zold::Fetch.new(
54
+ wallets: wallets, copies: copies.root,
55
+ remotes: remotes, log: test_log
56
+ ).run(['fetch', '--ignore-score-weakness'])
57
+ rescue StandardError => _
58
+ sleep 1
59
+ retry if (retries += 1) < 3
60
+ end
56
61
  assert_equal(1, copies.all.count)
57
62
  assert_equal('1', copies.all[0][:name])
58
63
  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.14.4
4
+ version: 0.14.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -375,7 +375,6 @@ files:
375
375
  - lib/zold/commands/pull.rb
376
376
  - lib/zold/commands/push.rb
377
377
  - lib/zold/commands/remote.rb
378
- - lib/zold/commands/routines/bonuses.rb
379
378
  - lib/zold/commands/routines/reconnect.rb
380
379
  - lib/zold/commands/routines/spread.rb
381
380
  - lib/zold/commands/show.rb
@@ -410,7 +409,6 @@ files:
410
409
  - lib/zold/wallet.rb
411
410
  - lib/zold/wallets.rb
412
411
  - resources/remotes
413
- - test/commands/routines/test_bonuses.rb
414
412
  - test/commands/routines/test_reconnect.rb
415
413
  - test/commands/routines/test_spread.rb
416
414
  - test/commands/test_alias.rb
@@ -496,7 +494,6 @@ test_files:
496
494
  - features/gem_package.feature
497
495
  - features/step_definitions/steps.rb
498
496
  - features/support/env.rb
499
- - test/commands/routines/test_bonuses.rb
500
497
  - test/commands/routines/test_reconnect.rb
501
498
  - test/commands/routines/test_spread.rb
502
499
  - test/commands/test_alias.rb
@@ -1,76 +0,0 @@
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 '../remote'
22
- require_relative '../pull'
23
- require_relative '../pay'
24
- require_relative '../push'
25
-
26
- # Pay bonuses routine.
27
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
29
- # License:: MIT
30
- module Zold
31
- # Routines module
32
- module Routines
33
- # Pay bonuses to random nodes
34
- class Bonuses
35
- def initialize(opts, wallets, remotes, copies, farm, log: Log::Quiet.new)
36
- @opts = opts
37
- @wallets = wallets
38
- @remotes = remotes
39
- @copies = copies
40
- @farm = farm
41
- @log = log
42
- end
43
-
44
- def exec(_ = 0)
45
- sleep(@opts['bonus-time'] * 60) unless @opts['routine-immediately']
46
- raise '--private-key is required to pay bonuses' unless @opts['private-key']
47
- raise '--bonus-wallet is required to pay bonuses' unless @opts['bonus-wallet']
48
- raise '--bonus-amount is required to pay bonuses' unless @opts['bonus-amount']
49
- winners = Remote.new(remotes: @remotes, log: @log, farm: @farm).run(
50
- ['remote', 'elect', @opts['bonus-wallet'], '--private-key', @opts['private-key']] +
51
- (@opts['ignore-score-weakness'] ? ['--ignore-score-weakness'] : [])
52
- )
53
- return if winners.empty?
54
- unless @wallets.find(Id.new(@opts['bonus-wallet'])).exists?
55
- Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
56
- ['pull', @opts['bonus-wallet']] +
57
- (@opts['ignore-score-weakness'] ? ['--ignore-score-weakness'] : [])
58
- )
59
- end
60
- winners.each do |score|
61
- Pay.new(wallets: @wallets, remotes: @remotes, log: @log).run(
62
- [
63
- 'pay', @opts['bonus-wallet'], score.invoice, @opts['bonus-amount'].to_s,
64
- "Hosting bonus for #{score.host} #{score.port} #{score.value}",
65
- '--private-key', @opts['private-key']
66
- ]
67
- )
68
- end
69
- Push.new(wallets: @wallets, remotes: @remotes, log: @log).run(
70
- ['push', @opts['bonus-wallet']] +
71
- (@opts['ignore-score-weakness'] ? ['--ignore-score-weakness'] : [])
72
- )
73
- end
74
- end
75
- end
76
- end
@@ -1,72 +0,0 @@
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 'minitest/autorun'
22
- require 'webmock/minitest'
23
- require_relative '../../test__helper'
24
- require_relative '../../fake_home'
25
- require_relative '../../node/fake_node'
26
- require_relative '../../../lib/zold/node/farm.rb'
27
- require_relative '../../../lib/zold/commands/push'
28
- require_relative '../../../lib/zold/commands/pay'
29
- require_relative '../../../lib/zold/commands/routines/bonuses.rb'
30
-
31
- # Bonuses test.
32
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
34
- # License:: MIT
35
- class TestBonuses < Minitest::Test
36
- def test_pays_bonuses
37
- FakeHome.new.run do |home|
38
- FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
39
- bank = home.create_wallet
40
- Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
41
- ['pay', home.create_wallet.id.to_s, bank.id.to_s, '100', '--force', '--private-key=id_rsa']
42
- )
43
- assert_equal(Zold::Amount.new(zld: 100.0), bank.balance)
44
- opts = {
45
- 'ignore-score-weakness' => true,
46
- 'routine-immediately' => true,
47
- 'private-key' => 'id_rsa',
48
- 'bonus-wallet' => bank.id.to_s,
49
- 'bonus-amount' => 1,
50
- 'bonus-time' => 0
51
- }
52
- score = Zold::Score.new(Time.now, 'fake-node.local', 999, 'NOPREFIX@ffffffffffffffff', strength: 1)
53
- 16.times { score = score.next }
54
- remotes = home.remotes
55
- remotes.add('localhost', port)
56
- remotes.add(score.host, score.port)
57
- stub_request(:get, "http://#{score.host}:#{score.port}/").to_return(
58
- status: 200,
59
- body: {
60
- version: Zold::VERSION,
61
- score: score.to_h
62
- }.to_json
63
- )
64
- Zold::Routines::Bonuses.new(
65
- opts, home.wallets, remotes, home.copies(bank).root,
66
- Zold::Farm::Empty.new, log: test_log
67
- ).exec
68
- assert_equal(Zold::Amount.new(zld: 99.0), bank.balance)
69
- end
70
- end
71
- end
72
- end