Skip to content

Commit 20bdbc6

Browse files
committed
apollo_committer: add new request handler
1 parent 8a3d6fb commit 20bdbc6

4 files changed

Lines changed: 76 additions & 8 deletions

File tree

crates/apollo_committer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ license.workspace = true
77
description = "State root commitment computation component for the Starknet sequencer."
88

99
[features]
10-
testing = []
1110
os_input = ["apollo_committer_types/os_input", "starknet_committer/os_input"]
11+
testing = []
1212

1313
[dependencies]
1414
apollo_committer_config.workspace = true
@@ -17,7 +17,7 @@ apollo_infra.workspace = true
1717
apollo_metrics.workspace = true
1818
async-trait.workspace = true
1919
starknet_api.workspace = true
20-
starknet_committer.workspace = true
20+
starknet_committer = { workspace = true, features = ["os_input"] }
2121
starknet_patricia_storage = { workspace = true, features = ["rocksdb_storage"] }
2222
tracing.workspace = true
2323

crates/apollo_committer/src/committer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use starknet_committer::db::forest_trait::{
4141
EmptyInitialReadContext,
4242
ForestMetadataType,
4343
ForestStorageWithEmptyReadContext,
44+
ForestWriterWithMetadataAndWitnesses,
4445
};
4546
use starknet_committer::db::index_db::IndexDb;
4647
#[cfg(feature = "os_input")]
@@ -396,8 +397,8 @@ where
396397
#[cfg(not(feature = "os_input"))]
397398
{
398399
self.forest_storage
399-
.write_with_metadata(&filled_forest, metadata, deleted_nodes)
400-
.await
400+
.write_with_metadata(&filled_forest, metadata, deleted_nodes)
401+
.await
401402
}
402403
#[cfg(feature = "os_input")]
403404
{
@@ -411,7 +412,7 @@ where
411412
.await
412413
}
413414
}
414-
.map_err(|err| self.map_internal_error(err))?;
415+
.map_err(|err| self.map_internal_error(err))?;
415416
block_measurements.attempt_to_stop_measurement(Action::Write, n_write_entries).ok();
416417
block_measurements.attempt_to_stop_measurement(Action::EndToEnd, 0).ok();
417418
update_metrics(height, &block_measurements.block_measurement);

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)