Skip to content

Commit 647af45

Browse files
committed
apollo_committer: add new request handler
1 parent 9a0da7d commit 647af45

6 files changed

Lines changed: 97 additions & 4 deletions

File tree

crates/apollo_batcher/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description = "Block building and transaction batching component for the Starkne
88

99
[features]
1010
cairo_native = ["blockifier/cairo_native"]
11-
os_input = ["apollo_reverts/os_input", "apollo_storage/os_input"]
11+
os_input = ["apollo_committer_types/os_input", "apollo_reverts/os_input", "apollo_storage/os_input"]
1212
testing = []
1313

1414
[lints]

crates/apollo_batcher/src/commitment_manager/commitment_manager_impl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,16 @@ impl<S: StateCommitterTrait> CommitmentManager<S> {
551551
COMMITMENT_MANAGER_REVERT_BLOCK_LATENCY.increment(task_duration);
552552
COMMITMENT_MANAGER_REVERT_BLOCK_COUNT.increment(1);
553553
}
554+
#[cfg(feature = "os_input")]
555+
CommitterRequestLabelValue::ReadPathsAndCommitBlock => {
556+
debug!(
557+
"Read paths and commit block latency for block {height}: {task_duration} \
558+
milliseconds."
559+
);
560+
// TODO(Ariel): Add dedicated metrics once we use os_input in prod.
561+
COMMITMENT_MANAGER_COMMIT_BLOCK_LATENCY.increment(task_duration);
562+
COMMITMENT_MANAGER_COMMIT_BLOCK_COUNT.increment(1);
563+
}
554564
}
555565
}
556566
}

crates/apollo_batcher/src/commitment_manager/types.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,17 @@ impl TaskTimer {
107107
pub(crate) fn start_timer(&mut self, task: CommitterRequestLabelValue, height: BlockNumber) {
108108
let instant = Instant::now();
109109
match task {
110-
CommitterRequestLabelValue::CommitBlock => self.commit.insert(height, instant),
111-
CommitterRequestLabelValue::RevertBlock => self.revert.insert(height, instant),
112-
};
110+
CommitterRequestLabelValue::CommitBlock => {
111+
self.commit.insert(height, instant);
112+
}
113+
#[cfg(feature = "os_input")]
114+
CommitterRequestLabelValue::ReadPathsAndCommitBlock => {
115+
self.commit.insert(height, instant);
116+
}
117+
CommitterRequestLabelValue::RevertBlock => {
118+
self.revert.insert(height, instant);
119+
}
120+
}
113121
}
114122

115123
/// Returns the duration of the task in milliseconds.
@@ -120,6 +128,8 @@ impl TaskTimer {
120128
) -> Option<u128> {
121129
let map = match task {
122130
CommitterRequestLabelValue::CommitBlock => &mut self.commit,
131+
#[cfg(feature = "os_input")]
132+
CommitterRequestLabelValue::ReadPathsAndCommitBlock => &mut self.commit,
123133
CommitterRequestLabelValue::RevertBlock => &mut self.revert,
124134
};
125135

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
}

crates/apollo_committer_types/src/test_utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::committer_types::{
1010
RevertBlockRequest,
1111
RevertBlockResponse,
1212
};
13+
#[cfg(feature = "os_input")]
14+
use crate::committer_types::{ReadPathsAndCommitBlockRequest, ReadPathsAndCommitBlockResponse};
1315
use crate::communication::{CommitterClient, MockCommitterClient};
1416
use crate::errors::CommitterClientResult;
1517

@@ -39,6 +41,15 @@ impl CommitterClient for MockCommitterClientWithOffset {
3941
self.set_offset(input.height).await;
4042
self.inner.revert_block(input).await
4143
}
44+
45+
#[cfg(feature = "os_input")]
46+
async fn read_paths_and_commit_block(
47+
&self,
48+
input: ReadPathsAndCommitBlockRequest,
49+
) -> CommitterClientResult<ReadPathsAndCommitBlockResponse> {
50+
self.set_offset(input.commit.height).await;
51+
self.inner.read_paths_and_commit_block(input).await
52+
}
4253
}
4354

4455
impl MockCommitterClientWithOffset {

0 commit comments

Comments
 (0)