radiator 0.3.0dev4 → 0.3.0dev5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/radiator/api.rb +47 -28
- data/lib/radiator/stream.rb +14 -11
- data/lib/radiator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0300379f694e6b5d2fe18be77196a8f9b4b9f37
|
4
|
+
data.tar.gz: 00b66899ce104b1c808e29f7eb54c4db3c62972a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ae0d2cc76c491041bcdcc438fbe32bede7173ce9249a2b170990a605bd9a95aba01901589e7acc452a42776eefbb71767f52313004f5638ffdfc1e376164f0b
|
7
|
+
data.tar.gz: 348db9e3128b82025986f9972199fd8063bf46266fbfcf6e1424d973c879cca7c96ab20fc3c8c0cfec720d570ff91f697a413bc197cd917be9c60356e84c5ed6
|
data/Gemfile.lock
CHANGED
data/lib/radiator/api.rb
CHANGED
@@ -336,6 +336,7 @@ module Radiator
|
|
336
336
|
def method_missing(m, *args, &block)
|
337
337
|
super unless respond_to_missing?(m)
|
338
338
|
|
339
|
+
method_name = [api_name, m].join('.')
|
339
340
|
response = nil
|
340
341
|
options = {
|
341
342
|
jsonrpc: "2.0",
|
@@ -351,12 +352,12 @@ module Radiator
|
|
351
352
|
tries += 1
|
352
353
|
|
353
354
|
begin
|
354
|
-
if @recover_transactions_on_error
|
355
|
+
if @recover_transactions_on_error && api_name == :network_broadcast_api
|
355
356
|
signatures = extract_signatures(options)
|
356
357
|
|
357
358
|
if tries > 1 && !!signatures && signatures.any?
|
358
359
|
if !!(response = recover_transaction(signatures, rpc_id, timestamp))
|
359
|
-
|
360
|
+
warning 'Found recovered transaction after retry.', method_name
|
360
361
|
response = Hashie::Mash.new(response)
|
361
362
|
end
|
362
363
|
end
|
@@ -366,54 +367,61 @@ module Radiator
|
|
366
367
|
response = request(options)
|
367
368
|
|
368
369
|
response = if response.nil?
|
369
|
-
|
370
|
+
error "No response, retrying ...", method_name
|
370
371
|
elsif !response.kind_of? Net::HTTPSuccess
|
371
|
-
|
372
|
+
warning "Unexpected response (code: #{response.code}): #{response.inspect}, retrying ...", method_name
|
372
373
|
else
|
373
374
|
case response.code
|
374
375
|
when '200'
|
375
376
|
body = response.body
|
376
377
|
response = JSON[body]
|
377
378
|
|
378
|
-
if response
|
379
|
-
|
379
|
+
if response['id'] != options[:id]
|
380
|
+
warning "Unexpected rpc_id (expected: #{options[:id]}, got: #{response['id']}), retrying ...", method_name
|
381
|
+
elsif response.keys.include?('error')
|
382
|
+
case response['error']['code']
|
383
|
+
when -32601 # Assert Exception:method_itr != api_itr->second.end(): Could not find method ...
|
384
|
+
nil
|
385
|
+
else
|
386
|
+
Hashie::Mash.new(response)
|
387
|
+
end
|
380
388
|
else
|
381
389
|
Hashie::Mash.new(response)
|
382
390
|
end
|
383
|
-
when '400' then
|
384
|
-
when '502' then
|
385
|
-
when '503' then
|
386
|
-
when '504' then
|
391
|
+
when '400' then warning 'Code 400: Bad Request, retrying ...', method_name
|
392
|
+
when '502' then warning 'Code 502: Bad Gateway, retrying ...', method_name
|
393
|
+
when '503' then warning 'Code 503: Service Unavailable, retrying ...', method_name
|
394
|
+
when '504' then warning 'Code 504: Gateway Timeout, retrying ...', method_name
|
387
395
|
else
|
388
|
-
|
396
|
+
warning "Unknown code #{response.code}, retrying ...", method_name
|
389
397
|
ap response
|
390
398
|
end
|
391
399
|
end
|
392
400
|
end
|
393
401
|
rescue Net::HTTP::Persistent::Error => e
|
394
|
-
|
402
|
+
warning "Unable to perform request: #{e} :: #{!!e.cause ? "cause: #{e.cause.message}" : ''}, retrying ...", method_name
|
395
403
|
rescue Errno::ECONNREFUSED => e
|
396
|
-
|
404
|
+
warning 'Connection refused, retrying ...', method_name
|
397
405
|
rescue Errno::EADDRNOTAVAIL => e
|
398
|
-
|
406
|
+
warning 'Node not available, retrying ...', method_name
|
399
407
|
rescue Net::ReadTimeout => e
|
400
|
-
|
408
|
+
warning 'Node read timeout, retrying ...', method_name
|
401
409
|
rescue Net::OpenTimeout => e
|
402
|
-
|
410
|
+
warning 'Node timeout, retrying ...', method_name
|
403
411
|
rescue RangeError => e
|
404
|
-
|
412
|
+
warning 'Range Error, retrying ...', method_name
|
405
413
|
rescue OpenSSL::SSL::SSLError => e
|
406
|
-
|
414
|
+
warning "SSL Error (#{e.message}), retrying ...", method_name
|
407
415
|
rescue SocketError => e
|
408
|
-
|
416
|
+
warning "Socket Error (#{e.message}), retrying ...", method_name
|
409
417
|
rescue JSON::ParserError => e
|
410
|
-
|
418
|
+
warning "JSON Parse Error (#{e.message}), retrying ...", method_name
|
411
419
|
response = nil
|
412
420
|
rescue ApiError => e
|
413
|
-
|
414
|
-
rescue => e
|
415
|
-
|
416
|
-
|
421
|
+
warning "ApiError (#{e.message}), retrying ...", method_name
|
422
|
+
# rescue => e
|
423
|
+
# warning "Unknown exception from request, retrying ...", method_name
|
424
|
+
# ap e if defined? ap
|
417
425
|
end
|
418
426
|
|
419
427
|
if !!response
|
@@ -479,8 +487,6 @@ module Radiator
|
|
479
487
|
end
|
480
488
|
|
481
489
|
def extract_signatures(options)
|
482
|
-
return unless options[:params].include? :network_broadcast_api
|
483
|
-
|
484
490
|
options[:params].map do |param|
|
485
491
|
next unless defined? param.map
|
486
492
|
|
@@ -526,7 +532,7 @@ module Radiator
|
|
526
532
|
def reset_failover
|
527
533
|
@url = @preferred_url.dup
|
528
534
|
@failover_urls = @preferred_failover_urls.dup
|
529
|
-
|
535
|
+
warning "Failover reset, going back to #{@url} ..."
|
530
536
|
end
|
531
537
|
|
532
538
|
def pop_failover_url
|
@@ -538,7 +544,7 @@ module Radiator
|
|
538
544
|
|
539
545
|
@uri = nil
|
540
546
|
@url = pop_failover_url
|
541
|
-
|
547
|
+
warning "Failing over to #{@url} ..."
|
542
548
|
end
|
543
549
|
|
544
550
|
def backoff
|
@@ -555,5 +561,18 @@ module Radiator
|
|
555
561
|
@backoff_sleep = nil
|
556
562
|
end
|
557
563
|
end
|
564
|
+
|
565
|
+
def send_log(level, message, prefix = nil)
|
566
|
+
if !!prefix
|
567
|
+
@logger.send level, "#{prefix} :: #{message}"
|
568
|
+
else
|
569
|
+
@logger.send level, "#{message}"
|
570
|
+
end
|
571
|
+
|
572
|
+
nil
|
573
|
+
end
|
574
|
+
|
575
|
+
def error(message, prefix = nil); send_log(:error, message, prefix); end
|
576
|
+
def warning(message, prefix = nil); send_log(:warn, message, prefix); end
|
558
577
|
end
|
559
578
|
end
|
data/lib/radiator/stream.rb
CHANGED
@@ -225,7 +225,7 @@ module Radiator
|
|
225
225
|
head_block = api.get_dynamic_global_properties do |properties|
|
226
226
|
if properties.head_block_number.nil?
|
227
227
|
# This can happen if a reverse proxy is acting up.
|
228
|
-
|
228
|
+
warning "Bad block sequence after height: #{latest_block_number}"
|
229
229
|
throw :sequence
|
230
230
|
end
|
231
231
|
|
@@ -242,7 +242,7 @@ module Radiator
|
|
242
242
|
throw :sequence
|
243
243
|
elsif head_block < latest_block_number
|
244
244
|
# This can happen if a reverse proxy is acting up.
|
245
|
-
|
245
|
+
warning "Invalid block sequence at height: #{head_block}"
|
246
246
|
sleep 0.5
|
247
247
|
throw :sequence
|
248
248
|
end
|
@@ -253,7 +253,7 @@ module Radiator
|
|
253
253
|
if range.size > 400
|
254
254
|
# When the range is 400 blocks, the stream will be behind by about
|
255
255
|
# 20 minutes. Time to warn.
|
256
|
-
|
256
|
+
warning "Stream behind by #{range.size} blocks (about #{(range.size * 3) / 60.0} minutes)."
|
257
257
|
end
|
258
258
|
|
259
259
|
[*range].each do |n|
|
@@ -263,8 +263,11 @@ module Radiator
|
|
263
263
|
end
|
264
264
|
|
265
265
|
api.get_block(n) do |current_block, error|
|
266
|
-
if
|
267
|
-
|
266
|
+
if current_block.nil?
|
267
|
+
warning "Node responded with: empty block, retrying ..."
|
268
|
+
throw :sequence
|
269
|
+
elsif !!error
|
270
|
+
warning "Node responded with: #{error.message || 'unknown error'}, retrying ..."
|
268
271
|
ap error
|
269
272
|
throw :sequence
|
270
273
|
end
|
@@ -278,10 +281,10 @@ module Radiator
|
|
278
281
|
sleep 3 / range.size
|
279
282
|
end
|
280
283
|
rescue StreamError; raise
|
281
|
-
rescue => e
|
282
|
-
|
283
|
-
|
284
|
-
|
284
|
+
# rescue => e
|
285
|
+
# warning "Unknown streaming error: #{e.inspect}, retrying ... "
|
286
|
+
# ap e
|
287
|
+
# redo
|
285
288
|
end; end
|
286
289
|
end
|
287
290
|
end
|
@@ -292,7 +295,7 @@ module Radiator
|
|
292
295
|
begin
|
293
296
|
@api.shutdown
|
294
297
|
rescue => e
|
295
|
-
|
298
|
+
warning("Unable to shut down: #{e}")
|
296
299
|
end
|
297
300
|
|
298
301
|
@api = nil
|
@@ -360,7 +363,7 @@ module Radiator
|
|
360
363
|
raise StreamError, JSON[response.error] if !!response.error
|
361
364
|
result = response.result
|
362
365
|
break if !!result
|
363
|
-
|
366
|
+
warnning "#{key}: #{param} result missing, retrying with timeout: #{@timeout || INITIAL_TIMEOUT} seconds"
|
364
367
|
shutdown
|
365
368
|
sleep timeout
|
366
369
|
end
|
data/lib/radiator/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.0dev5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|