You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider removing all Instant::now() and using tokio::time::*. Offloading these low level details to Future on Tokio runtime may increase performance. Futures are optimized to be polled efficiently. Also using Instant::now() leads to non-exact timeouts and loop_speed because the checks are always if the elapsed time is greater or lesser than a fixed Duration.
pubasyncfnwait_for_cosmos_online(contact:&Contact,timeout:Duration){let start = Instant::now();whileletErr(CosmosGrpcError::NodeNotSynced) | Err(CosmosGrpcError::ChainNotRunning) =
contact.wait_for_next_block(timeout).await{sleep(Duration::from_secs(1)).await;ifInstant::now() - start > timeout {panic!("Cosmos node has not come online during timeout!")}}
contact.wait_for_next_block(timeout).await.unwrap();
contact.wait_for_next_block(timeout).await.unwrap();
contact.wait_for_next_block(timeout).await.unwrap();}
<< SIDENOTE >>
There are 3 timeout calls at the end.
Does this mean wait_for_cosmos_online will take 4 * timeout to terminate? Is this an expected behavior?
The above code may be transformed to,
pubasyncfnwait_for_cosmos_online(contact:&Contact,timeout:Duration) -> Result<(),GrpcError>{match tokio::time::timeout(timeout, contact.wait_for_next_block(timeout)).await{Ok(Err(CosmosGrpcError::NodeNotSynced) | Err(CosmosGrpcError::ChainNotRunning)) => panic!("Cosmos node has not come online during timeout!"),Err(_) => debug!("timedout")}for _ in0..3{
contact.wait_for_next_block(timeout).await?;}}
pubasyncfnget_last_event_nonce_with_retry(client:&mutGravityQueryClient<Channel>,our_cosmos_address:CosmosAddress,prefix:String,) -> u64{letmut res =
get_last_event_nonce_for_validator(client, our_cosmos_address, prefix.clone()).await;while res.is_err(){error!("Failed to get last event nonce, is the Cosmos GRPC working? {:?}",
res
);sleep(RETRY_TIME).await;
res = get_last_event_nonce_for_validator(client, our_cosmos_address, prefix.clone()).await;}
res.unwrap()}
may be transformed to,
pubasyncfn get_last_event_nonce_with_retry(client:&mutGravityQueryClient<Channel>,our_cosmos_address:CosmosAddress,prefix:String,) -> u64{loop{matchget_last_event_nonce_for_validator(client, our_cosmos_address, prefix.clone()).await{Ok(last_nonce) => {break last_none;},Err(res) = {error!("Failed to get last event nonce, is the Cosmos GRPC working? {:?}",
res
);sleep(RETRY_TIME).await;}}}}
let start = Instant::now();loop{let res = grpc
.denom_to_erc20(QueryDenomToErc20Request{denom: denom.clone(),}).await;ifletOk(val) = res {info!("Asset {} has accepted new ERC20 representation {}",
denom,
val.into_inner().erc20
);exit(0);}ifInstant::now() - start > Duration::from_secs(100){info!("Your ERC20 contract was not adopted, double check the metadata and try again");exit(1);}delay_for(Duration::from_secs(1)).await;}
may be transformed to,
match tokio::time::timeout(std::time::Duration::from_secs(100),async{loop{let res = grpc
.denom_to_erc20(QueryDenomToErc20Request{denom: denom.clone(),}).await;ifletOk(val) = res {break val;}
tokio::time::sleep(std::time::Duration::from_secs(1)).await;}}).await{Ok(val) => {info!("Asset {} has accepted new ERC20 representation {}",
denom,
val.into_inner().erc20
);exit(0);},Err(_) => {info!("Your ERC20 contract was not adopted, double check the metadata and try again");exit(1);},}
Surfaced from @informalsystems audit of Althea Gravity Bridge at commit 19a4cfe
severity: Informational
type: Restructuring proposal
difficulty: Intermediate
Involved artifacts
Description
Instant::now()
and usingtokio::time::*
. Offloading these low level details to Future on Tokio runtime may increase performance. Futures are optimized to be polled efficiently. Also usingInstant::now()
leads to non-exacttimeouts
andloop_speed
because the checks are always if the elapsed time is greater or lesser than a fixedDuration
.Here is an example on
cargo +nightly bench
It produces the following on my machine.
The
tokio::time::timeout
version is almost three times faster than theloop
version.Affected files
orchestrator/test_runner/src/transaction_stress_test.rs
orchestrator/test_runner/src/relay_market.rs
orchestrator/test_runner/src/happy_path.rs
orchestrator/test_runner/src/happy_path_v2.rs
orchestrator/cosmos_gravity/src/utils.rs
For example,
orchestrator/cosmos_gravity/src/utils.rs#L11-L24
The above code may be transformed to,
orchestrator/cosmos_gravity/src/utils.rs#L27-L43
may be transformed to,
orchestrator/gbt/src/client/deploy_erc20_representation.rs#L74-L95
may be transformed to,
Consider refactoring
main loops
.Affected files
orchestrator/orchestrator/src/main_loop.rs
orchestrator/relayer/src/main_loop.rs
may be transformed to,
The text was updated successfully, but these errors were encountered: