zold 0.14.36 → 0.14.37

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
  SHA1:
3
- metadata.gz: e0ac9a7fc3634c563abae9dce0f68ca709d46490
4
- data.tar.gz: 59bb7653c11021d3d46c6cab7124480c9db2a103
3
+ metadata.gz: e60384f0c0c624aa8351fbb37ba157ab55ecec6c
4
+ data.tar.gz: 45c724b470053a6d46787589ff8a8815f8bd2dc2
5
5
  SHA512:
6
- metadata.gz: cc4d99b314585fc077c82779463f09505d71f787a560087a2d55f3ab17184580df1aa0f12de8e0afb49914a0f2bff5d5064f343d579a9fe0d289562cacf94efe
7
- data.tar.gz: 1995bae0601aa6cd84b5de1f3eeb58b27914f2d4d2935a503fa5226c88d12eaa659a6a76bcac58dae8b7103dac813ba90be1e66597490af4bf899e8f77ead092
6
+ metadata.gz: '08171d0370b3d30ae360159cc144fe7fb687110c09bad086b3c7ce37b984f49e76419dd864d55a22696e0a582a6b569b4ffb43ec04ec01c9dfdae30b144708b5'
7
+ data.tar.gz: cdd6f7908645858c273be17c94b3741aab8a5dd15fdfff65450a9d01ad79f34d97d290942c1529342eed4c31785fed78a650ad556b2dfe2036c25d8ba20e3514
data/bin/zold CHANGED
@@ -31,10 +31,13 @@ end
31
31
 
32
32
  require 'slop'
33
33
  require 'rainbow'
34
+ require 'cachy'
35
+ require 'moneta'
34
36
  require_relative '../lib/zold'
35
37
  require_relative '../lib/zold/version'
36
38
  require_relative '../lib/zold/wallet'
37
39
  require_relative '../lib/zold/wallets'
40
+ require_relative '../lib/zold/tree_wallets'
38
41
  require_relative '../lib/zold/sync_wallets'
39
42
  require_relative '../lib/zold/log'
40
43
  require_relative '../lib/zold/key'
@@ -46,6 +49,8 @@ require_relative '../lib/zold/version_file'
46
49
 
47
50
  Thread.current.name = 'main'
48
51
 
52
+ Cachy.cache_store = Moneta.new(:Memory)
53
+
49
54
  Encoding.default_external = Encoding::UTF_8
50
55
  Encoding.default_internal = Encoding::UTF_8
51
56
 
@@ -158,9 +163,16 @@ Available options:"
158
163
  Zold::ProtocolUp.new(Dir.pwd, log).exec
159
164
  require_relative '../upgrades/rename_foreign_wallets'
160
165
  Zold::RenameForeignWallets.new(Dir.pwd, opts['network'], log).exec
166
+ if command == 'node'
167
+ require_relative '../upgrades/move_wallets_into_tree'
168
+ Zold::MoveWalletsIntoTree.new(Dir.pwd, log).exec
169
+ end
161
170
  end
162
171
 
163
- wallets = Zold::SyncWallets.new(Zold::Wallets.new('.'), File.join(zoldata, 'locks'), log: log)
172
+ wallets = Zold::SyncWallets.new(
173
+ command == 'node' ? Zold::TreeWallets.new('.') : Zold::Wallets.new('.'),
174
+ File.join(zoldata, 'locks'), log: log
175
+ )
164
176
  remotes = Zold::Remotes.new(file: File.join(zoldata, 'remotes'), network: opts['network'])
165
177
  copies = File.join(zoldata, 'copies')
166
178
 
@@ -183,6 +195,9 @@ Available options:"
183
195
  when 'show'
184
196
  require_relative '../lib/zold/commands/show'
185
197
  Zold::Show.new(wallets: wallets, log: log).run(args)
198
+ when 'list'
199
+ require_relative '../lib/zold/commands/list'
200
+ Zold::List.new(wallets: wallets, log: log).run(args)
186
201
  when 'fetch'
187
202
  require_relative '../lib/zold/commands/fetch'
