From d89c5fb5e35250b63e0c8b6e0828f91565d4f98e Mon Sep 17 00:00:00 2001 From: Arnon Hod Date: Tue, 17 Dec 2024 15:24:30 +0200 Subject: [PATCH] feat(starknet_batcher): add state diff to decision reached response (#2722) --- crates/starknet_batcher/src/batcher.rs | 4 ++-- crates/starknet_batcher/src/batcher_test.rs | 8 +++++--- crates/starknet_batcher_types/src/batcher_types.rs | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/starknet_batcher/src/batcher.rs b/crates/starknet_batcher/src/batcher.rs index d03d1a5fe4..950ddce4f0 100644 --- a/crates/starknet_batcher/src/batcher.rs +++ b/crates/starknet_batcher/src/batcher.rs @@ -383,8 +383,8 @@ impl Batcher { let ProposalOutput { state_diff, nonces: address_to_nonce, tx_hashes, .. } = proposal_output; - self.commit_proposal_and_block(state_diff, address_to_nonce, tx_hashes).await?; - Ok(DecisionReachedResponse {}) + self.commit_proposal_and_block(state_diff.clone(), address_to_nonce, tx_hashes).await?; + Ok(DecisionReachedResponse { state_diff }) } async fn commit_proposal_and_block( diff --git a/crates/starknet_batcher/src/batcher_test.rs b/crates/starknet_batcher/src/batcher_test.rs index e55d76bf45..d776e08abe 100644 --- a/crates/starknet_batcher/src/batcher_test.rs +++ b/crates/starknet_batcher/src/batcher_test.rs @@ -526,7 +526,7 @@ async fn decision_reached() { .return_once(move |_| { async move { Some(Ok(ProposalOutput { - state_diff: ThinStateDiff::default(), + state_diff: test_state_diff(), commitment: ProposalCommitment::default(), tx_hashes: test_tx_hashes(), nonces: test_contract_nonces(), @@ -549,12 +549,14 @@ async fn decision_reached() { .storage_writer .expect_commit_proposal() .times(1) - .with(eq(INITIAL_HEIGHT), eq(ThinStateDiff::default())) + .with(eq(INITIAL_HEIGHT), eq(test_state_diff())) .returning(|_, _| Ok(())); let mut batcher = create_batcher(mock_dependencies); - batcher.decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID }).await.unwrap(); + let response = + batcher.decision_reached(DecisionReachedInput { proposal_id: PROPOSAL_ID }).await.unwrap(); + assert_eq!(response.state_diff, test_state_diff()); } #[rstest] diff --git a/crates/starknet_batcher_types/src/batcher_types.rs b/crates/starknet_batcher_types/src/batcher_types.rs index fd0032dbeb..09765aeb2d 100644 --- a/crates/starknet_batcher_types/src/batcher_types.rs +++ b/crates/starknet_batcher_types/src/batcher_types.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; use starknet_api::block::{BlockHashAndNumber, BlockInfo, BlockNumber}; use starknet_api::core::StateDiffCommitment; use starknet_api::executable_transaction::Transaction; +use starknet_api::state::ThinStateDiff; use crate::errors::BatcherError; @@ -89,7 +90,9 @@ pub struct SendProposalContentResponse { } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct DecisionReachedResponse {} +pub struct DecisionReachedResponse { + pub state_diff: ThinStateDiff, +} #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub enum ProposalStatus {