Skip to content

Commit

Permalink
Use CosmosSdk as the chain type if omitted, for backward compatibility
Browse files Browse the repository at this point in the history
Doing this requires a bit of hack, due to serde's lack of support
for specifying a default variant when a tag is not provided.

See the doc comment on the `ChainConfig` struct for more details.
  • Loading branch information
romac committed Jan 16, 2024
1 parent 990f93f commit 35321c6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
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
15 changes: 12 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
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

0 comments on commit 35321c6

Please sign in to comment.