radiator 0.4.0pre1 → 0.4.0pre2

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: b0f7aaa5e12224ae48fdfe1535182583e298d97f
4
- data.tar.gz: 5ec823c95e96ad1a44ceb0b77bc08b72aede7f8e
3
+ metadata.gz: ec41122ec4298e304c921f89355e437830c9fd78
4
+ data.tar.gz: 5aec651358eea83415241b2c6295122951d833c0
5
5
  SHA512:
6
- metadata.gz: 6b7736813af94b8ef03e1b80e0f43aa593b194c48f71094e672798d3791eab2f0925ee313d1ea5b8b749cc8b753e0209f9298205038c5ff71b43015289eedc27
7
- data.tar.gz: 55248de7d7142432b2d8b3a11a9e536c34915ba52bea098e38988e4c3c180ace704cfe852aa9a65914b6afc702f6bd94a6a831c2e5a1a7b6ee623b31c5e8aa53
6
+ metadata.gz: 33e83e99337f5e9146a39e65057bcd88693f9d208fbcef91acba1f0b5d3741fed47a2d98e70110e3a326c3d771bf4b3ec68c5cd9dceb3271c35676d676f46b3c
7
+ data.tar.gz: 170b5bec982a6f359cbdc64d0d89e7e695e13687c70a54867edd33424190ec216934502631e493e54494b42d395a22a1819b2ce63402df9fa8570f53c234b5e9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- radiator (0.4.0pre1)
4
+ radiator (0.4.0pre2)
5
5
  awesome_print (~> 1.7, >= 1.7.0)
6
6
  bitcoin-ruby (~> 0.0, >= 0.0.11)
7
7
  ffi (~> 1.9, >= 1.9.18)
@@ -16,7 +16,7 @@ GEM
16
16
  addressable (2.5.2)
17
17
  public_suffix (>= 2.0.2, < 4.0)
18
18
  awesome_print (1.8.0)
19
- bitcoin-ruby (0.0.17)
19
+ bitcoin-ruby (0.0.18)
20
20
  connection_pool (2.2.1)
21
21
  crack (0.4.3)
22
22
  safe_yaml (~> 1.0.0)
data/Rakefile CHANGED
@@ -57,14 +57,13 @@ task :test_live_stream, [:chain, :persist] do |t, args|
57
57
  chain = args[:chain] || 'steem'
58
58
  persist = (args[:persist] || 'true') == 'true'
59
59
  last_block_number = 0
60
- options = {chain: chain, persist: persist}
61
- api = Radiator::Api.new(options)
60
+ options = {chain: chain, persist: persist, url: 'https://api.steemitstage.com'}
62
61
  total_ops = 0.0
63
62
  total_vops = 0.0
64
63
  elapsed = 0
65
64
  count = 0
66
65
 
67
- Radiator::Stream.new(options).blocks do |b, n|
66
+ Radiator::Stream.new(options).blocks do |b, n, api|
68
67
  start = Time.now.utc
69
68
 
70
69
  if last_block_number == 0
@@ -75,6 +74,7 @@ task :test_live_stream, [:chain, :persist] do |t, args|
75
74
  o = t.map(&:operations)
76
75
  op_size = o.map(&:size).reduce(0, :+)
77
76
  total_ops += op_size
77
+
78
78
  api.get_ops_in_block(n, true) do |vops, error|
79
79
  if !!error
80
80
  puts "Error on get_ops_in_block for block #{n}"
data/lib/radiator/api.rb CHANGED
@@ -205,11 +205,25 @@ module Radiator
205
205
  @preferred_url = @url.dup
206
206
  @failover_urls = options[:failover_urls]
207
207
  @debug = !!options[:debug]
208
- @logger = options[:logger] || Radiator.logger
209
- @hashie_logger = options[:hashie_logger] || Logger.new(nil)
210
208
  @max_requests = options[:max_requests] || 30
211
209
  @ssl_verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
212
210
  @ssl_version = options[:ssl_version]
211
+
212
+ @self_logger = false
213
+ @logger = if options[:logger].nil?
214
+ @self_logger = true
215
+ Radiator.logger
216
+ else
217
+ options[:logger]
218
+ end
219
+
220
+ @self_hashie_logger = false
221
+ @hashie_logger = if options[:hashie_logger].nil?
222
+ @self_hashie_logger = true
223
+ Logger.new(nil)
224
+ else
225
+ options[:hashie_logger]
226
+ end
213
227
 
