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

fix: sovereign state root in host consensus states #178

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions modules/sov-consensus-state-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serde = { workspace = true }
serde_json = { workspace = true, optional = true }
thiserror = { workspace = true }
uint = "0.9"
tracing = { workspace = true }

# ibc dependencies
ibc-app-transfer = { workspace = true, features = [ "borsh", "schema" ] }
Expand Down
4 changes: 2 additions & 2 deletions modules/sov-consensus-state-tracker/src/celestia_da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use sov_rollup_interface::da::BlockHeaderTrait;
use crate::HasConsensusState;

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

let da_params = TmConsensusParams::new(
tendermint::Time::from_unix_timestamp(
Expand Down
7 changes: 5 additions & 2 deletions modules/sov-consensus-state-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ 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};
use sov_state::Storage;
use tracing::info;

/// Implement HasConsensusState for all DaSpecs that you wish to support, and
/// extract the consensus state from the header.
pub trait HasConsensusState: DaSpec {
fn consensus_state(header: &Self::BlockHeader) -> HostConsensusState;
fn consensus_state(header: &Self::BlockHeader, user_hash: [u8; 32]) -> HostConsensusState;
}

#[derive(Clone)]
Expand Down Expand Up @@ -137,7 +138,7 @@ where
.host_height_map
.set(&height, kernel_working_set.inner);

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

self.ibc.host_timestamp_map.set(
&consensus_state.timestamp().into(),
Expand All @@ -149,6 +150,8 @@ where
&consensus_state,
kernel_working_set.inner,
);

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

gas_price
Expand Down
4 changes: 2 additions & 2 deletions modules/sov-consensus-state-tracker/src/mock_da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use sov_rollup_interface::da::BlockHeaderTrait;
use crate::HasConsensusState;

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

let da_params = TmConsensusParams::new(
tendermint::Time::from_unix_timestamp(
Expand Down
Loading