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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b709aac2407041d491d0d08abb766ce404dc0cf
4
- data.tar.gz: d007d6f2d7d20b096450f05c196790da6374b76e
3
+ metadata.gz: a0300379f694e6b5d2fe18be77196a8f9b4b9f37
4
+ data.tar.gz: 00b66899ce104b1c808e29f7eb54c4db3c62972a
5
5
  SHA512:
6
- metadata.gz: 073339bb35cbffff34c4adedfef58534b0827aac9757f903f94f7a2ae56adb27ef8468dc85271895a725a70eb425015faa3609424fc266d88581e81f0acd023e
7
- data.tar.gz: a7cae3da19c410b1fceb01b717de6b4199dea2f7ebbd8018b7f1ef21c07e6da58439c0016508d60c7d1b9c6f8bd9f488b66179519018f7c40afc50a6e2a5f581
6
+ metadata.gz: 5ae0d2cc76c491041bcdcc438fbe32bede7173ce9249a2b170990a605bd9a95aba01901589e7acc452a42776eefbb71767f52313004f5638ffdfc1e376164f0b
7
+ data.tar.gz: 348db9e3128b82025986f9972199fd8063bf46266fbfcf6e1424d973c879cca7c96ab20fc3c8c0cfec720d570ff91f697a413bc197cd917be9c60356e84c5ed6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- radiator (0.3.0dev4)
4
+ radiator (0.3.0dev5)
5
5
  bitcoin-ruby (= 0.0.11)
6
6
  ffi (= 1.9.18)
7
7
  hashie (~> 3.5, >= 3.5.5)
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
- @logger.warn 'Found recovered transaction after retry.'
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
- @logger.error "No response, retrying ..."; nil
370
+ error "No response, retrying ...", method_name
370
371
  elsif !response.kind_of? Net::HTTPSuccess
371
- @logger.warn "Unexpected response (code: #{response.code}): #{response.inspect}, retrying ..."; nil
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.keys.include?('result') && response['result'].nil?
379
- @logger.warn 'Invalid response from node, retrying ...'; nil
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 @logger.warn 'Code 400: Bad Request, retrying ...'; nil
384
- when '502' then @logger.warn 'Code 502: Bad Gateway, retrying ...'; nil
385
- when '503' then @logger.warn 'Code 503: Service Unavailable, retrying ...'; nil
386
- when '504' then @logger.warn 'Code 504: Gateway Timeout, retrying ...'; nil
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
- @logger.warn "Unknown code #{response.code}, retrying ..."
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
- @logger.warn "Unable to perform request: #{e} :: #{!!e.cause ? "cause: #{e.cause.message}" : ''}, retrying ..."
402
+ warning "Unable to perform request: #{e} :: #{!!e.cause ? "cause: #{e.cause.message}" : ''}, retrying ...", method_name
395
403
  rescue Errno::ECONNREFUSED => e
396
- @logger.warn 'Connection refused, retrying ...'
404
+ warning 'Connection refused, retrying ...', method_name
397
405
  rescue Errno::EADDRNOTAVAIL => e
398
- @logger.warn 'Node not available, retrying ...'
406
+ warning 'Node not available, retrying ...', method_name
399
407
  rescue Net::ReadTimeout => e
400
- @logger.warn 'Node read timeout, retrying ...'
408
+ warning 'Node read timeout, retrying ...', method_name
401
409
  rescue Net::OpenTimeout => e
402
- @logger.warn 'Node timeout, retrying ...'
410
+ warning 'Node timeout, retrying ...', method_name
403
411
  rescue RangeError => e
404
- @logger.warn 'Range Error, retrying ...'
412
+ warning 'Range Error, retrying ...', method_name
405
413
  rescue OpenSSL::SSL::SSLError => e
406
- @logger.warn "SSL Error (#{e.message}), retrying ..."
414
+ warning "SSL Error (#{e.message}), retrying ...", method_name
407
415
  rescue SocketError => e
408
- @logger.warn "Socket Error (#{e.message}), retrying ..."
416
+ warning "Socket Error (#{e.message}), retrying ...", method_name
409
417
  rescue JSON::ParserError => e
410
- @logger.warn "JSON Parse Error (#{e.message}), retrying ..."
418
+ warning "JSON Parse Error (#{e.message}), retrying ...", method_name
411
419
  response = nil
412
420
  rescue ApiError => e
413
- @logger.warn "ApiError (#{e.message}), retrying ..."
414
- rescue => e
415
- @logger.warn "Unknown exception from request, retrying ..."
416
- ap e if defined? ap
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
- @logger.warn "Failover reset, going back to #{@url} ..."
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
- @logger.warn "Failing over to #{@url} ..."
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
@@ -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
- @logger.warn "Bad block sequence after height: #{latest_block_number}"
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
- @logger.warn "Invalid block sequence at height: #{head_block}"
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
- @logger.warn "Stream behind by #{range.size} blocks (about #{(range.size * 3) / 60.0} minutes)."
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 !!error
267
- @logger.warn "Node responded with: #{error.message || 'unknown error'}"
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
- @logger.warn "Unknown streaming error: #{e.inspect}, retrying ... "
283
- ap e
284
- redo
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
- @logger.warn("Unable to shut down: #{e}")
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
- @logger.warn "#{key}: #{param} result missing, retrying with timeout: #{@timeout || INITIAL_TIMEOUT} seconds"
366
+ warnning "#{key}: #{param} result missing, retrying with timeout: #{@timeout || INITIAL_TIMEOUT} seconds"
364
367
  shutdown
365
368
  sleep timeout
366
369
  end
@@ -1,3 +1,3 @@
1
1
  module Radiator
2
- VERSION = '0.3.0dev4'
2
+ VERSION = '0.3.0dev5'
3
3
  end
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.0dev4
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-02 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler