Skip to content

Commit 11dc0c3

Browse files
committed
apollo_committer: add new request handler
1 parent de95d91 commit 11dc0c3

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

crates/apollo_committer/src/communication.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ 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+
#[cfg(feature = "os_input")]
6+
use starknet_committer::db::forest_trait::forest_trait_witnesses::ForestStorageWithWitnesses;
7+
#[cfg(not(feature = "os_input"))]
58
use starknet_committer::db::forest_trait::ForestStorageWithEmptyReadContext;
9+
#[cfg(feature = "os_input")]
10+
use starknet_patricia_storage::storage_trait::ImmutableReadOnlyStorage;
611

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

914
pub type LocalCommitterServer =
1015
LocalComponentServer<ApolloCommitter, CommitterRequest, CommitterResponse>;
1116
pub type RemoteCommitterServer = RemoteComponentServer<CommitterRequest, CommitterResponse>;
1217

18+
#[cfg(not(feature = "os_input"))]
1319
#[async_trait]
1420
impl<S: StorageConstructor, ForestDB: ForestStorageWithEmptyReadContext<Storage = S>>
1521
ComponentRequestHandler<CommitterRequest, CommitterResponse> for Committer<S, ForestDB>
@@ -25,3 +31,28 @@ impl<S: StorageConstructor, ForestDB: ForestStorageWithEmptyReadContext<Storage
2531
}
2632
}
2733
}
34+
35+
#[cfg(feature = "os_input")]
36+
#[async_trait]
37+
impl<S, ForestDB> ComponentRequestHandler<CommitterRequest, CommitterResponse>
38+
for Committer<S, ForestDB>
39+
where
40+
S: StorageConstructor + ImmutableReadOnlyStorage + 'static,
41+
ForestDB: ForestStorageWithWitnesses<Storage = S>,
42+
{
43+
async fn handle_request(&mut self, request: CommitterRequest) -> CommitterResponse {
44+
match request {
45+
CommitterRequest::CommitBlock(commit_block_request) => {
46+
CommitterResponse::CommitBlock(self.commit_block(commit_block_request).await)
47+
}
48+
CommitterRequest::RevertBlock(revert_block_request) => {
49+
CommitterResponse::RevertBlock(self.revert_block(revert_block_request).await)
50+
}
51+
CommitterRequest::ReadPathsAndCommitBlock(req) => {
52+
CommitterResponse::ReadPathsAndCommitBlock(
53+
self.read_paths_and_commit_block(req).await,
54+
)
55+
}
56+
}
57+
}
58+
}

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)