188
203
  Zold::Fetch.new(wallets: wallets, remotes: remotes, copies: copies, log: log).run(args)
@@ -67,15 +67,11 @@ if [ $(echo ${json} | jq -r '.entrance.history_size') == "0" ]; then
67
67
  echo "The history doesn't have a wallet, it's a bug"
68
68
  exit 6
69
69
  fi
70
- if [ ! $(echo ${json} | jq -r '.wallets') == "1" ]; then
71
- echo "The wallet is not there for some reason, it's a bug"
72
- exit 7
73
- fi
74
70
 
75
71
  # Now, we remove the wallet from the second node and expect the first
76
72
  # one to "spread" it again, almost immediately. The second node should
77
73
  # have the wallet very soon.
78
- rm -f ${second}/0000000000000000.z
74
+ rm -f ${second}/**/*.z
79
75
  i=0
80
76
  until zold fetch 0000000000000000 --ignore-score-weakness; do
81
77
  echo 'Failed to fetch, let us try again'
@@ -51,7 +51,3 @@ if [ ! $(echo ${json} | jq -r '.entrance.history_size') == "1" ]; then
51
51
  echo "The history doesn't have a wallet, it's a bug"
52
52
  exit -1
53
53
  fi
54
- if [ ! $(echo ${json} | jq -r '.wallets') == "1" ]; then
55
- echo "The wallet is not there for some reason, it's a bug"
56
- exit -1
57
- fi
@@ -41,6 +41,7 @@ module Zold
41
41
 
42
42
  def write(content)
43
43
  raise 'Content can\'t be nil' if content.nil?
44
+ FileUtils.mkdir_p(File.dirname(@file))
44
45
  @mutex.synchronize do
45
46
  File.open(@file, 'wb') do |f|
46
47
  f.write(content)
@@ -35,6 +35,9 @@ module Zold
35
35
  # How many threads to use for processing
36
36
  THREADS = Concurrent.processor_count * 8
37
37
 
38
+ # Queue length
39
+ MAX_QUEUE = Concurrent.processor_count * 64
40
+
38
41
  # Max items in the queue. If there will be more, push() requests
39
42
  # will be rejected.
40
43
  MAX_QUEUE = 128
@@ -65,7 +68,7 @@ module Zold
65
68
  @entrance.start do
66
69
  FileUtils.mkdir_p(@dir)
67
70
  @pool = Concurrent::FixedThreadPool.new(
68
- AsyncEntrance::THREADS, max_queue: AsyncEntrance::THREADS, fallback_policy: :abort
71
+ AsyncEntrance::THREADS, max_queue: AsyncEntrance::MAX_QUEUE, fallback_policy: :abort
69
72
  )
70
73
  AsyncEntrance::THREADS.times do |t|
71
74
  @pool.post do
@@ -57,7 +57,8 @@ module Zold
57
57
 
58
58
  def to_text
59
59
  @threads.map do |t|
60
- "#{t.name}: status=#{t.status}; alive=#{t.alive?};\n #{t.backtrace.join("\n ")}"
60
+ trace = t.backtrace || []
61
+ "#{t.name}: status=#{t.status}; alive=#{t.alive?};\n #{trace.join("\n ")}"
61
62
  end.join("\n")
62
63
  end
63
64
 
@@ -25,6 +25,7 @@ STDOUT.sync = true
25
25
  require 'json'
26
26
  require 'sinatra/base'
27
27
  require 'webrick'
28
+ require 'cachy'
28
29
  require 'get_process_mem'
29
30
  require 'diffy'
30
31
  require 'usagewatch_ext'
@@ -166,9 +167,8 @@ while #{settings.address} is in '#{settings.network}'"
166
167
  memory: GetProcessMem.new.bytes.to_i,
167
168
  platform: RUBY_PLATFORM,
168
169
  load: Usagewatch.uw_load.to_f,
169
- uptime: `uptime`.strip,
170
170
  threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
171
- wallets: settings.wallets.all.count,
171
+ wallets: Cachy.cache(:a_key, expires_in: 5 * 60) { settings.wallets.all.count },
172
172
  remotes: settings.remotes.all.count,
