Skip to content

Commit

Permalink
fix loop errors while getting gravity bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
kstoykov committed Aug 30, 2021
1 parent 8800f54 commit bb72acb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
43 changes: 27 additions & 16 deletions orchestrator/orchestrator/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ pub async fn eth_oracle_main_loop(
// a bit of logic that tires to keep things running every LOOP_SPEED seconds exactly
// this is not required for any specific reason. In fact we expect and plan for
// the timing being off significantly
let elapsed = Instant::now() - loop_start;
if elapsed < ETH_ORACLE_LOOP_SPEED {
delay_for(ETH_ORACLE_LOOP_SPEED - elapsed).await;
}
loop_delay(loop_start).await;
// let elapsed = Instant::now() - loop_start;
// if elapsed < ETH_ORACLE_LOOP_SPEED {
// delay_for(ETH_ORACLE_LOOP_SPEED - elapsed).await;
// }
}
}

Expand All @@ -195,17 +196,19 @@ pub async fn eth_signer_main_loop(
let our_cosmos_address = cosmos_key.to_address(&contact.get_prefix()).unwrap();
let our_ethereum_address = ethereum_key.to_public_key().unwrap();
let mut grpc_client = grpc_client;
let gravity_id = get_gravity_id(gravity_contract_address, our_ethereum_address, &web3).await;
if gravity_id.is_err() {
error!("Failed to get GravityID, check your Eth node");
return;
}
let gravity_id = gravity_id.unwrap();
let gravity_id = String::from_utf8(gravity_id.clone()).expect("Invalid GravityID");


loop {
let loop_start = Instant::now();

let gravity_id = get_gravity_id(gravity_contract_address, our_ethereum_address, &web3).await;
if gravity_id.is_err() {
error!("Failed to get GravityID, check your Eth node");
loop_delay(loop_start).await;
continue;
}
let gravity_id = gravity_id.unwrap();
let gravity_id = String::from_utf8(gravity_id.clone()).expect("Invalid GravityID");

let latest_eth_block = web3.eth_block_number().await;
let latest_cosmos_block = contact.get_chain_status().await;
match (latest_eth_block, latest_cosmos_block) {
Expand Down Expand Up @@ -348,10 +351,11 @@ pub async fn eth_signer_main_loop(
// a bit of logic that tires to keep things running every LOOP_SPEED seconds exactly
// this is not required for any specific reason. In fact we expect and plan for
// the timing being off significantly
let elapsed = Instant::now() - loop_start;
if elapsed < ETH_SIGNER_LOOP_SPEED {
delay_for(ETH_SIGNER_LOOP_SPEED - elapsed).await;
}
loop_delay(loop_start).await;
// let elapsed = Instant::now() - loop_start;
// if elapsed < ETH_SIGNER_LOOP_SPEED {
// delay_for(ETH_SIGNER_LOOP_SPEED - elapsed).await;
// }
}
}

Expand All @@ -376,3 +380,10 @@ fn check_for_fee_error(res: Result<TxResponse, CosmosGrpcError>, fee: &Coin) {
}
}
}

async fn loop_delay(loop_start: Instant) {
let elapsed = Instant::now() - loop_start;
if elapsed < ETH_SIGNER_LOOP_SPEED {
delay_for(ETH_SIGNER_LOOP_SPEED - elapsed).await;
}
}
20 changes: 15 additions & 5 deletions orchestrator/relayer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub async fn relayer_main_loop(
gravity_contract_address: EthAddress,
) {
let mut grpc_client = grpc_client;

loop {
let loop_start = Instant::now();

Expand All @@ -38,7 +39,8 @@ pub async fn relayer_main_loop(
get_gravity_id(gravity_contract_address, our_ethereum_address, &web3).await;
if gravity_id.is_err() {
error!("Failed to get GravityID, check your Eth node");
return;
loop_delay(loop_start).await;
continue;
}
let gravity_id = gravity_id.unwrap();
let gravity_id = String::from_utf8(gravity_id.clone()).expect("Invalid GravityID");
Expand Down Expand Up @@ -79,9 +81,17 @@ pub async fn relayer_main_loop(
// a bit of logic that tires to keep things running every 5 seconds exactly
// this is not required for any specific reason. In fact we expect and plan for
// the timing being off significantly
let elapsed = Instant::now() - loop_start;
if elapsed < LOOP_SPEED {
delay_for(LOOP_SPEED - elapsed).await;
}
loop_delay(loop_start).await;
// let elapsed = Instant::now() - loop_start;
// if elapsed < LOOP_SPEED {
// delay_for(LOOP_SPEED - elapsed).await;
// }
}
}

async fn loop_delay(loop_start: Instant) {
let elapsed = Instant::now() - loop_start;
if elapsed < LOOP_SPEED {
delay_for(LOOP_SPEED - elapsed).await;
}
}

0 comments on commit bb72acb

Please sign in to comment.