Skip to content

Commit

Permalink
Merge pull request #2112 from input-output-hk/ensemble/2111/add-offse…
Browse files Browse the repository at this point in the history
…t-for-era-conversion-with-pallas-observer

Fix: adjust era offset in `PallasChainObserver` for correct display name
  • Loading branch information
dlachaume authored Nov 14, 2024
2 parents f64b6e4 + d279713 commit 85bc542
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.4.87"
version = "0.4.88"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions mithril-common/src/chain_observer/pallas_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ use crate::{

use super::model::{try_inspect, Datum, Datums};

// The era value returned from the queries_v16::get_current_era has an offset of -1 with the era value of the pallas_traverse::Era due to Cardano node implementation.
// It needs to be compensated to get the correct era display name.
const ERA_OFFSET: u16 = 1;

/// A runner that uses Pallas library to interact with a Cardano node using N2C Ouroboros mini-protocols
pub struct PallasChainObserver {
socket: PathBuf,
Expand Down Expand Up @@ -426,7 +430,7 @@ impl ChainObserver for PallasChainObserver {

let era = self.get_era(client.statequery()).await?;

let era = Era::try_from(era)
let era = Era::try_from(era + ERA_OFFSET)
.with_context(|| "PallasChainObserver failed to convert: '{era}' to Era")?;

self.post_process_statequery(&mut client).await?;
Expand Down Expand Up @@ -905,7 +909,8 @@ mod tests {

let (_, client_res) = tokio::join!(server, client);
let era = client_res.expect("Client failed");
let expected_era = Era::try_from(4).unwrap().to_string();

let expected_era = Era::try_from(4 + ERA_OFFSET).unwrap().to_string();
assert_eq!(era, expected_era);
}

Expand Down

0 comments on commit 85bc542

Please sign in to comment.