zold 0.23.2 → 0.23.3

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
  SHA256:
3
- metadata.gz: 80fd01894077496778a2d3822bfc7769d0c4131624451c8c7b78eaab893d9f91
4
- data.tar.gz: 3f37c9fd37e3f90441924e2007108407185b195e2a70c065a2bb03ae4dde019f
3
+ metadata.gz: dcee21bf3bb05178a256b359ede470686c37b7345357b7f719dd0c11a5d7d241
4
+ data.tar.gz: 3fceea07fea00200236a6222187bf31d025492983261a9c8d1d493eae748fc7b
5
5
  SHA512:
6
- metadata.gz: 3a8a94e45d6887cebdba5290d87d4f453076b9c950528b5e8ed10de4bdd5a66ae670e784eab926adbfe481a78e157857d963b86218ede7a03c92693d50871c8b
7
- data.tar.gz: fffd910f78c3de62a67f88e41e3a11c7c3042897949e482949bbc5e98851cd3fe5bda0335433840fc69effe6d270c2a5a2d4aae126060345ce24aad448b9af88
6
+ metadata.gz: c060d5f127ab9a1ee2c26245473c7005255f2e5a9a71d9b9cbea1249ee3253b27e5e90de549b98931a2cdb2ee97f06ba7d0d23bf6f350fd204d708cef191f442
7
+ data.tar.gz: 428a4cc6a041e838add1fa192b8e53bf837c62567b4440e1287a6fcb684e4aee57f96c1bec3e0391e0a63e5330466b91f0a3ba72d8cfddca1f804a4d58ec2899
@@ -50,14 +50,17 @@ module Zold
50
50
  class Fetch
51
51
  prepend ThreadBadge
52
52
 
53
+ # Raises when fetch fails.
54
+ class Error < StandardError; end
55
+
53
56
  # Raises when there are only edge nodes and not a single master one.
54
- class EdgesOnly < StandardError; end
57
+ class EdgesOnly < Error; end
55
58
 
56
59
  # Raises when there are not enough successful nodes.
57
- class NoQuorum < StandardError; end
60
+ class NoQuorum < Error; end
58
61
 
59
62
  # Raises when the wallet wasn't found in all visible nodes.
60
- class NotFound < StandardError; end
63
+ class NotFound < Error; end
61
64
 
62
65
  def initialize(wallets:, remotes:, copies:, log: Log::NULL)
63
66
  @wallets = wallets
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'delegate'
24
+ require 'zache'
24
25
  require_relative 'log'
25
26
  require_relative 'thread_pool'
26
27
  require_relative 'commands/pull'
@@ -44,6 +45,7 @@ module Zold
44
45
  @pool = pool
45
46
  @queue = []
46
47
  @mutex = Mutex.new
48
+ @missed = Zache.new
47
49
  @pool.add do
48
50
  Endless.new('hungry', log: log).run { pull }
49
51
  end
@@ -55,9 +57,12 @@ module Zold
55
57
  unless wallet.exists?
56
58
  if @queue.size > 256
57
59
  @log.error("Hungry queue is full with #{@queue.size} wallets, can't add #{id}")
60
+ elsif @missed.exists?(id)
61
+ @log.error("Hungry queue has seen #{id} just #{Age.new(@missed.mtime(id))} and it was not-found")
58
62
  else
59
63
  @mutex.synchronize do
60
64
  unless @queue.include?(id)
65
+ @missed.put(id, lifetime: 5 * 60)
61
66
  @queue << id
62
67
  @log.debug("Hungry queue got #{id}, at the pos no.#{@queue.size - 1}")
63
68
  end
@@ -73,14 +78,15 @@ module Zold
73
78
  def pull
74
79
  id = @mutex.synchronize { @queue.pop }
75
80
  if id.nil?
76
- sleep 1
81
+ sleep 0.2
77
82
  return
78
83
  end
79
84
  begin
80
85
  Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
81
86
  ['pull', id.to_s, "--network=#{@network}", '--tolerate-edges', '--tolerate-quorum=1']
82
87
  )
83
- rescue Fetch::EdgesOnly => e
88
+ @missed.remove(id)
89
+ rescue Fetch::Error => e
84
90
  @log.error("Can't hungry-pull #{id}: #{e.message}")
85
91
  end
86
92
  end
@@ -25,6 +25,7 @@ require 'openssl'
25
25
  require 'zache'
26
26
  require_relative '../log'
27
27
  require_relative '../size'
28
+ require_relative '../age'
28
29
 
29
30
  # The entrance that ignores something we've seen already.
30
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -54,7 +55,8 @@ module Zold
54
55
  before = @zache.get(id.to_s, lifetime: @period) { '' }
55
56
  after = hash(id, body)
56
57
  if before == after
57
- @log.debug("Spam of #{id} ignored #{Size.new(body.length)}")
58
+ @log.debug("Spam of #{id} ignored; the wallet content of #{Size.new(body.length)} \
59
+ and '#{after[0..8]}' hash has already been seen #{Age.new(@zache.mtime(id.to_s))} ago")
58
60
  return []
59
61
  end
60
62
  @zache.put(id.to_s, after)
@@ -25,7 +25,7 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.23.2'
28
+ VERSION = '0.23.3'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
@@ -46,7 +46,7 @@ class FakeHome
46
46
  Dir.mktmpdir do |dir|
47
47
  FileUtils.copy(File.expand_path(File.join(__dir__, '../fixtures/id_rsa')), File.join(dir, 'id_rsa'))
48
48
  result = yield FakeHome.new(dir, log: @log)
49
- sleep 0.1 # It's a workaround against a bug (without it tests fail sporadically)
49
+ sleep 0.5 # It's a workaround against a bug (without it tests fail sporadically)
50
50
  result
51
51
  end
52
52
  end
@@ -51,6 +51,26 @@ class TestHungryWallets < Zold::Test
51
51
  end
52
52
  end
53
53
 
54
+ def test_doesnt_pull_twice_if_not_found
55
+ FakeHome.new(log: test_log).run do |home|
56
+ id = Zold::Id.new
57
+ get = stub_request(:get, "http://localhost:4096/wallet/#{id}").to_return(status: 404)
58
+ remotes = home.remotes
59
+ remotes.add('localhost', 4096)
60
+ pool = Zold::ThreadPool.new('test', log: test_log)
61
+ wallets = Zold::HungryWallets.new(
62
+ home.wallets, remotes, File.join(home.dir, 'copies'),
63
+ pool, log: test_log
64
+ )
65
+ 3.times do
66
+ wallets.acq(id) { |w| assert(!w.exists?) }
67
+ sleep 0.2
68
+ end
69
+ pool.join(2)
70
+ assert_requested(get, times: 1)
71
+ end
72
+ end
73
+
54
74
  def test_doesnt_pull_wallet_if_exists
55
75
  FakeHome.new(log: test_log).run do |home|
56
76
  pool = Zold::ThreadPool.new('test', log: test_log)
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.23.2
4
+ version: 0.23.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2019-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -753,7 +753,7 @@ licenses:
753
753
  - MIT
754
754
  metadata: {}
755
755
  post_install_message: |-
756
- Thanks for installing Zold 0.23.2!
756
+ Thanks for installing Zold 0.23.3!
757
757
  Study our White Paper: https://papers.zold.io/wp.pdf
758
758
  Read our blog posts: https://blog.zold.io
759
759
  Try ZLD online wallet at: https://wts.zold.io