zold 0.14.12 → 0.14.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/http.rb +6 -1
- data/lib/zold/node/async_entrance.rb +13 -10
- data/lib/zold/node/front.rb +7 -1
- data/lib/zold/patch.rb +15 -4
- data/lib/zold/txn.rb +16 -16
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_fetch.rb +12 -5
- data/test/test_zold.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c46c2740b4034dae78391ab88d747116977858
|
4
|
+
data.tar.gz: 89bcbf8445379dddbff308e0dfb0a60fb11157e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1236cdbd4219b2b61dd11ffe556f26e867a2a91985d14c1d670ed2388393451e38fef70baefbaa0dd699c56b754798350a9e9afbdd116fdb7f5e21b0074ee586
|
7
|
+
data.tar.gz: ae55db8d0224a10c1facebf9a3e52dc2f7be2baf9285138af232b808bba340171f74335237abf0a13909e24bf772671016de48873ec04858d552c8fc44905975
|
data/lib/zold/http.rb
CHANGED
@@ -50,6 +50,10 @@ module Zold
|
|
50
50
|
# production one.
|
51
51
|
NETWORK_HEADER = 'X-Zold-Network'
|
52
52
|
|
53
|
+
# HTTP header we add, in order to inform the node about our
|
54
|
+
# protocol.
|
55
|
+
PROTOCOL_HEADER = 'X-Zold-Protocol'
|
56
|
+
|
53
57
|
# @todo #98:30m/DEV The following two statements are seen as issues by rubocop
|
54
58
|
# raising a Lint/AmbiguousBlockAssociation offense. It is somthing
|
55
59
|
# that could be solved by changing the TargetRubyVersion in .rubocop.yml
|
@@ -119,7 +123,8 @@ module Zold
|
|
119
123
|
'Connection': 'close',
|
120
124
|
'Accept-Encoding': 'gzip'
|
121
125
|
}
|
122
|
-
headers[Http::VERSION_HEADER] = VERSION
|
126
|
+
headers[Http::VERSION_HEADER] = Zold::VERSION
|
127
|
+
headers[Http::PROTOCOL_HEADER] = Zold::PROTOCOL.to_s
|
123
128
|
headers[Http::NETWORK_HEADER] = network
|
124
129
|
headers[Http::SCORE_HEADER] = score.reduced(4).to_text if score.valid? && !score.expired? && score.value > 3
|
125
130
|
headers
|
@@ -45,6 +45,17 @@ module Zold
|
|
45
45
|
@mutex = Mutex.new
|
46
46
|
end
|
47
47
|
|
48
|
+
def to_json
|
49
|
+
json = {
|
50
|
+
'queue': queue.count,
|
51
|
+
'pool.length': @pool.length,
|
52
|
+
'pool.running': @pool.running?
|
53
|
+
}
|
54
|
+
opts = queue
|
55
|
+
json['queue_age'] = opts.empty? ? 0 : Time.now - File.mtime(File.join(@dir, opts[0]))
|
56
|
+
@entrance.to_json.merge(json)
|
57
|
+
end
|
58
|
+
|
48
59
|
def start
|
49
60
|
@entrance.start do
|
50
61
|
FileUtils.mkdir_p(@dir)
|
@@ -53,8 +64,8 @@ module Zold
|
|
53
64
|
)
|
54
65
|
AsyncEntrance::THREADS.times do
|
55
66
|
@pool.post do
|
56
|
-
|
57
|
-
|
67
|
+
loop do
|
68
|
+
VerboseThread.new(@log).run(true) do
|
58
69
|
take
|
59
70
|
break if @pool.shuttingdown?
|
60
71
|
sleep Random.rand(100) / 100
|
@@ -77,14 +88,6 @@ module Zold
|
|
77
88
|
end
|
78
89
|
end
|
79
90
|
|
80
|
-
def to_json
|
81
|
-
@entrance.to_json.merge(
|
82
|
-
'queue': queue.count,
|
83
|
-
'pool.length': @pool.length,
|
84
|
-
'pool.running': @pool.running?
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
91
|
def push(id, body)
|
89
92
|
@mutex.synchronize do
|
90
93
|
AtomicFile.new(File.join(@dir, id.to_s)).write(body)
|
data/lib/zold/node/front.rb
CHANGED
@@ -74,6 +74,11 @@ module Zold
|
|
74
74
|
raise "Network name mismatch, you are in '#{header}', we are in '#{settings.network}'"
|
75
75
|
end
|
76
76
|
end
|
77
|
+
check_header(Http::PROTOCOL_HEADER) do |header|
|
78
|
+
if header != settings.protocol.to_s
|
79
|
+
raise "Protocol mismatch, you are in '#{header}', we are in '#{settings.protocol}'"
|
80
|
+
end
|
81
|
+
end
|
77
82
|
check_header(Http::SCORE_HEADER) do |header|
|
78
83
|
if settings.remotes.all.empty?
|
79
84
|
settings.log.debug("#{request.url}: we are in standalone mode, won't update remotes")
|
@@ -98,7 +103,7 @@ module Zold
|
|
98
103
|
headers['Cache-Control'] = 'no-cache'
|
99
104
|
headers['Connection'] = 'close'
|
100
105
|
headers['X-Zold-Version'] = settings.version
|
101
|
-
headers[
|
106
|
+
headers[Http::PROTOCOL_HEADER] = settings.protocol.to_s
|
102
107
|
headers['Access-Control-Allow-Origin'] = '*'
|
103
108
|
headers[Http::SCORE_HEADER] = score.reduced(16).to_s
|
104
109
|
end
|
@@ -161,6 +166,7 @@ module Zold
|
|
161
166
|
wallets: settings.wallets.all.count,
|
162
167
|
mtime: wallet.mtime.utc.iso8601,
|
163
168
|
digest: wallet.digest,
|
169
|
+
balance: wallet.balance.to_i,
|
164
170
|
body: AtomicFile.new(wallet.path).read
|
165
171
|
}.to_json
|
166
172
|
end
|
data/lib/zold/patch.rb
CHANGED
@@ -58,13 +58,24 @@ module Zold
|
|
58
58
|
end
|
59
59
|
@network = wallet.network
|
60
60
|
end
|
61
|
-
|
62
|
-
|
61
|
+
unless wallet.network == @network
|
62
|
+
@log.error("The wallet is from a different network '#{wallet.network}', ours is '#{@network}'")
|
63
|
+
return
|
64
|
+
end
|
65
|
+
unless wallet.key == @key
|
66
|
+
@log.error('Public key mismatch')
|
67
|
+
return
|
68
|
+
end
|
69
|
+
unless wallet.id == @id
|
70
|
+
@log.error("Wallet ID mismatch, ours is #{@id}, theirs is #{wallet.id}")
|
71
|
+
return
|
63
72
|
end
|
64
|
-
raise 'Public key mismatch' if wallet.key != @key
|
65
|
-
raise "Wallet ID mismatch: #{@id} != #{wallet.id}" if wallet.id != @id
|
66
73
|
wallet.txns.each do |txn|
|
67
74
|
next if @txns.find { |t| t == txn }
|
75
|
+
if @txns.find { |t| t.id == txn.id && t.bnf == txn.bnf }
|
76
|
+
@log.error("A transaction with the same ID #{t.id} and BNF #{t.bnf} already exists")
|
77
|
+
next
|
78
|
+
end
|
68
79
|
if txn.amount.negative?
|
69
80
|
dup = @txns.find { |t| t.id == txn.id && t.amount.negative? }
|
70
81
|
if dup
|
data/lib/zold/txn.rb
CHANGED
@@ -110,27 +110,27 @@ module Zold
|
|
110
110
|
def self.parse(line, idx = 0)
|
111
111
|
regex = Regexp.new(
|
112
112
|
'^' + [
|
113
|
-
'([0-9a-f]{4})',
|
114
|
-
'([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
|
115
|
-
'([0-9a-f]{16})',
|
116
|
-
"(
|
117
|
-
'([0-9a-f]{16})',
|
118
|
-
"(
|
119
|
-
'([A-Za-z0-9+/]+={0,3})?'
|
113
|
+
'(?<id>[0-9a-f]{4})',
|
114
|
+
'(?<date>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)',
|
115
|
+
'(?<amount>[0-9a-f]{16})',
|
116
|
+
"(?<prefix>#{Txn::RE_PREFIX})",
|
117
|
+
'(?<bnf>[0-9a-f]{16})',
|
118
|
+
"(?<details>#{Txn::RE_DETAILS})",
|
119
|
+
'(?<sign>[A-Za-z0-9+/]+={0,3})?'
|
120
120
|
].join(';') + '$'
|
121
121
|
)
|
122
122
|
clean = line.strip
|
123
|
-
|
124
|
-
|
123
|
+
parts = regex.match(clean)
|
124
|
+
raise "Invalid line ##{idx}: #{line.inspect} #{regex}" unless parts
|
125
125
|
txn = Txn.new(
|
126
|
-
Hexnum.parse(parts[
|
127
|
-
Time.parse(parts[
|
128
|
-
Amount.new(coins: Hexnum.parse(parts[
|
129
|
-
parts[
|
130
|
-
Id.new(parts[
|
131
|
-
parts[
|
126
|
+
Hexnum.parse(parts[:id]).to_i,
|
127
|
+
Time.parse(parts[:date]),
|
128
|
+
Amount.new(coins: Hexnum.parse(parts[:amount]).to_i),
|
129
|
+
parts[:prefix],
|
130
|
+
Id.new(parts[:bnf]),
|
131
|
+
parts[:details]
|
132
132
|
)
|
133
|
-
txn.sign = parts[
|
133
|
+
txn.sign = parts[:sign]
|
134
134
|
txn
|
135
135
|
end
|
136
136
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_fetch.rb
CHANGED
@@ -59,11 +59,18 @@ class TestFetch < Minitest::Test
|
|
59
59
|
remotes.add('localhost', 80)
|
60
60
|
remotes.add('localhost', 81)
|
61
61
|
copies = home.copies(wallet)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
begin
|
63
|
+
retries ||= 0
|
64
|
+
Zold::Fetch.new(wallets: home.wallets, copies: copies.root, remotes: remotes, log: test_log).run(
|
65
|
+
['fetch', '--ignore-score-weakness', wallet.id.to_s]
|
66
|
+
)
|
67
|
+
rescue StandardError => _
|
68
|
+
sleep 1
|
69
|
+
retry if (retries += 1) < 3
|
70
|
+
end
|
71
|
+
assert_equal(1, copies.all.count)
|
72
|
+
assert_equal('1', copies.all[0][:name])
|
73
|
+
assert_equal(0, copies.all[0][:score])
|
67
74
|
end
|
68
75
|
end
|
69
76
|
end
|
data/test/test_zold.rb
CHANGED