-
Notifications
You must be signed in to change notification settings - Fork 52
chore: relayer shared utils #684
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //! Common service patterns and utilities for relayer modules | ||
| //! This module provides shared functionality for `RelayerService` implementations | ||
| use tendermint::Hash; | ||
| use tonic::Status; | ||
|
|
||
| /// Convert `anyhow::Error` to `tonic::Status` | ||
| #[inline] | ||
| #[must_use] | ||
| pub fn to_tonic_status(err: anyhow::Error) -> Status { | ||
| Status::from_error(err.into()) | ||
| } | ||
|
|
||
| /// Parse Cosmos transaction hashes from request | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns a `Status` error if any transaction ID cannot be parsed as a valid hash | ||
| #[inline] | ||
| #[allow(clippy::result_large_err)] | ||
| pub fn parse_cosmos_tx_hashes(tx_ids: Vec<Vec<u8>>) -> Result<Vec<Hash>, Status> { | ||
| tx_ids | ||
| .into_iter() | ||
| .map(Hash::try_from) | ||
| .collect::<Result<Vec<_>, _>>() | ||
| .map_err(|e| Status::from_error(e.into())) | ||
| } | ||
|
|
||
| /// Parse Ethereum transaction hashes from request | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns a `Status` error if any transaction ID is not exactly 32 bytes | ||
| #[inline] | ||
| #[allow(clippy::result_large_err)] | ||
| pub fn parse_eth_tx_hashes(tx_ids: Vec<Vec<u8>>) -> Result<Vec<[u8; 32]>, Status> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better to return |
||
| tx_ids | ||
| .into_iter() | ||
| .map(|tx_id| { | ||
| tx_id | ||
| .try_into() | ||
| .map_err(|tx| format!("invalid tx hash: {tx:?}")) | ||
| }) | ||
| .collect::<Result<Vec<[u8; 32]>, _>>() | ||
| .map_err(|e| Status::from_error(e.into())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto: probably should use |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| //! Utilities for Tendermint light client configuration | ||
| //! This module provides common functionality for creating and configuring Tendermint client states | ||
| use ibc_proto_eureka::{ | ||
| google::protobuf::Duration, | ||
| ibc::{ | ||
| core::client::v1::Height, | ||
| lightclients::tendermint::v1::{ClientState, Fraction}, | ||
| }, | ||
| }; | ||
|
|
||
| /// Default trust level for Tendermint light clients (1/3) | ||
| #[must_use] | ||
| pub const fn default_trust_level() -> Fraction { | ||
| Fraction { | ||
| numerator: 1, | ||
| denominator: 3, | ||
| } | ||
| } | ||
|
|
||
| /// Default max clock drift for Tendermint light clients (15 seconds) | ||
| #[must_use] | ||
| pub const fn default_max_clock_drift() -> Duration { | ||
| Duration { | ||
| seconds: 15, | ||
| nanos: 0, | ||
| } | ||
| } | ||
|
|
||
| /// Build a Tendermint client state with common defaults | ||
| /// | ||
| /// # Arguments | ||
| /// * `chain_id` - The chain ID | ||
| /// * `height` - The latest height | ||
| /// * `trusting_period` - The trusting period | ||
| /// * `unbonding_period` - The unbonding period | ||
| /// * `proof_specs` - The proof specifications for ICS23 | ||
| /// | ||
| /// Returns a `ClientState` with default trust level, max clock drift, and the provided proof specs | ||
| #[must_use] | ||
| pub fn build_tendermint_client_state( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this function should also take And if these fields are |
||
| chain_id: String, | ||
| height: Height, | ||
| trusting_period: Duration, | ||
| unbonding_period: Duration, | ||
| proof_specs: Vec<ics23::ProofSpec>, | ||
| ) -> ClientState { | ||
| ClientState { | ||
| chain_id, | ||
| trust_level: Some(default_trust_level()), | ||
| trusting_period: Some(trusting_period), | ||
| unbonding_period: Some(unbonding_period), | ||
| max_clock_drift: Some(default_max_clock_drift()), | ||
| latest_height: Some(height), | ||
| proof_specs, | ||
| upgrade_path: vec!["upgrade".to_string(), "upgradedIBCState".to_string()], | ||
| ..Default::default() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,16 +8,19 @@ | |
| unused_crate_dependencies | ||
| )] | ||
|
|
||
| use ics23 as _; | ||
| use tendermint as _; | ||
|
|
||
|
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these needed? |
||
| pub mod tx_builder; | ||
|
|
||
| use std::collections::HashMap; | ||
|
|
||
| use ibc_eureka_relayer_lib::{ | ||
| listener::{cosmos_sdk, ChainListenerService}, | ||
| service_utils::{parse_cosmos_tx_hashes, to_tonic_status}, | ||
| tx_builder::TxBuilderService, | ||
| }; | ||
| use ibc_eureka_utils::rpc::TendermintRpcExt; | ||
| use tendermint::Hash; | ||
| use tendermint_rpc::HttpClient; | ||
| use tonic::{Request, Response}; | ||
|
|
||
|
|
@@ -85,7 +88,7 @@ impl RelayerService for CosmosToCosmosRelayerModuleService { | |
| .target_listener | ||
| .chain_id() | ||
| .await | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?, | ||
| .map_err(to_tonic_status)?, | ||
| ibc_version: "2".to_string(), | ||
| ibc_contract: String::new(), | ||
| }), | ||
|
|
@@ -94,7 +97,7 @@ impl RelayerService for CosmosToCosmosRelayerModuleService { | |
| .src_listener | ||
| .chain_id() | ||
| .await | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?, | ||
| .map_err(to_tonic_status)?, | ||
| ibc_version: "2".to_string(), | ||
| ibc_contract: String::new(), | ||
| }), | ||
|
|
@@ -112,19 +115,9 @@ impl RelayerService for CosmosToCosmosRelayerModuleService { | |
| let inner_req = request.into_inner(); | ||
| tracing::info!("Got {} source tx IDs", inner_req.source_tx_ids.len()); | ||
| tracing::info!("Got {} timeout tx IDs", inner_req.timeout_tx_ids.len()); | ||
| let src_txs = inner_req | ||
| .source_tx_ids | ||
| .into_iter() | ||
| .map(Hash::try_from) | ||
| .collect::<Result<Vec<_>, _>>() | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?; | ||
| let src_txs = parse_cosmos_tx_hashes(inner_req.source_tx_ids)?; | ||
|
|
||
| let target_txs = inner_req | ||
| .timeout_tx_ids | ||
| .into_iter() | ||
| .map(Hash::try_from) | ||
| .collect::<Result<Vec<_>, _>>() | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?; | ||
| let target_txs = parse_cosmos_tx_hashes(inner_req.timeout_tx_ids)?; | ||
|
|
||
| let src_events = self | ||
| .src_listener | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| unused_crate_dependencies | ||
| )] | ||
|
|
||
| use tendermint as _; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this do? |
||
|
|
||
| pub mod tx_builder; | ||
|
|
||
| use alloy::{ | ||
|
|
@@ -16,6 +18,7 @@ use alloy::{ | |
| }; | ||
| use ibc_eureka_relayer_lib::{ | ||
| listener::{cosmos_sdk, eth_eureka, ChainListenerService}, | ||
| service_utils::{parse_cosmos_tx_hashes, to_tonic_status}, | ||
| tx_builder::TxBuilderService, | ||
| }; | ||
| use ibc_eureka_utils::rpc::TendermintRpcExt; | ||
|
|
@@ -25,7 +28,6 @@ use sp1_ics07_tendermint_prover::programs::{ | |
| }; | ||
| use sp1_prover::components::CpuProverComponents; | ||
| use sp1_sdk::{Prover, ProverClient}; | ||
| use tendermint::Hash; | ||
| use tendermint_rpc::HttpClient; | ||
| use tonic::{Request, Response}; | ||
| use tx_builder::TxBuilder; | ||
|
|
@@ -249,16 +251,12 @@ impl RelayerService for CosmosToEthRelayerModuleService { | |
| .eth_listener | ||
| .chain_id() | ||
| .await | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?, | ||
| .map_err(to_tonic_status)?, | ||
| ibc_version: "2".to_string(), | ||
| ibc_contract: self.tx_builder.ics26_router.address().to_string(), | ||
| }), | ||
| source_chain: Some(api::Chain { | ||
| chain_id: self | ||
| .tm_listener | ||
| .chain_id() | ||
| .await | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?, | ||
| chain_id: self.tm_listener.chain_id().await.map_err(to_tonic_status)?, | ||
| ibc_version: "2".to_string(), | ||
| ibc_contract: String::new(), | ||
| }), | ||
|
|
@@ -276,12 +274,7 @@ impl RelayerService for CosmosToEthRelayerModuleService { | |
| let inner_req = request.into_inner(); | ||
| tracing::info!("Got {} source tx IDs", inner_req.source_tx_ids.len()); | ||
| tracing::info!("Got {} timeout tx IDs", inner_req.timeout_tx_ids.len()); | ||
| let cosmos_txs = inner_req | ||
| .source_tx_ids | ||
| .into_iter() | ||
| .map(Hash::try_from) | ||
| .collect::<Result<Vec<_>, _>>() | ||
| .map_err(|e| tonic::Status::from_error(e.into()))?; | ||
| let cosmos_txs = parse_cosmos_tx_hashes(inner_req.source_tx_ids)?; | ||
|
|
||
| let eth_txs = inner_req | ||
| .timeout_tx_ids | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably should use
to_tonic_statusfrom above.