zold 0.10.16 → 0.10.17

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: 536093f30ee45d39b82fbc770313fce6128ac912
4
- data.tar.gz: 24babf9751c618fd19ca6cb4ae0bcd1459995ff9
3
+ metadata.gz: f82eb3e8bbf86a83ea78315d7ecb2018ef1f6fcb
4
+ data.tar.gz: 9fc982bf05be569cb2bf9d1fe821fb6fcb9d1f53
5
5
  SHA512:
6
- metadata.gz: d892b348b6b8b60e59d3543efc5d2634c33d8ca7083436df2295ba9de24ab06471fd926b722e701aa7593b4d85911598d32eb7546f82d27288dbe435923230ac
7
- data.tar.gz: 79e9f411780263871b9c39d22d47a5a68cb8c6ba65b57f3fe3df538127e30031ec152e43ab33c21d1f91b290fc249d4aae1d53dd091c3a4ce34e0359ac212f4a
6
+ metadata.gz: 0df44ded0be61884ca4ceb84cc844bc20867abc8cc96a23ea510285ef6daabf371c1660423bcdd696ddbced6e0886318ad7b987f920703f032c8211b360c8fbe
7
+ data.tar.gz: d89ea78fff3c9e9f7c8434b93b29bf6532d224509f259db03212aafbbd0440ab52fca845a27c25a4b801054954cde3826bc1a6b2c66004b6a4835b706586ee32
data/README.md CHANGED
@@ -106,6 +106,8 @@ to start the node and make sure it will be online even when you log off
106
106
  $ nohup bash -c 'while CMD; do gem install zold; done' &
