From 3ffd922a495ae19664edfe009041ede025e95e6f Mon Sep 17 00:00:00 2001 From: Rano | Ranadeep Date: Tue, 11 Jun 2024 18:35:09 +0200 Subject: [PATCH] fix: sovereign state root in host consensus states (#178) * use correct consensus state root * log instructions * use tracing::info --- Cargo.lock | 1 + modules/sov-consensus-state-tracker/Cargo.toml | 1 + modules/sov-consensus-state-tracker/src/celestia_da.rs | 4 ++-- modules/sov-consensus-state-tracker/src/lib.rs | 7 +++++-- modules/sov-consensus-state-tracker/src/mock_da.rs | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4c68066..4cdc8568 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6145,6 +6145,7 @@ dependencies = [ "sov-state", "tendermint 0.36.0", "thiserror", + "tracing", "uint", ] diff --git a/modules/sov-consensus-state-tracker/Cargo.toml b/modules/sov-consensus-state-tracker/Cargo.toml index d206c4c6..8d49da39 100644 --- a/modules/sov-consensus-state-tracker/Cargo.toml +++ b/modules/sov-consensus-state-tracker/Cargo.toml @@ -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" ] } diff --git a/modules/sov-consensus-state-tracker/src/celestia_da.rs b/modules/sov-consensus-state-tracker/src/celestia_da.rs index 895ee11c..675342ec 100644 --- a/modules/sov-consensus-state-tracker/src/celestia_da.rs +++ b/modules/sov-consensus-state-tracker/src/celestia_da.rs @@ -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( diff --git a/modules/sov-consensus-state-tracker/src/lib.rs b/modules/sov-consensus-state-tracker/src/lib.rs index bd616727..6129f672 100644 --- a/modules/sov-consensus-state-tracker/src/lib.rs +++ b/modules/sov-consensus-state-tracker/src/lib.rs @@ -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)] @@ -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(), @@ -149,6 +150,8 @@ where &consensus_state, kernel_working_set.inner, ); + + info!("Host ConsensusState is stored at {height}: {consensus_state:?}"); } gas_price diff --git a/modules/sov-consensus-state-tracker/src/mock_da.rs b/modules/sov-consensus-state-tracker/src/mock_da.rs index 61af1b5f..bb774490 100644 --- a/modules/sov-consensus-state-tracker/src/mock_da.rs +++ b/modules/sov-consensus-state-tracker/src/mock_da.rs @@ -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(