-
Notifications
You must be signed in to change notification settings - Fork 370
/
Copy pathclient.rs
62 lines (53 loc) · 1.96 KB
/
client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Cosmos-specific client settings.
use core::time::Duration;
use tracing::warn;
use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold;
use crate::config::ChainConfig;
use crate::foreign_client::CreateOptions;
use crate::util::pretty::PrettyDuration;
/// 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 {}",
PrettyDuration(&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/hermes/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
}