15
15
} ,
16
16
anyhow:: Result ,
17
17
ethers:: {
18
+ contract:: ContractError ,
18
19
providers:: {
19
20
Middleware ,
20
21
Provider ,
@@ -58,7 +59,11 @@ async fn get_latest_safe_block(chain_state: &BlockchainState) -> BlockNumber {
58
59
return latest_confirmed_block - chain_state. reveal_delay_blocks
59
60
}
60
61
Err ( e) => {
61
- tracing:: error!( "Error while getting block number. error: {:?}" , e) ;
62
+ tracing:: error!(
63
+ "Chain: {} - error while getting block number. error: {:?}" ,
64
+ & chain_state. id,
65
+ e
66
+ ) ;
62
67
time:: sleep ( RETRY_INTERVAL ) . await ;
63
68
}
64
69
}
@@ -72,12 +77,12 @@ pub async fn run_keeper_threads(
72
77
chain_eth_config : EthereumConfig ,
73
78
chain_state : BlockchainState ,
74
79
) {
75
- tracing:: info!( "Starting keeper for chain : {}" , & chain_state. id) ;
80
+ tracing:: info!( "Chain : {} - starting keeper " , & chain_state. id) ;
76
81
77
82
let latest_safe_block = get_latest_safe_block ( & chain_state) . await ;
78
83
79
84
tracing:: info!(
80
- "Latest safe block for chain {} : {} " ,
85
+ "Chain: {} - latest safe block : {}" ,
81
86
& chain_state. id,
82
87
& latest_safe_block
83
88
) ;
@@ -104,7 +109,7 @@ pub async fn run_keeper_threads(
104
109
)
105
110
. await ;
106
111
tracing:: info!(
107
- "Backlog processing for chain : {} completed" ,
112
+ "Chain : {} - backlog processing completed" ,
108
113
& backlog_chain_state. id
109
114
) ;
110
115
} ) ;
@@ -124,7 +129,7 @@ pub async fn run_keeper_threads(
124
129
. await
125
130
{
126
131
tracing:: error!(
127
- "Error in watching blocks for chain: {}, {:?}" ,
132
+ "Chain: {} - error in watching blocks. error: {:?}" ,
128
133
& watch_blocks_chain_state. id,
129
134
e
130
135
) ;
@@ -159,7 +164,8 @@ pub async fn process_event(
159
164
Ok ( result) => result,
160
165
Err ( e) => {
161
166
tracing:: error!(
162
- "Error while revealing for provider: {} and sequence number: {} with error: {:?}" ,
167
+ "Chain: {} - error while revealing for provider: {} and sequence number: {} with error: {:?}" ,
168
+ & chain_config. id,
163
169
event. provider_address,
164
170
event. sequence_number,
165
171
e
@@ -188,28 +194,49 @@ pub async fn process_event(
188
194
189
195
if gas_estimate > gas_limit {
190
196
tracing:: error!(
191
- "Gas estimate for reveal with callback is higher than the gas limit for chain: {} " ,
197
+ "Chain: {} - gas estimate for reveal with callback is higher than the gas limit" ,
192
198
& chain_config. id
193
199
) ;
194
200
return Ok ( ( ) ) ;
195
201
}
196
202
197
- let res = contract
203
+ let contract_call = contract
198
204
. reveal_with_callback (
199
205
event. provider_address ,
200
206
event. sequence_number ,
201
207
event. user_random_number ,
202
208
provider_revelation,
203
209
)
204
- . gas ( gas_estimate)
205
- . send ( )
206
- . await ?
207
- . await ;
210
+ . gas ( gas_estimate) ;
211
+
212
+ let res = contract_call. send ( ) . await ;
213
+
214
+ let pending_tx = match res {
215
+ Ok ( pending_tx) => pending_tx,
216
+ Err ( e) => match e {
217
+ // If there is a provider error, we weren't able to send the transaction.
218
+ // We will return an error. So, that the caller can decide what to do (retry).
219
+ ContractError :: ProviderError { e } => return Err ( e. into ( ) ) ,
220
+ // For all the other errors, it is likely the case we won't be able to reveal for
221
+ // ever. We will return an Ok(()) to signal that we have processed this reveal
222
+ // and concluded that its Ok to not reveal.
223
+ _ => {
224
+ tracing:: error!(
225
+ "Chain: {} - error while revealing for provider: {} and sequence number: {} with error: {:?}" ,
226
+ & chain_config. id,
227
+ event. provider_address,
228
+ event. sequence_number,
229
+ e
230
+ ) ;
231
+ return Ok ( ( ) ) ;
232
+ }
233
+ } ,
234
+ } ;
208
235
209
- match res {
210
- Ok ( _ ) => {
236
+ match pending_tx . await {
237
+ Ok ( res ) => {
211
238
tracing:: info!(
212
- "Revealed on chain : {} for provider: {} and sequence number: {} with res: {:?}" ,
239
+ "Chain : {} - revealed for provider: {} and sequence number: {} with res: {:?}" ,
213
240
& chain_config. id,
214
241
event. provider_address,
215
242
event. sequence_number,
@@ -219,7 +246,8 @@ pub async fn process_event(
219
246
}
220
247
Err ( e) => {
221
248
tracing:: error!(
222
- "Error while revealing for provider: {} and sequence number: {} with error: {:?}" ,
249
+ "Chain: {} - error while revealing for provider: {} and sequence number: {} with error: {:?}" ,
250
+ & chain_config. id,
223
251
event. provider_address,
224
252
event. sequence_number,
225
253
e
@@ -232,7 +260,8 @@ pub async fn process_event(
232
260
} ,
233
261
Err ( e) => {
234
262
tracing:: error!(
235
- "Error while simulating reveal for provider: {} and sequence number: {} \n error: {:?}" ,
263
+ "Chain: {} - error while simulating reveal for provider: {} and sequence number: {} \n error: {:?}" ,
264
+ & chain_config. id,
236
265
event. provider_address,
237
266
event. sequence_number,
238
267
e
@@ -252,7 +281,7 @@ pub async fn process_block_range(
252
281
chain_state : api:: BlockchainState ,
253
282
) {
254
283
tracing:: info!(
255
- "Processing blocks for chain : {} from block : {} to block : {}" ,
284
+ "Chain : {} - processing blocks from : {} to: {}" ,
256
285
& chain_state. id,
257
286
block_range. from,
258
287
block_range. to
@@ -280,7 +309,7 @@ pub async fn process_block_range(
280
309
process_event ( event. clone ( ) , & chain_state, & contract, gas_limit) . await
281
310
{
282
311
tracing:: error!(
283
- "Error while processing event for chain: {} and sequence number: {}. Waiting for {} seconds before retry. error: {:?}" ,
312
+ "Chain: {} - error while processing event for sequence number: {}. Waiting for {} seconds before retry. error: {:?}" ,
284
313
& chain_state. id,
285
314
& event. sequence_number,
286
315
RETRY_INTERVAL . as_secs( ) ,
@@ -290,7 +319,7 @@ pub async fn process_block_range(
290
319
}
291
320
}
292
321
tracing:: info!(
293
- "Backlog processed for chain : {} from block: {} to block: {}" ,
322
+ "Chain : {} - backlog processed from block: {} to block: {}" ,
294
323
& chain_state. id,
295
324
& current_block,
296
325
& to_block
@@ -299,7 +328,7 @@ pub async fn process_block_range(
299
328
}
300
329
Err ( e) => {
301
330
tracing:: error!(
302
- "Error while getting events for chain: {} from block: {} to block: {}. Waiting for {} seconds before retry. error: {:?}" ,
331
+ "Chain: {} - error while getting events from block: {} to block: {}. Waiting for {} seconds before retry. error: {:?}" ,
303
332
& chain_state. id,
304
333
& current_block,
305
334
& to_block,
@@ -328,15 +357,26 @@ pub async fn watch_blocks(
328
357
geth_rpc_wss : Option < String > ,
329
358
) -> Result < ( ) > {
330
359
tracing:: info!(
331
- "Watching blocks to handle new events for chain: {} " ,
360
+ "Chain: {} - watching blocks to handle new events" ,
332
361
& chain_state. id
333
362
) ;
334
363
let mut last_safe_block_processed = latest_safe_block;
335
364
336
365
let provider_option = match geth_rpc_wss {
337
- Some ( wss) => Some ( Provider :: < Ws > :: connect ( wss) . await ?) ,
366
+ Some ( wss) => Some ( match Provider :: < Ws > :: connect ( wss. clone ( ) ) . await {
367
+ Ok ( provider) => provider,
368
+ Err ( e) => {
369
+ tracing:: error!(
370
+ "Chain: {} - error while connecting to wss: {}. error: {:?}" ,
371
+ & chain_state. id,
372
+ wss,
373
+ e
374
+ ) ;
375
+ return Err ( e. into ( ) ) ;
376
+ }
377
+ } ) ,
338
378
None => {
339
- tracing:: info!( "No wss provided for chain: {} " , & chain_state. id) ;
379
+ tracing:: info!( "Chain: {} - no wss provided " , & chain_state. id) ;
340
380
None
341
381
}
342
382
} ;
@@ -367,15 +407,19 @@ pub async fn watch_blocks(
367
407
{
368
408
Ok ( _) => {
369
409
tracing:: info!(
370
- "Block range sent to handle events for chain {} : {} to {}" ,
410
+ "Chain: {} - block range sent to handle events from : {} to: {}" ,
371
411
& chain_state. id,
372
412
& last_safe_block_processed + 1 ,
373
413
& latest_safe_block
374
414
) ;
375
415
last_safe_block_processed = latest_safe_block;
376
416
}
377
417
Err ( e) => {
378
- tracing:: error!( "Error while sending block range to handle events for chain {}. These will be handled in next call. error: {:?}" , & chain_state. id, e) ;
418
+ tracing:: error!(
419
+ "Chain: {} - error while sending block range to handle events. These will be handled in next call. error: {:?}" ,
420
+ & chain_state. id,
421
+ e
422
+ ) ;
379
423
}
380
424
} ;
381
425
}
@@ -391,7 +435,7 @@ pub async fn process_new_blocks(
391
435
) {
392
436
loop {
393
437
tracing:: info!(
394
- "Waiting for new block ranges to process for chain: {} " ,
438
+ "Chain: {} - waiting for new block ranges to process" ,
395
439
& chain_state. id
396
440
) ;
397
441
if let Some ( block_range) = rx. recv ( ) . await {
0 commit comments