Skip to content

Commit

Permalink
Add client update CLI (#158)
Browse files Browse the repository at this point in the history
* Add client update CLI

* Revert cargo.lock itertools version downgrade

* Rename build_from_chain.rs to build.rs

* Fix renaming
  • Loading branch information
ljoss17 authored Dec 20, 2024
1 parent 1647355 commit 315bed3
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 3 deletions.
1 change: 1 addition & 0 deletions relayer/crates/starknet-cli/src/commands/client/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod subcommand;
23 changes: 23 additions & 0 deletions relayer/crates/starknet-cli/src/commands/client/subcommand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use hermes_cli_components::impls::commands::client::update::UpdateClientArgs;
use hermes_cli_components::traits::command::{CanRunCommand, CommandRunner};

#[derive(Debug, clap::Subcommand)]
pub enum ClientSubCommand {
UpdateClient(UpdateClientArgs),
}

pub struct RunClientSubCommand;

impl<App> CommandRunner<App, ClientSubCommand> for RunClientSubCommand
where
App: CanRunCommand<UpdateClientArgs>,
{
async fn run_command(
app: &App,
subcommand: &ClientSubCommand,
) -> Result<App::Output, App::Error> {
match subcommand {
ClientSubCommand::UpdateClient(args) => app.run_command(args).await,
}
}
}
1 change: 1 addition & 0 deletions relayer/crates/starknet-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod client;
pub mod query;
17 changes: 16 additions & 1 deletion relayer/crates/starknet-cli/src/contexts/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use cgp::core::field::impls::use_field::WithField;
use cgp::core::types::impls::WithType;
use cgp::prelude::*;
use hermes_cli_components::impls::commands::bootstrap::chain::RunBootstrapChainCommand;
use hermes_cli_components::impls::commands::client::update::{
RunUpdateClientCommand, UpdateClientArgs,
};
use hermes_cli_components::impls::commands::queries::client_state::{
QueryClientStateArgs, RunQueryClientStateCommand,
};
Expand Down Expand Up @@ -55,9 +58,11 @@ use hermes_starknet_integration_tests::contexts::chain_driver::StarknetChainDriv
use hermes_starknet_relayer::contexts::builder::StarknetBuilder;
use hermes_test_components::chain_driver::traits::config::ConfigUpdater;
use ibc::core::client::types::Height;
use ibc::core::host::types::identifiers::ClientId as CosmosClientId;
use starknet::core::types::Felt;
use toml::to_string_pretty;

use crate::commands::client::subcommand::{ClientSubCommand, RunClientSubCommand};
use crate::commands::query::subcommand::{QuerySubCommand, RunQuerySubCommand};
use crate::impls::bootstrap::starknet_chain::{BootstrapStarknetChainArgs, LoadStarknetBootstrap};
use crate::impls::bootstrap::subcommand::{BootstrapSubCommand, RunBootstrapSubCommand};
Expand Down Expand Up @@ -134,6 +139,11 @@ delegate_components! {
(QueryConsensusStateArgs, symbol!("client_id")): ParseFromString<ClientId>,
(QueryConsensusStateArgs, symbol!("query_height")): ParseFromOptionalString<u64>,
(QueryConsensusStateArgs, symbol!("consensus_height")): ParseFromOptionalString<Height>,

(UpdateClientArgs, symbol!("host_chain_id")): ParseFromString<Felt>,
(UpdateClientArgs, symbol!("client_id")): ParseFromString<ClientId>,
(UpdateClientArgs, symbol!("counterparty_client_id")): ParseFromString<CosmosClientId>,
(UpdateClientArgs, symbol!("target_height")): ParseFromOptionalString<Height>,
}
}

Expand All @@ -146,6 +156,9 @@ delegate_components! {
QueryClientStateArgs: RunQueryClientStateCommand,
QueryConsensusStateArgs: RunQueryConsensusStateCommand,

ClientSubCommand: RunClientSubCommand,
UpdateClientArgs: RunUpdateClientCommand,

BootstrapStarknetChainArgs: RunBootstrapChainCommand<UpdateStarknetConfig>,
}
}
Expand Down Expand Up @@ -203,10 +216,12 @@ pub trait CanUseStarknetApp:
+ CanRunCommand<AllSubCommands>
+ CanRunCommand<BootstrapSubCommand>
+ CanRunCommand<BootstrapStarknetChainArgs>
+ CanLoadBuilder
+ CanLoadBuilder<Builder = StarknetBuilder>
+ CanRunCommand<QuerySubCommand>
+ CanRunCommand<QueryClientStateArgs>
+ CanRunCommand<QueryConsensusStateArgs>
+ CanRunCommand<ClientSubCommand>
+ CanRunCommand<UpdateClientArgs>
{
}

Expand Down
3 changes: 2 additions & 1 deletion relayer/crates/starknet-cli/src/impls/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use hermes_error::traits::wrap::WrapError;
use hermes_error::types::Error;
use hermes_relayer_components::error::traits::retry::RetryableErrorComponent;
use hermes_runtime::types::error::TokioRuntimeError;
use ibc::core::host::types::error::DecodingError;
use ibc::core::host::types::error::{DecodingError, IdentifierError};
use starknet_types_core::felt::FromStrError;

