forked from informalsystems/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom options of the
create client
command (informalsystems#2004)
* Rework of CreateParams -> ClientOptions * Split CreateOptions and ClientSettings ClientSettings is now realized from CreateOptions and chain configurations. * Update docs in relayer/src/chain/client.rs Co-authored-by: Adi Seredinschi <adi@informal.systems> * Improve help for --clock-drift Explain that the value goes directly into the client state parameter. * Rework ClientSettings Make the settings specific to the chain type, in anticipation of support for non-Cosmos chains. * Builder pattern for foreign client tests Change the test framework API to bootstrap ForeignClient and ForeignClientPair to use the builder pattern. The client_settings methods are used to override the default client settings. * Add client setting overrides to the test framework * Warn when client clock drift exceeds max_block_time * relayer: Sanitize imports in mod chain
- Loading branch information
Showing
23 changed files
with
575 additions
and
208 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
.changelog/unreleased/bug-fixes/1921-create-client-options.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Apply client options specified with the `create client` command. | ||
([#1921](https://github.com/informalsystems/ibc-rs/issues/1921)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! Data structures and logic to set up IBC client's parameters. | ||
|
||
use crate::chain::cosmos; | ||
use crate::config::ChainConfig; | ||
use crate::foreign_client::CreateOptions; | ||
|
||
/// Client parameters for the `build_create_client` operation. | ||
/// | ||
/// The parameters are specialized for each supported chain type. | ||
#[derive(Clone, Debug)] | ||
pub enum ClientSettings { | ||
Tendermint(cosmos::client::Settings), | ||
} | ||
|
||
impl ClientSettings { | ||
/// Takes the settings from the user-supplied options if they have been specified, | ||
/// falling back to defaults using the configuration of the source | ||
/// and the destination chain. | ||
pub fn for_create_command( | ||
options: CreateOptions, | ||
src_chain_config: &ChainConfig, | ||
dst_chain_config: &ChainConfig, | ||
) -> Self { | ||
// Currently, only Tendermint chain pairs are supported by | ||
// ForeignClient::build_create_client_and_send. Support for | ||
// heterogeneous chains is left for future revisions. | ||
ClientSettings::Tendermint(cosmos::client::Settings::for_create_command( | ||
options, | ||
src_chain_config, | ||
dst_chain_config, | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! Cosmos-specific client settings. | ||
|
||
use core::time::Duration; | ||
|
||
use tracing::warn; | ||
|
||
use ibc::core::ics02_client::trust_threshold::TrustThreshold; | ||
|
||
use crate::config::ChainConfig; | ||
use crate::foreign_client::CreateOptions; | ||
|
||
/// Cosmos-specific client parameters for the `build_client_state` operation. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct Settings { | ||
pub max_clock_drift: Duration, | ||
pub trusting_period: Option<Duration>, | ||
pub trust_threshold: TrustThreshold, | ||
} | ||
|
||
impl Settings { | ||
pub fn for_create_command( | ||
options: CreateOptions, | ||
src_chain_config: &ChainConfig, | ||
dst_chain_config: &ChainConfig, | ||
) -> Self { | ||
let max_clock_drift = match options.max_clock_drift { | ||
None => calculate_client_state_drift(src_chain_config, dst_chain_config), | ||
Some(user_value) => { | ||
if user_value > dst_chain_config.max_block_time { | ||
warn!( | ||
"user specified max_clock_drift ({:?}) exceeds max_block_time \ | ||
of the destination chain {}", | ||
user_value, dst_chain_config.id, | ||
); | ||
} | ||
user_value | ||
} | ||
}; | ||
let trust_threshold = options | ||
.trust_threshold | ||
.unwrap_or_else(|| src_chain_config.trust_threshold.into()); | ||
Settings { | ||
max_clock_drift, | ||
trusting_period: options.trusting_period, | ||
trust_threshold, | ||
} | ||
} | ||
} | ||
|
||
/// The client state clock drift must account for destination | ||
/// chain block frequency and clock drift on source and dest. | ||
/// https://github.com/informalsystems/ibc-rs/issues/1445 | ||
fn calculate_client_state_drift( | ||
src_chain_config: &ChainConfig, | ||
dst_chain_config: &ChainConfig, | ||
) -> Duration { | ||
src_chain_config.clock_drift + dst_chain_config.clock_drift + dst_chain_config.max_block_time | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.