214
228
  if @failover_urls.nil?
215
229
  @failover_urls = Api::default_failover_urls(@chain) - [@url]
@@ -306,15 +320,19 @@ module Radiator
306
320
  @block_api.shutdown if !!@block_api && @block_api != self
307
321
  @block_api = nil
308
322
 
309
- if !!@logger && defined?(@logger.close)
310
- if defined?(@logger.closed?)
311
- @logger.close unless @logger.closed?
323
+ if @self_logger
324
+ if !!@logger && defined?(@logger.close)
325
+ if defined?(@logger.closed?)
326
+ @logger.close unless @logger.closed?
327
+ end
312
328
  end
313
329
  end
314
330
 
315
- if !!@hashie_logger && defined?(@hashie_logger.close)
316
- if defined?(@hashie_logger.closed?)
317
- @hashie_logger.close unless @hashie_logger.closed?
331
+ if @self_hashie_logger
332
+ if !!@hashie_logger && defined?(@hashie_logger.close)
333
+ if defined?(@hashie_logger.closed?)
334
+ @hashie_logger.close unless @hashie_logger.closed?
335
+ end
318
336
  end
319
337
  end
320
338
  end
@@ -747,6 +765,7 @@ module Radiator
747
765
  @backoff_sleep ||= 0.01
748
766
 
749
767
  @backoff_sleep *= 2
768
+ GC.start
750
769
  sleep @backoff_sleep
751
770
  ensure
752
771
  if !!@backoff_at && Time.now.utc - @backoff_at > 300
@@ -35,6 +35,19 @@ module Radiator
35
35
  ).map(&:to_sym)
36
36
  VALID_OPTIONS.each { |option| attr_accessor option }
37
37
 
38
+ def self.parse_slug(*args)
39
+ args = [args].flatten
40
+
41
+ if args.size == 1
42
+ case args[0]
43
+ when String then split_slug(args[0])
44
+ when Hash then [args[0]['author'], args[0]['permlink']]
45
+ end
46
+ else
47
+ args
48
+ end
49
+ end
50
+
38
51
  def initialize(options = {})
39
52
  options = options.dup
40
53
  options.each do |k, v|
@@ -98,7 +111,7 @@ module Radiator
98
111
  # @param args [String || Array<String>] Slug or author, permlink of comment.
99
112
  # @return [Hash]
100
113
  def find_comment(*args)
101
- author, permlink = normalize_author_permlink(args)
114
+ author, permlink = Chain.parse_slug(args)
102
115
 
103
116
  api.get_content(author, permlink) do |comment, err|
104
117
  raise ChainError, ErrorParser.new(err) if !!err
@@ -241,6 +254,15 @@ module Radiator
241
254
  end
242
255
  end
243
256
  private
257
+ def self.split_slug(slug)
258
+ slug = slug.split('@').last
259
+ author = slug.split('/')[0]
260
+ permlink = slug.split('/')[1..-1].join('/')
261
+ permlink = permlink.split('#')[0]
262
+
263
+ [author, permlink]
264
+ end
265
+
244
266
  def build_options
