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 +4 -4
 - data/lib/zold/commands/fetch.rb +6 -3
 - data/lib/zold/hungry_wallets.rb +8 -2
 - data/lib/zold/node/nospam_entrance.rb +3 -1
 - data/lib/zold/version.rb +1 -1
 - data/test/fake_home.rb +1 -1
 - data/test/test_hungry_wallets.rb +20 -0
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: dcee21bf3bb05178a256b359ede470686c37b7345357b7f719dd0c11a5d7d241
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3fceea07fea00200236a6222187bf31d025492983261a9c8d1d493eae748fc7b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c060d5f127ab9a1ee2c26245473c7005255f2e5a9a71d9b9cbea1249ee3253b27e5e90de549b98931a2cdb2ee97f06ba7d0d23bf6f350fd204d708cef191f442
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 428a4cc6a041e838add1fa192b8e53bf837c62567b4440e1287a6fcb684e4aee57f96c1bec3e0391e0a63e5330466b91f0a3ba72d8cfddca1f804a4d58ec2899
         
     | 
    
        data/lib/zold/commands/fetch.rb
    CHANGED
    
    | 
         @@ -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 <  
     | 
| 
      
 57 
     | 
    
         
            +
                class EdgesOnly < Error; end
         
     | 
| 
       55 
58 
     | 
    
         | 
| 
       56 
59 
     | 
    
         
             
                # Raises when there are not enough successful nodes.
         
     | 
| 
       57 
     | 
    
         
            -
                class NoQuorum <  
     | 
| 
      
 60 
     | 
    
         
            +
                class NoQuorum < Error; end
         
     | 
| 
       58 
61 
     | 
    
         | 
| 
       59 
62 
     | 
    
         
             
                # Raises when the wallet wasn't found in all visible nodes.
         
     | 
| 
       60 
     | 
    
         
            -
                class NotFound <  
     | 
| 
      
 63 
     | 
    
         
            +
                class NotFound < Error; end
         
     | 
| 
       61 
64 
     | 
    
         | 
| 
       62 
65 
     | 
    
         
             
                def initialize(wallets:, remotes:, copies:, log: Log::NULL)
         
     | 
| 
       63 
66 
     | 
    
         
             
                  @wallets = wallets
         
     | 
    
        data/lib/zold/hungry_wallets.rb
    CHANGED
    
    | 
         @@ -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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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)
         
     | 
    
        data/lib/zold/version.rb
    CHANGED
    
    
    
        data/test/fake_home.rb
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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
         
     | 
    
        data/test/test_hungry_wallets.rb
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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 
     | 
    
         
            +
            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. 
     | 
| 
      
 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
         
     |