diff --git a/crates/relayer-cosmos/src/base/error.rs b/crates/relayer-cosmos/src/base/error.rs index 43e6cd87f6..5eefdcbc05 100644 --- a/crates/relayer-cosmos/src/base/error.rs +++ b/crates/relayer-cosmos/src/base/error.rs @@ -55,9 +55,3 @@ impl Clone for Error { Error(self.detail().clone(), ErrorMessageTracer::new_message(self)) } } - -impl From for Error { - fn from(e: TokioError) -> Error { - Error::tokio(e) - } -} diff --git a/crates/relayer-cosmos/src/base/impls/chain.rs b/crates/relayer-cosmos/src/base/impls/chain.rs index b658fa9a58..62d2f6f7cc 100644 --- a/crates/relayer-cosmos/src/base/impls/chain.rs +++ b/crates/relayer-cosmos/src/base/impls/chain.rs @@ -12,6 +12,8 @@ use ibc_relayer_framework::base::one_for_all::traits::chain::{ OfaBaseChain, OfaChainTypes, OfaIbcChain, }; use ibc_relayer_framework::base::one_for_all::traits::runtime::OfaRuntimeContext; +use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; +use ibc_relayer_runtime::tokio::error::Error as TokioError; use ibc_relayer_types::clients::ics07_tendermint::consensus_state::ConsensusState; use ibc_relayer_types::core::ics04_channel::events::WriteAcknowledgement; use ibc_relayer_types::core::ics04_channel::packet::Sequence; @@ -27,7 +29,6 @@ use crate::base::error::Error; use crate::base::traits::chain::CosmosChain; use crate::base::types::chain::CosmosChainWrapper; use crate::base::types::message::CosmosIbcMessage; -use crate::base::types::runtime::CosmosRuntimeContext; impl OfaChainTypes for CosmosChainWrapper where @@ -37,7 +38,7 @@ where type Error = Error; - type Runtime = CosmosRuntimeContext; + type Runtime = TokioRuntimeContext; type Height = Height; @@ -73,6 +74,10 @@ impl OfaBaseChain for CosmosChainWrapper where Chain: CosmosChain, { + fn runtime_error(e: TokioError) -> Error { + Error::tokio(e) + } + fn encode_raw_message(message: &CosmosIbcMessage, signer: &Signer) -> Result { (message.to_protobuf_fn)(signer).map_err(Error::encode) } @@ -108,7 +113,7 @@ where } } - fn runtime(&self) -> &OfaRuntimeContext { + fn runtime(&self) -> &OfaRuntimeContext { &self.runtime } diff --git a/crates/relayer-cosmos/src/base/impls/relay.rs b/crates/relayer-cosmos/src/base/impls/relay.rs index 2655551d69..0bb70135ac 100644 --- a/crates/relayer-cosmos/src/base/impls/relay.rs +++ b/crates/relayer-cosmos/src/base/impls/relay.rs @@ -23,7 +23,8 @@ use crate::base::traits::relay::CosmosRelay; use crate::base::types::chain::CosmosChainWrapper; use crate::base::types::message::CosmosIbcMessage; use crate::base::types::relay::CosmosRelayWrapper; -use crate::base::types::runtime::CosmosRuntimeContext; +use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; +use ibc_relayer_runtime::tokio::error::Error as TokioError; impl OfaRelayTypes for CosmosRelayWrapper where @@ -33,7 +34,7 @@ where type Error = Error; - type Runtime = CosmosRuntimeContext; + type Runtime = TokioRuntimeContext; type Packet = Packet; @@ -47,6 +48,18 @@ impl OfaBaseRelay for CosmosRelayWrapper where Relay: CosmosRelay, { + fn runtime_error(e: TokioError) -> Error { + Error::tokio(e) + } + + fn src_chain_error(e: Error) -> Error { + e + } + + fn dst_chain_error(e: Error) -> Error { + e + } + fn mismatch_ibc_events_count_error(expected: usize, actual: usize) -> Self::Error { Error::mismatch_ibc_events_count(expected, actual) } @@ -90,7 +103,7 @@ where &packet.timeout_timestamp } - fn runtime(&self) -> &OfaRuntimeContext { + fn runtime(&self) -> &OfaRuntimeContext { &self.runtime } diff --git a/crates/relayer-cosmos/src/base/types/chain.rs b/crates/relayer-cosmos/src/base/types/chain.rs index e358e97b21..04c7958813 100644 --- a/crates/relayer-cosmos/src/base/types/chain.rs +++ b/crates/relayer-cosmos/src/base/types/chain.rs @@ -1,16 +1,15 @@ use alloc::sync::Arc; use ibc_relayer_framework::base::one_for_all::traits::runtime::OfaRuntimeContext; - -use crate::base::types::runtime::CosmosRuntimeContext; +use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; #[derive(Clone)] pub struct CosmosChainWrapper { pub chain: Arc, - pub runtime: OfaRuntimeContext, + pub runtime: OfaRuntimeContext, } impl CosmosChainWrapper { - pub fn new(chain: Arc, runtime: CosmosRuntimeContext) -> Self { + pub fn new(chain: Arc, runtime: TokioRuntimeContext) -> Self { Self { chain, runtime: OfaRuntimeContext::new(runtime), diff --git a/crates/relayer-cosmos/src/base/types/mod.rs b/crates/relayer-cosmos/src/base/types/mod.rs index 74f46863db..62aa64d830 100644 --- a/crates/relayer-cosmos/src/base/types/mod.rs +++ b/crates/relayer-cosmos/src/base/types/mod.rs @@ -1,4 +1,3 @@ pub mod chain; pub mod message; pub mod relay; -pub mod runtime; diff --git a/crates/relayer-cosmos/src/base/types/relay.rs b/crates/relayer-cosmos/src/base/types/relay.rs index 4e1cab322b..8a5c07db33 100644 --- a/crates/relayer-cosmos/src/base/types/relay.rs +++ b/crates/relayer-cosmos/src/base/types/relay.rs @@ -1,21 +1,21 @@ use alloc::sync::Arc; use ibc_relayer_framework::base::one_for_all::traits::runtime::OfaRuntimeContext; use ibc_relayer_framework::common::one_for_all::types::chain::OfaChainWrapper; +use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; use crate::base::traits::relay::CosmosRelay; use crate::base::types::chain::CosmosChainWrapper; -use crate::base::types::runtime::CosmosRuntimeContext; #[derive(Clone)] pub struct CosmosRelayWrapper { pub relay: Arc, pub src_chain: OfaChainWrapper>, pub dst_chain: OfaChainWrapper>, - pub runtime: OfaRuntimeContext, + pub runtime: OfaRuntimeContext, } impl CosmosRelayWrapper { - pub fn new(relay: Arc, runtime: CosmosRuntimeContext) -> Self { + pub fn new(relay: Arc, runtime: TokioRuntimeContext) -> Self { let src_chain = OfaChainWrapper::new(CosmosChainWrapper::new( relay.src_chain().clone(), runtime.clone(), diff --git a/crates/relayer-cosmos/src/base/types/runtime.rs b/crates/relayer-cosmos/src/base/types/runtime.rs deleted file mode 100644 index eb095e76db..0000000000 --- a/crates/relayer-cosmos/src/base/types/runtime.rs +++ /dev/null @@ -1,5 +0,0 @@ -use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; - -use crate::base::error::Error; - -pub type CosmosRuntimeContext = TokioRuntimeContext; diff --git a/crates/relayer-cosmos/src/contexts/full/chain.rs b/crates/relayer-cosmos/src/contexts/full/chain.rs index af391ccffb..2ca0c90e65 100644 --- a/crates/relayer-cosmos/src/contexts/full/chain.rs +++ b/crates/relayer-cosmos/src/contexts/full/chain.rs @@ -3,7 +3,7 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::keyring::KeyEntry; use ibc_relayer_framework::common::one_for_all::presets::FullPreset; use ibc_relayer_framework::full::batch::context::new_batch_channel; -use ibc_relayer_framework::full::one_for_all::traits::batch::OfaBatchContext; +use ibc_relayer_framework::full::one_for_all::traits::batch::OfaBatchWrapper; use ibc_relayer_framework::full::one_for_all::traits::telemetry::OfaTelemetryWrapper; use ibc_relayer_types::signer::Signer; @@ -31,7 +31,7 @@ impl CosmosChainContext { key_entry: KeyEntry, telemetry: CosmosTelemetry, ) -> Self { - let batch_channel = new_batch_channel::>>(); + let batch_channel = new_batch_channel::>>(); let chain = Self { handle, diff --git a/crates/relayer-cosmos/src/contexts/full/relay.rs b/crates/relayer-cosmos/src/contexts/full/relay.rs index 089a68356a..42a51e06eb 100644 --- a/crates/relayer-cosmos/src/contexts/full/relay.rs +++ b/crates/relayer-cosmos/src/contexts/full/relay.rs @@ -8,11 +8,11 @@ use ibc_relayer_framework::full::batch::config::BatchConfig; use ibc_relayer_framework::full::batch::spawn::{ BatchMessageWorkerSpawner, CanSpawnBatchMessageWorker, }; +use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; use crate::base::traits::chain::CosmosChain; use crate::base::traits::relay::CosmosRelay; use crate::base::types::relay::CosmosRelayWrapper; -use crate::base::types::runtime::CosmosRuntimeContext; use crate::contexts::full::chain::CosmosChainContext; use crate::full::traits::relay::CosmosFullRelay; @@ -66,7 +66,7 @@ where } pub fn new_relay_context_with_batch( - runtime: CosmosRuntimeContext, + runtime: TokioRuntimeContext, src_chain: CosmosChainContext, dst_chain: CosmosChainContext, src_to_dst_client: ForeignClient, diff --git a/crates/relayer-cosmos/src/full/impls/chain.rs b/crates/relayer-cosmos/src/full/impls/chain.rs index 16f8307474..024f2025fc 100644 --- a/crates/relayer-cosmos/src/full/impls/chain.rs +++ b/crates/relayer-cosmos/src/full/impls/chain.rs @@ -1,8 +1,8 @@ use ibc_relayer_framework::full::one_for_all::traits::chain::OfaFullChain; use ibc_relayer_framework::full::one_for_all::traits::telemetry::OfaTelemetryWrapper; +use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; use crate::base::types::chain::CosmosChainWrapper; -use crate::base::types::runtime::CosmosRuntimeContext; use crate::full::traits::chain::CosmosFullChain; use crate::full::types::batch::CosmosBatchChannel; use crate::full::types::telemetry::CosmosTelemetry; @@ -11,7 +11,7 @@ impl OfaFullChain for CosmosChainWrapper where Chain: CosmosFullChain, { - type BatchContext = CosmosRuntimeContext; + type BatchContext = TokioRuntimeContext; type Telemetry = CosmosTelemetry; diff --git a/crates/relayer-cosmos/src/transaction/impls/broadcast.rs b/crates/relayer-cosmos/src/transaction/impls/broadcast.rs index 8832f6d45b..c5eca90fb9 100644 --- a/crates/relayer-cosmos/src/transaction/impls/broadcast.rs +++ b/crates/relayer-cosmos/src/transaction/impls/broadcast.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use ibc_proto::cosmos::tx::v1beta1::TxRaw; use ibc_relayer::chain::cosmos::types::tx::SignedTx; -use ibc_relayer_framework::base::core::traits::error::{HasError, InjectError}; +use ibc_relayer_framework::base::core::traits::error::{HasErrorType, InjectError}; use prost::EncodeError; use tendermint_rpc::endpoint::broadcast::tx_sync::Response; use tendermint_rpc::error::Error as RpcError; @@ -10,7 +10,7 @@ use tendermint_rpc::Client; use crate::transaction::traits::fields::{HasRpcAddress, HasRpcClient}; #[async_trait] -pub trait CanBroadcastTxSync: HasError { +pub trait CanBroadcastTxSync: HasErrorType { async fn broadcast_tx_sync(&self, tx: SignedTx) -> Result; } diff --git a/crates/relayer-cosmos/src/transaction/impls/decoders/account.rs b/crates/relayer-cosmos/src/transaction/impls/decoders/account.rs index bfa5311b4d..2f00ca3c98 100644 --- a/crates/relayer-cosmos/src/transaction/impls/decoders/account.rs +++ b/crates/relayer-cosmos/src/transaction/impls/decoders/account.rs @@ -1,13 +1,13 @@ use ibc_proto::cosmos::auth::v1beta1::{BaseAccount, EthAccount}; use ibc_proto::google::protobuf::Any; -use ibc_relayer_framework::base::core::traits::error::HasError; +use ibc_relayer_framework::base::core::traits::error::HasErrorType; use prost::{DecodeError, Message}; use crate::transaction::traits::decoders::account::AccountDecoder; pub struct DecodeCosmosOrEthAccount; -pub trait InjectDecodeCosmosOrEthAccountError: HasError { +pub trait InjectDecodeCosmosOrEthAccountError: HasErrorType { fn unknown_account_type_error(type_url: &str) -> Self::Error; fn empty_base_account_error() -> Self::Error; diff --git a/crates/relayer-cosmos/src/transaction/impls/encode.rs b/crates/relayer-cosmos/src/transaction/impls/encode.rs index 0c66d0691c..cdabfefe67 100644 --- a/crates/relayer-cosmos/src/transaction/impls/encode.rs +++ b/crates/relayer-cosmos/src/transaction/impls/encode.rs @@ -6,7 +6,7 @@ use ibc_relayer::chain::cosmos::types::account::AccountSequence; use ibc_relayer::chain::cosmos::types::tx::SignedTx; use ibc_relayer::config::AddressType; use ibc_relayer::keyring::errors::Error as KeyringError; -use ibc_relayer_framework::base::core::traits::error::{HasError, InjectError}; +use ibc_relayer_framework::base::core::traits::error::{HasErrorType, InjectError}; use prost::EncodeError; use crate::transaction::traits::fields::{ @@ -14,7 +14,7 @@ use crate::transaction::traits::fields::{ }; #[async_trait] -pub trait CanSignTx: HasError { +pub trait CanSignTx: HasErrorType { async fn sign_tx( &self, fee: &Fee, @@ -23,12 +23,12 @@ pub trait CanSignTx: HasError { ) -> Result; } -trait CanEncodeKeyBytes: HasError { +trait CanEncodeKeyBytes: HasErrorType { fn encode_key_bytes(&self) -> Result, Self::Error>; } #[async_trait] -trait CanEncodeSignerInfo: HasError { +trait CanEncodeSignerInfo: HasErrorType { async fn encode_signer_info( &self, account_sequence: &AccountSequence, @@ -36,23 +36,23 @@ trait CanEncodeSignerInfo: HasError { ) -> Result; } -trait CanEncodeTxBodyAndBytes: HasError { +trait CanEncodeTxBodyAndBytes: HasErrorType { fn encode_tx_body_and_bytes(&self, messages: &[Any]) -> Result<(TxBody, Vec), Self::Error>; } -trait CanEncodeAuthInfoAndBytes: HasError { +trait CanEncodeAuthInfoAndBytes: HasErrorType { fn encode_auth_info_and_bytes( signer_info: SignerInfo, fee: Fee, ) -> Result<(AuthInfo, Vec), Self::Error>; } -trait CanSignMessage: HasError { +trait CanSignMessage: HasErrorType { fn sign_message(&self, message: Vec) -> Result, Self::Error>; } #[async_trait] -trait CanEncodeSignDoc: HasError { +trait CanEncodeSignDoc: HasErrorType { async fn encode_sign_doc( &self, auth_info_bytes: Vec, @@ -63,7 +63,7 @@ trait CanEncodeSignDoc: HasError { #[async_trait] impl CanSignTx for Context where - Context: HasError + Context: HasErrorType + CanEncodeKeyBytes + CanEncodeSignerInfo + CanEncodeTxBodyAndBytes @@ -119,7 +119,7 @@ where #[async_trait] impl CanEncodeSignerInfo for Context where - Context: HasError + HasAddressType, + Context: HasErrorType + HasAddressType, { async fn encode_signer_info( &self, diff --git a/crates/relayer-cosmos/src/transaction/impls/estimate.rs b/crates/relayer-cosmos/src/transaction/impls/estimate.rs index b440f7caa9..5c1830ff5c 100644 --- a/crates/relayer-cosmos/src/transaction/impls/estimate.rs +++ b/crates/relayer-cosmos/src/transaction/impls/estimate.rs @@ -4,7 +4,7 @@ use core::marker::PhantomData; use ibc_proto::cosmos::tx::v1beta1::Fee; use ibc_relayer::chain::cosmos::gas::gas_amount_to_fee; use ibc_relayer::chain::cosmos::types::tx::SignedTx; -use ibc_relayer_framework::base::core::traits::error::{HasError, InjectError}; +use ibc_relayer_framework::base::core::traits::error::{HasErrorType, InjectError}; use ibc_relayer_types::core::ics24_host::identifier::ChainId; use tracing::{debug, error, warn}; @@ -12,7 +12,7 @@ use crate::transaction::impls::simulate::CanSendTxSimulate; use crate::transaction::traits::fields::{HasChainId, HasDefaultGas, HasGasConfig, HasMaxGas}; #[async_trait] -pub trait CanEstimateTxFees: HasError { +pub trait CanEstimateTxFees: HasErrorType { async fn estimate_tx_fees(&self, tx: SignedTx) -> Result; } @@ -33,12 +33,12 @@ where } #[async_trait] -pub trait TxGasEstimator { +pub trait TxGasEstimator { async fn estimate_gas_with_tx(context: &Context, tx: SignedTx) -> Result; } #[async_trait] -pub trait CanEstimateTxGas: HasError { +pub trait CanEstimateTxGas: HasErrorType { async fn estimate_gas_with_tx(&self, tx: SignedTx) -> Result; } @@ -69,7 +69,7 @@ where pub struct RecoverableTxGasEstimator(PhantomData); -pub trait HasRecoverableErrorForSimulation: HasError { +pub trait HasRecoverableErrorForSimulation: HasErrorType { fn can_recover_from_simulation_failure(e: &Self::Error) -> bool; } diff --git a/crates/relayer-cosmos/src/transaction/impls/queries/account.rs b/crates/relayer-cosmos/src/transaction/impls/queries/account.rs index 355f5b74ba..91df482e7c 100644 --- a/crates/relayer-cosmos/src/transaction/impls/queries/account.rs +++ b/crates/relayer-cosmos/src/transaction/impls/queries/account.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use ibc_proto::cosmos::auth::v1beta1::query_client::QueryClient; use ibc_proto::cosmos::auth::v1beta1::QueryAccountRequest; use ibc_relayer::chain::cosmos::types::account::Account; -use ibc_relayer_framework::base::core::traits::error::{HasError, InjectError}; +use ibc_relayer_framework::base::core::traits::error::{HasErrorType, InjectError}; use tonic::transport::Error as TransportError; use tonic::{Request, Status}; @@ -17,7 +17,7 @@ pub struct MaybeAccountQuerier; pub struct ReturnAccountFromContext; -pub trait InjectQueryAccountError: HasError { +pub trait InjectQueryAccountError: HasErrorType { fn address_not_found_error(address: &str) -> Self::Error; } @@ -62,7 +62,7 @@ where #[async_trait] impl AccountQuerier for MaybeAccountQuerier where - Context: HasError, + Context: HasErrorType, Context: MaybeHasAccount, BaseAccountQuerier: AccountQuerier, { @@ -83,7 +83,7 @@ where #[async_trait] impl AccountQuerier for ReturnAccountFromContext where - Context: HasError, + Context: HasErrorType, Context: HasAccount, { async fn query_account(context: &Context) -> Result { diff --git a/crates/relayer-cosmos/src/transaction/impls/queries/tx.rs b/crates/relayer-cosmos/src/transaction/impls/queries/tx.rs index 907d5cc15b..93ff08fbaa 100644 --- a/crates/relayer-cosmos/src/transaction/impls/queries/tx.rs +++ b/crates/relayer-cosmos/src/transaction/impls/queries/tx.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use ibc_relayer::chain::cosmos::query::tx_hash_query; use ibc_relayer::chain::requests::QueryTxHash; -use ibc_relayer_framework::base::core::traits::error::{HasError, InjectError}; +use ibc_relayer_framework::base::core::traits::error::{HasErrorType, InjectError}; use tendermint::Hash as TxHash; use tendermint_rpc::endpoint::tx::Response as TxResponse; use tendermint_rpc::{Client, Error as RpcError, Order}; @@ -9,7 +9,7 @@ use tendermint_rpc::{Client, Error as RpcError, Order}; use crate::transaction::traits::fields::{HasRpcClient, HasWaitTimeout}; #[async_trait] -pub trait CanQueryTxResponse: HasError { +pub trait CanQueryTxResponse: HasErrorType { async fn query_tx_response(&self, tx_hash: &TxHash) -> Result, Self::Error>; } diff --git a/crates/relayer-cosmos/src/transaction/impls/response.rs b/crates/relayer-cosmos/src/transaction/impls/response.rs index e9fe01607f..cadb192e65 100644 --- a/crates/relayer-cosmos/src/transaction/impls/response.rs +++ b/crates/relayer-cosmos/src/transaction/impls/response.rs @@ -1,11 +1,11 @@ -use ibc_relayer_framework::base::core::traits::error::HasError; +use ibc_relayer_framework::base::core::traits::error::HasErrorType; use tendermint::abci::Code; -pub trait InjectRpcResponseError: HasError { +pub trait InjectRpcResponseError: HasErrorType { fn rpc_response_error(code: Code) -> Self::Error; } -pub trait CanValidateRpcResponse: HasError { +pub trait CanValidateRpcResponse: HasErrorType { fn validate_rpc_response_code(code: Code) -> Result<(), Self::Error>; } diff --git a/crates/relayer-cosmos/src/transaction/impls/simulate.rs b/crates/relayer-cosmos/src/transaction/impls/simulate.rs index 2bafd9454a..87a04f7e7d 100644 --- a/crates/relayer-cosmos/src/transaction/impls/simulate.rs +++ b/crates/relayer-cosmos/src/transaction/impls/simulate.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use ibc_proto::cosmos::tx::v1beta1::service_client::ServiceClient; use ibc_proto::cosmos::tx::v1beta1::{SimulateRequest, SimulateResponse, Tx}; use ibc_relayer::chain::cosmos::types::tx::SignedTx; -use ibc_relayer_framework::base::core::traits::error::{HasError, InjectError}; +use ibc_relayer_framework::base::core::traits::error::{HasErrorType, InjectError}; use prost::EncodeError; use tonic::transport::Error as TransportError; use tonic::Status as StatusError; @@ -10,7 +10,7 @@ use tonic::Status as StatusError; use crate::transaction::traits::fields::HasGrpcAddress; #[async_trait] -pub trait CanSendTxSimulate: HasError { +pub trait CanSendTxSimulate: HasErrorType { async fn send_tx_simulate(&self, tx: SignedTx) -> Result; } diff --git a/crates/relayer-cosmos/src/transaction/impls/wait.rs b/crates/relayer-cosmos/src/transaction/impls/wait.rs index 71c662d324..6c1f2226e4 100644 --- a/crates/relayer-cosmos/src/transaction/impls/wait.rs +++ b/crates/relayer-cosmos/src/transaction/impls/wait.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use ibc_relayer_framework::base::core::traits::error::HasError; +use ibc_relayer_framework::base::core::traits::error::HasErrorType; use std::time::Instant; use tendermint::Hash as TxHash; use tendermint_rpc::endpoint::tx::Response as TxResponse; @@ -10,14 +10,14 @@ use crate::transaction::impls::response::CanValidateRpcResponse; use crate::transaction::traits::fields::HasWaitTimeout; #[async_trait] -pub trait CanWaitTxHash: HasError { +pub trait CanWaitTxHash: HasErrorType { async fn wait_tx_hash(&self, tx_hash: &TxHash) -> Result; } #[async_trait] pub trait TxHashWaiter where - Context: HasError, + Context: HasErrorType, { async fn wait_tx_hash( context: &Context, @@ -25,7 +25,7 @@ where ) -> Result; } -pub trait InjectWaitTxError: HasError { +pub trait InjectWaitTxError: HasErrorType { fn tx_no_confirmation_error() -> Self::Error; } diff --git a/crates/relayer-cosmos/src/transaction/traits/decoders/account.rs b/crates/relayer-cosmos/src/transaction/traits/decoders/account.rs index 4020670b5e..f9139b5fcc 100644 --- a/crates/relayer-cosmos/src/transaction/traits/decoders/account.rs +++ b/crates/relayer-cosmos/src/transaction/traits/decoders/account.rs @@ -1,14 +1,14 @@ use ibc_proto::cosmos::auth::v1beta1::BaseAccount; use ibc_proto::google::protobuf::Any; -use ibc_relayer_framework::base::core::traits::error::HasError; +use ibc_relayer_framework::base::core::traits::error::HasErrorType; -pub trait CanDecodeAccount: HasError { +pub trait CanDecodeAccount: HasErrorType { fn decode_account(&self, raw_account: Any) -> Result; } pub trait AccountDecoder where - Context: HasError, + Context: HasErrorType, { fn decode_account(context: &Context, raw_account: Any) -> Result; } diff --git a/crates/relayer-cosmos/src/transaction/traits/queries/account.rs b/crates/relayer-cosmos/src/transaction/traits/queries/account.rs index 72cf0ac1a3..674e088440 100644 --- a/crates/relayer-cosmos/src/transaction/traits/queries/account.rs +++ b/crates/relayer-cosmos/src/transaction/traits/queries/account.rs @@ -1,16 +1,16 @@ use async_trait::async_trait; use ibc_relayer::chain::cosmos::types::account::Account; -use ibc_relayer_framework::base::core::traits::error::HasError; +use ibc_relayer_framework::base::core::traits::error::HasErrorType; #[async_trait] -pub trait CanQueryAccount: HasError { +pub trait CanQueryAccount: HasErrorType { async fn query_account(&self) -> Result; } #[async_trait] pub trait AccountQuerier where - Context: HasError, + Context: HasErrorType, { async fn query_account(context: &Context) -> Result; } diff --git a/crates/relayer-cosmos/src/transaction/traits/tx_sender.rs b/crates/relayer-cosmos/src/transaction/traits/tx_sender.rs index 75227e1506..58a9d02971 100644 --- a/crates/relayer-cosmos/src/transaction/traits/tx_sender.rs +++ b/crates/relayer-cosmos/src/transaction/traits/tx_sender.rs @@ -1,23 +1,23 @@ use async_trait::async_trait; use ibc_proto::google::protobuf::Any; -use ibc_relayer_framework::base::core::traits::error::HasError; +use ibc_relayer_framework::base::core::traits::error::HasErrorType; use tendermint::abci::Event; use tendermint_rpc::endpoint::broadcast::tx_sync::Response; #[async_trait] -pub trait CanSendTx: HasError { +pub trait CanSendTx: HasErrorType { async fn send_tx_sync(&self, messages: &[Any]) -> Result>, Self::Error>; } #[async_trait] -pub trait CanSubmitTx: HasError { +pub trait CanSubmitTx: HasErrorType { async fn submit_tx(&self, messages: &[Any]) -> Result; } #[async_trait] pub trait TxSender where - Context: HasError, + Context: HasErrorType, { async fn send_tx( context: &Context, @@ -28,7 +28,7 @@ where #[async_trait] pub trait TxSubmitter where - Context: HasError, + Context: HasErrorType, { async fn submit_tx(context: &Context, messages: &[Any]) -> Result; } diff --git a/crates/relayer-framework/src/base/chain/traits/types.rs b/crates/relayer-framework/src/base/chain/traits/types.rs index 229893f240..5c3f8d212d 100644 --- a/crates/relayer-framework/src/base/chain/traits/types.rs +++ b/crates/relayer-framework/src/base/chain/traits/types.rs @@ -4,7 +4,7 @@ //! These traits can be implemented over the default `OfaBaseChain` trait if the //! behavior exposed by that trait and the `AfoBaseChain` trait are not desired. -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::core::traits::sync::Async; use crate::std_prelude::*; @@ -17,7 +17,7 @@ pub trait HasEventType: Async { } /// The minimal datatypes that any chain needs to expose. -pub trait HasChainTypes: HasMessageType + HasEventType + HasError { +pub trait HasChainTypes: HasMessageType + HasEventType + HasErrorType { type Height: Ord + Async; type Timestamp: Ord + Async; diff --git a/crates/relayer-framework/src/base/core/traits/error.rs b/crates/relayer-framework/src/base/core/traits/error.rs index b95988a1cf..4089b015dd 100644 --- a/crates/relayer-framework/src/base/core/traits/error.rs +++ b/crates/relayer-framework/src/base/core/traits/error.rs @@ -2,10 +2,10 @@ use core::fmt::Debug; use crate::base::core::traits::sync::Async; -pub trait HasError: Async { +pub trait HasErrorType: Async { type Error: Async + Debug; } -pub trait InjectError: HasError { +pub trait InjectError: HasErrorType { fn inject_error(e: E) -> Self::Error; } diff --git a/crates/relayer-framework/src/base/one_for_all/impls/chain/types.rs b/crates/relayer-framework/src/base/one_for_all/impls/chain/types.rs index e8ad161b8f..e251f0869b 100644 --- a/crates/relayer-framework/src/base/one_for_all/impls/chain/types.rs +++ b/crates/relayer-framework/src/base/one_for_all/impls/chain/types.rs @@ -2,14 +2,14 @@ use crate::base::chain::traits::ibc_event::HasIbcEvents; use crate::base::chain::traits::types::{ HasChainTypes, HasEventType, HasIbcChainTypes, HasMessageType, }; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::one_for_all::traits::chain::{OfaBaseChain, OfaIbcChain}; use crate::base::one_for_all::traits::runtime::OfaRuntimeContext; use crate::base::runtime::traits::runtime::HasRuntime; use crate::common::one_for_all::types::chain::OfaChainWrapper; use crate::std_prelude::*; -impl HasError for OfaChainWrapper { +impl HasErrorType for OfaChainWrapper { type Error = Chain::Error; } @@ -19,6 +19,10 @@ impl HasRuntime for OfaChainWrapper { fn runtime(&self) -> &Self::Runtime { self.chain.runtime() } + + fn runtime_error(e: ::Error) -> Chain::Error { + Chain::runtime_error(e) + } } impl HasMessageType for OfaChainWrapper { diff --git a/crates/relayer-framework/src/base/one_for_all/impls/relay/types.rs b/crates/relayer-framework/src/base/one_for_all/impls/relay/types.rs index 686ab017ee..cde56c8319 100644 --- a/crates/relayer-framework/src/base/one_for_all/impls/relay/types.rs +++ b/crates/relayer-framework/src/base/one_for_all/impls/relay/types.rs @@ -1,5 +1,5 @@ use crate::base::chain::types::aliases::{ChannelId, Height, PortId, Sequence, Timestamp}; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::one_for_all::traits::chain::OfaChainTypes; use crate::base::one_for_all::traits::relay::OfaBaseRelay; use crate::base::one_for_all::traits::runtime::OfaRuntimeContext; @@ -9,7 +9,7 @@ use crate::common::one_for_all::types::chain::OfaChainWrapper; use crate::common::one_for_all::types::relay::OfaRelayWrapper; use crate::std_prelude::*; -impl HasError for OfaRelayWrapper { +impl HasErrorType for OfaRelayWrapper { type Error = Relay::Error; } @@ -19,6 +19,10 @@ impl HasRuntime for OfaRelayWrapper { fn runtime(&self) -> &Self::Runtime { self.relay.runtime() } + + fn runtime_error(e: ::Error) -> Relay::Error { + Relay::runtime_error(e) + } } impl HasRelayTypes for OfaRelayWrapper { @@ -28,6 +32,14 @@ impl HasRelayTypes for OfaRelayWrapper { type Packet = Relay::Packet; + fn src_chain_error(e: ::Error) -> Self::Error { + Relay::src_chain_error(e) + } + + fn dst_chain_error(e: ::Error) -> Self::Error { + Relay::dst_chain_error(e) + } + fn packet_src_port(packet: &Self::Packet) -> &PortId { Relay::packet_src_port(packet) } diff --git a/crates/relayer-framework/src/base/one_for_all/impls/runtime.rs b/crates/relayer-framework/src/base/one_for_all/impls/runtime.rs index ac1f81e4ec..c10d412635 100644 --- a/crates/relayer-framework/src/base/one_for_all/impls/runtime.rs +++ b/crates/relayer-framework/src/base/one_for_all/impls/runtime.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use core::future::Future; use core::time::Duration; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::one_for_all::traits::runtime::{LogLevel, OfaRuntime, OfaRuntimeContext}; use crate::base::runtime::traits::log::{ HasLogger, LevelDebug, LevelError, LevelInfo, LevelTrace, LevelWarn, @@ -16,7 +16,7 @@ pub struct OfaTime { pub time: Runtime::Time, } -impl HasError for OfaRuntimeContext { +impl HasErrorType for OfaRuntimeContext { type Error = Runtime::Error; } diff --git a/crates/relayer-framework/src/base/one_for_all/traits/chain.rs b/crates/relayer-framework/src/base/one_for_all/traits/chain.rs index 562ab9c6df..38c6458bf5 100644 --- a/crates/relayer-framework/src/base/one_for_all/traits/chain.rs +++ b/crates/relayer-framework/src/base/one_for_all/traits/chain.rs @@ -17,7 +17,7 @@ pub trait OfaChainTypes: Async { type Error: Async + Debug; - type Runtime: OfaRuntime; + type Runtime: OfaRuntime; type Height: Ord + Async; @@ -52,6 +52,8 @@ pub trait OfaChainTypes: Async { pub trait OfaBaseChain: OfaChainTypes { fn runtime(&self) -> &OfaRuntimeContext; + fn runtime_error(e: ::Error) -> Self::Error; + fn encode_raw_message( message: &Self::Message, signer: &Self::Signer, diff --git a/crates/relayer-framework/src/base/one_for_all/traits/relay.rs b/crates/relayer-framework/src/base/one_for_all/traits/relay.rs index 63a0f6cbfc..e793fc8cf0 100644 --- a/crates/relayer-framework/src/base/one_for_all/traits/relay.rs +++ b/crates/relayer-framework/src/base/one_for_all/traits/relay.rs @@ -22,27 +22,23 @@ pub trait OfaRelayTypes: Async { type Error: Async + Debug; - type Runtime: OfaRuntime; + type Runtime: OfaRuntime; type Packet: Async; - type SrcChain: OfaIbcChain< - Self::DstChain, - Error = Self::Error, - Runtime = Self::Runtime, - Preset = Self::Preset, - >; - - type DstChain: OfaIbcChain< - Self::SrcChain, - Error = Self::Error, - Runtime = Self::Runtime, - Preset = Self::Preset, - >; + type SrcChain: OfaIbcChain; + + type DstChain: OfaIbcChain; } #[async_trait] pub trait OfaBaseRelay: OfaRelayTypes { + fn runtime_error(e: ::Error) -> Self::Error; + + fn src_chain_error(e: ::Error) -> Self::Error; + + fn dst_chain_error(e: ::Error) -> Self::Error; + fn mismatch_ibc_events_count_error(expected: usize, actual: usize) -> Self::Error; fn packet_src_port(packet: &Self::Packet) -> &::PortId; diff --git a/crates/relayer-framework/src/base/relay/impls/message_senders/chain_sender.rs b/crates/relayer-framework/src/base/relay/impls/message_senders/chain_sender.rs index 944830c3dc..ba6f8daea7 100644 --- a/crates/relayer-framework/src/base/relay/impls/message_senders/chain_sender.rs +++ b/crates/relayer-framework/src/base/relay/impls/message_senders/chain_sender.rs @@ -2,7 +2,6 @@ use async_trait::async_trait; use crate::base::chain::traits::message_sender::CanSendMessages; use crate::base::chain::traits::types::HasIbcChainTypes; -use crate::base::core::traits::sync::Async; use crate::base::relay::traits::ibc_message_sender::IbcMessageSender; use crate::base::relay::traits::target::ChainTarget; use crate::base::relay::traits::types::HasRelayTypes; @@ -11,28 +10,21 @@ use crate::std_prelude::*; pub struct SendIbcMessagesToChain; #[async_trait] -impl IbcMessageSender - for SendIbcMessagesToChain +impl IbcMessageSender for SendIbcMessagesToChain where - Message: Async, - Event: Async, - Context: HasRelayTypes, - Target: ChainTarget, + Relay: HasRelayTypes, + Target: ChainTarget, TargetChain: CanSendMessages, - TargetChain: HasIbcChainTypes< - Target::CounterpartyChain, - Message = Message, - Event = Event, - Error = Error, - >, + TargetChain: HasIbcChainTypes, { async fn send_messages( - context: &Context, - messages: Vec, - ) -> Result>, Error> { - let events = Target::target_chain(context) + relay: &Relay, + messages: Vec, + ) -> Result>, Relay::Error> { + let events = Target::target_chain(relay) .send_messages(messages) - .await?; + .await + .map_err(Target::target_chain_error)?; Ok(events) } diff --git a/crates/relayer-framework/src/base/relay/impls/messages/wait_update_client.rs b/crates/relayer-framework/src/base/relay/impls/messages/wait_update_client.rs index b8a9d077ee..a18ad094e3 100644 --- a/crates/relayer-framework/src/base/relay/impls/messages/wait_update_client.rs +++ b/crates/relayer-framework/src/base/relay/impls/messages/wait_update_client.rs @@ -20,17 +20,17 @@ use crate::std_prelude::*; pub struct WaitUpdateClient(PhantomData); #[async_trait] -impl +impl UpdateClientMessageBuilder for WaitUpdateClient where - Relay: HasRelayTypes, - Relay: HasRuntime, + Relay: HasRelayTypes, + Relay: HasRuntime, Target: ChainTarget, InUpdateClient: UpdateClientMessageBuilder, - CounterpartyChain: HasIbcChainTypes, + CounterpartyChain: HasIbcChainTypes, TargetChain: HasIbcChainTypes, CounterpartyChain: CanQueryChainStatus, - Runtime: CanSleep, + Relay::Runtime: CanSleep, Height: Ord + Async, { async fn build_update_client_messages( @@ -41,7 +41,11 @@ where let chain = Target::counterparty_chain(context); loop { - let current_status = chain.query_chain_status().await?; + let current_status = chain + .query_chain_status() + .await + .map_err(Target::counterparty_chain_error)?; + let current_height = CounterpartyChain::chain_status_height(¤t_status); if current_height > height { diff --git a/crates/relayer-framework/src/base/relay/impls/packet_relayers/general/full_relay.rs b/crates/relayer-framework/src/base/relay/impls/packet_relayers/general/full_relay.rs index 915f15aafa..e313776af3 100644 --- a/crates/relayer-framework/src/base/relay/impls/packet_relayers/general/full_relay.rs +++ b/crates/relayer-framework/src/base/relay/impls/packet_relayers/general/full_relay.rs @@ -24,7 +24,12 @@ where Relay::DstChain: CanQueryChainStatus, { async fn relay_packet(relay: &Relay, packet: &Packet) -> Result<(), Relay::Error> { - let destination_status = relay.destination_chain().query_chain_status().await?; + let destination_status = relay + .destination_chain() + .query_chain_status() + .await + .map_err(Relay::dst_chain_error)?; + let destination_height = Relay::DstChain::chain_status_height(&destination_status); let destination_timestamp = Relay::DstChain::chain_status_timestamp(&destination_status); @@ -43,7 +48,11 @@ where .relay_timeout_unordered_packet(destination_height, packet) .await?; } else { - let source_chain_status = relay.source_chain().query_chain_status().await?; + let source_chain_status = relay + .source_chain() + .query_chain_status() + .await + .map_err(Relay::src_chain_error)?; let write_ack = relay .relay_receive_packet( @@ -52,7 +61,12 @@ where ) .await?; - let destination_status = relay.destination_chain().query_chain_status().await?; + let destination_status = relay + .destination_chain() + .query_chain_status() + .await + .map_err(Relay::dst_chain_error)?; + let destination_height = Relay::DstChain::chain_status_height(&destination_status); if let Some(ack) = write_ack { diff --git a/crates/relayer-framework/src/base/relay/impls/packet_relayers/receive/skip_received_packet.rs b/crates/relayer-framework/src/base/relay/impls/packet_relayers/receive/skip_received_packet.rs index 52d4e39422..c27996d47d 100644 --- a/crates/relayer-framework/src/base/relay/impls/packet_relayers/receive/skip_received_packet.rs +++ b/crates/relayer-framework/src/base/relay/impls/packet_relayers/receive/skip_received_packet.rs @@ -34,7 +34,8 @@ where Relay::packet_dst_channel_id(packet), Relay::packet_sequence(packet), ) - .await?; + .await + .map_err(Relay::dst_chain_error)?; if !is_packet_received { Relayer::relay_receive_packet(relay, source_height, packet).await diff --git a/crates/relayer-framework/src/base/relay/impls/packet_relayers/timeout_unordered/wait_timeout.rs b/crates/relayer-framework/src/base/relay/impls/packet_relayers/timeout_unordered/wait_timeout.rs index acfa21c135..e090de84e2 100644 --- a/crates/relayer-framework/src/base/relay/impls/packet_relayers/timeout_unordered/wait_timeout.rs +++ b/crates/relayer-framework/src/base/relay/impls/packet_relayers/timeout_unordered/wait_timeout.rs @@ -39,7 +39,11 @@ where let chain = context.destination_chain(); loop { - let counterparty_status = chain.query_chain_status().await?; + let counterparty_status = chain + .query_chain_status() + .await + .map_err(Relay::dst_chain_error)?; + let counterparty_height = Relay::DstChain::chain_status_height(&counterparty_status); if counterparty_height > destination_height { diff --git a/crates/relayer-framework/src/base/relay/traits/ibc_message_sender.rs b/crates/relayer-framework/src/base/relay/traits/ibc_message_sender.rs index 444c7d331b..eb03d4124c 100644 --- a/crates/relayer-framework/src/base/relay/traits/ibc_message_sender.rs +++ b/crates/relayer-framework/src/base/relay/traits/ibc_message_sender.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use crate::base::chain::traits::types::HasIbcChainTypes; use crate::base::chain::types::aliases::{Event, Message}; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::core::traits::sync::Async; use crate::base::relay::traits::target::ChainTarget; use crate::base::relay::traits::types::HasRelayTypes; @@ -31,7 +31,7 @@ where ) -> Result>>, Context::Error>; } -pub trait InjectMismatchIbcEventsCountError: HasError { +pub trait InjectMismatchIbcEventsCountError: HasErrorType { fn mismatch_ibc_events_count_error(expected: usize, actual: usize) -> Self::Error; } diff --git a/crates/relayer-framework/src/base/relay/traits/target.rs b/crates/relayer-framework/src/base/relay/traits/target.rs index 3801689996..03847dd6b5 100644 --- a/crates/relayer-framework/src/base/relay/traits/target.rs +++ b/crates/relayer-framework/src/base/relay/traits/target.rs @@ -1,5 +1,6 @@ use crate::base::chain::traits::types::HasIbcChainTypes; use crate::base::chain::types::aliases::ClientId; +use crate::base::core::traits::error::HasErrorType; use crate::base::core::traits::sync::Async; use crate::base::relay::traits::types::HasRelayTypes; @@ -10,9 +11,15 @@ pub struct SourceTarget; pub struct DestinationTarget; pub trait ChainTarget: Async + Default + private::Sealed { - type TargetChain: HasIbcChainTypes; + type TargetChain: HasIbcChainTypes; - type CounterpartyChain: HasIbcChainTypes; + type CounterpartyChain: HasIbcChainTypes; + + fn target_chain_error(e: ::Error) -> Relay::Error; + + fn counterparty_chain_error( + e: ::Error, + ) -> Relay::Error; fn target_chain(context: &Relay) -> &Self::TargetChain; @@ -30,8 +37,19 @@ impl private::Sealed for DestinationTarget {} impl ChainTarget for SourceTarget { type TargetChain = Relay::SrcChain; + type CounterpartyChain = Relay::DstChain; + fn target_chain_error(e: ::Error) -> Relay::Error { + Relay::src_chain_error(e) + } + + fn counterparty_chain_error( + e: ::Error, + ) -> Relay::Error { + Relay::dst_chain_error(e) + } + fn target_chain(context: &Relay) -> &Self::TargetChain { context.source_chain() } @@ -53,8 +71,19 @@ impl ChainTarget for SourceTarget { impl ChainTarget for DestinationTarget { type TargetChain = Relay::DstChain; + type CounterpartyChain = Relay::SrcChain; + fn target_chain_error(e: ::Error) -> Relay::Error { + Relay::dst_chain_error(e) + } + + fn counterparty_chain_error( + e: ::Error, + ) -> Relay::Error { + Relay::src_chain_error(e) + } + fn target_chain(context: &Relay) -> &Self::TargetChain { context.destination_chain() } diff --git a/crates/relayer-framework/src/base/relay/traits/types.rs b/crates/relayer-framework/src/base/relay/traits/types.rs index 457499fca1..55ad0405df 100644 --- a/crates/relayer-framework/src/base/relay/traits/types.rs +++ b/crates/relayer-framework/src/base/relay/traits/types.rs @@ -2,16 +2,20 @@ use crate::base::chain::traits::types::HasIbcChainTypes; use crate::base::chain::types::aliases::{ ChannelId, ClientId, Height, PortId, Sequence, Timestamp, }; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::core::traits::sync::Async; -pub trait HasRelayTypes: HasError { - type SrcChain: HasIbcChainTypes; +pub trait HasRelayTypes: HasErrorType { + type SrcChain: HasIbcChainTypes; - type DstChain: HasIbcChainTypes; + type DstChain: HasIbcChainTypes; type Packet: Async; + fn src_chain_error(e: ::Error) -> Self::Error; + + fn dst_chain_error(e: ::Error) -> Self::Error; + fn packet_src_port(packet: &Self::Packet) -> &PortId; fn packet_src_channel_id(packet: &Self::Packet) -> &ChannelId; diff --git a/crates/relayer-framework/src/base/relay/types/relay_to_chain.rs b/crates/relayer-framework/src/base/relay/types/relay_to_chain.rs index 5c8c17126e..b24ab6645f 100644 --- a/crates/relayer-framework/src/base/relay/types/relay_to_chain.rs +++ b/crates/relayer-framework/src/base/relay/types/relay_to_chain.rs @@ -3,7 +3,7 @@ use core::marker::PhantomData; use crate::base::chain::traits::message_sender::CanSendMessages; use crate::base::chain::traits::types::{HasChainTypes, HasEventType, HasMessageType}; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::relay::traits::target::ChainTarget; use crate::base::relay::traits::types::HasRelayTypes; use crate::std_prelude::*; @@ -37,7 +37,7 @@ pub struct RelayToChain { pub phantom: PhantomData, } -impl HasError for RelayToChain +impl HasErrorType for RelayToChain where Relay: HasRelayTypes, Target: ChainTarget, @@ -71,7 +71,7 @@ where type Timestamp = ::Timestamp; fn estimate_message_len(message: &Self::Message) -> Result { - Target::TargetChain::estimate_message_len(message) + Target::TargetChain::estimate_message_len(message).map_err(Target::target_chain_error) } } @@ -89,5 +89,6 @@ where Target::target_chain(&self.relay) .send_messages(messages) .await + .map_err(Target::target_chain_error) } } diff --git a/crates/relayer-framework/src/base/runtime/traits/runtime.rs b/crates/relayer-framework/src/base/runtime/traits/runtime.rs index 4f100819af..513996d01c 100644 --- a/crates/relayer-framework/src/base/runtime/traits/runtime.rs +++ b/crates/relayer-framework/src/base/runtime/traits/runtime.rs @@ -1,7 +1,9 @@ -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; -pub trait HasRuntime: HasError { - type Runtime: HasError; +pub trait HasRuntime: HasErrorType { + type Runtime: HasErrorType; fn runtime(&self) -> &Self::Runtime; + + fn runtime_error(e: ::Error) -> Self::Error; } diff --git a/crates/relayer-framework/src/base/transaction/traits/types.rs b/crates/relayer-framework/src/base/transaction/traits/types.rs index 25e4cd4575..73639971a7 100644 --- a/crates/relayer-framework/src/base/transaction/traits/types.rs +++ b/crates/relayer-framework/src/base/transaction/traits/types.rs @@ -1,8 +1,8 @@ use crate::base::chain::traits::types::{HasEventType, HasMessageType}; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::core::traits::sync::Async; -pub trait HasTxTypes: HasMessageType + HasEventType + HasError { +pub trait HasTxTypes: HasMessageType + HasEventType + HasErrorType { type Transaction: Async; type Nonce: Async; diff --git a/crates/relayer-framework/src/full/one_for_all/impls/batch.rs b/crates/relayer-framework/src/full/one_for_all/impls/batch.rs index 3af41f89a1..fa0afb9283 100644 --- a/crates/relayer-framework/src/full/one_for_all/impls/batch.rs +++ b/crates/relayer-framework/src/full/one_for_all/impls/batch.rs @@ -10,7 +10,7 @@ use crate::base::relay::traits::target::{DestinationTarget, SourceTarget}; use crate::common::one_for_all::types::relay::OfaRelayWrapper; use crate::full::batch::context::{BatchChannel, BatchContext, HasBatchContext}; use crate::full::batch::message_sender::CanSendIbcMessagesFromBatchWorker; -use crate::full::one_for_all::traits::batch::{OfaBatch, OfaBatchContext}; +use crate::full::one_for_all::traits::batch::{OfaBatch, OfaBatchWrapper}; use crate::full::one_for_all::traits::chain::OfaFullChain; use crate::std_prelude::*; @@ -31,7 +31,7 @@ where } #[async_trait] -impl BatchContext for OfaBatchContext +impl BatchContext for OfaBatchWrapper where Chain: OfaFullChain, Batch: OfaBatch, @@ -91,9 +91,11 @@ where impl HasBatchContext for OfaRelayWrapper where Relay: OfaBaseRelay, - Relay::SrcChain: OfaFullChain, + // TODO: do not require the chain error to be the same as relay error. + // this can be fixed in #2816. + Relay::SrcChain: OfaFullChain, { - type BatchContext = OfaBatchContext; + type BatchContext = OfaBatchWrapper; fn batch_channel( &self, @@ -108,9 +110,9 @@ where impl HasBatchContext for OfaRelayWrapper where Relay: OfaBaseRelay, - Relay::DstChain: OfaFullChain, + Relay::DstChain: OfaFullChain, { - type BatchContext = OfaBatchContext; + type BatchContext = OfaBatchWrapper; fn batch_channel( &self, diff --git a/crates/relayer-framework/src/full/one_for_all/impls/preset.rs b/crates/relayer-framework/src/full/one_for_all/impls/preset.rs index 2a4e579563..b57d161d05 100644 --- a/crates/relayer-framework/src/full/one_for_all/impls/preset.rs +++ b/crates/relayer-framework/src/full/one_for_all/impls/preset.rs @@ -32,8 +32,8 @@ where impl OfaRelayPreset for FullPreset where Relay: OfaFullRelay, - Relay::SrcChain: OfaFullChain, - Relay::DstChain: OfaFullChain, + Relay::SrcChain: OfaFullChain, + Relay::DstChain: OfaFullChain, { type PacketRelayer = FilterRelayer>; diff --git a/crates/relayer-framework/src/full/one_for_all/traits/batch.rs b/crates/relayer-framework/src/full/one_for_all/traits/batch.rs index cab4d9b7ff..9b59da1bfc 100644 --- a/crates/relayer-framework/src/full/one_for_all/traits/batch.rs +++ b/crates/relayer-framework/src/full/one_for_all/traits/batch.rs @@ -6,7 +6,7 @@ use crate::base::one_for_all::traits::chain::OfaChainTypes; use crate::std_prelude::*; #[derive(Clone)] -pub struct OfaBatchContext { +pub struct OfaBatchWrapper { pub phantom: PhantomData, } diff --git a/crates/relayer-framework/src/full/relay/impls/packet_relayers/retry.rs b/crates/relayer-framework/src/full/relay/impls/packet_relayers/retry.rs index 042effbd7c..ad71861c8c 100644 --- a/crates/relayer-framework/src/full/relay/impls/packet_relayers/retry.rs +++ b/crates/relayer-framework/src/full/relay/impls/packet_relayers/retry.rs @@ -2,7 +2,7 @@ use core::marker::PhantomData; use async_trait::async_trait; -use crate::base::core::traits::error::HasError; +use crate::base::core::traits::error::HasErrorType; use crate::base::relay::traits::packet_relayer::PacketRelayer; use crate::base::relay::traits::types::HasRelayTypes; use crate::base::relay::types::aliases::Packet; @@ -12,7 +12,7 @@ pub struct RetryRelayer { pub phantom: PhantomData, } -pub trait SupportsPacketRetry: HasError { +pub trait SupportsPacketRetry: HasErrorType { const MAX_RETRY: usize; fn is_retryable_error(e: &Self::Error) -> bool; diff --git a/crates/relayer-runtime/src/tokio/context.rs b/crates/relayer-runtime/src/tokio/context.rs index fb95170950..4a3f45fd6f 100644 --- a/crates/relayer-runtime/src/tokio/context.rs +++ b/crates/relayer-runtime/src/tokio/context.rs @@ -1,8 +1,6 @@ use alloc::sync::Arc; use async_trait::async_trait; -use core::fmt::Debug; use core::future::Future; -use core::marker::PhantomData; use core::time::Duration; use std::sync::Mutex; use std::time::Instant; @@ -11,39 +9,26 @@ use tokio::sync::{mpsc, oneshot}; use tokio::time::sleep; use tracing; -use ibc_relayer_framework::base::core::traits::sync::Async; use ibc_relayer_framework::base::one_for_all::traits::chain::OfaBaseChain; use ibc_relayer_framework::base::one_for_all::traits::runtime::{LogLevel, OfaRuntime}; use ibc_relayer_framework::full::one_for_all::traits::batch::OfaBatch; use super::error::Error as TokioError; -pub struct TokioRuntimeContext { +#[derive(Clone)] +pub struct TokioRuntimeContext { pub runtime: Arc, - pub phantom: PhantomData, } -impl TokioRuntimeContext { +impl TokioRuntimeContext { pub fn new(runtime: Arc) -> Self { - Self { - runtime, - phantom: PhantomData, - } - } -} - -impl Clone for TokioRuntimeContext { - fn clone(&self) -> Self { - Self::new(self.runtime.clone()) + Self { runtime } } } #[async_trait] -impl OfaRuntime for TokioRuntimeContext -where - Error: From + Debug + Async, -{ - type Error = Error; +impl OfaRuntime for TokioRuntimeContext { + type Error = TokioError; type Time = Instant; @@ -79,10 +64,9 @@ where } #[async_trait] -impl OfaBatch for TokioRuntimeContext +impl OfaBatch for TokioRuntimeContext where - Chain: OfaBaseChain, - Error: From + Clone + Async, + Chain: OfaBaseChain, { type BatchSender = mpsc::UnboundedSender<(Vec, Self::ResultSender)>; type BatchReceiver = @@ -108,7 +92,7 @@ where ) -> Result<(), Chain::Error> { sender .send((messages, result_sender)) - .map_err(|_| TokioError::channel_closed().into()) + .map_err(|_| Chain::runtime_error(TokioError::channel_closed())) } async fn try_receive_batch( @@ -116,13 +100,13 @@ where ) -> Result, Self::ResultSender)>, Chain::Error> { let mut receiver = receiver_lock .lock() - .map_err(|_| TokioError::poisoned_lock())?; + .map_err(|_| Chain::runtime_error(TokioError::poisoned_lock()))?; match receiver.try_recv() { Ok(batch) => Ok(Some(batch)), Err(mpsc::error::TryRecvError::Empty) => Ok(None), Err(mpsc::error::TryRecvError::Disconnected) => { - Err(TokioError::channel_closed().into()) + Err(Chain::runtime_error(TokioError::channel_closed())) } } } @@ -132,7 +116,7 @@ where ) -> Result>, Chain::Error>, Chain::Error> { result_receiver .await - .map_err(|_| TokioError::channel_closed().into()) + .map_err(|_| Chain::runtime_error(TokioError::channel_closed())) } fn send_result( @@ -141,6 +125,6 @@ where ) -> Result<(), Chain::Error> { result_sender .send(events) - .map_err(|_| TokioError::channel_closed().into()) + .map_err(|_| Chain::runtime_error(TokioError::channel_closed())) } }