Skip to content

Commit

Permalink
Add and remove profiling (#4136)
Browse files Browse the repository at this point in the history
* Add and remove profiling

* Apply suggestions from code review

Co-authored-by: Romain Ruetschi <[email protected]>
Signed-off-by: Luca Joss <[email protected]>

---------

Signed-off-by: Luca Joss <[email protected]>
Co-authored-by: Romain Ruetschi <[email protected]>
  • Loading branch information
ljoss17 and romac authored Aug 12, 2024
1 parent e099709 commit 012bb8b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
51 changes: 42 additions & 9 deletions crates/relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,6 @@ impl CosmosSdkChain {
height_query: QueryHeight,
prove: bool,
) -> Result<QueryResponse, Error> {
crate::time!("query",
{
"src_chain": self.config().id.to_string(),
});

let data = data.into();
if !data.is_provable() & prove {
return Err(Error::private_store());
Expand Down Expand Up @@ -1197,6 +1192,12 @@ impl ChainEndpoint for CosmosSdkChain {
}

fn query_balance(&self, key_name: Option<&str>, denom: Option<&str>) -> Result<Balance, Error> {
crate::time!(
"query_balance",
{
"src_chain": self.config().id.to_string(),
}
);
// If a key_name is given, extract the account hash.
// Else retrieve the account from the configuration file.
let key = match key_name {
Expand All @@ -1212,6 +1213,12 @@ impl ChainEndpoint for CosmosSdkChain {
}

fn query_all_balances(&self, key_name: Option<&str>) -> Result<Vec<Balance>, Error> {
crate::time!(
"query_all_balances",
{
"src_chain": self.config().id.to_string(),
}
);
// If a key_name is given, extract the account hash.
// Else retrieve the account from the configuration file.
let key = match key_name {
Expand Down Expand Up @@ -1893,6 +1900,12 @@ impl ChainEndpoint for CosmosSdkChain {
request: QueryPacketCommitmentRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
crate::time!(
"query_packet_commitment",
{
"src_chain": self.config().id.to_string(),
}
);
let res = self.query(
CommitmentsPath {
port_id: request.port_id,
Expand Down Expand Up @@ -2050,6 +2063,12 @@ impl ChainEndpoint for CosmosSdkChain {
request: QueryPacketReceiptRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
crate::time!(
"query_packet_receipt",
{
"src_chain": self.config().id.to_string(),
}
);
let res = self.query(
ReceiptsPath {
port_id: request.port_id,
Expand Down Expand Up @@ -2115,6 +2134,12 @@ impl ChainEndpoint for CosmosSdkChain {
request: QueryPacketAcknowledgementRequest,
include_proof: IncludeProof,
) -> Result<(Vec<u8>, Option<MerkleProof>), Error> {
crate::time!(
"query_packet_acknowledgement",
{
"src_chain": self.config().id.to_string(),
}
);
let res = self.query(
AcksPath {
port_id: request.port_id,
Expand Down Expand Up @@ -2347,10 +2372,6 @@ impl ChainEndpoint for CosmosSdkChain {
/// 1. Client Update request - returns a vector with at most one update client event
/// 2. Transaction event request - returns all IBC events resulted from a Tx execution
fn query_txs(&self, request: QueryTxRequest) -> Result<Vec<IbcEventWithHeight>, Error> {
crate::time!("query_txs",
{
"src_chain": self.config().id.to_string(),
});
crate::telemetry!(query, self.id(), "query_txs");

self.block_on(query_txs(
Expand Down Expand Up @@ -2446,6 +2467,12 @@ impl ChainEndpoint for CosmosSdkChain {
&self,
request: QueryHostConsensusStateRequest,
) -> Result<Self::ConsensusState, Error> {
crate::time!(
"query_host_consensus_state",
{
"src_chain": self.config().id.to_string(),
}
);
let height = match request.height {
QueryHeight::Latest => TmHeight::from(0u32),
QueryHeight::Specific(ibc_height) => TmHeight::from(ibc_height),
Expand Down Expand Up @@ -2476,6 +2503,12 @@ impl ChainEndpoint for CosmosSdkChain {
height: ICSHeight,
settings: ClientSettings,
) -> Result<Self::ClientState, Error> {
crate::time!(
"build_client_state",
{
"src_chain": self.config().id.to_string(),
}
);
let ClientSettings::Tendermint(settings) = settings;
let unbonding_period = self.unbonding_period()?;
let trusting_period = settings
Expand Down
6 changes: 6 additions & 0 deletions crates/relayer/src/chain/cosmos/query/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ pub async fn query_txs(
}

QueryTxRequest::Transaction(tx) => {
crate::time!(
"query_txs: transaction hash",
{
"src_chain": chain_id,
}
);
let mut response = rpc_client
.tx_search(
tx_hash_query(&tx),
Expand Down
7 changes: 7 additions & 0 deletions crates/relayer/src/foreign_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,13 @@ impl<DstChain: ChainHandle, SrcChain: ChainHandle> ForeignClient<DstChain, SrcCh
target_height: Height,
maybe_trusted_height: Option<Height>,
) -> Result<Vec<MsgUpdateClient>, ForeignClientError> {
crate::time!(
"build_update_client_with_trusted",
{
"src_chain": self.src_chain().id(),
"dst_chain": self.dst_chain().id(),
}
);
// Get the latest client state on destination.
let (client_state, _) = self.validated_client_state()?;

Expand Down
12 changes: 12 additions & 0 deletions crates/relayer/src/light_client/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ impl super::LightClient<CosmosSdkChain> for LightClient {
client_state: &AnyClientState,
now: Time,
) -> Result<Verified<TmHeader>, Error> {
crate::time!(
"light_client.tendermint.header_and_minimal_set",
{
"src_chain": self.chain_id.to_string(),
}
);
let Verified { target, supporting } =
self.verify(trusted_height, target_height, client_state, now)?;

Expand All @@ -81,6 +87,12 @@ impl super::LightClient<CosmosSdkChain> for LightClient {
client_state: &AnyClientState,
now: Time,
) -> Result<Verified<LightBlock>, Error> {
crate::time!(
"light_client.tendermint.verify",
{
"src_chain": self.chain_id.to_string(),
}
);
trace!(%trusted_height, %target_height, "light client verification");

if !self.enable_verification {
Expand Down

0 comments on commit 012bb8b

Please sign in to comment.