diff --git a/crates/katana/core/src/backend/mod.rs b/crates/katana/core/src/backend/mod.rs index d8c957b538..82b0d980ef 100644 --- a/crates/katana/core/src/backend/mod.rs +++ b/crates/katana/core/src/backend/mod.rs @@ -2,12 +2,13 @@ use std::sync::Arc; use katana_executor::{ExecutionOutput, ExecutionResult, ExecutorFactory}; use katana_primitives::block::{ - Block, FinalityStatus, GasPrices, Header, PartialHeader, SealedBlockWithStatus, + Block, FinalityStatus, GasPrices, Header, SealedBlock, SealedBlockWithStatus, }; use katana_primitives::chain_spec::ChainSpec; use katana_primitives::da::L1DataAvailabilityMode; use katana_primitives::env::BlockEnv; -use katana_primitives::transaction::TxHash; +use katana_primitives::receipt::Receipt; +use katana_primitives::transaction::{TxHash, TxWithHash}; use katana_primitives::Felt; use katana_provider::traits::block::{BlockHashProvider, BlockWriter}; use parking_lot::RwLock; @@ -35,6 +36,7 @@ pub struct Backend { } impl Backend { + // TODO: add test for this function pub fn do_mine_block( &self, block_env: &BlockEnv, @@ -54,47 +56,22 @@ impl Backend { } } - let prev_hash = BlockHashProvider::latest_hash(self.blockchain.provider())?; - let block_number = block_env.number; - let tx_count = txs.len(); - - let partial_header = PartialHeader { - number: block_number, - parent_hash: prev_hash, - version: self.chain_spec.version.clone(), - timestamp: block_env.timestamp, - sequencer_address: block_env.sequencer_address, - l1_da_mode: L1DataAvailabilityMode::Calldata, - l1_gas_prices: GasPrices { - eth: block_env.l1_gas_prices.eth, - strk: block_env.l1_gas_prices.strk, - }, - l1_data_gas_prices: GasPrices { - eth: block_env.l1_data_gas_prices.eth, - strk: block_env.l1_data_gas_prices.strk, - }, - }; - + let tx_count = txs.len() as u32; let tx_hashes = txs.iter().map(|tx| tx.hash).collect::>(); - let header = Header::new(partial_header, Felt::ZERO); - let block = Block { header, body: txs }.seal(); + + // create a new block and compute its commitment + let block = self.commit_block(block_env, txs, &receipts)?; let block = SealedBlockWithStatus { block, status: FinalityStatus::AcceptedOnL2 }; + let block_number = block.block.header.number; - BlockWriter::insert_block_with_states_and_receipts( - self.blockchain.provider(), + self.blockchain.provider().insert_block_with_states_and_receipts( block, execution_output.states, receipts, traces, )?; - info!( - target: LOG_TARGET, - block_number = %block_number, - tx_count = %tx_count, - "Block mined.", - ); - + info!(target: LOG_TARGET, %block_number, %tx_count, "Block mined."); Ok(MinedBlockOutcome { block_number, txs: tx_hashes, stats: execution_output.stats }) } @@ -121,4 +98,44 @@ impl Backend { ) -> Result { self.do_mine_block(block_env, Default::default()) } + + fn commit_block( + &self, + block_env: &BlockEnv, + transactions: Vec, + receipts: &[Receipt], + ) -> Result { + // get the hash of the latest committed block + let parent_hash = self.blockchain.provider().latest_hash()?; + let events_count = receipts.iter().map(|r| r.events().len() as u32).sum::(); + let transaction_count = transactions.len() as u32; + + let l1_gas_prices = + GasPrices { eth: block_env.l1_gas_prices.eth, strk: block_env.l1_gas_prices.strk }; + let l1_data_gas_prices = GasPrices { + eth: block_env.l1_data_gas_prices.eth, + strk: block_env.l1_data_gas_prices.strk, + }; + + let header = Header { + parent_hash, + events_count, + l1_gas_prices, + transaction_count, + l1_data_gas_prices, + state_root: Felt::ZERO, + number: block_env.number, + events_commitment: Felt::ZERO, + timestamp: block_env.timestamp, + receipts_commitment: Felt::ZERO, + state_diff_commitment: Felt::ZERO, + transactions_commitment: Felt::ZERO, + l1_da_mode: L1DataAvailabilityMode::Calldata, + sequencer_address: block_env.sequencer_address, + protocol_version: self.chain_spec.version.clone(), + }; + + let sealed = Block { header, body: transactions }.seal(); + Ok(sealed) + } } diff --git a/crates/katana/core/src/backend/storage.rs b/crates/katana/core/src/backend/storage.rs index 9781135fdd..6b4b989026 100644 --- a/crates/katana/core/src/backend/storage.rs +++ b/crates/katana/core/src/backend/storage.rs @@ -353,18 +353,15 @@ mod tests { let block_number = blockchain.provider().latest_number().unwrap(); let block_hash = blockchain.provider().latest_hash().unwrap(); - let block = blockchain - .provider() - .block_by_hash(dummy_block.block.header.hash) - .unwrap() - .unwrap(); + let block = + blockchain.provider().block_by_hash(dummy_block.block.hash).unwrap().unwrap(); let tx = blockchain.provider().transaction_by_hash(dummy_tx.hash).unwrap().unwrap(); let tx_exec = blockchain.provider().transaction_execution(dummy_tx.hash).unwrap().unwrap(); - assert_eq!(block_hash, dummy_block.block.header.hash); - assert_eq!(block_number, dummy_block.block.header.header.number); + assert_eq!(block_hash, dummy_block.block.hash); + assert_eq!(block_number, dummy_block.block.header.number); assert_eq!(block, dummy_block.block.unseal()); assert_eq!(tx, dummy_tx); assert_eq!(tx_exec, TxExecInfo::default()); diff --git a/crates/katana/core/src/service/block_producer.rs b/crates/katana/core/src/service/block_producer.rs index aa08a3937c..07ef33aa62 100644 --- a/crates/katana/core/src/service/block_producer.rs +++ b/crates/katana/core/src/service/block_producer.rs @@ -581,7 +581,7 @@ impl InstantBlockProducer { parent_hash, number: block_env.number, timestamp: block_env.timestamp, - version: backend.chain_spec.version.clone(), + protocol_version: backend.chain_spec.version.clone(), sequencer_address: block_env.sequencer_address, l1_da_mode: L1DataAvailabilityMode::Calldata, l1_gas_prices: block_env.l1_gas_prices.clone(), diff --git a/crates/katana/executor/tests/fixtures/mod.rs b/crates/katana/executor/tests/fixtures/mod.rs index 6390374a26..716d2c32e7 100644 --- a/crates/katana/executor/tests/fixtures/mod.rs +++ b/crates/katana/executor/tests/fixtures/mod.rs @@ -89,7 +89,7 @@ pub fn state_provider(chain: &ChainSpec) -> Box { /// [state_provider]. #[rstest::fixture] pub fn valid_blocks() -> [ExecutableBlock; 3] { - let version = CURRENT_STARKNET_VERSION; + let protocol_version = CURRENT_STARKNET_VERSION; let chain_id = ChainId::parse("KATANA").unwrap(); let sequencer_address = ContractAddress(1u64.into()); @@ -103,7 +103,7 @@ pub fn valid_blocks() -> [ExecutableBlock; 3] { [ ExecutableBlock { header: PartialHeader { - version: version.clone(), + protocol_version: protocol_version.clone(), number: 1, timestamp: 100, sequencer_address, @@ -153,7 +153,7 @@ pub fn valid_blocks() -> [ExecutableBlock; 3] { }, ExecutableBlock { header: PartialHeader { - version: version.clone(), + protocol_version: protocol_version.clone(), number: 2, timestamp: 200, sequencer_address, @@ -186,7 +186,7 @@ pub fn valid_blocks() -> [ExecutableBlock; 3] { }, ExecutableBlock { header: PartialHeader { - version, + protocol_version, number: 3, timestamp: 300, sequencer_address, diff --git a/crates/katana/primitives/src/block.rs b/crates/katana/primitives/src/block.rs index 7fd904cf32..8e8a6492d7 100644 --- a/crates/katana/primitives/src/block.rs +++ b/crates/katana/primitives/src/block.rs @@ -42,14 +42,14 @@ pub enum FinalityStatus { #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PartialHeader { + pub parent_hash: BlockHash, pub number: BlockNumber, - pub parent_hash: Felt, pub timestamp: u64, pub sequencer_address: ContractAddress, - pub version: ProtocolVersion, pub l1_gas_prices: GasPrices, pub l1_data_gas_prices: GasPrices, pub l1_da_mode: L1DataAvailabilityMode, + pub protocol_version: ProtocolVersion, } // TODO: change names to wei and fri @@ -77,51 +77,49 @@ impl GasPrices { pub struct Header { pub parent_hash: BlockHash, pub number: BlockNumber, - pub timestamp: u64, + pub state_diff_commitment: Felt, + pub transactions_commitment: Felt, + pub receipts_commitment: Felt, + pub events_commitment: Felt, pub state_root: Felt, + pub timestamp: u64, + pub transaction_count: u32, + pub events_count: u32, pub sequencer_address: ContractAddress, - pub protocol_version: ProtocolVersion, pub l1_gas_prices: GasPrices, pub l1_data_gas_prices: GasPrices, pub l1_da_mode: L1DataAvailabilityMode, + pub protocol_version: ProtocolVersion, } impl Default for Header { fn default() -> Self { Self { timestamp: 0, + events_count: 0, + transaction_count: 0, + state_root: Felt::ZERO, + events_commitment: Felt::ZERO, number: BlockNumber::default(), - state_root: Felt::default(), + receipts_commitment: Felt::ZERO, + state_diff_commitment: Felt::ZERO, parent_hash: BlockHash::default(), l1_gas_prices: GasPrices::default(), - protocol_version: ProtocolVersion::default(), - sequencer_address: ContractAddress::default(), + transactions_commitment: Felt::ZERO, l1_data_gas_prices: GasPrices::default(), + sequencer_address: ContractAddress::default(), l1_da_mode: L1DataAvailabilityMode::Calldata, + protocol_version: ProtocolVersion::default(), } } } impl Header { - pub fn new(partial_header: PartialHeader, state_root: Felt) -> Self { - Self { - state_root, - number: partial_header.number, - protocol_version: partial_header.version, - timestamp: partial_header.timestamp, - parent_hash: partial_header.parent_hash, - sequencer_address: partial_header.sequencer_address, - l1_gas_prices: partial_header.l1_gas_prices, - l1_da_mode: partial_header.l1_da_mode, - l1_data_gas_prices: partial_header.l1_data_gas_prices, - } - } - /// Computes the hash of the header. pub fn compute_hash(&self) -> Felt { compute_hash_on_elements(&vec![ self.number.into(), // block number - self.state_root, // state root + Felt::ZERO, // state root self.sequencer_address.into(), // sequencer address self.timestamp.into(), // block timestamp Felt::ZERO, // transaction commitment @@ -131,11 +129,6 @@ impl Header { self.parent_hash, // parent hash ]) } - - fn seal(self) -> SealedHeader { - let hash = self.compute_hash(); - SealedHeader { hash, header: self } - } } /// Represents a Starknet full block. @@ -156,12 +149,13 @@ pub struct BlockWithTxHashes { impl Block { /// Seals the block. This computes the hash of the block. pub fn seal(self) -> SealedBlock { - SealedBlock { header: self.header.seal(), body: self.body } + let hash = self.header.compute_hash(); + SealedBlock { hash, header: self.header, body: self.body } } /// Seals the block with a given hash. pub fn seal_with_hash(self, hash: BlockHash) -> SealedBlock { - SealedBlock { header: SealedHeader { hash, header: self.header }, body: self.body } + SealedBlock { hash, header: self.header, body: self.body } } /// Seals the block with a given block hash and status. @@ -174,27 +168,21 @@ impl Block { } } +/// A full Starknet block that has been sealed. #[derive(Debug, Clone)] -pub struct SealedHeader { - /// The hash of the header. +pub struct SealedBlock { + /// The block hash. pub hash: BlockHash, /// The block header. pub header: Header, -} - -/// A full Starknet block that has been sealed. -#[derive(Debug, Clone)] -pub struct SealedBlock { - /// The sealed block header. - pub header: SealedHeader, - /// The block body. + /// The block transactions. pub body: Vec, } impl SealedBlock { /// Unseal the block. pub fn unseal(self) -> Block { - Block { header: self.header.header, body: self.body } + Block { header: self.header, body: self.body } } } diff --git a/crates/katana/primitives/src/chain_spec.rs b/crates/katana/primitives/src/chain_spec.rs index 22474c4340..c574600bd5 100644 --- a/crates/katana/primitives/src/chain_spec.rs +++ b/crates/katana/primitives/src/chain_spec.rs @@ -55,6 +55,12 @@ impl ChainSpec { protocol_version: self.version.clone(), number: self.genesis.number, timestamp: self.genesis.timestamp, + events_count: 0, + transaction_count: 0, + events_commitment: Felt::ZERO, + receipts_commitment: Felt::ZERO, + state_diff_commitment: Felt::ZERO, + transactions_commitment: Felt::ZERO, state_root: self.genesis.state_root, parent_hash: self.genesis.parent_hash, l1_da_mode: L1DataAvailabilityMode::Calldata, @@ -338,9 +344,12 @@ mod tests { }; // setup expected storage values - let expected_block = Block { header: Header { + events_commitment: Felt::ZERO, + receipts_commitment: Felt::ZERO, + state_diff_commitment: Felt::ZERO, + transactions_commitment: Felt::ZERO, number: chain_spec.genesis.number, timestamp: chain_spec.genesis.timestamp, state_root: chain_spec.genesis.state_root, @@ -350,6 +359,8 @@ mod tests { l1_data_gas_prices: chain_spec.genesis.gas_prices.clone(), l1_da_mode: L1DataAvailabilityMode::Calldata, protocol_version: CURRENT_STARKNET_VERSION, + transaction_count: 0, + events_count: 0, }, body: Vec::new(), }; @@ -361,7 +372,6 @@ mod tests { assert_eq!(actual_block.header.number, expected_block.header.number); assert_eq!(actual_block.header.timestamp, expected_block.header.timestamp); - assert_eq!(actual_block.header.state_root, expected_block.header.state_root); assert_eq!(actual_block.header.parent_hash, expected_block.header.parent_hash); assert_eq!(actual_block.header.sequencer_address, expected_block.header.sequencer_address); assert_eq!(actual_block.header.l1_gas_prices, expected_block.header.l1_gas_prices); @@ -371,6 +381,8 @@ mod tests { ); assert_eq!(actual_block.header.l1_da_mode, expected_block.header.l1_da_mode); assert_eq!(actual_block.header.protocol_version, expected_block.header.protocol_version); + assert_eq!(actual_block.header.transaction_count, expected_block.header.transaction_count); + assert_eq!(actual_block.header.events_count, expected_block.header.events_count); assert_eq!(actual_block.body, expected_block.body); if cfg!(feature = "slot") { diff --git a/crates/katana/rpc/rpc-types/src/block.rs b/crates/katana/rpc/rpc-types/src/block.rs index 16dfd7bd5c..7636d542ff 100644 --- a/crates/katana/rpc/rpc-types/src/block.rs +++ b/crates/katana/rpc/rpc-types/src/block.rs @@ -72,7 +72,7 @@ impl PendingBlockWithTxs { l1_gas_price, timestamp: header.timestamp, parent_hash: header.parent_hash, - starknet_version: header.version.to_string(), + starknet_version: header.protocol_version.to_string(), sequencer_address: header.sequencer_address.into(), l1_da_mode: L1DataAvailabilityMode::Calldata, @@ -153,7 +153,7 @@ impl PendingBlockWithTxHashes { l1_gas_price, timestamp: header.timestamp, parent_hash: header.parent_hash, - starknet_version: header.version.to_string(), + starknet_version: header.protocol_version.to_string(), sequencer_address: header.sequencer_address.into(), l1_da_mode: header.l1_da_mode, l1_data_gas_price, @@ -268,7 +268,7 @@ impl PendingBlockWithReceipts { parent_hash: header.parent_hash, l1_da_mode: header.l1_da_mode, l1_data_gas_price, - starknet_version: header.version.to_string(), + starknet_version: header.protocol_version.to_string(), }) } } diff --git a/crates/katana/rpc/rpc/src/starknet/read.rs b/crates/katana/rpc/rpc/src/starknet/read.rs index 4346e337ba..899f7fb33a 100644 --- a/crates/katana/rpc/rpc/src/starknet/read.rs +++ b/crates/katana/rpc/rpc/src/starknet/read.rs @@ -90,7 +90,7 @@ impl StarknetApiServer for StarknetApi { number: block_env.number, parent_hash: latest_hash, timestamp: block_env.timestamp, - version: this.inner.backend.chain_spec.version.clone(), + protocol_version: this.inner.backend.chain_spec.version.clone(), sequencer_address: block_env.sequencer_address, }; @@ -182,7 +182,7 @@ impl StarknetApiServer for StarknetApi { parent_hash: latest_hash, timestamp: block_env.timestamp, sequencer_address: block_env.sequencer_address, - version: this.inner.backend.chain_spec.version.clone(), + protocol_version: this.inner.backend.chain_spec.version.clone(), }; // TODO(kariy): create a method that can perform this filtering for us instead @@ -240,7 +240,7 @@ impl StarknetApiServer for StarknetApi { l1_data_gas_prices, number: block_env.number, parent_hash: latest_hash, - version: this.inner.backend.chain_spec.version.clone(), + protocol_version: this.inner.backend.chain_spec.version.clone(), timestamp: block_env.timestamp, sequencer_address: block_env.sequencer_address, }; diff --git a/crates/katana/storage/db/src/version.rs b/crates/katana/storage/db/src/version.rs index c1600f0b0c..bd879ec249 100644 --- a/crates/katana/storage/db/src/version.rs +++ b/crates/katana/storage/db/src/version.rs @@ -5,7 +5,7 @@ use std::mem; use std::path::{Path, PathBuf}; /// Current version of the database. -pub const CURRENT_DB_VERSION: u32 = 2; +pub const CURRENT_DB_VERSION: u32 = 3; /// Name of the version file. const DB_VERSION_FILE_NAME: &str = "db.version"; @@ -81,6 +81,6 @@ mod tests { #[test] fn test_current_version() { use super::CURRENT_DB_VERSION; - assert_eq!(CURRENT_DB_VERSION, 2, "Invalid current database version") + assert_eq!(CURRENT_DB_VERSION, 3, "Invalid current database version") } } diff --git a/crates/katana/storage/provider/src/providers/db/mod.rs b/crates/katana/storage/provider/src/providers/db/mod.rs index 77a1c03ad0..87dc8498cb 100644 --- a/crates/katana/storage/provider/src/providers/db/mod.rs +++ b/crates/katana/storage/provider/src/providers/db/mod.rs @@ -606,10 +606,10 @@ impl BlockWriter for DbProvider { executions: Vec, ) -> ProviderResult<()> { self.0.update(move |db_tx| -> ProviderResult<()> { - let block_hash = block.block.header.hash; - let block_number = block.block.header.header.number; + let block_hash = block.block.hash; + let block_number = block.block.header.number; - let block_header = block.block.header.header; + let block_header = block.block.header; let transactions = block.block.body; let tx_count = transactions.len() as u64; @@ -882,7 +882,7 @@ mod tests { // get values - let block_id: BlockHashOrNumber = block.block.header.hash.into(); + let block_id: BlockHashOrNumber = block.block.hash.into(); let latest_number = provider.latest_number().unwrap(); let latest_hash = provider.latest_hash().unwrap(); @@ -921,9 +921,9 @@ mod tests { assert_eq!(body_indices.tx_count, tx_count); assert_eq!(block_status, FinalityStatus::AcceptedOnL2); - assert_eq!(block.block.header.hash, latest_hash); + assert_eq!(block.block.hash, latest_hash); assert_eq!(block.block.body.len() as u64, tx_count); - assert_eq!(block.block.header.header.number, latest_number); + assert_eq!(block.block.header.number, latest_number); assert_eq!(block.block.unseal(), actual_block); assert_eq!(nonce1, felt!("1")); diff --git a/crates/katana/storage/provider/src/providers/fork/mod.rs b/crates/katana/storage/provider/src/providers/fork/mod.rs index a11cea3e54..5383d3c960 100644 --- a/crates/katana/storage/provider/src/providers/fork/mod.rs +++ b/crates/katana/storage/provider/src/providers/fork/mod.rs @@ -469,10 +469,10 @@ impl BlockWriter for ForkedProvider { ) -> ProviderResult<()> { let mut storage = self.storage.write(); - let block_hash = block.block.header.hash; - let block_number = block.block.header.header.number; + let block_hash = block.block.hash; + let block_number = block.block.header.number; - let block_header = block.block.header.header; + let block_header = block.block.header; let txs = block.block.body; // create block body indices diff --git a/crates/katana/storage/provider/src/providers/in_memory/mod.rs b/crates/katana/storage/provider/src/providers/in_memory/mod.rs index 34b7172419..869ca50c3c 100644 --- a/crates/katana/storage/provider/src/providers/in_memory/mod.rs +++ b/crates/katana/storage/provider/src/providers/in_memory/mod.rs @@ -463,10 +463,10 @@ impl BlockWriter for InMemoryProvider { ) -> ProviderResult<()> { let mut storage = self.storage.write(); - let block_hash = block.block.header.hash; - let block_number = block.block.header.header.number; + let block_hash = block.block.hash; + let block_number = block.block.header.number; - let block_header = block.block.header.header; + let block_header = block.block.header; let txs = block.block.body; // create block body indices diff --git a/crates/katana/storage/provider/tests/block.rs b/crates/katana/storage/provider/tests/block.rs index 8d1b5c33f5..5f11a6cf10 100644 --- a/crates/katana/storage/provider/tests/block.rs +++ b/crates/katana/storage/provider/tests/block.rs @@ -100,8 +100,8 @@ where executions.clone(), )?; - assert_eq!(provider.latest_number().unwrap(), block.block.header.header.number); - assert_eq!(provider.latest_hash().unwrap(), block.block.header.hash); + assert_eq!(provider.latest_number().unwrap(), block.block.header.number); + assert_eq!(provider.latest_hash().unwrap(), block.block.hash); } let actual_transactions_in_range = provider.transaction_in_range(0..total_txs).unwrap(); @@ -117,10 +117,10 @@ where ); for (block, receipts, executions) in blocks { - let block_id = BlockHashOrNumber::Hash(block.block.header.hash); + let block_id = BlockHashOrNumber::Hash(block.block.hash); - let expected_block_num = block.block.header.header.number; - let expected_block_hash = block.block.header.hash; + let expected_block_num = block.block.header.number; + let expected_block_hash = block.block.hash; let expected_block = block.block.unseal(); let expected_block_env = BlockEnv { @@ -210,8 +210,8 @@ where vec![], )?; - assert_eq!(provider.latest_number().unwrap(), block.block.header.header.number); - assert_eq!(provider.latest_hash().unwrap(), block.block.header.hash); + assert_eq!(provider.latest_number().unwrap(), block.block.header.number); + assert_eq!(provider.latest_hash().unwrap(), block.block.hash); } let actual_blocks_in_range = provider.blocks_in_range(0..=count)?; @@ -223,10 +223,10 @@ where ); for block in blocks { - let block_id = BlockHashOrNumber::Hash(block.block.header.hash); + let block_id = BlockHashOrNumber::Hash(block.block.hash); - let expected_block_num = block.block.header.header.number; - let expected_block_hash = block.block.header.hash; + let expected_block_num = block.block.header.number; + let expected_block_hash = block.block.hash; let expected_block = block.block.unseal(); let expected_block_env = BlockEnv { diff --git a/crates/katana/storage/provider/tests/fixtures.rs b/crates/katana/storage/provider/tests/fixtures.rs index e5a08186cb..776aa3c04a 100644 --- a/crates/katana/storage/provider/tests/fixtures.rs +++ b/crates/katana/storage/provider/tests/fixtures.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use katana_db::mdbx; use katana_primitives::address; use katana_primitives::block::{ - BlockHashOrNumber, FinalityStatus, Header, SealedBlock, SealedBlockWithStatus, SealedHeader, + BlockHashOrNumber, FinalityStatus, Header, SealedBlock, SealedBlockWithStatus, }; use katana_primitives::class::{CompiledClass, FlattenedSierraClass, SierraClass}; use katana_primitives::contract::ContractAddress; @@ -188,10 +188,8 @@ where SealedBlockWithStatus { status: FinalityStatus::AcceptedOnL2, block: SealedBlock { - header: SealedHeader { - hash: i.into(), - header: Header { number: i, ..Default::default() }, - }, + hash: i.into(), + header: Header { number: i, ..Default::default() }, body: Default::default(), }, }, diff --git a/crates/katana/storage/provider/tests/utils.rs b/crates/katana/storage/provider/tests/utils.rs index 122372f98a..8b552a107a 100644 --- a/crates/katana/storage/provider/tests/utils.rs +++ b/crates/katana/storage/provider/tests/utils.rs @@ -46,7 +46,7 @@ pub fn generate_dummy_blocks_and_receipts( let header = Header { parent_hash, number: i, ..Default::default() }; let block = Block { header, body }.seal_with_hash(Felt::from(rand::random::())); - parent_hash = block.header.hash; + parent_hash = block.hash; blocks.push(( SealedBlockWithStatus { block, status: FinalityStatus::AcceptedOnL2 }, @@ -68,7 +68,7 @@ pub fn generate_dummy_blocks_empty(count: u64) -> Vec { let block = Block { header, body }.seal_with_hash(Felt::from(rand::random::())); - parent_hash = block.header.hash; + parent_hash = block.hash; blocks.push(SealedBlockWithStatus { block, status: FinalityStatus::AcceptedOnL2 }); } diff --git a/crates/saya/core/src/lib.rs b/crates/saya/core/src/lib.rs index edfcb8f23a..2efb1ea88a 100644 --- a/crates/saya/core/src/lib.rs +++ b/crates/saya/core/src/lib.rs @@ -151,7 +151,7 @@ impl Saya { let mut block = self.config.block_range.0.max(1); // Genesis block is not proven. We advance to block 1 let block_before_the_first = self.provider.fetch_block(block - 1).await; - let mut previous_block_state_root = block_before_the_first?.header.header.state_root; + let mut previous_block_state_root = block_before_the_first?.header.state_root; let mut mock_state_hash = Felt::from(0u64); loop { @@ -293,7 +293,7 @@ impl Saya { // Shift the state roots to the right by one, as proof of each block is based on the // previous state root let mut state_roots = vec![previous_block_state_root]; - state_roots.extend(fetched_blocks.iter().map(|block| block.header.header.state_root)); + state_roots.extend(fetched_blocks.iter().map(|block| block.header.state_root)); let previous_block_state_root = state_roots.pop().unwrap(); let mut state_updates_and_exec_info = vec![]; @@ -327,7 +327,7 @@ impl Saya { .zip(state_roots) .zip(state_updates_and_exec_info) .map(|((block, prev_state_root), (state_updates, exec_infos))| FetchedBlockInfo { - block_number: block.header.header.number, + block_number: block.header.number, block, prev_state_root, state_updates, @@ -400,7 +400,7 @@ impl Saya { let mut state_diff_prover_input = ProgramInput { prev_state_root, block_number, - block_hash: block.block.header.hash, + block_hash: block.block.hash, config_hash: Felt::from(0u64), message_to_starknet_segment, message_to_appchain_segment, diff --git a/crates/saya/provider/src/rpc/mod.rs b/crates/saya/provider/src/rpc/mod.rs index 4ed2354d05..606efaa683 100644 --- a/crates/saya/provider/src/rpc/mod.rs +++ b/crates/saya/provider/src/rpc/mod.rs @@ -5,9 +5,7 @@ use std::sync::Arc; use anyhow::anyhow; use jsonrpsee::http_client::HttpClientBuilder; -use katana_primitives::block::{ - BlockIdOrTag, BlockNumber, GasPrices, Header, SealedBlock, SealedHeader, -}; +use katana_primitives::block::{BlockIdOrTag, BlockNumber, GasPrices, Header, SealedBlock}; use katana_primitives::chain::ChainId; use katana_primitives::conversion::rpc as rpc_converter; use katana_primitives::state::StateUpdatesWithDeclaredClasses; @@ -88,25 +86,29 @@ impl Provider for JsonRpcProvider { .collect::, _>>()?; Ok(SealedBlock { - header: SealedHeader { - hash: block.block_hash, - header: Header { - parent_hash: block.parent_hash, - number: block.block_number, - l1_gas_prices: GasPrices::new( - block.l1_gas_price.price_in_wei.to_u128().unwrap(), - block.l1_gas_price.price_in_fri.to_u128().unwrap(), - ), - l1_data_gas_prices: GasPrices::new( - block.l1_data_gas_price.price_in_wei.to_u128().unwrap(), - block.l1_data_gas_price.price_in_fri.to_u128().unwrap(), - ), - l1_da_mode: block.l1_da_mode, - timestamp: block.timestamp, - state_root: block.new_root, - sequencer_address: block.sequencer_address.into(), - protocol_version: ProtocolVersion::parse(&block.starknet_version).unwrap(), - }, + hash: block.block_hash, + header: Header { + events_count: 0, + transaction_count: 0, + events_commitment: Felt::ZERO, + receipts_commitment: Felt::ZERO, + state_diff_commitment: Felt::ZERO, + transactions_commitment: Felt::ZERO, + parent_hash: block.parent_hash, + number: block.block_number, + l1_gas_prices: GasPrices::new( + block.l1_gas_price.price_in_wei.to_u128().unwrap(), + block.l1_gas_price.price_in_fri.to_u128().unwrap(), + ), + l1_data_gas_prices: GasPrices::new( + block.l1_data_gas_price.price_in_wei.to_u128().unwrap(), + block.l1_data_gas_price.price_in_fri.to_u128().unwrap(), + ), + l1_da_mode: block.l1_da_mode, + timestamp: block.timestamp, + state_root: block.new_root, + sequencer_address: block.sequencer_address.into(), + protocol_version: ProtocolVersion::parse(&block.starknet_version).unwrap(), }, body: txs, }) diff --git a/spawn-and-move-db.tar.gz b/spawn-and-move-db.tar.gz index 83660e1286..8a26c58a2a 100644 Binary files a/spawn-and-move-db.tar.gz and b/spawn-and-move-db.tar.gz differ diff --git a/types-test-db.tar.gz b/types-test-db.tar.gz index 81ec4bd7b0..db63053e92 100644 Binary files a/types-test-db.tar.gz and b/types-test-db.tar.gz differ