Skip to content

Commit cd31e55

Browse files
committed
apollo_committer: add new request handler
1 parent cc78b2a commit cd31e55

4 files changed

Lines changed: 76 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_committer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = "State root commitment computation component for the Starknet sequ
88

99
[features]
1010
testing = []
11+
os_input = ["apollo_committer_types/os_input"]
1112

1213
[dependencies]
1314
apollo_committer_config.workspace = true
@@ -16,7 +17,7 @@ apollo_infra.workspace = true
1617
apollo_metrics.workspace = true
1718
async-trait.workspace = true
1819
starknet_api.workspace = true
19-
starknet_committer.workspace = true
20+
starknet_committer = { workspace = true, features = ["os_input"] }
2021
starknet_patricia_storage = { workspace = true, features = ["rocksdb_storage"] }
2122
tracing.workspace = true
2223

crates/apollo_committer/src/communication.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@ use apollo_committer_types::communication::{CommitterRequest, CommitterResponse}
22
use apollo_infra::component_definitions::ComponentRequestHandler;
33
use apollo_infra::component_server::{LocalComponentServer, RemoteComponentServer};
44
use async_trait::async_trait;
5-
use starknet_committer::db::forest_trait::ForestStorageWithEmptyReadContext;
5+
#[cfg(feature = "os_input")]
6+
use starknet_committer::db::forest_trait::ForestStorageWithWitnesses;
7+
#[cfg(not(feature = "os_input"))]
8+
use starknet_committer::db::forest_trait::{
9+
ForestStorageWithEmptyReadContext,
10+
ForestWriterWithMetadataAndWitnesses,
11+
};
12+
#[cfg(feature = "os_input")]
13+
use starknet_patricia_storage::storage_trait::ImmutableReadOnlyStorage;
614

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

917
pub type LocalCommitterServer =
1018
LocalComponentServer<ApolloCommitter, CommitterRequest, CommitterResponse>;
1119
pub type RemoteCommitterServer = RemoteComponentServer<CommitterRequest, CommitterResponse>;
1220

21+
#[cfg(not(feature = "os_input"))]
1322
#[async_trait]
14-
impl<S: StorageConstructor, ForestDB: ForestStorageWithEmptyReadContext<Storage = S>>
15-
ComponentRequestHandler<CommitterRequest, CommitterResponse> for Committer<S, ForestDB>
23+
impl<S: StorageConstructor, ForestDB> ComponentRequestHandler<CommitterRequest, CommitterResponse>
24+
for Committer<S, ForestDB>
25+
where
26+
ForestDB: ForestStorageWithEmptyReadContext<Storage = S> + ForestWriterWithMetadataAndWitnesses,
1627
{
1728
async fn handle_request(&mut self, request: CommitterRequest) -> CommitterResponse {
1829
match request {
@@ -25,3 +36,28 @@ impl<S: StorageConstructor, ForestDB: ForestStorageWithEmptyReadContext<Storage
2536
}
2637
}
2738
}
39+
40+
#[cfg(feature = "os_input")]
41+
#[async_trait]
42+
impl<S, ForestDB> ComponentRequestHandler<CommitterRequest, CommitterResponse>
43+
for Committer<S, ForestDB>
44+
where
45+
S: StorageConstructor + ImmutableReadOnlyStorage + 'static,
46+
ForestDB: ForestStorageWithWitnesses<Storage = S>,
47+
{
48+
async fn handle_request(&mut self, request: CommitterRequest) -> CommitterResponse {
49+
match request {
50+
CommitterRequest::CommitBlock(commit_block_request) => {
51+
CommitterResponse::CommitBlock(self.commit_block(commit_block_request).await)
52+
}
53+
CommitterRequest::RevertBlock(revert_block_request) => {
54+
CommitterResponse::RevertBlock(self.revert_block(revert_block_request).await)
55+
}
56+
CommitterRequest::ReadPathsAndCommitBlock(req) => {
57+
CommitterResponse::ReadPathsAndCommitBlock(
58+
self.read_paths_and_commit_block(req).await,
59+
)
60+
}
61+
}
62+
}
63+
}

crates/apollo_committer_types/src/communication.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use crate::committer_types::{
2121
RevertBlockRequest,
2222
RevertBlockResponse,
2323
};
24+
#[cfg(feature = "os_input")]
25+
use crate::committer_types::{ReadPathsAndCommitBlockRequest, ReadPathsAndCommitBlockResponse};
2426
use crate::errors::{CommitterClientError, CommitterClientResult, CommitterResult};
2527

2628
pub type LocalCommitterClient = LocalComponentClient<CommitterRequest, CommitterResponse>;
@@ -43,6 +45,14 @@ pub trait CommitterClient: Send + Sync {
4345
&self,
4446
input: RevertBlockRequest,
4547
) -> CommitterClientResult<RevertBlockResponse>;
48+
49+
#[cfg(feature = "os_input")]
50+
/// Applies the state diff, collects merged Patricia witnesses for OS input, and persists replay
51+
/// data (digest + payload).
52+
async fn read_paths_and_commit_block(
53+
&self,
54+
input: ReadPathsAndCommitBlockRequest,
55+
) -> CommitterClientResult<ReadPathsAndCommitBlockResponse>;
4656
}
4757

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

5971
impl_debug_for_infra_requests_and_responses!(CommitterRequest);
@@ -64,6 +76,8 @@ impl PrioritizedRequest for CommitterRequest {}
6476
pub enum CommitterResponse {
6577
CommitBlock(CommitterResult<CommitBlockResponse>),
6678
RevertBlock(CommitterResult<RevertBlockResponse>),
79+
#[cfg(feature = "os_input")]
80+
ReadPathsAndCommitBlock(CommitterResult<ReadPathsAndCommitBlockResponse>),
6781
}
6882

6983
impl_debug_for_infra_requests_and_responses!(CommitterResponse);
@@ -109,4 +123,21 @@ where
109123
Direct
110124
)
111125
}
126+
127+
#[cfg(feature = "os_input")]
128+
async fn read_paths_and_commit_block(
129+
&self,
130+
input: ReadPathsAndCommitBlockRequest,
131+
) -> CommitterClientResult<ReadPathsAndCommitBlockResponse> {
132+
let request = CommitterRequest::ReadPathsAndCommitBlock(input);
133+
handle_all_response_variants!(
134+
self,
135+
request,
136+
CommitterResponse,
137+
ReadPathsAndCommitBlock,
138+
CommitterClientError,
139+
CommitterError,
140+
Direct
141+
)
142+
}
112143
}

0 commit comments

Comments
 (0)