Skip to content

Commit

Permalink
rpc: Support for CometBFT 1.0 in CompatMode (#12)
Browse files Browse the repository at this point in the history
* rpc: update documentation for CompatMode

The V0_37 variant is the default that persists into 1.0.
The docs need to explain this, since we decided not to rename
the mode variant to V1

* rpc: CompatMode::from_version support for 1.x

Recognize CometBFT major version 1 as one that is supported by the
default dialect.
  • Loading branch information
mzabaluev authored Jan 26, 2024
1 parent 438e464 commit 7db4a48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[cometbft-rpc]` Support CometBFT versions 1.x as recognized by
`CompatMode::from_version`
([\#12](https://github.com/cometbft/cometbft-rs/pull/12))
16 changes: 15 additions & 1 deletion rpc/src/client/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::Error;
pub enum CompatMode {
/// Use a compatibility mode for the RPC protocol used in CometBFT 0.34.
V0_34,
/// Use a compatibility mode for the RPC protocol used in CometBFT 0.37 and 0.38.
/// Use a compatibility mode for the RPC protocol used since CometBFT 0.37.
/// This is the default mode that has persisted into CometBFT 1.0.
V0_37,
}

Expand Down Expand Up @@ -47,6 +48,7 @@ impl CompatMode {
.map_err(|_| Error::invalid_cometbft_version(raw_version))?;

match (version.major, version.minor) {
(1, _) => Ok(CompatMode::V0_37),
(0, 34) => Ok(CompatMode::V0_34),
(0, 37) => Ok(CompatMode::V0_37),
(0, 38) => Ok(CompatMode::V0_37),
Expand Down Expand Up @@ -95,6 +97,18 @@ mod tests {
);
let res = CompatMode::from_version(parse_version("v0.39.0"));
assert!(res.is_err());
assert_eq!(
CompatMode::from_version(parse_version("v1.0.0-alpha.1")).unwrap(),
CompatMode::V0_37
);
assert_eq!(
CompatMode::from_version(parse_version("v1.0.0")).unwrap(),
CompatMode::V0_37
);
assert_eq!(
CompatMode::from_version(parse_version("v1.1.0")).unwrap(),
CompatMode::V0_37
);
let res = CompatMode::from_version(parse_version("poobah"));
assert!(res.is_err());
}
Expand Down

0 comments on commit 7db4a48

Please sign in to comment.