Skip to content
Closed
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
7 changes: 2 additions & 5 deletions crates/apollo_committer/src/committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,26 +307,33 @@ 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(
committer: &mut ApolloTestCommitter,
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(
committer: &mut ApolloTestCommitter,
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
Expand Down
14 changes: 6 additions & 8 deletions crates/starknet_committer/src/db/forest_trait_witnesses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<InitialReadContext: EmptyInitialReadContext> + 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<Option<StateCommitmentInfos>>;
) -> ForestResult<Option<CompressedStateCommitmentInfos>>;

/// 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.
Expand Down
21 changes: 9 additions & 12 deletions crates/starknet_committer/src/db/index_db/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -369,23 +368,21 @@ fn singleton_metadata_key(prefix: &[u8; 32]) -> Vec<u8> {
impl<S: Storage + ImmutableReadOnlyStorage + Sync + Send + 'static> ForestReaderWithWitnesses
for IndexDb<S>
{
async fn read_commitment_infos(
async fn read_compressed_commitment_infos(
&mut self,
height: BlockNumber,
) -> ForestResult<Option<StateCommitmentInfos>> {
) -> ForestResult<Option<CompressedStateCommitmentInfos>> {
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)),
))
})?)
}
})
}

Expand Down
Loading