Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r2r] improve rpc client rotation of tendermint #1675

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use async_trait::async_trait;
use bitcrypto::{dhash160, sha256};
use common::executor::{abortable_queue::AbortableQueue, AbortableSystem};
use common::executor::{AbortedError, Timer};
use common::log::warn;
use common::log::{debug, warn};
use common::{get_utc_timestamp, now_ms, Future01CompatExt, DEX_FEE_ADDR_PUBKEY};
use cosmrs::bank::MsgSend;
use cosmrs::crypto::secp256k1::SigningKey;
Expand Down Expand Up @@ -182,16 +182,19 @@ impl RpcCommonOps for TendermintCoin {
let mut client_impl = self.client.0.lock().await;
// try to find first live client
for (i, client) in client_impl.rpc_clients.clone().into_iter().enumerate() {
if client
.perform(HealthRequest)
.timeout(Duration::from_secs(3))
.await
.is_ok()
{
// Bring the live client to the front of rpc_clients
client_impl.rpc_clients.rotate_left(i);
return Ok(client);
}
match client.perform(HealthRequest).timeout(Duration::from_secs(5)).await {
Ok(Ok(_)) => {
// Bring the live client to the front of rpc_clients
client_impl.rpc_clients.rotate_left(i);
return Ok(client);
},
Ok(Err(rpc_error)) => {
debug!("Could not perform healthcheck on: {:?}. Error: {}", &client, rpc_error);
},
Err(timeout_error) => {
debug!("Healthcheck timeout exceed on: {:?}. Error: {}", &client, timeout_error);
},
};
}
return Err(TendermintCoinRpcError::RpcClientError(
"All the current rpc nodes are unavailable.".to_string(),
Expand Down