Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: build correct host ConsensusState (#180)
Browse files Browse the repository at this point in the history
* fix with visible hash

* fix timestamp in consensus state

* log da height too

* use modulo
  • Loading branch information
rnbguy authored Jun 13, 2024
1 parent 4cc8152 commit 6081f8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions modules/sov-consensus-state-tracker/src/celestia_da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ use sov_celestia_client::consensus_state::ConsensusState as HostConsensusState;
use sov_celestia_client::types::consensus_state::{
ConsensusState as SovConsensusState, TmConsensusParams,
};
use sov_rollup_interface::da::BlockHeaderTrait;

use crate::HasConsensusState;

impl HasConsensusState for CelestiaSpec {
fn consensus_state(header: &CelestiaHeader, user_hash: [u8; 32]) -> HostConsensusState {
let sovereign_params = CommitmentRoot::from_bytes(&user_hash).into();

let protobuf_time = tendermint::time::Time::decode(header.header.time.as_slice())
.expect("Timestamp must be valid");

let da_params = TmConsensusParams::new(
tendermint::Time::from_unix_timestamp(
header.time().secs(),
header.time().subsec_nanos(),
protobuf_time.unix_timestamp(),
u32::try_from(protobuf_time.unix_timestamp_nanos() % 1_000_000_000)
.expect("no overflow"),
)
.expect("Could not obtain timestamp from header"),
tendermint::Hash::decode_vec(&header.header.next_validators_hash)
Expand Down
9 changes: 7 additions & 2 deletions modules/sov-consensus-state-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ibc_core::client::types::Height;
pub use mock_da::*;
use sov_celestia_client::consensus_state::ConsensusState as HostConsensusState;
use sov_ibc::context::HOST_REVISION_NUMBER;
use sov_modules_api::da::BlockHeaderTrait;
use sov_modules_api::kernel_state::BootstrapWorkingSet;
use sov_modules_api::runtime::capabilities::{BatchSelector, Kernel, KernelSlotHooks};
use sov_modules_api::{DaSpec, Gas, KernelModule, KernelWorkingSet, Spec, StateCheckpoint};
Expand Down Expand Up @@ -138,7 +139,9 @@ where
.host_height_map
.set(&height, kernel_working_set.inner);

let consensus_state = Da::consensus_state(slot_header, pre_state_root.clone().into());
let visible_hash = S::VisibleHash::from(pre_state_root.clone());

let consensus_state = Da::consensus_state(slot_header, visible_hash.into());

self.ibc.host_timestamp_map.set(
&consensus_state.timestamp().into(),
Expand All @@ -151,7 +154,9 @@ where
kernel_working_set.inner,
);

info!("Host ConsensusState is stored at {height}: {consensus_state:?}");
let da_height = slot_header.height();

info!("Host ConsensusState is stored at rollup {height} and DA {da_height}: {consensus_state:?}");
}

gas_price
Expand Down

0 comments on commit 6081f8e

Please sign in to comment.