Skip to content

fix: support chain identifiers without {chain_name}-{revision_number} pattern #941

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

Merged
merged 42 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c8d3584
optional revision number for chain id
rnbguy Nov 1, 2023
f93ea96
add additional methods
rnbguy Nov 1, 2023
6a6fc4f
update tests
rnbguy Nov 1, 2023
674501f
add changelog entry
rnbguy Nov 1, 2023
4296b0e
new test for codecov
rnbguy Nov 1, 2023
03301c2
revert optional u64
rnbguy Nov 2, 2023
a068d57
rename method
rnbguy Nov 2, 2023
f0c8c21
update tests
rnbguy Nov 2, 2023
840fabd
visualize actual testcases
rnbguy Nov 2, 2023
60cf0cf
revert method rename
rnbguy Nov 2, 2023
6c89049
update changelog entry
rnbguy Nov 2, 2023
a3b6fd9
refactor ChainId::new
rnbguy Nov 3, 2023
b8534b7
rm ChainId::has_revision_number method
rnbguy Nov 3, 2023
51d5770
refactor ChainId::set_revision_number to ChainId::increment_revision_…
rnbguy Nov 3, 2023
63ac38f
rm old set unset revision_number test
rnbguy Nov 3, 2023
257152e
add tests for ChainId::increment_revision_number
rnbguy Nov 3, 2023
ad57856
add length validation tests
rnbguy Nov 3, 2023
ebe39ea
refactor source code for ChainId::new
rnbguy Nov 3, 2023
20302f0
fix doc test
rnbguy Nov 3, 2023
6cc3d28
fix chain identifier length validation
rnbguy Nov 3, 2023
23ca22e
update tests
rnbguy Nov 3, 2023
091f291
fix typo
rnbguy Nov 3, 2023
5782666
reword changelog entry
rnbguy Nov 3, 2023
22f5b8f
reword doc string
rnbguy Nov 3, 2023
02fb312
fix ChainId::validate_length
rnbguy Nov 3, 2023
a19ac45
add ChainId::validate_length in tests
rnbguy Nov 3, 2023
e8375b0
replace ID with identifier
rnbguy Nov 3, 2023
a4648d7
use validate_prefix_length over validate_identifier_length
rnbguy Nov 3, 2023
69301f8
optimize validate_prefix_length
rnbguy Nov 3, 2023
5302611
rename changelog entry
rnbguy Nov 3, 2023
1ee65f2
fix incorrect doc comment
rnbguy Nov 3, 2023
b53b5bd
use u64::checked_add
rnbguy Nov 4, 2023
784633b
update doc comment
rnbguy Nov 4, 2023
c7c6619
update doc tests
rnbguy Nov 4, 2023
a850f06
simplify validate_prefix_length
rnbguy Nov 4, 2023
6c7ae89
tests for validate_prefix_length
rnbguy Nov 4, 2023
8281ce8
fix tests
rnbguy Nov 4, 2023
198b991
add changelog entry
rnbguy Nov 4, 2023
c0577b7
import test_log::test
rnbguy Nov 6, 2023
ae09ee2
fix rstest test attribute
rnbguy Nov 6, 2023
0e41b74
cargo fmt
rnbguy Nov 6, 2023
94ede00
fix typo
rnbguy Nov 6, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Support chain identifiers without the `{chain_name}-{revision_number}` pattern
of Tendermint chains. ([\#940](https://github.com/cosmos/ibc-rs/issues/940)).
12 changes: 6 additions & 6 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ mod tests {
fn client_state_new() {
// Define a "default" set of parameters to reuse throughout these tests.
let default_params: ClientStateParams = ClientStateParams {
id: ChainId::new("ibc", 0).unwrap(),
id: ChainId::new("ibc-0").unwrap(),
trust_level: TrustThreshold::ONE_THIRD,
trusting_period: Duration::new(64000, 0),
unbonding_period: Duration::new(128000, 0),
Expand Down Expand Up @@ -870,17 +870,17 @@ mod tests {
want_pass: true,
},
Test {
name: "Valid long (50 chars) chain-id that satisfies revision_number length < `u16::MAX` length".to_string(),
name: "Valid long (50 chars) chain-id that satisfies revision_number length < `u64::MAX` length".to_string(),
params: ClientStateParams {
id: ChainId::new(&"a".repeat(29), 0).unwrap(),
id: ChainId::new(&format!("{}-{}", "a".repeat(29), 0)).unwrap(),
..default_params.clone()
},
want_pass: true,
},
Test {
name: "Invalid too-long (51 chars) chain-id".to_string(),
params: ClientStateParams {
id: ChainId::new(&"a".repeat(30), 0).unwrap(),
id: ChainId::new(&format!("{}-{}", "a".repeat(30), 0)).unwrap(),
..default_params.clone()
},
want_pass: false,
Expand Down Expand Up @@ -993,7 +993,7 @@ mod tests {
fn client_state_verify_height() {
// Define a "default" set of parameters to reuse throughout these tests.
let default_params: ClientStateParams = ClientStateParams {
id: ChainId::new("ibc", 1).unwrap(),
id: ChainId::new("ibc-1").unwrap(),
trust_level: TrustThreshold::ONE_THIRD,
trusting_period: Duration::new(64000, 0),
unbonding_period: Duration::new(128000, 0),
Expand Down Expand Up @@ -1173,7 +1173,7 @@ pub mod test_util {
pub fn get_dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState {
#[allow(deprecated)]
RawTmClientState {
chain_id: ChainId::new("ibc", 0).expect("Never fails").to_string(),
chain_id: ChainId::new("ibc-0").expect("Never fails").to_string(),
trust_level: Some(Fraction {
numerator: 1,
denominator: 3,
Expand Down
42 changes: 21 additions & 21 deletions crates/ibc/src/core/ics02_client/handler/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod tests {
/// contained in the store and has not expired.
#[test]
fn test_consensus_state_pruning() {
let chain_id = ChainId::new("mockgaiaA", 1).unwrap();
let chain_id = ChainId::new("mockgaiaA-1").unwrap();

let client_height = Height::new(1, 1).unwrap();

Expand Down Expand Up @@ -295,10 +295,10 @@ mod tests {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();
let update_height = Height::new(1, 21).unwrap();
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

let mut ctx = MockContext::new(
ChainId::new("mockgaiaA", 1).unwrap(),
ChainId::new("mockgaiaA-1").unwrap(),
HostType::Mock,
5,
Height::new(1, 1).unwrap(),
Expand Down Expand Up @@ -343,10 +343,10 @@ mod tests {
fn test_update_synthetic_tendermint_client_validator_change_ok() {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

let mut ctx_a = MockContextConfig::builder()
.host_id(ChainId::new("mockgaiaA", 1).unwrap())
.host_id(ChainId::new("mockgaiaA-1").unwrap())
.latest_height(Height::new(1, 1).unwrap())
.build()
.with_client_config(
Expand Down Expand Up @@ -435,10 +435,10 @@ mod tests {
fn test_update_synthetic_tendermint_client_validator_change_fail() {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

let ctx_a = MockContextConfig::builder()
.host_id(ChainId::new("mockgaiaA", 1).unwrap())
.host_id(ChainId::new("mockgaiaA-1").unwrap())
.latest_height(Height::new(1, 1).unwrap())
.build()
.with_client_config(
Expand Down Expand Up @@ -515,10 +515,10 @@ mod tests {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();
let update_height = Height::new(1, 21).unwrap();
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

let mut ctx = MockContext::new(
ChainId::new("mockgaiaA", 1).unwrap(),
ChainId::new("mockgaiaA-1").unwrap(),
HostType::Mock,
5,
Height::new(1, 1).unwrap(),
Expand Down Expand Up @@ -565,8 +565,8 @@ mod tests {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();

let ctx_a_chain_id = ChainId::new("mockgaiaA", 1).unwrap();
let ctx_b_chain_id = ChainId::new("mockgaiaB", 1).unwrap();
let ctx_a_chain_id = ChainId::new("mockgaiaA-1").unwrap();
let ctx_b_chain_id = ChainId::new("mockgaiaB-1").unwrap();
let start_height = Height::new(1, 11).unwrap();

let mut ctx_a = MockContext::new(ctx_a_chain_id, HostType::Mock, 5, start_height)
Expand Down Expand Up @@ -695,7 +695,7 @@ mod tests {
let chain_start_height = Height::new(1, 11).unwrap();

let ctx = MockContext::new(
ChainId::new("mockgaiaA", 1).unwrap(),
ChainId::new("mockgaiaA-1").unwrap(),
HostType::Mock,
5,
chain_start_height,
Expand All @@ -708,7 +708,7 @@ mod tests {
);

let ctx_b = MockContext::new(
ChainId::new("mockgaiaB", 1).unwrap(),
ChainId::new("mockgaiaB-1").unwrap(),
HostType::SyntheticTendermint,
5,
client_height,
Expand Down Expand Up @@ -835,11 +835,11 @@ mod tests {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();
let misbehaviour_height = Height::new(1, 21).unwrap();
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

// Create a mock context for chain-A with a synthetic tendermint light client for chain-B
let mut ctx_a = MockContext::new(
ChainId::new("mockgaiaA", 1).unwrap(),
ChainId::new("mockgaiaA-1").unwrap(),
HostType::Mock,
5,
Height::new(1, 1).unwrap(),
Expand Down Expand Up @@ -896,11 +896,11 @@ mod tests {
let client_id = ClientId::new(tm_client_type(), 0).unwrap();
let client_height = Height::new(1, 20).unwrap();
let misbehaviour_height = Height::new(1, 21).unwrap();
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

// Create a mock context for chain-A with a synthetic tendermint light client for chain-B
let mut ctx_a = MockContext::new(
ChainId::new("mockgaiaA", 1).unwrap(),
ChainId::new("mockgaiaA-1").unwrap(),
HostType::Mock,
5,
Height::new(1, 1).unwrap(),
Expand Down Expand Up @@ -955,7 +955,7 @@ mod tests {

#[test]
fn test_expired_client() {
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

let update_height = Height::new(1, 21).unwrap();
let client_height = update_height.sub(3).unwrap();
Expand All @@ -967,7 +967,7 @@ mod tests {
let trusting_period = Duration::from_secs(64);

let mut ctx = MockContextConfig::builder()
.host_id(ChainId::new("mockgaiaA", 1).unwrap())
.host_id(ChainId::new("mockgaiaA-1").unwrap())
.latest_height(Height::new(1, 1).unwrap())
.latest_timestamp(timestamp)
.build()
Expand Down Expand Up @@ -995,7 +995,7 @@ mod tests {

#[test]
fn test_client_update_max_clock_drift() {
let chain_id_b = ChainId::new("mockgaiaB", 1).unwrap();
let chain_id_b = ChainId::new("mockgaiaB-1").unwrap();

let client_height = Height::new(1, 20).unwrap();

Expand All @@ -1006,7 +1006,7 @@ mod tests {
let max_clock_drift = Duration::from_secs(64);

let ctx_a = MockContextConfig::builder()
.host_id(ChainId::new("mockgaiaA", 1).unwrap())
.host_id(ChainId::new("mockgaiaA-1").unwrap())
.latest_height(Height::new(1, 1).unwrap())
.latest_timestamp(timestamp)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mod tests {

let ctx_default = MockContext::default();
let ctx_new = MockContext::new(
ChainId::new("mockgaia", latest_height.revision_number()).unwrap(),
ChainId::new(&format!("mockgaia-{}", latest_height.revision_number())).unwrap(),
HostType::Mock,
max_history_size,
latest_height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ mod tests {
};

let ctx_new = MockContext::new(
ChainId::new("mockgaia", 0).unwrap(),
ChainId::new("mockgaia-0").unwrap(),
HostType::Mock,
max_history_size,
host_chain_height,
Expand Down
Loading