107
107
  ```
108
108
 
109
+ The software will update itself automatically to new versions.
110
+
109
111
  Grateful users of the system will pay "taxes" to your wallet
110
112
  for the maintenance of their wallets.
111
113
 
@@ -58,31 +58,31 @@ module Zold
58
58
 
59
59
  def start(host, port, strength: 8, threads: 8)
60
60
  @log.debug('Zero-threads farm won\'t score anything!') if threads.zero?
61
+ @best << Score.new(Time.now, host, port, @invoice, strength: strength)
61
62
  @scores = Queue.new
62
- history(host, port, strength).each do |s|
63
- @best << s
64
- @scores << s
65
- end
63
+ history.each { |s| @scores << s }
66
64
  @threads = (1..threads).map do |t|
67
65
  Thread.new do
68
66
  VerboseThread.new(@log).run do
69
67
  Thread.current.name = "farm-#{t}"
70
68
  loop do
69
+ if @scores.length < 4
70
+ @scores << Score.new(
71
+ Time.now, host, port, @invoice,
72
+ strength: strength
73
+ )
74
+ end
71
75
  s = @scores.pop
72
76
  next unless s.valid?
77
+ next if s.expired?
78
+ next if s.strength < strength
73
79
  @semaphore.synchronize do
80
+ save(s)
74
81
  before = @best.map(&:value).max
75
82
  @best << s
76
83
  after = @best.map(&:value).max
77
84
  @best.reject! { |b| b.value < after }
78
- File.write(@cache, @best.map(&:to_s).join("\n"))
79
- @log.debug("#{Thread.current.name}: best is #{@best[0]}") if before != after
80
- end
81
- if @scores.length < 4
82
- @scores << Score.new(
83
- Time.now, host, port, @invoice,
84
- strength: strength
85
- )
85
+ @log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after
86
86
  end
87
87
  @scores << s.next
88
88
  end
@@ -102,11 +102,15 @@ module Zold
102
102
 
103
103
  private
104
104
 
105
- def history(host, port, strength)
105
+ def save(score)
106
+ File.write(@cache, (history.reject(&:expired?) + [score]).map(&:to_s).join("\n"))
107
+ end
108
+
109
+ def history
106
110
  if File.exist?(@cache)
107
111
  File.readlines(@cache).map { |t| Score.parse(t) }
108
112
  else
109
- [Score.new(Time.now, host, port, @invoice, strength: strength)]
113
+ []
110
114
  end
111
115
  end
112
116
  end
data/lib/zold/score.rb CHANGED
@@ -65,17 +65,18 @@ module Zold
65
65
  end
66
66
 
67
67
  def self.parse(text)
68
- m = Regexp.new(
68
+ re = Regexp.new(
69
69
  '^' + [
70
70
  '([0-9]+)/(?<strength>[0-9]+):',
71
- '(?<time>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
72
- '(?<host>[0-9a-z\.\-]+)',
73
- '(?<port>[0-9]+)',
74
- '(?<invoice>[a-zA-Z0-9]{8,32}@[a-f0-9]{16})',
75
- '(?<suffixes>[a-zA-Z0-9 ]+)'
76
- ].join(' ') + '$'
77
- ).match(text)
78
- raise "Invalid score '#{text}'" if m.nil?
71
+ ' (?<time>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
72
+ ' (?<host>[0-9a-z\.\-]+)',
73
+ ' (?<port>[0-9]+)',
74
+ ' (?<invoice>[a-zA-Z0-9]{8,32}@[a-f0-9]{16})',
75
+ '(?<suffixes>( [a-zA-Z0-9]+)*)'
76
+ ].join + '$'
77
+ )
78
+ m = re.match(text.strip)
79
+ raise "Invalid score '#{text}', doesn't match: #{re}" if m.nil?
79
80
  Score.new(
80
81
  Time.parse(m[:time]), m[:host],
81
82
  m[:port].to_i, m[:invoice],
@@ -136,7 +137,8 @@ module Zold
136
137
  time: @time.utc.iso8601,
137
138
  suffixes: @suffixes,
138
139
  strength: @strength,
139
- hash: value.zero? ? nil : hash
140
+ hash: value.zero? ? nil : hash,
141
+ minutes: ((Time.now - @time) / 60).to_i
140
142
  }
141
143
  end
142
144
 
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.10.16'.freeze
26
+ VERSION = '0.10.17'.freeze
27
27
  end
@@ -21,13 +21,14 @@
21
21
  require 'minitest/autorun'
22
22
  require 'rack/test'
23
23
  require 'tmpdir'
24
+ require_relative '../test__helper'
24
25
  require_relative '../../lib/zold/log'
25
26
  require_relative '../../lib/zold/node/farm'
26
27
 
27
28
  class FarmTest < Minitest::Test
28
29
  def test_makes_best_score_in_background
29
30
  Dir.mktmpdir 'test' do |dir|
30
- farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'))
31
+ farm = Zold::Farm.new('NOPREFIX@ffffffffffffffff', File.join(dir, 'f'), log: $log)
31
32
  farm.start('localhost', 80, threads: 4, strength: 2)
32
33
  sleep 0.1 while farm.best.empty? || farm.best[0].value.zero?
33
34
  assert(farm.best[0].value > 0)
@@ -37,7 +38,7 @@ class FarmTest < Minitest::Test
37
38
 
38
39
  def test_correct_score_from_empty_farm
39
40
  Dir.mktmpdir 'test' do |dir|
40
- farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'))
41
+ farm = Zold::Farm.new('NOPREFIX@cccccccccccccccc', File.join(dir, 'f'), log: $log)
41
42
  farm.start('example.com', 8080, threads: 0, strength: 1)
42
43
  score = farm.best[0]
43
44
  assert_equal(0, score.value)
data/test/test_score.rb CHANGED
@@ -86,6 +86,17 @@ class TestScore < Minitest::Test
86
86
  assert(!score.expired?)
87
87
  end
88
88
 
89
+ def test_prints_and_parses_zero_score
90
+ time = Time.now
91
+ score = Zold::Score.parse(
92
+ Zold::Score.new(
93
+ time, '192.168.0.1', 1, 'NOPREFIX@ffffffffffffffff', []
94
+ ).to_s
95
+ )
96
+ assert_equal(0, score.value)
97
+ assert(!score.expired?)
98
+ end
99
+
89
100
  def test_finds_next_score
90
101
  score = Zold::Score.new(
91
102
  Time.now, 'localhost', 443,
@@ -0,0 +1,53 @@
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_relative 'test__helper'
23
+ require_relative '../lib/zold/verbose_thread'
24
+
25
+ # VerboseThread test.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
28
+ # License:: MIT
29
+ class TestVerboseThread < Minitest::Test
30
+ def test_exceptions_are_logged
31
+ assert_raises RuntimeError do
32
+ Zold::VerboseThread.new(Zold::Log::Quiet.new).run do
33
+ raise 'Intentional'
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_syntax_exceptions_are_logged
39
+ assert_raises NoMethodError do
40
+ Zold::VerboseThread.new(Zold::Log::Quiet.new).run do
41
+ this_method_doesnt_exist(1)
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_grammar_exceptions_are_logged
47
+ assert_raises NameError do
48
+ Zold::VerboseThread.new(Zold::Log::Quiet.new).run do
49
+ the syntax is broken here
50
+ end
51
+ end
52
+ end
53
+ end
data/wp/wp.tex CHANGED
@@ -52,36 +52,36 @@ and suggests a different architecture for digital wallet maintenance.
52
52
  \section{Motivation}
53
53
 
54
54
  Bitcoin, the first decentralized digital currency, was released in January 2009~\parencite{nakamoto2008}.
55
- During a few following years ``a libertarian fairy tale'' and ``a simple Silicon Valley exercise in hype''
55
+ In the following years ``a libertarian fairy tale'' and ``a simple Silicon Valley exercise in hype''
56
56
  turned into ``a catalyst to reshape the financial system in ways that are more
57
57
  powerful for individuals and businesses alike,'' according to \textcite{andreessen2014}.
58
58
  At the moment, as~\textcite{van2014} claimed, ``the question is not whether Bitcoin has value; it already does.
59
59
  The question is whether the efficiencies of a cybercurrency
60
60
  like Bitcoin can be merged with the certainties of an honest central bank.''
61
61
 
62
- The core component of Bitcoin is the Blockchain technology, which
62
+ The core component of Bitcoin is Blockchain technology, which
63
63
  ``ensures the elimination of the double-spend problem, with the help
64
64
  of public-key cryptography'' and ``coins are transferred by the
65
65
  digital signature of a hash''~\parencite{pilkington2016}.
66
- Very soon after the Bitcoin invention similar products were introduced,
66
+ Very soon after Bitcoin was created, similar products were introduced,
67
67
  which were also based on the principles of Blockchain, such as
68
68
  Etherium~\parencite{buterin2013}.
69
69
 
70
- Even though Blockchain is a sound solution of the double-spending
70
+ Even though Blockchain is a sound solution to the double-spending
71
71
  problem, there could be other solutions,
72
72
  including different ``proof-of'' alternatives.%
73
73
  \footnote{%
74
74
  \url{https://goo.gl/aqzf2Q}:
75
75
  ``Proof-of-Burn'': instead of bringing the money together into computer equipment,
76
- the owner burns the coins. Here the coins to the address where they are
76
+ the owner burns the coins by sending to an address where they are
77
77
  irretrievable. By doing this, the owner gets a privilege to
78
78
  mine on the system.
79
79
  ``Proof-of-Stake'': the coins exist from the start, and
80
80
  the validators get a reward in the form of transaction fees.
81
81
  ``Proof-Of-Capacity'': one pays with the hard drive space. The more
82
- is the hard drive space; the more is the probability of mining
82
+ dedicated hard drive space, the higher probability of mining
83
83
  the next block and earning a reward.
84
- ``Proof-of-Elapsed-Time'': one uses Trusted Execution Environment or TEE
84
+ ``Proof-of-Elapsed-Time'': one uses a Trusted Execution Environment or TEE
85
85
  to ensure a random looter production.
86
86
  }
87
87
  For example, \textcite{everaere2010} gave
@@ -90,11 +90,11 @@ a summary of them and introduced their own;
90
90
  ``a truly distributed ledger system based on a lean graph of cross-verifying transactions'';
91
91
  recently IOTA, a ``tangle-based cryptocurrency,'' was launched~\parencite{popov2017}.
92
92
 
93
- Zold also is a decentralized digital currency that maintains its ledgers
94
- at an unpredicable amount of anonymous and untrustable server nodes, trying to guarantee
93
+ Zold is also a decentralized digital currency that maintains its ledgers
94
+ through an unpredicable amount of anonymous and untrustable server nodes, trying to guarantee
95
95
  data consistency. The architecture of Zold is not Blockchain-based.
96
96
  The development of Zold was motivated by the desire to overcome
97
- two obvious disadvantages of the majority of all existing cryptocyrrencies:
97
+ two obvious disadvantages present in the majority of all existing cryptocyrrencies:
98
98
 
99
99
  The first problem is that transaction processing is rather slow.%
100
100
  \footnote{%
@@ -121,7 +121,7 @@ Moreover, according to~\textcite{kaskaloglu2014},
121
121
 
122
122
  Thus, the speed is low and the processing fees are high.
123
123
  Zold was created as an attempt to resolve these two problems
124
- of existing Blockchain-based digital currencies.
124
+ with existing Blockchain-based digital currencies.
125
125
 
126
126
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
127
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.10.16
4
+ version: 0.10.17
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-06-01 00:00:00.000000000 Z
11
+ date: 2018-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -367,6 +367,7 @@ files:
367
367
  - test/test_signature.rb
368
368
  - test/test_tax.rb
369
369
  - test/test_txn.rb
370
+ - test/test_verbose_thread.rb
370
371
  - test/test_wallet.rb
371
372
  - test/test_wallets.rb
372
373
  - test/test_zold.rb
@@ -441,6 +442,7 @@ test_files:
441
442
  - test/test_signature.rb
442
443
  - test/test_tax.rb
443
444
  - test/test_txn.rb
445
+ - test/test_verbose_thread.rb
444
446
  - test/test_wallet.rb
445
447
  - test/test_wallets.rb
446
448
  - test/test_zold.rb