173
173
  nscore: settings.remotes.all.map { |r| r[:score] }.inject(&:+) || 0,
174
174
  farm: settings.farm.to_json,
@@ -59,10 +59,10 @@ module Zold
59
59
  break if lock.flock(File::LOCK_EX | File::LOCK_NB)
60
60
  sleep 0.1
61
61
  cycles += 1
62
- delay = Time.now - start
62
+ delay = (Time.now - start).round(2)
63
63
  if delay > @timeout
64
64
  raise "##{Process.pid}/#{Thread.current.name} can't get exclusive access to the wallet #{id} \
65
- because of the lock at #{lock.path}: #{File.read(lock)}"
65
+ because of the lock at #{lock.path}, after #{delay}s of waiting: #{File.read(lock)}"
66
66
  end
67
67
  if (cycles % 20).zero? && delay > 10
68
68
  @log.info("##{Process.pid}/#{Thread.current.name} still waiting for \
@@ -0,0 +1,63 @@
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
+ require 'pathname'
23
+ require_relative 'id'
24
+ require_relative 'wallet'
25
+
26
+ # The local collection of wallets.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
29
+ # License:: MIT
30
+ module Zold
31
+ # Collection of local wallets, in a tree of directories
32
+ class TreeWallets
33
+ def initialize(dir)
34
+ @dir = dir
35
+ end
36
+
37
+ def to_s
38
+ path
39
+ end
40
+
41
+ def path
42
+ FileUtils.mkdir_p(@dir)
43
+ File.expand_path(@dir)
44
+ end
45
+
46
+ # Returns the list of their IDs (as plain text)
47
+ def all
48
+ Dir.glob("#{path}/**/*#{Wallet::EXTENSION}").select do |f|
49
+ basename = File.basename(f, Wallet::EXTENSION)
50
+ File.file?(f) &&
51
+ !File.directory?(f) &&
52
+ basename =~ /^[0-9a-fA-F]{16}$/ &&
53
+ Id.new(basename).to_s == basename
54
+ end.map { |w| File.basename(w, Wallet::EXTENSION) }
55
+ end
56
+
57
+ def find(id)
58
+ raise 'Id can\'t be nil' if id.nil?
59
+ raise 'Id must be of type Id' unless id.is_a?(Id)
60
+ yield Zold::Wallet.new(File.join(path, (id.to_s.split('', 5).take(4) + [id.to_s]).join('/')))
61
+ end
62
+ end
63
+ 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.14.36'
28
+ VERSION = '0.14.37'
29
29
  PROTOCOL = 2
30
30
  end
data/test/test__helper.rb CHANGED
@@ -24,6 +24,8 @@ gem 'openssl'
24
24
  require 'openssl'
25
25
  require 'minitest/autorun'
26
26
  require 'concurrent'
27
+ require 'cachy'
28
+ require 'moneta'
27
29
 
28
30
  STDOUT.sync = true
29
31
 
@@ -36,6 +38,8 @@ if ENV['CI'] == 'true'
36
38
  SimpleCov.formatter = SimpleCov::Formatter::Codecov
37
39
  end
38
40
 
41
+ Cachy.cache_store = Moneta.new(:Memory)
42
+
39
43
  module Minitest
40
44
  class Test
41
45
  def assert_wait(max: 30)
@@ -0,0 +1,46 @@
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_relative '../lib/zold/key'
26
+ require_relative '../lib/zold/id'
27
+ require_relative '../lib/zold/tree_wallets'
28
+
29
+ # TreeWallets test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestTreeWallets < Minitest::Test
34
+ def test_adds_wallet
35
+ Dir.mktmpdir do |dir|
36
+ wallets = Zold::TreeWallets.new(dir)
37
+ id = Zold::Id.new('abcd0123abcd0123')
38
+ wallets.find(id) do |wallet|
39
+ wallet.init(id, Zold::Key.new(file: 'fixtures/id_rsa.pub'))
40
+ assert_equal(1, wallets.all.count)
41
+ assert_equal(id.to_s, wallets.all[0])
42
+ assert(wallet.path.end_with?('/a/b/c/d/abcd0123abcd0123.z'), wallet.path)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
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 'fileutils'
24
+ require_relative '../lib/zold/version'
25
+ require_relative '../lib/zold/wallet'
26
+
27
+ module Zold
28
+ # Move wallets into tree
29
+ class MoveWalletsIntoTree
30
+ def initialize(home, log)
31
+ @home = home
32
+ @log = log
33
+ end
34
+
35
+ def exec
36
+ Dir.new(@home).each do |path|
37
+ next unless path =~ /^[a-f0-9]{16}#{Wallet::EXTENSION}$/
38
+ f = File.join(@home, path)
39
+ target = File.join(@home, (path.split('', 5).take(4) + [path]).join('/'))
40
+ FileUtils.mkdir_p(File.dirname(target))
41
+ FileUtils.mv(f, target)
42
+ @log.info("Wallet #{path} moved to #{target}")
43
+ end
44
+ end
45
+ end
46
+ end
data/zold.gemspec CHANGED
@@ -54,6 +54,7 @@ and suggests a different architecture for digital wallet maintenance.'
54
54
  s.test_files = s.files.grep(%r{^(test|features)/})
55
55
  s.rdoc_options = ['--charset=UTF-8']
56
56
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
57
+ s.add_runtime_dependency 'cachy', '0.4.2'
57
58
  s.add_runtime_dependency 'concurrent-ruby', '~>1.0'
58
59
  s.add_runtime_dependency 'cucumber', '~>3.1' # has to stay here for Heroku
59
60
  s.add_runtime_dependency 'diffy', '~>3.2'
@@ -61,6 +62,7 @@ and suggests a different architecture for digital wallet maintenance.'
61
62
  s.add_runtime_dependency 'dry-types', '~>0.13.2'
62
63
  s.add_runtime_dependency 'get_process_mem', '0.2.2'
63
64
  s.add_runtime_dependency 'json', '~>1.8'
65
+ s.add_runtime_dependency 'moneta', '1.0.0'
64
66
  s.add_runtime_dependency 'openssl', '~>2.1'
65
67
  s.add_runtime_dependency 'rainbow', '~>3.0'
66
68
  s.add_runtime_dependency 'rake', '~>12.3' # has to stay here for Heroku
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.36
4
+ version: 0.14.37
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-08-16 00:00:00.000000000 Z
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cachy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: concurrent-ruby
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '1.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: moneta
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.0
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: openssl
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -481,6 +509,7 @@ files:
481
509
  - lib/zold/signature.rb
482
510
  - lib/zold/sync_wallets.rb
483
511
  - lib/zold/tax.rb
512
+ - lib/zold/tree_wallets.rb
484
513
  - lib/zold/txn.rb
485
514
  - lib/zold/type.rb
486
515
  - lib/zold/upgrades.rb
@@ -539,6 +568,7 @@ files:
539
568
  - test/test_signature.rb
540
569
  - test/test_sync_wallets.rb
541
570
  - test/test_tax.rb
571
+ - test/test_tree_wallets.rb
542
572
  - test/test_txn.rb
543
573
  - test/test_upgrades.rb
544
574
  - test/test_verbose_thread.rb
@@ -548,6 +578,7 @@ files:
548
578
  - test/test_zold.rb
549
579
  - test/upgrades/test_protocol_up.rb
550
580
  - upgrades/2.rb
581
+ - upgrades/move_wallets_into_tree.rb
551
582
  - upgrades/protocol_up.rb
552
583
  - upgrades/rename_foreign_wallets.rb
553
584
  - zold.gemspec
@@ -630,6 +661,7 @@ test_files:
630
661
  - test/test_signature.rb
631
662
  - test/test_sync_wallets.rb
632
663
  - test/test_tax.rb
664
+ - test/test_tree_wallets.rb
633
665
  - test/test_txn.rb
634
666
  - test/test_upgrades.rb
635
667
  - test/test_verbose_thread.rb