Skip to content

Commit

Permalink
feat(starknet_batcher): add communication for get_height (#2581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Dec 9, 2024
1 parent 6c27e41 commit 72f6f76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/starknet_batcher/src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use starknet_api::state::ThinStateDiff;
use starknet_batcher_types::batcher_types::{
BatcherResult,
DecisionReachedInput,
GetHeightResponse,
GetProposalContent,
GetProposalContentInput,
GetProposalContentResponse,
Expand Down Expand Up @@ -301,6 +302,12 @@ impl Batcher {
Ok(())
}

// TODO(Arni): Implement this function.
#[instrument(skip(self), err)]
pub async fn get_height(&mut self) -> BatcherResult<GetHeightResponse> {
todo!("Implement this function");
}

#[instrument(skip(self), err)]
pub async fn get_proposal_content(
&mut self,
Expand Down
3 changes: 3 additions & 0 deletions crates/starknet_batcher/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ impl ComponentRequestHandler<BatcherRequest, BatcherResponse> for Batcher {
BatcherRequest::ProposeBlock(input) => {
BatcherResponse::ProposeBlock(self.propose_block(input).await)
}
BatcherRequest::GetCurrentHeight => {
BatcherResponse::GetCurrentHeight(self.get_height().await)
}
BatcherRequest::GetProposalContent(input) => {
BatcherResponse::GetProposalContent(self.get_proposal_content(input).await)
}
Expand Down
5 changes: 5 additions & 0 deletions crates/starknet_batcher_types/src/batcher_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pub struct GetProposalContentInput {
pub proposal_id: ProposalId,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GetHeightResponse {
pub height: BlockNumber,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GetProposalContentResponse {
pub content: GetProposalContent,
Expand Down
16 changes: 16 additions & 0 deletions crates/starknet_batcher_types/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use thiserror::Error;
use crate::batcher_types::{
BatcherResult,
DecisionReachedInput,
GetHeightResponse,
GetProposalContentInput,
GetProposalContentResponse,
ProposeBlockInput,
Expand All @@ -44,6 +45,8 @@ pub type SharedBatcherClient = Arc<dyn BatcherClient>;
pub trait BatcherClient: Send + Sync {
/// Starts the process of building a proposal.
async fn propose_block(&self, input: ProposeBlockInput) -> BatcherClientResult<()>;
/// Gets the first height that is not written in the storage yet.
async fn get_height(&self) -> BatcherClientResult<GetHeightResponse>;
/// Gets the next available content from the proposal stream (only relevant when building a
/// proposal).
async fn get_proposal_content(
Expand Down Expand Up @@ -80,13 +83,15 @@ pub enum BatcherRequest {
ValidateBlock(ValidateBlockInput),
SendProposalContent(SendProposalContentInput),
StartHeight(StartHeightInput),
GetCurrentHeight,
DecisionReached(DecisionReachedInput),
AddSyncBlock(SyncBlock),
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum BatcherResponse {
ProposeBlock(BatcherResult<()>),
GetCurrentHeight(BatcherResult<GetHeightResponse>),
GetProposalContent(BatcherResult<GetProposalContentResponse>),
ValidateBlock(BatcherResult<()>),
SendProposalContent(BatcherResult<SendProposalContentResponse>),
Expand Down Expand Up @@ -154,6 +159,17 @@ where
handle_response_variants!(BatcherResponse, StartHeight, BatcherClientError, BatcherError)
}

async fn get_height(&self) -> BatcherClientResult<GetHeightResponse> {
let request = BatcherRequest::GetCurrentHeight;
let response = self.send(request).await;
handle_response_variants!(
BatcherResponse,
GetCurrentHeight,
BatcherClientError,
BatcherError
)
}

async fn decision_reached(&self, input: DecisionReachedInput) -> BatcherClientResult<()> {
let request = BatcherRequest::DecisionReached(input);
let response = self.send(request).await;
Expand Down

0 comments on commit 72f6f76

Please sign in to comment.