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 e9f48948b8..c8a7448968 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs @@ -56,6 +56,7 @@ use starknet_batcher_types::batcher_types::{ }; use starknet_batcher_types::communication::BatcherClient; use starknet_state_sync_types::communication::SharedStateSyncClient; +use starknet_state_sync_types::state_sync_types::SyncBlock; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; use tracing::{debug, debug_span, info, instrument, trace, warn, Instrument}; @@ -325,22 +326,44 @@ impl ConsensusContext for SequencerConsensusContext { // TODO(matan): Broadcast the decision to the network. let proposal_id; + let transactions; { 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; + (transactions, proposal_id) = + proposals.get(&BlockNumber(height)).unwrap().get(&block).unwrap().clone(); + proposals.retain(|&h, _| h > BlockNumber(height)); } // TODO(dvir): return from the batcher's 'decision_reached' function the relevant data to // build a blob. - self.batcher.decision_reached(DecisionReachedInput { proposal_id }).await.unwrap(); + let state_diff = self + .batcher + .decision_reached(DecisionReachedInput { proposal_id }) + .await + .unwrap() + .state_diff; // TODO(dvir): pass here real `BlobParameters` info. // TODO(dvir): when passing here the correct `BlobParameters`, also test that // `prepare_blob_for_next_height` is called with the correct parameters. self.cende_ambassador.prepare_blob_for_next_height(BlobParameters::default()).await; + let transaction_hashes = + transactions.iter().map(|tx| tx.tx_hash()).collect::>(); + + let sync_block = + SyncBlock { block_number: BlockNumber(height), state_diff, transaction_hashes }; + + let state_sync_client = self.state_sync_client.clone(); + tokio::spawn(async move { + state_sync_client + .add_new_block(BlockNumber(height), sync_block) + .await + .expect("Failed to add new block.") + }); + Ok(()) }