forked from informalsystems/hermes
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CompatMode configuration (informalsystems#3667)
* Update test bootstrap to work with Celestia chain * Update Nix flake and add Celestia CI job * Add changelog entry * Add guide section for 'compat_mode' configuration * Apply suggestions from code review Co-authored-by: Romain Ruetschi <[email protected]> Signed-off-by: Luca Joss <[email protected]> * Implement serialization and deserialization for CompatMode * Update crates/relayer/src/util/compat_mode.rs Co-authored-by: Romain Ruetschi <[email protected]> Signed-off-by: Luca Joss <[email protected]> --------- Signed-off-by: Luca Joss <[email protected]> Co-authored-by: Romain Ruetschi <[email protected]>
- Loading branch information
Showing
37 changed files
with
369 additions
and
47 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
.changelog/unreleased/features/ibc-relayer/3623-compat-mode-configurability.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- Add an optional per-chain setting `compat_mode`, which can be | ||
used to specify which CometBFT compatibility mode is used for interacting with the node over RPC. | ||
([\#3623](https://github.com/informalsystems/hermes/issues/3623)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use core::fmt::{Display, Error as FmtError, Formatter}; | ||
use core::str::FromStr; | ||
use serde::Deserialize; | ||
use serde::Deserializer; | ||
use serde::Serialize; | ||
use serde::Serializer; | ||
|
||
use tendermint_rpc::client::CompatMode as TmCompatMode; | ||
|
||
use crate::config::Error; | ||
|
||
/// CometBFT RPC compatibility mode | ||
/// | ||
/// Can be removed in favor of the one in tendermint-rs, once | ||
/// <https://github.com/informalsystems/tendermint-rs/pull/1367> is merged. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub enum CompatMode { | ||
/// Use version 0.34 of the protocol. | ||
V0_34, | ||
/// Use version 0.37 of the protocol. | ||
V0_37, | ||
} | ||
|
||
impl Display for CompatMode { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { | ||
match self { | ||
Self::V0_34 => write!(f, "v0.34"), | ||
Self::V0_37 => write!(f, "v0.37"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for CompatMode { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
const VALID_COMPAT_MODES: &str = "0.34, 0.37"; | ||
|
||
// Trim leading 'v', if present | ||
match s.trim_start_matches('v') { | ||
"0.34" => Ok(CompatMode::V0_34), | ||
"0.37" => Ok(CompatMode::V0_37), | ||
_ => Err(Error::invalid_compat_mode( | ||
s.to_string(), | ||
VALID_COMPAT_MODES, | ||
)), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for CompatMode { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
use serde::de; | ||
|
||
let s = String::deserialize(deserializer)?; | ||
FromStr::from_str(&s).map_err(de::Error::custom) | ||
} | ||
} | ||
|
||
impl Serialize for CompatMode { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
self.to_string().serialize(serializer) | ||
} | ||
} | ||
|
||
impl From<TmCompatMode> for CompatMode { | ||
fn from(value: TmCompatMode) -> Self { | ||
match value { | ||
TmCompatMode::V0_34 => Self::V0_34, | ||
TmCompatMode::V0_37 => Self::V0_37, | ||
} | ||
} | ||
} | ||
|
||
impl From<CompatMode> for TmCompatMode { | ||
fn from(value: CompatMode) -> Self { | ||
match value { | ||
CompatMode::V0_34 => Self::V0_34, | ||
CompatMode::V0_37 => Self::V0_37, | ||
} | ||
} | ||
} | ||
|
||
impl CompatMode { | ||
pub fn equal_to_tm_compat_mode(&self, tm_compat_mode: TmCompatMode) -> bool { | ||
match self { | ||
Self::V0_34 => tm_compat_mode == TmCompatMode::V0_34, | ||
Self::V0_37 => tm_compat_mode == TmCompatMode::V0_37, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use tracing::warn; | ||
|
||
use tendermint::Version; | ||
use tendermint_rpc::client::CompatMode as TmCompatMode; | ||
|
||
use crate::config::compat_mode::CompatMode; | ||
use crate::error::Error; | ||
|
||
/// This is a wrapper around tendermint-rs CompatMode::from_version() method. | ||
/// | ||
pub fn compat_mode_from_version( | ||
configured_version: &Option<CompatMode>, | ||
version: Version, | ||
) -> Result<CompatMode, Error> { | ||
let queried_version = TmCompatMode::from_version(version); | ||
|
||
// This will prioritize the use of the CompatMode specified in Hermes configuration file | ||
match (configured_version, queried_version) { | ||
(Some(configured), Ok(queried)) if !configured.equal_to_tm_compat_mode(queried) => { | ||
warn!("be wary of potential `compat_mode` misconfiguration. Configured version: {}, chain version: {}. Hermes will use the configured `compat_mode` version `{}`. If this configuration is done on purpose this message can be ignored.", configured, queried, configured); | ||
Ok(configured.clone()) | ||
} | ||
(Some(configured), _) => Ok(configured.clone()), | ||
(_, Ok(queried)) => Ok(queried.into()), | ||
(_, Err(e)) => Err(Error::invalid_compat_mode(e)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
stride-consumer | ||
migaloo | ||
neutron | ||
celestia | ||
; | ||
|
||
python = nixpkgs.python3.withPackages (p: [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
guide/src/documentation/configuration/comet-compat-mode.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# CometBFT Compatibility modes | ||
|
||
## Overview | ||
|
||
There are two different compatibility modes for CometBFT, one for version v0.34 and one for versions v0.37 and v0.38. In order to verify the compatiblity used Hermes queries the node's `/status` endpoint, which contains the CometBFT version used. This can be an issue if a chain uses a custom version which does not output the version string Hermes expects. To still be able to relay for these chains a configuration can be set in Hermes. | ||
|
||
## Configuration | ||
|
||
The configuration is set per chain and can take two values `0.34` and `0.37`, other values will be invalid: | ||
|
||
```toml | ||
[[chains]] | ||
... | ||
compat_mode = '0.34' | ||
``` | ||
|
||
Hermes will act in the following way whether or not the configuration is set: | ||
|
||
* `compat_mode` is specified and the version queried from `/status` is the same as the one configured: Use that version without log output | ||
* `compat_mode` is specified but the version queried from `/status` differs: The compatibility mode configured is used, but a warning log is outputted | ||
* `compat_mode` is not specified but /status returns a correct version: The compatibility mode retrieved from the endpoint is used | ||
* `compat_mode` is not specified and /status does not return a valid version: Hermes stops and outputs an error informing the user that the `compat_mode` needs to be configured | ||
|
||
The configuration can also be found in the example [config.toml](https://github.com/informalsystems/hermes/blob/{{#include ../../templates/hermes-version.md}}/config.toml#382) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.