Skip to content

Commit

Permalink
rpc: revert the latest CompatMode to V0_37
Browse files Browse the repository at this point in the history
Will do V1 as version-prefixed requests.
  • Loading branch information
mzabaluev committed Jan 23, 2024
1 parent 923b97a commit 515dbd8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
23 changes: 9 additions & 14 deletions rpc/src/client/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::Error;
pub enum CompatMode {
/// Use a compatibility mode for the RPC protocol used in CometBFT 0.34.
V0_34,
/// Use the RPC protocol that's been in use since CometBFT 0.37.
V1,
/// Use a compatibility mode for the RPC protocol used in CometBFT 0.37 and 0.38.
V0_37,
}

impl Default for CompatMode {
Expand All @@ -25,7 +25,7 @@ impl Default for CompatMode {
impl CompatMode {
/// The latest supported version, selected by default.
pub const fn latest() -> Self {
Self::V1
Self::V0_37
}

/// Parse the CometBFT version string to determine
Expand All @@ -47,10 +47,9 @@ impl CompatMode {
.map_err(|_| Error::invalid_cometbft_version(raw_version))?;

match (version.major, version.minor) {
(1, _) => Ok(CompatMode::V1),
(0, 34) => Ok(CompatMode::V0_34),
(0, 37) => Ok(CompatMode::V1),
(0, 38) => Ok(CompatMode::V1),
(0, 37) => Ok(CompatMode::V0_37),
(0, 38) => Ok(CompatMode::V0_37),
_ => Err(Error::unsupported_cometbft_version(version.to_string())),
}
}
Expand All @@ -60,7 +59,7 @@ impl fmt::Display for CompatMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CompatMode::V0_34 => f.write_str("v0.34"),
CompatMode::V1 => f.write_str("v1.0"),
CompatMode::V0_37 => f.write_str("v0.37"),
}
}
}
Expand All @@ -84,19 +83,15 @@ mod tests {
);
assert_eq!(
CompatMode::from_version(parse_version("v0.37.0-pre1")).unwrap(),
CompatMode::V1
CompatMode::V0_37
);
assert_eq!(
CompatMode::from_version(parse_version("v0.37.0")).unwrap(),
CompatMode::V1
CompatMode::V0_37
);
assert_eq!(
CompatMode::from_version(parse_version("v0.38.0")).unwrap(),
CompatMode::V1
);
assert_eq!(
CompatMode::from_version(parse_version("v1.0.0")).unwrap(),
CompatMode::V1
CompatMode::V0_37
);
let res = CompatMode::from_version(parse_version("v0.39.0"));
assert!(res.is_err());
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/client/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ macro_rules! perform_with_compat {
($self:expr, $request:expr) => {{
let request = $request;
match $self.compat {
CompatMode::V1 => {
CompatMode::V0_37 => {
$self
.perform_with_dialect(request, crate::dialect::v1::Dialect)
.await
Expand Down
6 changes: 3 additions & 3 deletions rpc/src/client/transport/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Client for HttpClient {
{
let height = height.into();
match self.compat {
CompatMode::V1 => self.perform(endpoint::header::Request::new(height)).await,
CompatMode::V0_37 => self.perform(endpoint::header::Request::new(height)).await,
CompatMode::V0_34 => {
// Back-fill with a request to /block endpoint and
// taking just the header from the response.
Expand All @@ -246,7 +246,7 @@ impl Client for HttpClient {
hash: Hash,
) -> Result<endpoint::header_by_hash::Response, Error> {
match self.compat {
CompatMode::V1 => {
CompatMode::V0_37 => {
self.perform(endpoint::header_by_hash::Request::new(hash))
.await
},
Expand All @@ -267,7 +267,7 @@ impl Client for HttpClient {
/// `/broadcast_evidence`: broadcast an evidence.
async fn broadcast_evidence(&self, e: Evidence) -> Result<endpoint::evidence::Response, Error> {
match self.compat {
CompatMode::V1 => self.perform(endpoint::evidence::Request::new(e)).await,
CompatMode::V0_37 => self.perform(endpoint::evidence::Request::new(e)).await,
CompatMode::V0_34 => {
self.perform_with_dialect(endpoint::evidence::Request::new(e), v0_34::Dialect)
.await
Expand Down
10 changes: 5 additions & 5 deletions rpc/src/client/transport/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Client for WebSocketClient {
{
let height = height.into();
match self.compat {
CompatMode::V1 => self.perform(endpoint::header::Request::new(height)).await,
CompatMode::V0_37 => self.perform(endpoint::header::Request::new(height)).await,
CompatMode::V0_34 => {
// Back-fill with a request to /block endpoint and
// taking just the header from the response.
Expand All @@ -272,7 +272,7 @@ impl Client for WebSocketClient {
hash: Hash,
) -> Result<endpoint::header_by_hash::Response, Error> {
match self.compat {
CompatMode::V1 => {
CompatMode::V0_37 => {
self.perform(endpoint::header_by_hash::Request::new(hash))
.await
},
Expand Down Expand Up @@ -889,7 +889,7 @@ impl WebSocketClientDriver {

async fn handle_text_msg(&mut self, msg: String) -> Result<(), Error> {
let parse_res = match self.compat {
CompatMode::V1 => event::v1::DeEvent::from_string(&msg).map(Into::into),
CompatMode::V0_37 => event::v1::DeEvent::from_string(&msg).map(Into::into),
CompatMode::V0_34 => event::v0_34::DeEvent::from_string(&msg).map(Into::into),
};
if let Ok(ev) = parse_res {
Expand Down Expand Up @@ -1439,7 +1439,7 @@ mod tests {
println!("Creating client RPC WebSocket connection...");
let url = server.node_addr.clone().try_into().unwrap();
let (client, driver) = WebSocketClient::builder(url)
.compat_mode(CompatMode::V1)
.compat_mode(CompatMode::V0_37)
.build()
.await
.unwrap();
Expand Down Expand Up @@ -1506,7 +1506,7 @@ mod tests {
println!("Creating client RPC WebSocket connection...");
let url = server.node_addr.clone().try_into().unwrap();
let (client, driver) = WebSocketClient::builder(url)
.compat_mode(CompatMode::V1)
.compat_mode(CompatMode::V0_37)
.build()
.await
.unwrap();
Expand Down

0 comments on commit 515dbd8

Please sign in to comment.