Skip to content
Open
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
2 changes: 1 addition & 1 deletion crates/apollo_committer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apollo_infra.workspace = true
apollo_metrics.workspace = true
async-trait.workspace = true
starknet_api.workspace = true
starknet_committer.workspace = true
starknet_committer = { workspace = true, features = ["os_input"] }
starknet_patricia_storage = { workspace = true, features = ["rocksdb_storage"] }
tracing.workspace = true

Expand Down
39 changes: 37 additions & 2 deletions crates/apollo_committer/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ use apollo_committer_types::communication::{CommitterRequest, CommitterResponse}
use apollo_infra::component_definitions::ComponentRequestHandler;
use apollo_infra::component_server::{LocalComponentServer, RemoteComponentServer};
use async_trait::async_trait;
#[cfg(feature = "os_input")]
use starknet_committer::db::forest_trait::forest_trait_witnesses::ForestStorageWithWitnesses;
#[cfg(not(feature = "os_input"))]
use starknet_committer::db::forest_trait::forest_trait_witnesses::ForestWriterWithMetadataAndWitnesses;
#[cfg(not(feature = "os_input"))]
use starknet_committer::db::forest_trait::ForestStorageWithEmptyReadContext;
#[cfg(feature = "os_input")]
use starknet_patricia_storage::storage_trait::ImmutableReadOnlyStorage;

use crate::committer::{ApolloCommitter, Committer, StorageConstructor};

pub type LocalCommitterServer =
LocalComponentServer<ApolloCommitter, CommitterRequest, CommitterResponse>;
pub type RemoteCommitterServer = RemoteComponentServer<CommitterRequest, CommitterResponse>;

#[cfg(not(feature = "os_input"))]
#[async_trait]
impl<S: StorageConstructor, ForestDB: ForestStorageWithEmptyReadContext<Storage = S>>
ComponentRequestHandler<CommitterRequest, CommitterResponse> for Committer<S, ForestDB>
impl<S: StorageConstructor, ForestDB> ComponentRequestHandler<CommitterRequest, CommitterResponse>
for Committer<S, ForestDB>
where
ForestDB: ForestStorageWithEmptyReadContext<Storage = S> + ForestWriterWithMetadataAndWitnesses,
{
async fn handle_request(&mut self, request: CommitterRequest) -> CommitterResponse {
match request {
Expand All @@ -25,3 +35,28 @@ impl<S: StorageConstructor, ForestDB: ForestStorageWithEmptyReadContext<Storage
}
}
}

#[cfg(feature = "os_input")]
#[async_trait]
impl<S, ForestDB> ComponentRequestHandler<CommitterRequest, CommitterResponse>
for Committer<S, ForestDB>
where
S: StorageConstructor + ImmutableReadOnlyStorage + 'static,
ForestDB: ForestStorageWithWitnesses<Storage = S>,
{
async fn handle_request(&mut self, request: CommitterRequest) -> CommitterResponse {
match request {
CommitterRequest::CommitBlock(commit_block_request) => {
CommitterResponse::CommitBlock(self.commit_block(commit_block_request).await)
}
CommitterRequest::RevertBlock(revert_block_request) => {
CommitterResponse::RevertBlock(self.revert_block(revert_block_request).await)
}
CommitterRequest::ReadPathsAndCommitBlock(req) => {
CommitterResponse::ReadPathsAndCommitBlock(
self.read_paths_and_commit_block(req).await,
)
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated handler arms risk diverging across feature-gated impls

Low Severity

The CommitBlock and RevertBlock match arms in handle_request are fully duplicated across the #[cfg(not(feature = "os_input"))] and #[cfg(feature = "os_input")] impl blocks. If future changes update one arm (e.g., adding logging, wrapping the response, or handling a new variant) without updating the other, the two feature-gated paths silently diverge. The split is needed because the two impls have different trait bounds, but the shared logic could be extracted into a helper method on Committer to avoid the duplication.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 98a2d45. Configure here.

}
31 changes: 31 additions & 0 deletions crates/apollo_committer_types/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::committer_types::{
RevertBlockRequest,
RevertBlockResponse,
};
#[cfg(feature = "os_input")]
use crate::committer_types::{ReadPathsAndCommitBlockRequest, ReadPathsAndCommitBlockResponse};
use crate::errors::{CommitterClientError, CommitterClientResult, CommitterResult};

pub type LocalCommitterClient = LocalComponentClient<CommitterRequest, CommitterResponse>;
Expand All @@ -43,6 +45,14 @@ pub trait CommitterClient: Send + Sync {
&self,
input: RevertBlockRequest,
) -> CommitterClientResult<RevertBlockResponse>;

#[cfg(feature = "os_input")]
/// Applies the state diff, collects merged Patricia witnesses for OS input, and persists replay
/// data (digest + payload).
async fn read_paths_and_commit_block(
&self,
input: ReadPathsAndCommitBlockRequest,
) -> CommitterClientResult<ReadPathsAndCommitBlockResponse>;
}

#[derive(Serialize, Deserialize, Clone, AsRefStr, EnumDiscriminants)]
Expand All @@ -54,6 +64,8 @@ pub trait CommitterClient: Send + Sync {
pub enum CommitterRequest {
CommitBlock(CommitBlockRequest),
RevertBlock(RevertBlockRequest),
#[cfg(feature = "os_input")]
ReadPathsAndCommitBlock(ReadPathsAndCommitBlockRequest),
}

impl_debug_for_infra_requests_and_responses!(CommitterRequest);
Expand All @@ -64,6 +76,8 @@ impl PrioritizedRequest for CommitterRequest {}
pub enum CommitterResponse {
CommitBlock(CommitterResult<CommitBlockResponse>),
RevertBlock(CommitterResult<RevertBlockResponse>),
#[cfg(feature = "os_input")]
ReadPathsAndCommitBlock(CommitterResult<ReadPathsAndCommitBlockResponse>),
}

impl_debug_for_infra_requests_and_responses!(CommitterResponse);
Expand Down Expand Up @@ -109,4 +123,21 @@ where
Direct
)
}

#[cfg(feature = "os_input")]
async fn read_paths_and_commit_block(
&self,
input: ReadPathsAndCommitBlockRequest,
) -> CommitterClientResult<ReadPathsAndCommitBlockResponse> {
let request = CommitterRequest::ReadPathsAndCommitBlock(input);
handle_all_response_variants!(
self,
request,
CommitterResponse,
ReadPathsAndCommitBlock,
CommitterClientError,
CommitterError,
Direct
)
}
}
Loading