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 12ba86891a..7f9f17bc64 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs @@ -294,16 +294,17 @@ impl ConsensusContext for SequencerConsensusContext { // TODO(matan): Broadcast the decision to the network. + let height = BlockNumber(height); let proposal_id; { let mut proposals = self .valid_proposals .lock() .expect("Lock on active proposals was poisoned due to a previous panic"); - proposal_id = proposals.get(&BlockNumber(height)).unwrap().get(&block).unwrap().1; - proposals.retain(|&h, _| h > BlockNumber(height)); + proposal_id = proposals.get(&height).unwrap().get(&block).unwrap().1; + proposals.retain(|&h, _| h > height); } - self.batcher.decision_reached(DecisionReachedInput { proposal_id }).await.unwrap(); + self.batcher.decision_reached(DecisionReachedInput { proposal_id, height }).await.unwrap(); Ok(()) } diff --git a/crates/starknet_batcher/src/batcher.rs b/crates/starknet_batcher/src/batcher.rs index 851e3e02c6..4ccdbf0957 100644 --- a/crates/starknet_batcher/src/batcher.rs +++ b/crates/starknet_batcher/src/batcher.rs @@ -364,7 +364,7 @@ impl Batcher { let address_to_nonce = state_diff.nonces.iter().map(|(k, v)| (*k, *v)).collect(); let tx_hashes = transaction_hashes.into_iter().collect(); - self.commit_proposal_and_block(Some(height), state_diff, address_to_nonce, tx_hashes).await + self.commit_proposal_and_block(height, state_diff, address_to_nonce, tx_hashes).await } #[instrument(skip(self), err)] @@ -384,26 +384,29 @@ impl Batcher { // TODO(Arni): Get the height from the proposal output or from the proposal id. Pass it to // commit proposal and block. set the variable as non-optional. - self.commit_proposal_and_block(None, state_diff.clone(), address_to_nonce, tx_hashes) - .await?; + self.commit_proposal_and_block( + input.height, + state_diff.clone(), + address_to_nonce, + tx_hashes, + ) + .await?; Ok(DecisionReachedResponse { state_diff }) } async fn commit_proposal_and_block( &mut self, - proposed_height: Option, + proposed_height: BlockNumber, state_diff: ThinStateDiff, address_to_nonce: HashMap, tx_hashes: HashSet, ) -> BatcherResult<()> { let height = self.get_height_from_storage()?; - if let Some(proposed_height) = proposed_height { - if height != proposed_height { - panic!( - "Proposed height {} does not match the current height {}.", - proposed_height, height - ); - } + if height != proposed_height { + panic!( + "Proposed height {} does not match the current height {}.", + proposed_height, height + ); } info!("Committing block at height {} and notifying mempool of the block.", height); diff --git a/crates/starknet_batcher/src/batcher_test.rs b/crates/starknet_batcher/src/batcher_test.rs index 5aa4b66215..7ba301382c 100644 --- a/crates/starknet_batcher/src/batcher_test.rs +++ b/crates/starknet_batcher/src/batcher_test.rs @@ -555,8 +555,10 @@ async fn decision_reached() { let mut batcher = create_batcher(mock_dependencies); - let response = - batcher.decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID }).await.unwrap(); + let response = batcher + .decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID, height: INITIAL_HEIGHT }) + .await + .unwrap(); assert_eq!(response.state_diff, test_state_diff()); } @@ -573,8 +575,9 @@ async fn decision_reached_no_executed_proposal() { .return_once(|_| async move { None }.boxed()); let mut batcher = create_batcher(MockDependencies { proposal_manager, ..Default::default() }); - let decision_reached_result = - batcher.decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID }).await; + let decision_reached_result = batcher + .decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID, height: INITIAL_HEIGHT }) + .await; assert_eq!(decision_reached_result, Err(expected_error)); } diff --git a/crates/starknet_batcher_types/src/batcher_types.rs b/crates/starknet_batcher_types/src/batcher_types.rs index 09765aeb2d..ba172fe82e 100644 --- a/crates/starknet_batcher_types/src/batcher_types.rs +++ b/crates/starknet_batcher_types/src/batcher_types.rs @@ -114,6 +114,7 @@ pub struct StartHeightInput { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct DecisionReachedInput { pub proposal_id: ProposalId, + pub height: BlockNumber, } pub type BatcherResult = Result;