Skip to content
Draft
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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/apollo_committer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = "State root commitment computation component for the Starknet sequ

[features]
testing = []
os_input = ["apollo_committer_types/os_input"]

[dependencies]
apollo_committer_config.workspace = true
Expand All @@ -16,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
42 changes: 39 additions & 3 deletions crates/apollo_committer/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ 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;
use starknet_committer::db::forest_trait::ForestStorageWithEmptyReadContext;
#[cfg(feature = "os_input")]
use starknet_committer::db::forest_trait::ForestStorageWithWitnesses;
#[cfg(not(feature = "os_input"))]
use starknet_committer::db::forest_trait::{
ForestStorageWithEmptyReadContext,
ForestWriterWithMetadataAndWitnesses,
};
#[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 +36,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,
)
}
}
}
}
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