From d66e886eea831252d2355fa3d132205d5126295e Mon Sep 17 00:00:00 2001 From: Yoav Gross Date: Sun, 30 Aug 2026 07:25:44 +0000 Subject: [PATCH] apollo_committer,starknet_committer: forward stored compressed commitment infos on historical replay --- crates/apollo_committer/src/committer.rs | 7 ++----- .../request_paths_and_commit_block_tests.rs | 19 +++++++++++------ .../src/db/forest_trait_witnesses.rs | 14 ++++++------- .../starknet_committer/src/db/index_db/db.rs | 21 ++++++++----------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/crates/apollo_committer/src/committer.rs b/crates/apollo_committer/src/committer.rs index 64d6713fdd8..ca189820b1c 100644 --- a/crates/apollo_committer/src/committer.rs +++ b/crates/apollo_committer/src/committer.rs @@ -615,14 +615,11 @@ where } let state_commitment_infos = self .forest_storage - .read_commitment_infos(height) + .read_compressed_commitment_infos(height) .await .map_err(|error| self.map_internal_error_at_height(height, error))? .ok_or(CommitterError::MissingPatriciaPaths { height })?; - Ok(ReadPathsAndCommitBlockResponse { - global_root, - state_commitment_infos: state_commitment_infos.compress()?, - }) + Ok(ReadPathsAndCommitBlockResponse { global_root, state_commitment_infos }) } // Flow overview: // 1. Fetch patricia paths for the accessed keys. diff --git a/crates/apollo_committer/src/request_paths_and_commit_block_tests.rs b/crates/apollo_committer/src/request_paths_and_commit_block_tests.rs index b3f1f066521..e27818ca94f 100644 --- a/crates/apollo_committer/src/request_paths_and_commit_block_tests.rs +++ b/crates/apollo_committer/src/request_paths_and_commit_block_tests.rs @@ -307,10 +307,13 @@ async fn assert_witnesses_and_digest_present( committer.load_witnesses_digest(height).await.unwrap(), Some(*EXPECTED_ACCESSED_KEYS_DIGEST), ); - assert_eq!( - committer.forest_storage.read_commitment_infos(height).await.unwrap().as_ref(), - Some(expected_commitment_infos), - ); + let stored_commitment_infos = committer + .forest_storage + .read_compressed_commitment_infos(height) + .await + .unwrap() + .expect("commitment infos should be stored"); + assert_eq!(stored_commitment_infos.decompress().unwrap(), *expected_commitment_infos); } async fn assert_witnesses_and_digest_absent( @@ -318,7 +321,9 @@ async fn assert_witnesses_and_digest_absent( height: BlockNumber, ) { assert!(committer.load_witnesses_digest(height).await.unwrap().is_none()); - assert!(committer.forest_storage.read_commitment_infos(height).await.unwrap().is_none()); + assert!( + committer.forest_storage.read_compressed_commitment_infos(height).await.unwrap().is_none() + ); } async fn assert_witnesses_and_digest_stored( @@ -326,7 +331,9 @@ async fn assert_witnesses_and_digest_stored( height: BlockNumber, ) { assert!(committer.load_witnesses_digest(height).await.unwrap().is_some()); - assert!(committer.forest_storage.read_commitment_infos(height).await.unwrap().is_some()); + assert!( + committer.forest_storage.read_compressed_commitment_infos(height).await.unwrap().is_some() + ); } /// Commits `height` via [`crate::committer::Committer::read_paths_and_commit_block`] with a diff --git a/crates/starknet_committer/src/db/forest_trait_witnesses.rs b/crates/starknet_committer/src/db/forest_trait_witnesses.rs index b4f7215d879..d86551b33b1 100644 --- a/crates/starknet_committer/src/db/forest_trait_witnesses.rs +++ b/crates/starknet_committer/src/db/forest_trait_witnesses.rs @@ -19,11 +19,7 @@ use crate::forest::deleted_nodes::DeletedNodes; use crate::forest::filled_forest::FilledForest; use crate::forest::forest_errors::ForestResult; use crate::patricia_merkle_tree::tree::SortedLeafIndices; -use crate::patricia_merkle_tree::types::{ - CompressedStateCommitmentInfos, - StarknetForestProofs, - StateCommitmentInfos, -}; +use crate::patricia_merkle_tree::types::{CompressedStateCommitmentInfos, StarknetForestProofs}; /// The information required to write the OS-input commitment infos to the database. The payload /// is stored as given, so the caller compresses it (once) before handing it over. @@ -41,15 +37,17 @@ pub enum CommitmentInfosUpdate { Delete(BlockNumber), } -/// Reads the committed OS-input commitment infos ([`StateCommitmentInfos`]) for a block height. +/// Reads the committed OS-input commitment infos for a block height. #[async_trait] pub trait ForestReaderWithWitnesses: ForestReader + Send { - async fn read_commitment_infos( + /// Returns the infos as stored; callers that only forward them skip the decompress/re-compress + /// round trip. + async fn read_compressed_commitment_infos( &mut self, height: BlockNumber, - ) -> ForestResult>; + ) -> ForestResult>; /// Fetches Patricia witness paths for OS input, optionally staging serialized trie node KVs on /// an in-memory overlay so reads match post-commit state before the forest is persisted. diff --git a/crates/starknet_committer/src/db/index_db/db.rs b/crates/starknet_committer/src/db/index_db/db.rs index 1b9387c2e36..6fedcd3eb78 100644 --- a/crates/starknet_committer/src/db/index_db/db.rs +++ b/crates/starknet_committer/src/db/index_db/db.rs @@ -75,7 +75,6 @@ use crate::patricia_merkle_tree::types::{ CompiledClassHash, CompressedStateCommitmentInfos, StarknetForestProofs, - StateCommitmentInfos, }; /// Set to 2^251 + 1 to avoid collisions with contract addresses prefixes. @@ -369,23 +368,21 @@ fn singleton_metadata_key(prefix: &[u8; 32]) -> Vec { impl ForestReaderWithWitnesses for IndexDb { - async fn read_commitment_infos( + async fn read_compressed_commitment_infos( &mut self, height: BlockNumber, - ) -> ForestResult> { + ) -> ForestResult> { let db_key = DbKey(block_number_based_key(&PATRICIA_PATHS_PREFIX, DbBlockNumber(height))); Ok(match self.get_from_storage(db_key).await? { None => None, - Some(DbValue(bytes)) => Some( - CompressedStateCommitmentInfos::from_bytes(bytes) - .and_then(|compressed| compressed.decompress()) - .map_err(|e| { - ForestError::PatriciaStorage(PatriciaStorageError::Deserialization( - DeserializationError::ValueError(Box::new(e)), - )) - })?, - ), + Some(DbValue(bytes)) => { + Some(CompressedStateCommitmentInfos::from_bytes(bytes).map_err(|e| { + ForestError::PatriciaStorage(PatriciaStorageError::Deserialization( + DeserializationError::ValueError(Box::new(e)), + )) + })?) + } }) }