Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ toml = "0.8.19"
tonic = "0.12"
tracing = { version = "0.1.36", default-features = false }
tracing-subscriber = "0.3.14"
tryhard = "0.5.1"
uint = "0.9"
uuid = "1.10.5"

Expand Down
1 change: 1 addition & 0 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ toml = { workspace = true }
tonic = { workspace = true, features = ["tls", "tls-roots"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["fmt", "env-filter", "json"] }
tryhard = { workspace = true }
uuid = { workspace = true, features = ["v4"] }

[dev-dependencies]
Expand Down
169 changes: 109 additions & 60 deletions crates/relayer/src/chain/astria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use crate::{
keyring::{Ed25519KeyPair, KeyRing},
light_client::{tendermint::LightClient, LightClient as _},
misbehaviour::MisbehaviourEvidence,
util::grpc_retry,
};
use astria_core::crypto::VerificationKey;
use astria_core::primitive::v1::Address;
Expand Down Expand Up @@ -656,12 +657,21 @@ impl ChainEndpoint for AstriaChain {
) -> Result<Vec<IdentifiedAnyClientState>, Error> {
use crate::{chain::utils::client_id_suffix, util::pretty::PrettyIdentifiedClientState};

let mut client = self.ibc_client_grpc_client.clone();
let retry_config = grpc_retry::GrpcRetryConfig::default();

let request = tonic::Request::new(request.into());
let response = self
.block_on(client.client_states(request))
.map_err(|e| Error::grpc_status(e, "query_clients".to_owned()))?
.block_on(grpc_retry::retry_grpc_call(
&retry_config,
"query_clients",
|| async {
let mut client = self.ibc_client_grpc_client.clone();
let request = tonic::Request::new(request.clone().into());
client
.client_states(request)
.await
.map_err(|e| Error::grpc_status(e, "query_clients".to_owned()))
},
))?
.into_inner();

// Deserialize into domain type
Expand Down Expand Up @@ -694,24 +704,34 @@ impl ChainEndpoint for AstriaChain {
request: QueryClientStateRequest,
include_proof: IncludeProof,
) -> Result<(AnyClientState, Option<MerkleProof>), Error> {
let mut client = self.ibc_client_grpc_client.clone();

let mut req = ibc_proto::ibc::core::client::v1::QueryClientStateRequest {
client_id: request.client_id.to_string(),
}
.into_request();

let height = match request.height {
QueryHeight::Latest => 0.to_string(),
QueryHeight::Specific(h) => h.to_string(),
};

req.metadata_mut()
.insert("height", height.parse().expect("valid ascii"));
let retry_config = grpc_retry::GrpcRetryConfig::default();

let response = self
.block_on(client.client_state(req))
.map_err(|e| Error::grpc_status(e, "query_client_state".to_owned()))?
.block_on(grpc_retry::retry_grpc_call(
&retry_config,
"query_client_state",
|| async {
let mut client = self.ibc_client_grpc_client.clone();

let mut req = ibc_proto::ibc::core::client::v1::QueryClientStateRequest {
client_id: request.client_id.to_string(),
}
.into_request();

let height = match request.height {
QueryHeight::Latest => 0.to_string(),
QueryHeight::Specific(h) => h.to_string(),
};

req.metadata_mut()
.insert("height", height.parse().expect("valid ascii"));

client
.client_state(req)
.await
.map_err(|e| Error::grpc_status(e, "query_client_state".to_owned()))
},
))?
.into_inner();

let Some(client_state) = response.client_state else {
Expand All @@ -733,26 +753,36 @@ impl ChainEndpoint for AstriaChain {
request: QueryConsensusStateRequest,
include_proof: IncludeProof,
) -> Result<(AnyConsensusState, Option<MerkleProof>), Error> {
let mut client = self.ibc_client_grpc_client.clone();

let mut req = ibc_proto::ibc::core::client::v1::QueryConsensusStateRequest {
client_id: request.client_id.to_string(),
revision_height: request.consensus_height.revision_height(),
revision_number: request.consensus_height.revision_number(),
latest_height: false,
}
.into_request();

let map = req.metadata_mut();
let height_str: String = match request.query_height {
QueryHeight::Latest => 0.to_string(),
QueryHeight::Specific(h) => h.to_string(),
};
map.insert("height", height_str.parse().expect("valid ascii string"));
let retry_config = grpc_retry::GrpcRetryConfig::default();

let response = self
.block_on(client.consensus_state(req))
.map_err(|e| Error::grpc_status(e, "query_consensus_state".to_owned()))?
.block_on(grpc_retry::retry_grpc_call(
&retry_config,
"query_consensus_state",
|| async {
let mut client = self.ibc_client_grpc_client.clone();

let mut req = ibc_proto::ibc::core::client::v1::QueryConsensusStateRequest {
client_id: request.client_id.to_string(),
revision_height: request.consensus_height.revision_height(),
revision_number: request.consensus_height.revision_number(),
latest_height: false,
}
.into_request();

let map = req.metadata_mut();
let height_str: String = match request.query_height {
QueryHeight::Latest => 0.to_string(),
QueryHeight::Specific(h) => h.to_string(),
};
map.insert("height", height_str.parse().expect("valid ascii string"));

client
.consensus_state(req)
.await
.map_err(|e| Error::grpc_status(e, "query_consensus_state".to_owned()))
},
))?
.into_inner();

let Some(consensus_state) = response.consensus_state else {
Expand Down Expand Up @@ -780,16 +810,25 @@ impl ChainEndpoint for AstriaChain {
&self,
request: QueryConsensusStateHeightsRequest,
) -> Result<Vec<ICSHeight>, Error> {
let mut client = self.ibc_client_grpc_client.clone();

let req = ibc_proto::ibc::core::client::v1::QueryConsensusStateHeightsRequest {
client_id: request.client_id.to_string(),
pagination: Default::default(),
};
let retry_config = grpc_retry::GrpcRetryConfig::default();

let response = self
.block_on(client.consensus_state_heights(req))
.map_err(|e| Error::grpc_status(e, "query_consensus_state_heights".to_owned()))?
.block_on(grpc_retry::retry_grpc_call(
&retry_config,
"query_consensus_state_heights",
|| async {
let mut client = self.ibc_client_grpc_client.clone();

let req = ibc_proto::ibc::core::client::v1::QueryConsensusStateHeightsRequest {
client_id: request.client_id.to_string(),
pagination: Default::default(),
};

client.consensus_state_heights(req).await.map_err(|e| {
Error::grpc_status(e, "query_consensus_state_heights".to_owned())
})
},
))?
.into_inner();

let heights = response
Expand All @@ -804,22 +843,32 @@ impl ChainEndpoint for AstriaChain {
&self,
request: QueryUpgradedClientStateRequest,
) -> Result<(AnyClientState, MerkleProof), Error> {
let mut client = self.ibc_client_grpc_client.clone();
let mut req =
ibc_proto::ibc::core::client::v1::QueryUpgradedClientStateRequest {}.into_request();
let map = req.metadata_mut();
map.insert(
"height",
request
.upgrade_height
.to_string()
.parse()
.expect("valid ascii string"),
);
let retry_config = grpc_retry::GrpcRetryConfig::default();

let response = self
.block_on(client.upgraded_client_state(req))
.map_err(|e| Error::grpc_status(e, "query_upgraded_client_state".to_owned()))?
.block_on(grpc_retry::retry_grpc_call(
&retry_config,
"query_upgraded_client_state",
|| async {
let mut client = self.ibc_client_grpc_client.clone();
let mut req =
ibc_proto::ibc::core::client::v1::QueryUpgradedClientStateRequest {}
.into_request();
let map = req.metadata_mut();
map.insert(
"height",
request
.upgrade_height
.to_string()
.parse()
.expect("valid ascii string"),
);

client.upgraded_client_state(req).await.map_err(|e| {
Error::grpc_status(e, "query_upgraded_client_state".to_owned())
})
},
))?
.into_inner();

let client_state = response
Expand Down
58 changes: 31 additions & 27 deletions crates/relayer/src/chain/cosmos/query/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::info;
use crate::chain::cosmos::types::account::Account;
use crate::config::default::max_grpc_decoding_size;
use crate::error::Error;
use crate::util::create_grpc_client;
use crate::util::{create_grpc_client, grpc_retry};

/// EthAccount defines an Ethermint account.
/// TODO: remove when/if a canonical `EthAccount`
Expand Down Expand Up @@ -68,35 +68,39 @@ pub async fn query_account(
grpc_address: &Uri,
account_address: &str,
) -> Result<BaseAccount, Error> {
let mut client = create_grpc_client(grpc_address, QueryClient::new).await?;
let retry_config = grpc_retry::GrpcRetryConfig::default();

client = client.max_decoding_message_size(max_grpc_decoding_size().get_bytes() as usize);
grpc_retry::retry_grpc_call(&retry_config, "query_account", || async {
let mut client = create_grpc_client(grpc_address, QueryClient::new).await?;

let request = tonic::Request::new(QueryAccountRequest {
address: account_address.to_string(),
});
client = client.max_decoding_message_size(max_grpc_decoding_size().get_bytes() as usize);

let response = client.account(request).await;
let request = tonic::Request::new(QueryAccountRequest {
address: account_address.to_string(),
});

// Querying for an account might fail, i.e. if the account doesn't actually exist
let resp_account = match response
.map_err(|e| Error::grpc_status(e, "query_account".to_owned()))?
.into_inner()
.account
{
Some(account) => account,
None => return Err(Error::empty_query_account(account_address.to_string())),
};
let response = client
.account(request)
.await
.map_err(|e| Error::grpc_status(e, "query_account".to_owned()))?;

if resp_account.type_url == "/cosmos.auth.v1beta1.BaseAccount" {
Ok(BaseAccount::decode(resp_account.value.as_slice())
.map_err(|e| Error::protobuf_decode("BaseAccount".to_string(), e))?)
} else if resp_account.type_url.ends_with(".EthAccount") {
Ok(EthAccount::decode(resp_account.value.as_slice())
.map_err(|e| Error::protobuf_decode("EthAccount".to_string(), e))?
.base_account
.ok_or_else(Error::empty_base_account)?)
} else {
Err(Error::unknown_account_type(resp_account.type_url))
}
// Querying for an account might fail, i.e. if the account doesn't actually exist
let resp_account = match response.into_inner().account {
Some(account) => account,
None => return Err(Error::empty_query_account(account_address.to_string())),
};

if resp_account.type_url == "/cosmos.auth.v1beta1.BaseAccount" {
Ok(BaseAccount::decode(resp_account.value.as_slice())
.map_err(|e| Error::protobuf_decode("BaseAccount".to_string(), e))?)
} else if resp_account.type_url.ends_with(".EthAccount") {
Ok(EthAccount::decode(resp_account.value.as_slice())
.map_err(|e| Error::protobuf_decode("EthAccount".to_string(), e))?
.base_account
.ok_or_else(Error::empty_base_account)?)
} else {
Err(Error::unknown_account_type(resp_account.type_url))
}
})
.await
}
Loading
Loading