diff --git a/crates/papyrus_p2p_sync/src/client/header.rs b/crates/papyrus_p2p_sync/src/client/header.rs index 37f5d101de..635a09b559 100644 --- a/crates/papyrus_p2p_sync/src/client/header.rs +++ b/crates/papyrus_p2p_sync/src/client/header.rs @@ -122,7 +122,6 @@ impl DataStreamBuilder for HeaderStreamBuilder { } // TODO(Eitan): Use real header once SyncBlock contains data required by full nodes - // TODO(Eitan): Fill this with real header once SyncBlock has it. fn convert_sync_block_to_block_data( block_number: BlockNumber, sync_block: SyncBlock, @@ -132,6 +131,12 @@ impl DataStreamBuilder for HeaderStreamBuilder { block_hash: BlockHash(StarkHash::from(block_number.0)), block_header_without_hash: BlockHeaderWithoutHash { block_number, + timestamp: sync_block.timestamp, + l1_da_mode: sync_block.l1_da_mode, + sequencer: sync_block.sequencer, + l1_gas_price: sync_block.l1_gas_price, + l1_data_gas_price: sync_block.l1_data_gas_price, + l2_gas_price: sync_block.l2_gas_price, ..Default::default() }, state_diff_length: Some(sync_block.state_diff.len()), diff --git a/crates/starknet_batcher/src/batcher.rs b/crates/starknet_batcher/src/batcher.rs index 0aabda1a2a..f8684e6d58 100644 --- a/crates/starknet_batcher/src/batcher.rs +++ b/crates/starknet_batcher/src/batcher.rs @@ -384,8 +384,8 @@ impl Batcher { self.abort_active_height().await; self.active_height = None; } - - let SyncBlock { state_diff, transaction_hashes, block_number } = sync_block; + // TODO(AlonH): Use additional data from the sync block. + let SyncBlock { state_diff, transaction_hashes, block_number, .. } = sync_block; let address_to_nonce = state_diff.nonces.iter().map(|(k, v)| (*k, *v)).collect(); let tx_hashes = transaction_hashes.into_iter().collect(); let height = self.get_height_from_storage()?; diff --git a/crates/starknet_batcher/src/batcher_test.rs b/crates/starknet_batcher/src/batcher_test.rs index 704f31f3ca..b11791cd18 100644 --- a/crates/starknet_batcher/src/batcher_test.rs +++ b/crates/starknet_batcher/src/batcher_test.rs @@ -512,6 +512,7 @@ async fn add_sync_block() { block_number: INITIAL_HEIGHT, state_diff: test_state_diff(), transaction_hashes: test_tx_hashes().into_iter().collect(), + ..Default::default() }; batcher.add_sync_block(sync_block).await.unwrap(); } @@ -522,11 +523,8 @@ async fn add_sync_block() { async fn add_sync_block_mismatch_block_number() { let mut batcher = create_batcher(MockDependencies::default()); - let sync_block = SyncBlock { - block_number: INITIAL_HEIGHT.unchecked_next(), - state_diff: Default::default(), - transaction_hashes: Default::default(), - }; + let sync_block = + SyncBlock { block_number: INITIAL_HEIGHT.unchecked_next(), ..Default::default() }; batcher.add_sync_block(sync_block).await.unwrap(); } diff --git a/crates/starknet_state_sync/src/lib.rs b/crates/starknet_state_sync/src/lib.rs index 322e5cd70f..c2ccae1ebd 100644 --- a/crates/starknet_state_sync/src/lib.rs +++ b/crates/starknet_state_sync/src/lib.rs @@ -7,6 +7,7 @@ use futures::SinkExt; use papyrus_storage::body::BodyStorageReader; use papyrus_storage::compiled_class::CasmStorageReader; use papyrus_storage::db::TransactionKind; +use papyrus_storage::header::HeaderStorageReader; use papyrus_storage::state::StateStorageReader; use papyrus_storage::{StorageReader, StorageTxn}; use starknet_api::block::BlockNumber; @@ -80,17 +81,27 @@ impl ComponentRequestHandler for StateSync impl StateSync { fn get_block(&self, block_number: BlockNumber) -> StateSyncResult> { let txn = self.storage_reader.begin_ro_txn()?; - if let Some(block_transaction_hashes) = txn.get_block_transaction_hashes(block_number)? { - if let Some(thin_state_diff) = txn.get_state_diff(block_number)? { - return Ok(Some(SyncBlock { - block_number, - state_diff: thin_state_diff, - transaction_hashes: block_transaction_hashes, - })); - } - } - - Ok(None) + let block_header = txn.get_block_header(block_number)?; + let Some(block_transaction_hashes) = txn.get_block_transaction_hashes(block_number)? else { + return Ok(None); + }; + let Some(thin_state_diff) = txn.get_state_diff(block_number)? else { + return Ok(None); + }; + let Some(block_header) = block_header else { + return Ok(None); + }; + Ok(Some(SyncBlock { + state_diff: thin_state_diff, + block_number, + timestamp: block_header.block_header_without_hash.timestamp, + sequencer: block_header.block_header_without_hash.sequencer, + l1_gas_price: block_header.block_header_without_hash.l1_gas_price, + l1_data_gas_price: block_header.block_header_without_hash.l1_data_gas_price, + l2_gas_price: block_header.block_header_without_hash.l2_gas_price, + l1_da_mode: block_header.block_header_without_hash.l1_da_mode, + transaction_hashes: block_transaction_hashes, + })) } fn get_storage_at( diff --git a/crates/starknet_state_sync_types/src/communication.rs b/crates/starknet_state_sync_types/src/communication.rs index 4c1a56c794..512e774e91 100644 --- a/crates/starknet_state_sync_types/src/communication.rs +++ b/crates/starknet_state_sync_types/src/communication.rs @@ -95,6 +95,7 @@ pub enum StateSyncRequest { } #[derive(Clone, Debug, Serialize, Deserialize)] +#[allow(clippy::large_enum_variant)] pub enum StateSyncResponse { GetBlock(StateSyncResult>), AddNewBlock(StateSyncResult<()>), diff --git a/crates/starknet_state_sync_types/src/state_sync_types.rs b/crates/starknet_state_sync_types/src/state_sync_types.rs index a44350272b..d1239d2a44 100644 --- a/crates/starknet_state_sync_types/src/state_sync_types.rs +++ b/crates/starknet_state_sync_types/src/state_sync_types.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; -use starknet_api::block::BlockNumber; +use starknet_api::block::{BlockNumber, BlockTimestamp, GasPricePerToken}; +use starknet_api::core::SequencerContractAddress; +use starknet_api::data_availability::L1DataAvailabilityMode; use starknet_api::state::ThinStateDiff; use starknet_api::transaction::TransactionHash; @@ -12,10 +14,17 @@ pub type StateSyncResult = Result; /// /// Blocks that came from the state sync are trusted. Therefore, SyncBlock doesn't contain data /// needed for verifying the block -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct SyncBlock { - pub block_number: BlockNumber, pub state_diff: ThinStateDiff, // TODO: decide if we want block hash, parent block hash and full classes here. pub transaction_hashes: Vec, + + pub block_number: BlockNumber, + pub timestamp: BlockTimestamp, + pub sequencer: SequencerContractAddress, + pub l1_gas_price: GasPricePerToken, + pub l1_data_gas_price: GasPricePerToken, + pub l2_gas_price: GasPricePerToken, + pub l1_da_mode: L1DataAvailabilityMode, }