From 145844f19e70a69ad1376fa3f62ff5f2e800a90b Mon Sep 17 00:00:00 2001 From: Yael Doweck Date: Tue, 19 Nov 2024 10:48:58 +0200 Subject: [PATCH] chore(batcher): rename build_proposal => propose_block and validate_proposal => validate_block --- .../src/sequencer_consensus_context.rs | 12 ++--- .../src/sequencer_consensus_context_test.rs | 10 ++-- crates/starknet_batcher/src/batcher.rs | 46 +++++++++---------- crates/starknet_batcher/src/batcher_test.rs | 42 ++++++++--------- crates/starknet_batcher/src/communication.rs | 8 ++-- .../starknet_batcher/src/proposal_manager.rs | 8 ++-- .../src/proposal_manager_test.rs | 36 +++++++-------- .../src/batcher_types.rs | 4 +- .../src/communication.rs | 33 ++++++------- 9 files changed, 94 insertions(+), 105 deletions(-) diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs index a1fe9e3b0e3..54e7a8f7509 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs @@ -31,16 +31,16 @@ use papyrus_protobuf::consensus::{ use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockNumber}; use starknet_api::executable_transaction::Transaction; use starknet_batcher_types::batcher_types::{ - BuildProposalInput, DecisionReachedInput, GetProposalContent, GetProposalContentInput, ProposalId, ProposalStatus, + ProposeBlockInput, SendProposalContent, SendProposalContentInput, StartHeightInput, - ValidateProposalInput, + ValidateBlockInput, }; use starknet_batcher_types::communication::BatcherClient; use tracing::{debug, debug_span, error, info, trace, warn, Instrument}; @@ -106,7 +106,7 @@ impl ConsensusContext for SequencerConsensusContext { self.proposal_id += 1; let timeout = chrono::Duration::from_std(timeout).expect("Can't convert timeout to chrono::Duration"); - let build_proposal_input = BuildProposalInput { + let build_proposal_input = ProposeBlockInput { proposal_id, // TODO: Discuss with batcher team passing std Duration instead. deadline: chrono::Utc::now() + timeout, @@ -122,7 +122,7 @@ impl ConsensusContext for SequencerConsensusContext { // here also. debug!("Initiating proposal build: {build_proposal_input:?}"); batcher - .build_proposal(build_proposal_input) + .propose_block(build_proposal_input) .await .expect("Failed to initiate proposal build"); debug!("Broadcasting proposal init: {proposal_init:?}"); @@ -164,7 +164,7 @@ impl ConsensusContext for SequencerConsensusContext { let chrono_timeout = chrono::Duration::from_std(timeout).expect("Can't convert timeout to chrono::Duration"); - let input = ValidateProposalInput { + let input = ValidateBlockInput { proposal_id, deadline: chrono::Utc::now() + chrono_timeout, // TODO(Matan 3/11/2024): Add the real value of the retrospective block hash. @@ -174,7 +174,7 @@ impl ConsensusContext for SequencerConsensusContext { }), }; self.maybe_start_height(height).await; - batcher.validate_proposal(input).await.expect("Failed to initiate proposal validation"); + batcher.validate_block(input).await.expect("Failed to initiate proposal validation"); tokio::spawn( async move { let validate_fut = stream_validate_proposal( diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs index 0006955f65c..c5b1c127c50 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs @@ -19,17 +19,17 @@ use starknet_api::hash::PoseidonHash; use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs}; use starknet_api::transaction::TransactionHash; use starknet_batcher_types::batcher_types::{ - BuildProposalInput, GetProposalContent, GetProposalContentResponse, ProposalCommitment, ProposalId, ProposalStatus, + ProposeBlockInput, SendProposalContent, SendProposalContentInput, SendProposalContentResponse, StartHeightInput, - ValidateProposalInput, + ValidateBlockInput, }; use starknet_batcher_types::communication::MockBatcherClient; use starknet_types_core::felt::Felt; @@ -57,7 +57,7 @@ async fn build_proposal() { let mut batcher = MockBatcherClient::new(); let proposal_id = Arc::new(OnceLock::new()); let proposal_id_clone = Arc::clone(&proposal_id); - batcher.expect_build_proposal().returning(move |input: BuildProposalInput| { + batcher.expect_propose_block().returning(move |input: ProposeBlockInput| { proposal_id_clone.set(input.proposal_id).unwrap(); Ok(()) }); @@ -101,7 +101,7 @@ async fn validate_proposal_success() { let mut batcher = MockBatcherClient::new(); let proposal_id: Arc> = Arc::new(OnceLock::new()); let proposal_id_clone = Arc::clone(&proposal_id); - batcher.expect_validate_proposal().returning(move |input: ValidateProposalInput| { + batcher.expect_validate_block().returning(move |input: ValidateBlockInput| { proposal_id_clone.set(input.proposal_id).unwrap(); Ok(()) }); @@ -149,7 +149,7 @@ async fn validate_proposal_success() { async fn repropose() { // Receive a proposal. Then re-retrieve it. let mut batcher = MockBatcherClient::new(); - batcher.expect_validate_proposal().returning(move |_| Ok(())); + batcher.expect_validate_block().returning(move |_| Ok(())); batcher.expect_start_height().return_once(|input: StartHeightInput| { assert_eq!(input.height, BlockNumber(0)); Ok(()) diff --git a/crates/starknet_batcher/src/batcher.rs b/crates/starknet_batcher/src/batcher.rs index 1519586835f..792c5bd58a4 100644 --- a/crates/starknet_batcher/src/batcher.rs +++ b/crates/starknet_batcher/src/batcher.rs @@ -11,18 +11,18 @@ use starknet_api::executable_transaction::Transaction; use starknet_api::state::ThinStateDiff; use starknet_batcher_types::batcher_types::{ BatcherResult, - BuildProposalInput, DecisionReachedInput, GetProposalContent, GetProposalContentInput, GetProposalContentResponse, ProposalId, ProposalStatus, + ProposeBlockInput, SendProposalContent, SendProposalContentInput, SendProposalContentResponse, StartHeightInput, - ValidateProposalInput, + ValidateBlockInput, }; use starknet_batcher_types::errors::BatcherError; use starknet_mempool_types::communication::SharedMempoolClient; @@ -56,8 +56,8 @@ pub struct Batcher { pub storage_writer: Box, pub mempool_client: SharedMempoolClient, proposal_manager: Box, - build_proposals: HashMap, - validate_proposals: HashMap, + propose_streams: HashMap, + validate_streams: HashMap, } impl Batcher { @@ -74,24 +74,24 @@ impl Batcher { storage_writer, mempool_client, proposal_manager, - build_proposals: HashMap::new(), - validate_proposals: HashMap::new(), + propose_streams: HashMap::new(), + validate_streams: HashMap::new(), } } pub async fn start_height(&mut self, input: StartHeightInput) -> BatcherResult<()> { - self.build_proposals.clear(); - self.validate_proposals.clear(); + self.propose_streams.clear(); + self.validate_streams.clear(); self.proposal_manager.start_height(input.height).await.map_err(BatcherError::from) } #[instrument(skip(self), err)] - pub async fn build_proposal( + pub async fn propose_block( &mut self, - build_proposal_input: BuildProposalInput, + propose_block_input: ProposeBlockInput, ) -> BatcherResult<()> { - let proposal_id = build_proposal_input.proposal_id; - let deadline = deadline_as_instant(build_proposal_input.deadline)?; + let proposal_id = propose_block_input.proposal_id; + let deadline = deadline_as_instant(propose_block_input.deadline)?; let (output_tx_sender, output_tx_receiver) = tokio::sync::mpsc::unbounded_channel(); let tx_provider = ProposeTransactionProvider::new( @@ -102,23 +102,23 @@ impl Batcher { ); self.proposal_manager - .build_block_proposal( + .propose_block( proposal_id, - build_proposal_input.retrospective_block_hash, + propose_block_input.retrospective_block_hash, deadline, output_tx_sender, tx_provider, ) .await?; - self.build_proposals.insert(proposal_id, output_tx_receiver); + self.propose_streams.insert(proposal_id, output_tx_receiver); Ok(()) } #[instrument(skip(self), err)] - pub async fn validate_proposal( + pub async fn validate_block( &mut self, - validate_proposal_input: ValidateProposalInput, + validate_proposal_input: ValidateBlockInput, ) -> BatcherResult<()> { let proposal_id = validate_proposal_input.proposal_id; let deadline = deadline_as_instant(validate_proposal_input.deadline)?; @@ -132,7 +132,7 @@ impl Batcher { }; self.proposal_manager - .validate_block_proposal( + .validate_block( proposal_id, validate_proposal_input.retrospective_block_hash, deadline, @@ -140,7 +140,7 @@ impl Batcher { ) .await?; - self.validate_proposals.insert(proposal_id, input_tx_sender); + self.validate_streams.insert(proposal_id, input_tx_sender); Ok(()) } @@ -173,7 +173,7 @@ impl Batcher { match self.proposal_manager.get_proposal_status(proposal_id).await { InternalProposalStatus::Processing => { let tx_provider_sender = &self - .validate_proposals + .validate_streams .get(&proposal_id) .expect("Expecting tx_provider_sender to exist during batching."); for tx in txs { @@ -219,7 +219,7 @@ impl Batcher { } fn close_input_transaction_stream(&mut self, proposal_id: ProposalId) -> BatcherResult<()> { - self.validate_proposals + self.validate_streams .remove(&proposal_id) .ok_or(BatcherError::ProposalNotFound { proposal_id })?; Ok(()) @@ -233,7 +233,7 @@ impl Batcher { let proposal_id = get_proposal_content_input.proposal_id; let tx_stream = &mut self - .build_proposals + .propose_streams .get_mut(&proposal_id) .ok_or(BatcherError::ProposalNotFound { proposal_id })?; @@ -250,7 +250,7 @@ impl Batcher { // Finished streaming all the transactions. // TODO: Consider removing the proposal from the proposal manager and keep it in the batcher // for decision reached. - self.build_proposals.remove(&proposal_id); + self.propose_streams.remove(&proposal_id); let proposal_commitment = self.proposal_manager.await_proposal_commitment(proposal_id).await?; Ok(GetProposalContentResponse { diff --git a/crates/starknet_batcher/src/batcher_test.rs b/crates/starknet_batcher/src/batcher_test.rs index bf41a7b9169..05aede35bfb 100644 --- a/crates/starknet_batcher/src/batcher_test.rs +++ b/crates/starknet_batcher/src/batcher_test.rs @@ -18,7 +18,6 @@ use starknet_api::state::ThinStateDiff; use starknet_api::transaction::TransactionHash; use starknet_api::{contract_address, felt, nonce}; use starknet_batcher_types::batcher_types::{ - BuildProposalInput, DecisionReachedInput, GetProposalContent, GetProposalContentInput, @@ -26,11 +25,12 @@ use starknet_batcher_types::batcher_types::{ ProposalCommitment, ProposalId, ProposalStatus, + ProposeBlockInput, SendProposalContent, SendProposalContentInput, SendProposalContentResponse, StartHeightInput, - ValidateProposalInput, + ValidateBlockInput, }; use starknet_batcher_types::errors::BatcherError; use starknet_mempool_types::communication::MockMempoolClient; @@ -117,7 +117,7 @@ fn mock_proposal_manager_validate_flow() -> MockProposalManagerTraitWrapper { let mut proposal_manager = MockProposalManagerTraitWrapper::new(); mock_proposal_manager_common_expectations(&mut proposal_manager); proposal_manager - .expect_wrap_validate_block_proposal() + .expect_wrap_validate_block() .times(1) .with(eq(PROPOSAL_ID), eq(None), always(), always()) .return_once(|_, _, _, tx_provider| { @@ -147,7 +147,7 @@ fn mock_proposal_manager_validate_flow() -> MockProposalManagerTraitWrapper { #[rstest] #[tokio::test] -async fn validate_proposal_full_flow() { +async fn validate_block_full_flow() { let proposal_manager = mock_proposal_manager_validate_flow(); let mut batcher = batcher(proposal_manager); @@ -156,12 +156,12 @@ async fn validate_proposal_full_flow() { // batcher-proposal_manager unification. batcher.start_height(StartHeightInput { height: INITIAL_HEIGHT }).await.unwrap(); - let validate_proposal_input = ValidateProposalInput { + let validate_block_input = ValidateBlockInput { proposal_id: PROPOSAL_ID, deadline: deadline(), retrospective_block_hash: None, }; - batcher.validate_proposal(validate_proposal_input).await.unwrap(); + batcher.validate_block(validate_block_input).await.unwrap(); let send_proposal_input_txs = SendProposalContentInput { proposal_id: PROPOSAL_ID, @@ -256,7 +256,7 @@ async fn send_txs_to_an_invalid_proposal() { async fn send_finish_to_an_invalid_proposal() { let mut proposal_manager = MockProposalManagerTraitWrapper::new(); proposal_manager - .expect_wrap_validate_block_proposal() + .expect_wrap_validate_block() .times(1) .with(eq(PROPOSAL_ID), eq(None), always(), always()) .return_once(|_, _, _, _| { async move { Ok(()) } }.boxed()); @@ -272,12 +272,12 @@ async fn send_finish_to_an_invalid_proposal() { let mut batcher = batcher(proposal_manager); - let validate_proposal_input = ValidateProposalInput { + let validate_block_input = ValidateBlockInput { proposal_id: PROPOSAL_ID, deadline: deadline(), retrospective_block_hash: None, }; - batcher.validate_proposal(validate_proposal_input).await.unwrap(); + batcher.validate_block(validate_block_input).await.unwrap(); let send_proposal_input_txs = SendProposalContentInput { proposal_id: PROPOSAL_ID, content: SendProposalContent::Finish }; @@ -287,14 +287,14 @@ async fn send_finish_to_an_invalid_proposal() { #[rstest] #[tokio::test] -async fn build_proposal_full_flow() { +async fn propose_block_full_flow() { // Expecting 3 chunks of streamed txs. let expected_streamed_txs = test_txs(0..STREAMING_CHUNK_SIZE * 2 + 1); let txs_to_stream = expected_streamed_txs.clone(); let mut proposal_manager = MockProposalManagerTraitWrapper::new(); mock_proposal_manager_common_expectations(&mut proposal_manager); - proposal_manager.expect_wrap_build_block_proposal().times(1).return_once( + proposal_manager.expect_wrap_propose_block().times(1).return_once( move |_proposal_id, _block_hash, _deadline, tx_sender, _tx_provider| { simulate_build_block_proposal(tx_sender, txs_to_stream).boxed() }, @@ -304,7 +304,7 @@ async fn build_proposal_full_flow() { batcher.start_height(StartHeightInput { height: INITIAL_HEIGHT }).await.unwrap(); batcher - .build_proposal(BuildProposalInput { + .propose_block(ProposeBlockInput { proposal_id: PROPOSAL_ID, retrospective_block_hash: None, deadline: chrono::Utc::now() + chrono::Duration::seconds(1), @@ -443,7 +443,7 @@ trait ProposalManagerTraitWrapper: Send + Sync { height: BlockNumber, ) -> BoxFuture<'_, Result<(), StartHeightError>>; - fn wrap_build_block_proposal( + fn wrap_propose_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, @@ -452,7 +452,7 @@ trait ProposalManagerTraitWrapper: Send + Sync { tx_provider: ProposeTransactionProvider, ) -> BoxFuture<'_, Result<(), GenerateProposalError>>; - fn wrap_validate_block_proposal( + fn wrap_validate_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, @@ -484,7 +484,7 @@ impl ProposalManagerTrait for T { self.wrap_start_height(height).await } - async fn build_block_proposal( + async fn propose_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, @@ -492,7 +492,7 @@ impl ProposalManagerTrait for T { output_content_sender: tokio::sync::mpsc::UnboundedSender, tx_provider: ProposeTransactionProvider, ) -> Result<(), GenerateProposalError> { - self.wrap_build_block_proposal( + self.wrap_propose_block( proposal_id, retrospective_block_hash, deadline, @@ -502,20 +502,14 @@ impl ProposalManagerTrait for T { .await } - async fn validate_block_proposal( + async fn validate_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, deadline: tokio::time::Instant, tx_provider: ValidateTransactionProvider, ) -> Result<(), GenerateProposalError> { - self.wrap_validate_block_proposal( - proposal_id, - retrospective_block_hash, - deadline, - tx_provider, - ) - .await + self.wrap_validate_block(proposal_id, retrospective_block_hash, deadline, tx_provider).await } async fn take_proposal_result( diff --git a/crates/starknet_batcher/src/communication.rs b/crates/starknet_batcher/src/communication.rs index 31ef03b2d7b..d5b7ae5c7a4 100644 --- a/crates/starknet_batcher/src/communication.rs +++ b/crates/starknet_batcher/src/communication.rs @@ -12,8 +12,8 @@ pub type RemoteBatcherServer = RemoteComponentServer for Batcher { async fn handle_request(&mut self, request: BatcherRequest) -> BatcherResponse { match request { - BatcherRequest::BuildProposal(input) => { - BatcherResponse::BuildProposal(self.build_proposal(input).await) + BatcherRequest::ProposeBlock(input) => { + BatcherResponse::ProposeBlock(self.propose_block(input).await) } BatcherRequest::GetProposalContent(input) => { BatcherResponse::GetProposalContent(self.get_proposal_content(input).await) @@ -24,8 +24,8 @@ impl ComponentRequestHandler for Batcher { BatcherRequest::DecisionReached(input) => { BatcherResponse::DecisionReached(self.decision_reached(input).await) } - BatcherRequest::ValidateProposal(input) => { - BatcherResponse::ValidateProposal(self.validate_proposal(input).await) + BatcherRequest::ValidateBlock(input) => { + BatcherResponse::ValidateBlock(self.validate_block(input).await) } BatcherRequest::SendProposalContent(input) => { BatcherResponse::SendProposalContent(self.send_proposal_content(input).await) diff --git a/crates/starknet_batcher/src/proposal_manager.rs b/crates/starknet_batcher/src/proposal_manager.rs index 6b775457760..26ebbada3b0 100644 --- a/crates/starknet_batcher/src/proposal_manager.rs +++ b/crates/starknet_batcher/src/proposal_manager.rs @@ -82,7 +82,7 @@ pub(crate) enum InternalProposalStatus { pub trait ProposalManagerTrait: Send + Sync { async fn start_height(&mut self, height: BlockNumber) -> Result<(), StartHeightError>; - async fn build_block_proposal( + async fn propose_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, @@ -91,7 +91,7 @@ pub trait ProposalManagerTrait: Send + Sync { tx_provider: ProposeTransactionProvider, ) -> Result<(), GenerateProposalError>; - async fn validate_block_proposal( + async fn validate_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, @@ -188,7 +188,7 @@ impl ProposalManagerTrait for ProposalManager { /// transactions from the mempool. /// Requires tx_sender for sending the generated transactions to the caller. #[instrument(skip(self, tx_sender, tx_provider), err, fields(self.active_height))] - async fn build_block_proposal( + async fn propose_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, @@ -221,7 +221,7 @@ impl ProposalManagerTrait for ProposalManager { /// Starts validation of a block proposal for the given proposal_id and height with /// transactions from tx_receiver channel. #[instrument(skip(self, tx_provider), err, fields(self.active_height))] - async fn validate_block_proposal( + async fn validate_block( &mut self, proposal_id: ProposalId, retrospective_block_hash: Option, diff --git a/crates/starknet_batcher/src/proposal_manager_test.rs b/crates/starknet_batcher/src/proposal_manager_test.rs index 0b3ae70b6a2..4c9625f451d 100644 --- a/crates/starknet_batcher/src/proposal_manager_test.rs +++ b/crates/starknet_batcher/src/proposal_manager_test.rs @@ -126,24 +126,24 @@ fn proposal_deadline() -> tokio::time::Instant { tokio::time::Instant::now() + BLOCK_GENERATION_TIMEOUT } -async fn build_proposal_non_blocking( +async fn propose_block_non_blocking( proposal_manager: &mut ProposalManager, tx_provider: ProposeTransactionProvider, proposal_id: ProposalId, ) { let (output_sender, _receiver) = output_streaming(); proposal_manager - .build_block_proposal(proposal_id, None, proposal_deadline(), output_sender, tx_provider) + .propose_block(proposal_id, None, proposal_deadline(), output_sender, tx_provider) .await .unwrap(); } -async fn build_proposal( +async fn propose_block( proposal_manager: &mut ProposalManager, tx_provider: ProposeTransactionProvider, proposal_id: ProposalId, ) { - build_proposal_non_blocking(proposal_manager, tx_provider, proposal_id).await; + propose_block_non_blocking(proposal_manager, tx_provider, proposal_id).await; assert!(proposal_manager.await_active_proposal().await); } @@ -153,7 +153,7 @@ async fn validate_proposal( proposal_id: ProposalId, ) { proposal_manager - .validate_block_proposal(proposal_id, None, proposal_deadline(), tx_provider) + .validate_block(proposal_id, None, proposal_deadline(), tx_provider) .await .unwrap(); @@ -204,7 +204,7 @@ async fn duplicate_start_height(mock_dependencies: MockDependencies) { #[rstest] #[tokio::test] -async fn build_proposal_fails_without_start_height( +async fn propose_block_fails_without_start_height( mock_dependencies: MockDependencies, propose_tx_provider: ProposeTransactionProvider, output_streaming: ( @@ -214,7 +214,7 @@ async fn build_proposal_fails_without_start_height( ) { let mut proposal_manager = proposal_manager(mock_dependencies); let err = proposal_manager - .build_block_proposal( + .propose_block( ProposalId(0), None, proposal_deadline(), @@ -233,14 +233,14 @@ async fn validate_proposal_fails_without_start_height( ) { let mut proposal_manager = proposal_manager(mock_dependencies); let err = proposal_manager - .validate_block_proposal(ProposalId(0), None, proposal_deadline(), validate_tx_provider) + .validate_block(ProposalId(0), None, proposal_deadline(), validate_tx_provider) .await; assert_matches!(err, Err(GenerateProposalError::NoActiveHeight)); } #[rstest] #[tokio::test] -async fn build_proposal_success( +async fn propose_block_success( mut mock_dependencies: MockDependencies, propose_tx_provider: ProposeTransactionProvider, ) { @@ -248,7 +248,7 @@ async fn build_proposal_success( let mut proposal_manager = proposal_manager(mock_dependencies); proposal_manager.start_height(INITIAL_HEIGHT).await.unwrap(); - build_proposal(&mut proposal_manager, propose_tx_provider, ProposalId(0)).await; + propose_block(&mut proposal_manager, propose_tx_provider, ProposalId(0)).await; proposal_manager.take_proposal_result(ProposalId(0)).await.unwrap(); } @@ -279,9 +279,9 @@ async fn consecutive_proposal_generations_success( // Build and validate multiple proposals consecutively (awaiting on them to // make sure they finished successfully). - build_proposal(&mut proposal_manager, propose_tx_provider.clone(), ProposalId(0)).await; + propose_block(&mut proposal_manager, propose_tx_provider.clone(), ProposalId(0)).await; validate_proposal(&mut proposal_manager, validate_tx_provider(), ProposalId(1)).await; - build_proposal(&mut proposal_manager, propose_tx_provider, ProposalId(2)).await; + propose_block(&mut proposal_manager, propose_tx_provider, ProposalId(2)).await; validate_proposal(&mut proposal_manager, validate_tx_provider(), ProposalId(3)).await; } @@ -303,7 +303,7 @@ async fn multiple_proposals_generation_fail( // Build a proposal that will take a very long time to finish. let (output_sender_0, _rec_0) = output_streaming(); proposal_manager - .build_block_proposal( + .propose_block( ProposalId(0), None, proposal_deadline(), @@ -316,7 +316,7 @@ async fn multiple_proposals_generation_fail( // Try to generate another proposal while the first one is still being generated. let (output_sender_1, _rec_1) = output_streaming(); let another_generate_request = proposal_manager - .build_block_proposal( + .propose_block( ProposalId(1), None, proposal_deadline(), @@ -344,7 +344,7 @@ async fn take_proposal_result_no_active_proposal( proposal_manager.start_height(INITIAL_HEIGHT).await.unwrap(); - build_proposal(&mut proposal_manager, propose_tx_provider, ProposalId(0)).await; + propose_block(&mut proposal_manager, propose_tx_provider, ProposalId(0)).await; let expected_proposal_output = ProposalOutput::from(BlockExecutionArtifacts::create_for_testing()); @@ -368,7 +368,7 @@ async fn abort_active_proposal( let mut proposal_manager = proposal_manager(mock_dependencies); proposal_manager.start_height(INITIAL_HEIGHT).await.unwrap(); - build_proposal_non_blocking(&mut proposal_manager, propose_tx_provider, ProposalId(0)).await; + propose_block_non_blocking(&mut proposal_manager, propose_tx_provider, ProposalId(0)).await; proposal_manager.abort_proposal(ProposalId(0)).await; @@ -395,8 +395,8 @@ async fn abort_and_start_new_height( // Start the first height with 2 proposals. proposal_manager.start_height(INITIAL_HEIGHT).await.unwrap(); - build_proposal(&mut proposal_manager, propose_tx_provider.clone(), ProposalId(0)).await; - build_proposal_non_blocking(&mut proposal_manager, propose_tx_provider.clone(), ProposalId(1)) + propose_block(&mut proposal_manager, propose_tx_provider.clone(), ProposalId(0)).await; + propose_block_non_blocking(&mut proposal_manager, propose_tx_provider.clone(), ProposalId(1)) .await; // Start a new height. This should abort and delete all existing proposals. diff --git a/crates/starknet_batcher_types/src/batcher_types.rs b/crates/starknet_batcher_types/src/batcher_types.rs index c2830fc43dd..f12bb25513f 100644 --- a/crates/starknet_batcher_types/src/batcher_types.rs +++ b/crates/starknet_batcher_types/src/batcher_types.rs @@ -31,7 +31,7 @@ pub struct ProposalCommitment { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct BuildProposalInput { +pub struct ProposeBlockInput { pub proposal_id: ProposalId, pub deadline: chrono::DateTime, pub retrospective_block_hash: Option, @@ -59,7 +59,7 @@ pub enum GetProposalContent { #[derive(Clone, Debug, Serialize, Deserialize)] // TODO(Dan): Consider unifying with BuildProposalInput as they have the same fields. -pub struct ValidateProposalInput { +pub struct ValidateBlockInput { pub proposal_id: ProposalId, pub deadline: chrono::DateTime, pub retrospective_block_hash: Option, diff --git a/crates/starknet_batcher_types/src/communication.rs b/crates/starknet_batcher_types/src/communication.rs index 436ad3e13b5..d93d6ef2a1d 100644 --- a/crates/starknet_batcher_types/src/communication.rs +++ b/crates/starknet_batcher_types/src/communication.rs @@ -18,14 +18,14 @@ use thiserror::Error; use crate::batcher_types::{ BatcherResult, - BuildProposalInput, DecisionReachedInput, GetProposalContentInput, GetProposalContentResponse, + ProposeBlockInput, SendProposalContentInput, SendProposalContentResponse, StartHeightInput, - ValidateProposalInput, + ValidateBlockInput, }; use crate::errors::BatcherError; @@ -42,7 +42,7 @@ pub type SharedBatcherClient = Arc; #[async_trait] pub trait BatcherClient: Send + Sync { /// Starts the process of building a proposal. - async fn build_proposal(&self, input: BuildProposalInput) -> BatcherClientResult<()>; + async fn propose_block(&self, input: ProposeBlockInput) -> BatcherClientResult<()>; /// Gets the next available content from the proposal stream (only relevant when building a /// proposal). async fn get_proposal_content( @@ -50,7 +50,7 @@ pub trait BatcherClient: Send + Sync { input: GetProposalContentInput, ) -> BatcherClientResult; /// Starts the process of validating a proposal. - async fn validate_proposal(&self, input: ValidateProposalInput) -> BatcherClientResult<()>; + async fn validate_block(&self, input: ValidateBlockInput) -> BatcherClientResult<()>; /// Sends the content of a proposal. Only relevant when validating a proposal. /// Note: /// * The batcher acks when the content is received immediately, not waiting for it to finish @@ -73,9 +73,9 @@ pub trait BatcherClient: Send + Sync { #[derive(Debug, Serialize, Deserialize, Clone)] pub enum BatcherRequest { - BuildProposal(BuildProposalInput), + ProposeBlock(ProposeBlockInput), GetProposalContent(GetProposalContentInput), - ValidateProposal(ValidateProposalInput), + ValidateBlock(ValidateBlockInput), SendProposalContent(SendProposalContentInput), StartHeight(StartHeightInput), DecisionReached(DecisionReachedInput), @@ -83,9 +83,9 @@ pub enum BatcherRequest { #[derive(Debug, Serialize, Deserialize, Clone)] pub enum BatcherResponse { - BuildProposal(BatcherResult<()>), + ProposeBlock(BatcherResult<()>), GetProposalContent(BatcherResult), - ValidateProposal(BatcherResult<()>), + ValidateBlock(BatcherResult<()>), SendProposalContent(BatcherResult), StartHeight(BatcherResult<()>), DecisionReached(BatcherResult<()>), @@ -104,10 +104,10 @@ impl BatcherClient for ComponentClientType where ComponentClientType: Send + Sync + ComponentClient, { - async fn build_proposal(&self, input: BuildProposalInput) -> BatcherClientResult<()> { - let request = BatcherRequest::BuildProposal(input); + async fn propose_block(&self, input: ProposeBlockInput) -> BatcherClientResult<()> { + let request = BatcherRequest::ProposeBlock(input); let response = self.send(request).await; - handle_response_variants!(BatcherResponse, BuildProposal, BatcherClientError, BatcherError) + handle_response_variants!(BatcherResponse, ProposeBlock, BatcherClientError, BatcherError) } async fn get_proposal_content( @@ -124,15 +124,10 @@ where ) } - async fn validate_proposal(&self, input: ValidateProposalInput) -> BatcherClientResult<()> { - let request = BatcherRequest::ValidateProposal(input); + async fn validate_block(&self, input: ValidateBlockInput) -> BatcherClientResult<()> { + let request = BatcherRequest::ValidateBlock(input); let response = self.send(request).await; - handle_response_variants!( - BatcherResponse, - ValidateProposal, - BatcherClientError, - BatcherError - ) + handle_response_variants!(BatcherResponse, ValidateBlock, BatcherClientError, BatcherError) } async fn send_proposal_content(