Skip to content
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

Use CosmosSdk as the chain type if omitted, for backward compatibility #3787

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ port = 5555
# Specify the chain ID. Required
id = 'ibc-0'

# Specify the chain type, currently only `"CosmosSdk"` is supported.
# Specify the chain type, currently only `CosmosSdk` is supported.
# Default: CosmosSdk
type = "CosmosSdk"

# Whether or not this is a CCV consumer chain. Default: false
Expand Down Expand Up @@ -408,7 +409,6 @@ memo_prefix = ''

[[chains]]
id = 'ibc-1'
type = "CosmosSdk"
rpc_addr = 'http://127.0.0.1:26557'
grpc_addr = 'http://127.0.0.1:9091'
event_source = { mode = 'push', url = 'ws://127.0.0.1:26557/websocket', batch_delay = '500ms' }
Expand Down
1 change: 1 addition & 0 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ where
};

Ok(ChainConfig::CosmosSdk(CosmosSdkConfig {
r#type: Default::default(),
id: chain_data.chain_id,
rpc_addr: rpc_data.rpc_address,
grpc_addr: grpc_address,
Expand Down
1 change: 1 addition & 0 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ strum = { version = "0.25", features = ["derive"] }
tokio-stream = "0.1.14"
once_cell = "1.19.0"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"] }
monostate = "0.1.11"

[dependencies.byte-unit]
version = "4.0.19"
Expand Down
6 changes: 6 additions & 0 deletions crates/relayer/src/chain/cosmos/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::time::Duration;
use std::path::PathBuf;

use byte_unit::Byte;
use monostate::MustBe;
use serde_derive::{Deserialize, Serialize};
use tendermint_rpc::Url;

Expand All @@ -23,6 +24,11 @@ pub mod error;
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct CosmosSdkConfig {
/// The type of this chain, must be "CosmosSdk"
/// This is the default if not specified.
#[serde(default)]
pub r#type: MustBe!("CosmosSdk"),

/// The chain's network identifier
pub id: ChainId,

Expand Down
27 changes: 24 additions & 3 deletions crates/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use core::time::Duration;
use std::{fs, fs::File, io::Write, ops::Range, path::Path};

use byte_unit::Byte;
use serde_derive::{Deserialize, Serialize};
use serde::{Deserialize, Serialize};
use tendermint::block::Height as BlockHeight;
use tendermint_rpc::Url;
use tendermint_rpc::WebSocketClientUrl;
Expand Down Expand Up @@ -603,9 +603,18 @@ pub enum EventSourceMode {
},
}

// NOTE:
// To work around a limitation of serde, which does not allow
// to specify a default variant if not tag is present,
// every underlying chain config MUST have a field `r#type` of
// type `monotstate::MustBe!("VariantName")`.
//
// For chains other than CosmosSdk, this field MUST NOT be annotated
// with `#[serde(default)]`.
//
// See https://github.com/serde-rs/serde/issues/2231
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(tag = "type")]
#[serde(untagged)]
pub enum ChainConfig {
CosmosSdk(CosmosSdkConfig),
}
Expand Down Expand Up @@ -814,6 +823,18 @@ mod tests {
assert!(load(path).is_err());
}

#[test]
fn parse_default_chain_type() {
let path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/fixtures/relayer_conf_example_default_chain_type.toml"
);

let config = load(path).expect("could not parse config");

dbg!(config);
}

#[test]
fn serialize_valid_config() {
let path = concat!(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[global]
log_level = 'error'

[mode]

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = true

[[chains]]
id = 'chain_A'
rpc_addr = 'http://127.0.0.1:26657'
grpc_addr = 'http://127.0.0.1:9090'
event_source = { mode = 'push', url = 'ws://localhost:26657/websocket', batch_delay = '500ms' }
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
max_gas = 200000
gas_price = { price = 0.001, denom = 'stake' }
max_msg_num = 4
max_tx_size = 1048576
max_grpc_decoding_size = '4MiB'
clock_drift = '5s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }

[[chains]]
id = 'chain_B'
rpc_addr = 'http://127.0.0.1:26557'
grpc_addr = 'http://127.0.0.1:9090'
event_source = { mode = 'push', url = 'ws://localhost:26557/websocket', batch_delay = '500ms' }
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
gas_price = { price = 0.001, denom = 'stake' }
max_grpc_decoding_size = '5.91 MB'
clock_drift = '5s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'ethermint', proto_type = { pk_type = '/injective.crypto.v1beta1.ethsecp256k1.PubKey' } }
1 change: 1 addition & 0 deletions tools/test-framework/src/types/single/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl FullNode {
};

Ok(config::ChainConfig::CosmosSdk(CosmosSdkConfig {
r#type: Default::default(),
id: self.chain_driver.chain_id.clone(),
rpc_addr: Url::from_str(&self.chain_driver.rpc_address())?,
grpc_addr: Url::from_str(&self.chain_driver.grpc_address())?,
Expand Down
Loading