pub struct ProvideCliError;
Expand Down Expand Up @@ -52,6 +52,7 @@ delegate_components! {
FromStrError,
ParseIntError,
DecodingError,
IdentifierError,
TokioRuntimeError,
toml::de::Error,
toml::ser::Error,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod relay;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use core::marker::PhantomData;

use hermes_error::HermesError;
use hermes_relayer_components::build::traits::builders::relay_builder::RelayBuilder;
use hermes_relayer_components::multi::types::index::Index;
use hermes_starknet_chain_components::types::client_id::ClientId as StarknetClientId;
use ibc::core::host::types::identifiers::{ChainId, ClientId as CosmosClientId};
use starknet::core::types::Felt;

use crate::contexts::builder::{StarknetBuildComponents, StarknetBuilder};
use crate::contexts::starknet_to_cosmos_relay::StarknetToCosmosRelay;

impl RelayBuilder<StarknetBuilder, Index<0>, Index<1>> for StarknetBuildComponents {
async fn build_relay(
build: &StarknetBuilder,
_index: PhantomData<(Index<0>, Index<1>)>,
_src_chain_id: &Felt,
dst_chain_id: &ChainId,
src_client_id: &StarknetClientId,
dst_client_id: &CosmosClientId,
) -> Result<StarknetToCosmosRelay, HermesError> {
let src_chain = build.build_chain().await?;

let dst_chain = build.cosmos_builder.build_chain(dst_chain_id).await?;

Ok(
build.build_starknet_to_cosmos_relay(
src_chain,
dst_chain,
src_client_id,
dst_client_id,
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod build;
1 change: 1 addition & 0 deletions relayer/crates/starknet-relayer/src/build/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod components;
40 changes: 39 additions & 1 deletion relayer/crates/starknet-relayer/src/contexts/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ use hermes_relayer_components::build::traits::builders::chain_builder::{
CanBuildChain, ChainBuilder,
};
use hermes_relayer_components::multi::traits::chain_at::ChainTypeAtComponent;
use hermes_relayer_components::multi::traits::relay_at::RelayTypeAtComponent;
use hermes_relayer_components::multi::types::index::Index;
use hermes_runtime::types::runtime::HermesRuntime;
use hermes_runtime_components::traits::runtime::{RuntimeGetterComponent, RuntimeTypeComponent};
use hermes_starknet_chain_components::impls::types::config::StarknetChainConfig;
use hermes_starknet_chain_components::types::client_id::ClientId as StarknetClientId;
use hermes_starknet_chain_context::contexts::chain::StarknetChain;
use hermes_starknet_chain_context::impls::error::HandleStarknetChainError;
use ibc::core::host::types::identifiers::ChainId;
use ibc::core::host::types::identifiers::{ChainId, ClientId as CosmosClientId};
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::types::Felt;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::{JsonRpcClient, Provider};
use starknet::signers::{LocalWallet, SigningKey};
use url::Url;

use super::cosmos_to_starknet_relay::CosmosToStarknetRelay;
use crate::contexts::starknet_to_cosmos_relay::StarknetToCosmosRelay;

#[derive(Clone)]
pub struct StarknetBuilder {
pub fields: Arc<dyn HasStarknetBuilderFields>,
Expand Down Expand Up @@ -76,6 +81,7 @@ delegate_components! {
ChainTypeAtComponent<Index<1>>: WithType<CosmosChain>,
RuntimeTypeComponent: WithType<HermesRuntime>,
RuntimeGetterComponent: WithField<symbol!("runtime")>,
RelayTypeAtComponent<Index<0>, Index<1>>: WithType<StarknetToCosmosRelay>,
}
}

Expand Down Expand Up @@ -146,6 +152,38 @@ impl StarknetBuilder {

Ok(context)
}

pub fn build_starknet_to_cosmos_relay(
&self,
src_chain: StarknetChain,
dst_chain: CosmosChain,
src_client_id: &StarknetClientId,
dst_client_id: &CosmosClientId,
) -> StarknetToCosmosRelay {
StarknetToCosmosRelay::new(
self.runtime.clone(),
src_chain,
dst_chain,
src_client_id.clone(),
dst_client_id.clone(),
)
}

pub fn build_cosmos_to_starknet_relay(
&self,
src_chain: CosmosChain,
dst_chain: StarknetChain,
src_client_id: &CosmosClientId,
dst_client_id: &StarknetClientId,
) -> CosmosToStarknetRelay {
CosmosToStarknetRelay::new(
self.runtime.clone(),
src_chain,
dst_chain,
src_client_id.clone(),
dst_client_id.clone(),
)
}
}

pub trait CanUseStarknetBuilder: CanBuildChain<Index<0>> + CanBuildChain<Index<1>> {}
Expand Down
1 change: 1 addition & 0 deletions relayer/crates/starknet-relayer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate alloc;

pub mod build;
pub mod contexts;
pub mod impls;
pub mod presets;

0 comments on commit 315bed3

Please sign in to comment.