245
267
  {
246
268
  chain: chain,
@@ -262,23 +284,6 @@ module Radiator
262
284
  @follow_api ||= FollowApi.new(build_options)
263
285
  end
264
286
 
265
- def parse_slug(slug)
266
- slug = slug.split('@').last
267
- author = slug.split('/')[0]
268
- [author, slug.split('/')[1..-1].join('/')]
269
- end
270
-
271
- def normalize_author_permlink(args)
272
- if args.size == 1
273
- case args[0]
274
- when String then parse_slug(args[0])
275
- when Hash then [args[0]['author'], args[0]['permlink']]
276
- end
277
- else
278
- args
279
- end
280
- end
281
-
282
287
  def default_max_acepted_payout
283
288
  "1000000.000 #{default_debt_asset}"
284
289
  end
@@ -58,6 +58,14 @@ module Radiator
58
58
  end
59
59
 
60
60
  begin
61
+ if @error['data'].nil?
62
+ @expiry = false
63
+ @can_retry = false
64
+ @can_reprepare = false
65
+
66
+ return
67
+ end
68
+
61
69
  @error_code = @error['data']['code']
62
70
  stacks = @error['data']['stack']
63
71
  stack_formats = stacks.map { |s| s['format'] }
@@ -21,7 +21,7 @@ module Radiator
21
21
  MAX_TIMEOUT = 80
22
22
 
23
23
  # @private
24
- MAX_BLOCKS_PER_NODE = 1000
24
+ MAX_BLOCKS_PER_NODE = 10000
25
25
 
26
26
  RANGE_BEHIND_WARNING = 400
27
27
 
@@ -120,7 +120,7 @@ module Radiator
120
120
  # @param mode we have the choice between
121
121
  # * :head the last block
122
122
  # * :irreversible the block that is confirmed by 2/3 of all block producers and is thus irreversible!
123
- # @param block the block to execute for each result, optional.
123
+ # @param block the block to execute for each result, optional. Yields: |op, trx_id, block_num, api|
124
124
  # @param options [Hash] additional options
125
125
  # @option options [Boollean] :include_virtual Also stream virtual options. Setting this true will impact performance. Default: false.
126
126
  # @return [Hash]
@@ -148,19 +148,28 @@ module Radiator
148
148
  end.compact
149
149
 
150
150
  if include_virtual && !virtual_ops_collected
151
- api.get_ops_in_block(block_number, true) do |vops|
152
- vops.each do |vtx|
153
- next unless defined? vtx.op
151
+ catch :pop_vops do; begin
152
+ api.get_ops_in_block(block_number, true) do |vops, error|
153
+ if !!error
154
+ standby "Node responded with: #{error.message || 'unknown error'}, retrying ...", {
155
+ error: error,
156
+ and: {throw: :pop_vops}
157
+ }
158
+ end
154
159
 
155
- t = vtx.op.first.to_sym
156
- op = vtx.op.last
157
- if type.size == 1 && type.first == t
158
- ops << op
159
- elsif type.none? || type.include?(t)
160
- ops << {t => op}
160
+ vops.each do |vtx|
161
+ next unless defined? vtx.op
162
+
163
+ t = vtx.op.first.to_sym
164
+ op = vtx.op.last
165
+ if type.size == 1 && type.first == t
166
+ ops << op
167
+ elsif type.none? || type.include?(t)
168
+ ops << {t => op}
169
+ end
161
170
  end
162
171
  end
163
- end
172
+ end; end
164
173
 
165
174
  virtual_ops_collected = true
166
175
  end
@@ -170,7 +179,7 @@ module Radiator
170
179
  return ops unless !!block
171
180
 
172
181
  ops.each do |op|
173
- yield op, trx_id, block_number
182
+ yield op, trx_id, block_number, api
174
183
  end
175
184
  end
176
185
  end
@@ -186,7 +195,7 @@ module Radiator
186
195
  # @param mode we have the choice between
187
196
  # * :head the last block
188
197
  # * :irreversible the block that is confirmed by 2/3 of all block producers and is thus irreversible!
189
- # @param block the block to execute for each result, optional.
198
+ # @param block the block to execute for each result, optional. Yields: |tx, trx_id, api|
190
199
  # @return [Hash]
191
200
  def transactions(start = nil, mode = :irreversible, &block)
192
201
  blocks(start, mode) do |b, block_number|
@@ -198,7 +207,7 @@ module Radiator
198
207
  b['transaction_ids'][index]
199
208
  end
200
209
 
201
- yield transaction, trx_id, block_number
210
+ yield transaction, trx_id, block_number, api
202
211
  end
203
212
  end
204
213
  end
@@ -209,13 +218,27 @@ module Radiator
209
218
  # stream.blocks do |bk, num|
210
219
  # puts "[#{num}] #{bk.to_json}"
211
220
  # end
212
- #
221
+ #
222
+ # For convenience and memory management, the api used to poll the current
223
+ # block data is also available inside the block, e.g.:
224
+ #
225
+ # stream = Radiator::Stream.new
226
+ # stream.blocks do |bk, num, api|
227
+ # puts "[#{num}] #{bk.to_json}"
228
+ #
229
+ # api.get_ops_in_block(num, true) do |vops, error|
230
+ # puts vops
231
+ # end
232
+ # end
233
+ #
234
+ # This idiom is useful for very long running scripts.
235
+ #
213
236
  # @param start starting block
214
237
  # @param mode we have the choice between
215
238
  # * :head the last block
216
239
  # * :irreversible the block that is confirmed by 2/3 of all block producers and is thus irreversible!
217
240
  # @param max_blocks_per_node the number of blocks to read before trying a new node
218
- # @param block the block to execute for each result, optional.
241
+ # @param block the block to execute for each result, optional. Yields: |bk, num, api|
219
242
  # @return [Hash]
220
243
  def blocks(start = nil, mode = :irreversible, max_blocks_per_node = MAX_BLOCKS_PER_NODE, &block)
221
244
  reset_api
@@ -229,7 +252,14 @@ module Radiator
229
252
  break if stop?
230
253
 
231
254
  catch :sequence do; begin
232
- head_block = api.get_dynamic_global_properties do |properties|
255
+ head_block = api.get_dynamic_global_properties do |properties, error|
256
+ if !!error
257
+ standby "Node responded with: #{error.message || 'unknown error'}, retrying ...", {
258
+ error: error,
259
+ and: {throw: :sequence}
260
+ }
261
+ end
262
+
233
263
  break if stop?
234
264
 
235
265
  if properties.head_block_number.nil?
@@ -295,7 +325,7 @@ module Radiator
295
325
 
296
326
  latest_block_number = n
297
327
  return current_block, n if block.nil?
298
- yield current_block, n
328
+ yield current_block, n, api
299
329
  end
300
330
 
301
331
  start = head_block + 1
@@ -331,6 +361,7 @@ module Radiator
331
361
 
332
362
  @api = nil
333
363
  @block_api = nil
364
+ GC.start
334
365
  end
335
366
 
336
367
  # @private
@@ -25,13 +25,20 @@ module Radiator
25
25
  end
26
26
  end
27
27
 
28
- @logger = options[:logger] || Radiator.logger
29
28
  @chain ||= :steem
30
29
  @chain = @chain.to_sym
31
30
  @chain_id = chain_id options[:chain_id]
32
31
  @url = options[:url] || url
33
32
  @operations = options[:operations] || []
34
-
33
+
34
+ @self_logger = false
35
+ @logger = if options[:logger].nil?
36
+ @self_logger = true
37
+ Radiator.logger
38
+ else
39
+ options[:logger]
40
+ end
41
+
35
42
  unless NETWORK_CHAIN_IDS.include? @chain_id
36
43
  warning "Unknown chain id: #{@chain_id}"
37
44
  end
@@ -60,7 +67,7 @@ module Radiator
60
67
  @api = Api.new(options)
61
68
  @network_broadcast_api = NetworkBroadcastApi.new(options)
62
69
 
63
- ObjectSpace.define_finalizer(self, self.class.finalize(@api, @network_broadcast_api, @logger))
70
+ ObjectSpace.define_finalizer(self, self.class.finalize(@api, @network_broadcast_api, @self_logger, @logger))
64
71
  end
65
72
 
66
73
  def chain_id(chain_id = nil)
@@ -124,9 +131,11 @@ module Radiator
124
131
  @api.shutdown if !!@api
125
132
  @network_broadcast_api.shutdown if !!@network_broadcast_api
126
133
 
127
- if !!@logger && defined?(@logger.close)
128
- if defined?(@logger.closed?)
129
- @logger.close unless @logger.closed?
134
+ if @self_logger
135
+ if !!@logger && defined?(@logger.close)
136
+ if defined?(@logger.closed?)
137
+ @logger.close unless @logger.closed?
138
+ end
130
139
  end
131
140
  end
132
141
  end
@@ -251,7 +260,7 @@ module Radiator
251
260
  )
252
261
  end
253
262
 
254
- def self.finalize(api, network_broadcast_api, logger)
263
+ def self.finalize(api, network_broadcast_api, self_logger, logger)
255
264
  proc {
256
265
  if !!api && !api.stopped?
257
266
  puts "DESTROY: #{api.inspect}" if ENV['LOG'] == 'TRACE'
@@ -266,9 +275,11 @@ module Radiator
266
275
  end
267
276
 
268
277
  begin
269
- if !!logger && defined?(logger.close)
270
- if defined?(logger.closed?)
271
- logger.close unless logger.closed?
278
+ if self_logger
279
+ if !!logger && defined?(logger.close)
280
+ if defined?(logger.closed?)
281
+ logger.close unless logger.closed?
282
+ end
272
283
  end
273
284
  end
274
285
  rescue IOError, NoMethodError => _; end
@@ -1,4 +1,4 @@
1
1
  module Radiator
2
- VERSION = '0.4.0pre1'
2
+ VERSION = '0.4.0pre2'
3
3
  AGENT_ID = "radiator/#{VERSION}"
4
4
  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.4.0pre1
4
+ version: 0.4.0pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-17 00:00:00.000000000 Z
11
+ date: 2018-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler