Skip to content

Commit

Permalink
Sleep if send light client update failed (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en authored Sep 19, 2022
1 parent fbf9fd7 commit eb42e1f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ macro_rules! return_on_fail {
};
}

macro_rules! return_on_fail_and_sleep {
($res:expr, $msg:expr, $sleep_time:expr) => {
match $res {
Ok(val) => val,
Err(e) => {
warn!(target: "relay", "{}. Error: {}", $msg, e);
trace!(target: "relay", "Sleep {} secs before next loop", $sleep_time);
sleep(Duration::from_secs($sleep_time));
return;
}
}
};
}

pub struct Eth2NearRelay {
beacon_rpc_client: BeaconRPCClient,
eth1_rpc_client: Eth1RPCClient,
Expand Down Expand Up @@ -542,10 +556,11 @@ impl Eth2NearRelay {

info!(target: "relay", "Sending light client update");

let execution_outcome = return_on_fail!(
let execution_outcome = return_on_fail_and_sleep!(
self.eth_client_contract
.send_light_client_update(light_client_update),
"Fail to send light client update"
"Fail to send light client update",
self.sleep_time_on_sync_secs
);

if let FinalExecutionStatus::Failure(error_message) = execution_outcome.status {
Expand Down

0 comments on commit eb42e1f

Please sign in to comment.