diff --git a/CHANGELOG.md b/CHANGELOG.md index 82cf550955..633e67d6cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Removed + +- `storage_commitment` and `class_commitment` fields from the `pathfinder_subscribe_newHeads` method response. +- `class_commitment` from the `pathfinder_getProof` and `pathfinder_getClassProof` method responses. + ### Fixed - `pathfinder_getProof`, `pathfinder_getClassProof` return `ProofMissing` (10001) when Pathfinder is in `archive` mode and queried block's tries are empty. diff --git a/crates/common/src/header.rs b/crates/common/src/header.rs index 14d2617d02..234fc89db8 100644 --- a/crates/common/src/header.rs +++ b/crates/common/src/header.rs @@ -17,10 +17,8 @@ pub struct BlockHeader { pub strk_l2_gas_price: GasPrice, pub sequencer_address: SequencerAddress, pub starknet_version: StarknetVersion, - pub class_commitment: ClassCommitment, pub event_commitment: EventCommitment, pub state_commitment: StateCommitment, - pub storage_commitment: StorageCommitment, pub transaction_commitment: TransactionCommitment, pub transaction_count: usize, pub event_count: usize, @@ -88,11 +86,14 @@ impl BlockHeaderBuilder { self } - /// Sets the [StateCommitment] by calculating its value from the current + /// Sets the [StateCommitment] by calculating its value from the passed /// [StorageCommitment] and [ClassCommitment]. - pub fn calculated_state_commitment(mut self) -> Self { - self.0.state_commitment = - StateCommitment::calculate(self.0.storage_commitment, self.0.class_commitment); + pub fn calculated_state_commitment( + mut self, + storage_commitment: StorageCommitment, + class_commitment: ClassCommitment, + ) -> Self { + self.0.state_commitment = StateCommitment::calculate(storage_commitment, class_commitment); self } @@ -146,16 +147,6 @@ impl BlockHeaderBuilder { self } - pub fn storage_commitment(mut self, storage_commitment: StorageCommitment) -> Self { - self.0.storage_commitment = storage_commitment; - self - } - - pub fn class_commitment(mut self, class_commitment: ClassCommitment) -> Self { - self.0.class_commitment = class_commitment; - self - } - pub fn starknet_version(mut self, starknet_version: StarknetVersion) -> Self { self.0.starknet_version = starknet_version; self diff --git a/crates/p2p/src/client/peer_agnostic/fixtures.rs b/crates/p2p/src/client/peer_agnostic/fixtures.rs index aa3fde777c..e338a89e75 100644 --- a/crates/p2p/src/client/peer_agnostic/fixtures.rs +++ b/crates/p2p/src/client/peer_agnostic/fixtures.rs @@ -149,9 +149,6 @@ pub fn hdr(tag: i32) -> SignedBlockHeader { Tagged::get(format!("header {tag}"), || SignedBlockHeader { header: BlockHeader { number: BlockNumber::new_or_panic(tag as u64), - // TODO Set storage and class commitment - storage_commitment: Default::default(), - class_commitment: Default::default(), ..Faker.fake() }, ..Faker.fake() diff --git a/crates/p2p/src/client/types.rs b/crates/p2p/src/client/types.rs index 53cfc5e621..f6b3faabc9 100644 --- a/crates/p2p/src/client/types.rs +++ b/crates/p2p/src/client/types.rs @@ -11,7 +11,6 @@ use pathfinder_common::{ BlockHeader, BlockNumber, BlockTimestamp, - ClassCommitment, ClassHash, EventCommitment, Fee, @@ -22,7 +21,6 @@ use pathfinder_common::{ SignedBlockHeader, StateCommitment, StateDiffCommitment, - StorageCommitment, TransactionCommitment, TransactionHash, TransactionIndex, @@ -118,8 +116,6 @@ impl TryFromDto for SignedBlockHeader { l1_da_mode: TryFromDto::try_from_dto(dto.l1_data_availability_mode)?, state_diff_commitment: StateDiffCommitment(dto.state_diff_commitment.root.0), state_diff_length: dto.state_diff_commitment.state_diff_length, - class_commitment: ClassCommitment::ZERO, - storage_commitment: StorageCommitment::ZERO, }, signature, }) diff --git a/crates/pathfinder/examples/compute_pre0132_hashes.rs b/crates/pathfinder/examples/compute_pre0132_hashes.rs index 3c49935573..654f477126 100644 --- a/crates/pathfinder/examples/compute_pre0132_hashes.rs +++ b/crates/pathfinder/examples/compute_pre0132_hashes.rs @@ -8,7 +8,6 @@ use pathfinder_common::{ ReceiptCommitment, StarknetVersion, StateCommitment, - StorageCommitment, }; use pathfinder_lib::state::block_hash::{ calculate_event_commitment, @@ -119,10 +118,6 @@ fn main() -> anyhow::Result<()> { header.state_commitment != StateCommitment::ZERO, "state_commitment missing" ); - ensure!( - header.storage_commitment != StorageCommitment::ZERO, - "storage_commitment missing" - ); // Compute the block hash in the 0.13.2 style let header_data = get_header_data(&header); diff --git a/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs b/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs index 36a287c1b4..1556325c78 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs @@ -185,9 +185,6 @@ mod prop { let expected = overlapping::get(in_db, start_block, limit, step, num_blocks, direction) .into_iter().map(|Block { header, .. }| pathfinder_common::SignedBlockHeader { header: pathfinder_common::BlockHeader { - // TODO Set the storage and class commitment - storage_commitment: Default::default(), - class_commitment: Default::default(), ..header.header }, signature: header.signature, diff --git a/crates/pathfinder/src/state/sync.rs b/crates/pathfinder/src/state/sync.rs index 271ed344a7..2cc6d80b29 100644 --- a/crates/pathfinder/src/state/sync.rs +++ b/crates/pathfinder/src/state/sync.rs @@ -912,10 +912,8 @@ async fn l2_update( .sequencer_address .unwrap_or(SequencerAddress(Felt::ZERO)), starknet_version: block.starknet_version, - class_commitment, event_commitment, state_commitment, - storage_commitment, transaction_commitment, transaction_count, event_count, diff --git a/crates/pathfinder/src/state/sync/revert.rs b/crates/pathfinder/src/state/sync/revert.rs index 6abe0c2042..297127713d 100644 --- a/crates/pathfinder/src/state/sync/revert.rs +++ b/crates/pathfinder/src/state/sync/revert.rs @@ -4,6 +4,7 @@ use pathfinder_common::{ BlockNumber, ClassCommitment, ClassCommitmentLeafHash, + StateCommitment, StorageCommitment, }; use pathfinder_merkle_tree::{ClassCommitmentTree, StorageCommitmentTree}; @@ -37,31 +38,30 @@ pub fn revert_starknet_state( target_block: BlockNumber, target_header: BlockHeader, ) -> Result<(), anyhow::Error> { - revert_contract_updates( - transaction, - head, - target_block, - target_header.storage_commitment, - )?; - revert_class_updates( - transaction, - head, - target_block, - target_header.class_commitment, - )?; + let storage_commitment = revert_contract_updates(transaction, head, target_block)?; + let class_commitment = revert_class_updates(transaction, head, target_block)?; + + let state_commitment = StateCommitment::calculate(storage_commitment, class_commitment); + if state_commitment != target_header.state_commitment { + anyhow::bail!( + "State commitment mismatch: expected {}, calculated {}", + target_header.state_commitment, + state_commitment, + ); + } + transaction.coalesce_trie_removals(target_block) } /// Revert all contract/global storage trie updates. /// /// Fetches reverse updates from the database and updates all tries, returning -/// the storage commitment and the storage root node index. +/// the [`StorageCommitment`]. fn revert_contract_updates( transaction: &Transaction<'_>, head: BlockNumber, target_block: BlockNumber, - expected_storage_commitment: StorageCommitment, -) -> anyhow::Result<()> { +) -> anyhow::Result { let updates = transaction.reverse_contract_updates(head, target_block)?; let mut global_tree = @@ -91,14 +91,6 @@ fn revert_contract_updates( .commit() .context("Committing global state tree")?; - if expected_storage_commitment != storage_commitment { - anyhow::bail!( - "Storage commitment mismatch: expected {}, calculated {}", - expected_storage_commitment, - storage_commitment - ); - } - let root_idx = transaction .insert_storage_trie(&trie_update, target_block) .context("Persisting storage trie")?; @@ -108,16 +100,18 @@ fn revert_contract_updates( .context("Inserting storage root index")?; tracing::debug!(%target_block, %storage_commitment, "Committed global state tree"); - Ok(()) + Ok(storage_commitment) } /// Revert all class trie updates. +/// +/// Fetches reverse updates from the database and updates all tries, returning +/// the [`ClassCommitment`]. fn revert_class_updates( transaction: &Transaction<'_>, head: BlockNumber, target_block: BlockNumber, - expected_class_commitment: ClassCommitment, -) -> anyhow::Result<()> { +) -> anyhow::Result { let updates = transaction.reverse_sierra_class_updates(head, target_block)?; let mut class_tree = @@ -143,14 +137,6 @@ fn revert_class_updates( let (class_commitment, trie_update) = class_tree.commit().context("Committing class trie")?; - if expected_class_commitment != class_commitment { - anyhow::bail!( - "Storage commitment mismatch: expected {}, calculated {}", - expected_class_commitment, - class_commitment - ); - } - let root_idx = transaction .insert_class_trie(&trie_update, target_block) .context("Persisting class trie")?; @@ -161,5 +147,5 @@ fn revert_class_updates( tracing::debug!(%target_block, %class_commitment, "Committed class trie"); - Ok(()) + Ok(class_commitment) } diff --git a/crates/pathfinder/src/sync/checkpoint.rs b/crates/pathfinder/src/sync/checkpoint.rs index 60af655b26..eb1a7684ae 100644 --- a/crates/pathfinder/src/sync/checkpoint.rs +++ b/crates/pathfinder/src/sync/checkpoint.rs @@ -785,8 +785,6 @@ mod tests { eth_l2_gas_price: GasPrice(0), strk_l2_gas_price: GasPrice(0), l1_da_mode: L1DataAvailabilityMode::Calldata, - class_commitment: ClassCommitment::ZERO, - storage_commitment: StorageCommitment::ZERO, }, signature: BlockCommitmentSignature { r: dto.signature[0], diff --git a/crates/pathfinder/src/sync/state_updates.rs b/crates/pathfinder/src/sync/state_updates.rs index 8c4254cc78..e27b93f8aa 100644 --- a/crates/pathfinder/src/sync/state_updates.rs +++ b/crates/pathfinder/src/sync/state_updates.rs @@ -303,8 +303,6 @@ pub async fn batch_update_starknet_state( "State root mismatch"); return Err(SyncError::StateRootMismatch(peer)); } - db.update_storage_and_class_commitments(tail, storage_commitment, class_commitment) - .context("Updating storage and class commitments")?; db.commit().context("Committing db transaction")?; Ok(PeerData::new(peer, tail)) diff --git a/crates/pathfinder/src/sync/track.rs b/crates/pathfinder/src/sync/track.rs index 88c4bb9582..232321dbd0 100644 --- a/crates/pathfinder/src/sync/track.rs +++ b/crates/pathfinder/src/sync/track.rs @@ -788,12 +788,8 @@ impl ProcessStage for StoreBlock { strk_l2_gas_price: header.strk_l2_gas_price, sequencer_address: header.sequencer_address, starknet_version: header.starknet_version, - // Class commitment is updated after the class tries are updated. - class_commitment: ClassCommitment::ZERO, event_commitment: header.event_commitment, state_commitment: header.state_commitment, - // Storage commitment is updated after the storage tries are updated. - storage_commitment: StorageCommitment::ZERO, transaction_commitment: header.transaction_commitment, transaction_count: header.transaction_count, event_count: header.event_count, @@ -841,9 +837,6 @@ impl ProcessStage for StoreBlock { return Err(SyncError::StateRootMismatch(*peer)); } - db.update_storage_and_class_commitments(block_number, storage_commitment, class_commitment) - .context("Updating storage and class commitments")?; - classes.into_iter().try_for_each( |CompiledClass { block_number, diff --git a/crates/rpc/fixtures/mainnet.sqlite b/crates/rpc/fixtures/mainnet.sqlite index 17b3c9348b..e069fce490 100644 Binary files a/crates/rpc/fixtures/mainnet.sqlite and b/crates/rpc/fixtures/mainnet.sqlite differ diff --git a/crates/rpc/src/jsonrpc/websocket/data.rs b/crates/rpc/src/jsonrpc/websocket/data.rs index ab650a49c0..a496c43f7b 100644 --- a/crates/rpc/src/jsonrpc/websocket/data.rs +++ b/crates/rpc/src/jsonrpc/websocket/data.rs @@ -240,10 +240,8 @@ impl serde::Serialize for BlockHeader { strk_l2_gas_price, sequencer_address, starknet_version, - class_commitment, event_commitment, state_commitment, - storage_commitment, transaction_commitment, transaction_count, event_count, @@ -267,10 +265,8 @@ impl serde::Serialize for BlockHeader { map.serialize_entry("strk_l2_gas_price", &strk_l2_gas_price)?; map.serialize_entry("sequencer_address", &sequencer_address)?; map.serialize_entry("starknet_version", &starknet_version.to_string())?; - map.serialize_entry("class_commitment", &class_commitment)?; map.serialize_entry("event_commitment", &event_commitment)?; map.serialize_entry("state_commitment", &state_commitment)?; - map.serialize_entry("storage_commitment", &storage_commitment)?; map.serialize_entry("transaction_commitment", &transaction_commitment)?; map.serialize_entry("transaction_count", &transaction_count)?; map.serialize_entry("event_count", &event_count)?; diff --git a/crates/rpc/src/lib.rs b/crates/rpc/src/lib.rs index a6cb197e09..92709018d1 100644 --- a/crates/rpc/src/lib.rs +++ b/crates/rpc/src/lib.rs @@ -386,9 +386,7 @@ pub mod test_utils { .unwrap(); let header0 = BlockHeader::builder() .number(BlockNumber::GENESIS) - .storage_commitment(storage_commitment0) - .class_commitment(class_commitment0) - .calculated_state_commitment() + .calculated_state_commitment(storage_commitment0, class_commitment0) .finalize_with_hash(block_hash_bytes!(b"genesis")); db_txn.insert_block_header(&header0).unwrap(); db_txn @@ -428,9 +426,7 @@ pub mod test_utils { let header1 = header0 .child_builder() .timestamp(BlockTimestamp::new_or_panic(1)) - .storage_commitment(storage_commitment1) - .class_commitment(class_commitment1) - .calculated_state_commitment() + .calculated_state_commitment(storage_commitment1, class_commitment1) .eth_l1_gas_price(GasPrice::from(1)) .sequencer_address(sequencer_address_bytes!(&[1u8])) .finalize_with_hash(block_hash_bytes!(b"block 1")); @@ -514,9 +510,7 @@ pub mod test_utils { let header2 = header1 .child_builder() .timestamp(BlockTimestamp::new_or_panic(2)) - .storage_commitment(storage_commitment2) - .class_commitment(class_commitment2) - .calculated_state_commitment() + .calculated_state_commitment(storage_commitment2, class_commitment2) .eth_l1_gas_price(GasPrice::from(2)) .sequencer_address(sequencer_address_bytes!(&[2u8])) .finalize_with_hash(block_hash_bytes!(b"latest")); diff --git a/crates/rpc/src/method/trace_block_transactions.rs b/crates/rpc/src/method/trace_block_transactions.rs index 8dac5de8da..65c6876f52 100644 --- a/crates/rpc/src/method/trace_block_transactions.rs +++ b/crates/rpc/src/method/trace_block_transactions.rs @@ -1031,10 +1031,8 @@ pub(crate) mod tests { .sequencer_address .unwrap_or(SequencerAddress(Felt::ZERO)), starknet_version: block.starknet_version, - class_commitment: Default::default(), event_commitment: Default::default(), state_commitment: Default::default(), - storage_commitment: Default::default(), transaction_commitment: Default::default(), transaction_count, event_count, diff --git a/crates/rpc/src/pathfinder/methods/get_proof.rs b/crates/rpc/src/pathfinder/methods/get_proof.rs index 81acdb7a64..b336ca11b4 100644 --- a/crates/rpc/src/pathfinder/methods/get_proof.rs +++ b/crates/rpc/src/pathfinder/methods/get_proof.rs @@ -183,11 +183,6 @@ pub struct GetProofOutput { /// [contract_proof](GetProofOutput#contract_proof) is the global state /// commitment. state_commitment: Option, - /// Required to verify that the hash of the class commitment and the root of - /// the [contract_proof](GetProofOutput::contract_proof) matches the - /// [state_commitment](Self#state_commitment). Present only for Starknet - /// blocks 0.11.0 onwards. - class_commitment: Option, /// Membership / Non-membership proof for the queried contract contract_proof: ProofNodes, @@ -212,11 +207,6 @@ impl crate::dto::serialize::SerializeForVersion for GetProofOutput { #[derive(Debug, PartialEq)] pub struct GetClassProofOutput { - /// Required to verify that the hash of the class commitment and the root of - /// the [contract_proof](GetProofOutput::contract_proof) matches the - /// [state_commitment](Self#state_commitment). Present only for Starknet - /// blocks 0.11.0 onwards. - class_commitment: Option, /// Membership / Non-membership proof for the queried contract classes class_proof: ProofNodes, } @@ -279,10 +269,6 @@ pub async fn get_proof( StateCommitment::ZERO => None, other => Some(other), }; - let class_commitment = match header.class_commitment { - ClassCommitment::ZERO => None, - other => Some(other), - }; let storage_root_idx = tx .storage_root_index(header.number) @@ -298,7 +284,6 @@ pub async fn get_proof( // An empty proof is then a proof of non-membership in an empty block. return Ok(GetProofOutput { state_commitment, - class_commitment, contract_proof: ProofNodes(vec![]), contract_data: None, }); @@ -326,7 +311,6 @@ pub async fn get_proof( if contract_state_hash.is_none() { return Ok(GetProofOutput { state_commitment, - class_commitment, contract_proof, contract_data: None, }); @@ -382,7 +366,6 @@ pub async fn get_proof( Ok(GetProofOutput { state_commitment, - class_commitment, contract_proof, contract_data: Some(contract_data), }) @@ -425,11 +408,6 @@ pub async fn get_class_proof( .context("Fetching block header")? .ok_or(GetProofError::BlockNotFound)?; - let class_commitment = match header.class_commitment { - ClassCommitment::ZERO => None, - other => Some(other), - }; - let class_root_idx = tx .class_root_index(header.number) .context("Querying class root index")?; @@ -443,7 +421,6 @@ pub async fn get_class_proof( // - or all leaves were removed resulting in an empty trie // An empty proof is then a proof of non-membership in an empty block. return Ok(GetClassProofOutput { - class_commitment, class_proof: ProofNodes(vec![]), }); } @@ -459,10 +436,7 @@ pub async fn get_class_proof( let class_proof = ProofNodes(class_proof); - Ok(GetClassProofOutput { - class_commitment, - class_proof, - }) + Ok(GetClassProofOutput { class_proof }) }); jh.await.context("Database read panic or shutting down")? @@ -683,7 +657,6 @@ mod tests { assert_eq!( output, GetClassProofOutput { - class_commitment: None, class_proof: ProofNodes(vec![]) } ); diff --git a/crates/rpc/src/pending.rs b/crates/rpc/src/pending.rs index 7cf50e2969..1bfb1a9bfa 100644 --- a/crates/rpc/src/pending.rs +++ b/crates/rpc/src/pending.rs @@ -36,10 +36,8 @@ impl PendingData { starknet_version: self.block.starknet_version, // Pending block does not know what these are yet. hash: Default::default(), - class_commitment: Default::default(), event_commitment: Default::default(), state_commitment: Default::default(), - storage_commitment: Default::default(), transaction_commitment: Default::default(), transaction_count: Default::default(), event_count: Default::default(), diff --git a/crates/rpc/src/v06/method/trace_block_transactions.rs b/crates/rpc/src/v06/method/trace_block_transactions.rs index e18a12d4ac..97e8ab23bb 100644 --- a/crates/rpc/src/v06/method/trace_block_transactions.rs +++ b/crates/rpc/src/v06/method/trace_block_transactions.rs @@ -675,10 +675,8 @@ pub(crate) mod tests { .sequencer_address .unwrap_or(SequencerAddress(Felt::ZERO)), starknet_version: block.starknet_version, - class_commitment: Default::default(), event_commitment: Default::default(), state_commitment: Default::default(), - storage_commitment: Default::default(), transaction_commitment: Default::default(), transaction_count, event_count, diff --git a/crates/rpc/src/v06/method/trace_transaction.rs b/crates/rpc/src/v06/method/trace_transaction.rs index 780d01afc2..b658ee6470 100644 --- a/crates/rpc/src/v06/method/trace_transaction.rs +++ b/crates/rpc/src/v06/method/trace_transaction.rs @@ -346,10 +346,8 @@ pub mod tests { .sequencer_address .unwrap_or(SequencerAddress(Felt::ZERO)), starknet_version: block.starknet_version, - class_commitment: Default::default(), event_commitment: Default::default(), state_commitment: Default::default(), - storage_commitment: Default::default(), transaction_commitment: Default::default(), transaction_count, event_count, diff --git a/crates/storage/src/connection/block.rs b/crates/storage/src/connection/block.rs index fa2bf0f9e9..8c06e16efb 100644 --- a/crates/storage/src/connection/block.rs +++ b/crates/storage/src/connection/block.rs @@ -6,12 +6,10 @@ use pathfinder_common::{ BlockHash, BlockHeader, BlockNumber, - ClassCommitment, GasPrice, StarknetVersion, StateCommitment, StateDiffCommitment, - StorageCommitment, TransactionCommitment, }; @@ -23,13 +21,12 @@ impl Transaction<'_> { // Insert the header self.inner().execute( r"INSERT INTO block_headers - ( number, hash, parent_hash, storage_commitment, timestamp, eth_l1_gas_price, strk_l1_gas_price, eth_l1_data_gas_price, strk_l1_data_gas_price, eth_l2_gas_price, strk_l2_gas_price, sequencer_address, version, transaction_commitment, event_commitment, state_commitment, class_commitment, transaction_count, event_count, l1_da_mode, receipt_commitment, state_diff_commitment, state_diff_length) - VALUES (:number, :hash, :parent_hash, :storage_commitment, :timestamp, :eth_l1_gas_price, :strk_l1_gas_price, :eth_l1_data_gas_price, :strk_l1_data_gas_price, :eth_l2_gas_price, :strk_l2_gas_price, :sequencer_address, :version, :transaction_commitment, :event_commitment, :state_commitment, :class_commitment, :transaction_count, :event_count, :l1_da_mode, :receipt_commitment, :state_diff_commitment, :state_diff_length)", + ( number, hash, parent_hash, timestamp, eth_l1_gas_price, strk_l1_gas_price, eth_l1_data_gas_price, strk_l1_data_gas_price, eth_l2_gas_price, strk_l2_gas_price, sequencer_address, version, transaction_commitment, event_commitment, state_commitment, transaction_count, event_count, l1_da_mode, receipt_commitment, state_diff_commitment, state_diff_length) + VALUES (:number, :hash, :parent_hash, :timestamp, :eth_l1_gas_price, :strk_l1_gas_price, :eth_l1_data_gas_price, :strk_l1_data_gas_price, :eth_l2_gas_price, :strk_l2_gas_price, :sequencer_address, :version, :transaction_commitment, :event_commitment, :state_commitment, :transaction_count, :event_count, :l1_da_mode, :receipt_commitment, :state_diff_commitment, :state_diff_length)", named_params! { ":number": &header.number, ":hash": &header.hash, ":parent_hash": &header.parent_hash, - ":storage_commitment": &header.storage_commitment, ":timestamp": &header.timestamp, ":eth_l1_gas_price": &header.eth_l1_gas_price.to_be_bytes().as_slice(), ":strk_l1_gas_price": &header.strk_l1_gas_price.to_be_bytes().as_slice(), @@ -41,7 +38,6 @@ impl Transaction<'_> { ":version": &header.starknet_version.as_u32(), ":transaction_commitment": &header.transaction_commitment, ":event_commitment": &header.event_commitment, - ":class_commitment": &header.class_commitment, ":transaction_count": &header.transaction_count.try_into_sql_int()?, ":event_count": &header.event_count.try_into_sql_int()?, ":state_commitment": &header.state_commitment, @@ -478,29 +474,6 @@ impl Transaction<'_> { .context("Querying highest block with events") } - pub fn update_storage_and_class_commitments( - &self, - block_number: BlockNumber, - storage_commitment: StorageCommitment, - class_commitment: ClassCommitment, - ) -> anyhow::Result<()> { - let mut stmt = self - .inner() - .prepare_cached( - r"UPDATE block_headers SET storage_commitment=?, class_commitment=? WHERE number=?", - ) - .context("Preparing update statement")?; - - stmt.execute(params![ - &storage_commitment, - &class_commitment, - &block_number, - ]) - .context("Updating storage and class commitments")?; - - Ok(()) - } - pub fn event_counts( &self, block_number: BlockNumber, @@ -606,7 +579,6 @@ fn parse_row_as_header(row: &rusqlite::Row<'_>) -> rusqlite::Result let number = row.get_block_number("number")?; let hash = row.get_block_hash("hash")?; let parent_hash = row.get_block_hash("parent_hash")?; - let storage_commitment = row.get_storage_commitment("storage_commitment")?; let timestamp = row.get_timestamp("timestamp")?; let eth_l1_gas_price = row.get_gas_price("eth_l1_gas_price")?; let strk_l1_gas_price = row @@ -627,7 +599,6 @@ fn parse_row_as_header(row: &rusqlite::Row<'_>) -> rusqlite::Result let sequencer_address = row.get_sequencer_address("sequencer_address")?; let transaction_commitment = row.get_transaction_commitment("transaction_commitment")?; let event_commitment = row.get_event_commitment("event_commitment")?; - let class_commitment = row.get_class_commitment("class_commitment")?; let starknet_version = row.get_starknet_version("version")?; let event_count: usize = row.get("event_count")?; let transaction_count: usize = row.get("transaction_count")?; @@ -651,10 +622,8 @@ fn parse_row_as_header(row: &rusqlite::Row<'_>) -> rusqlite::Result eth_l2_gas_price, strk_l2_gas_price, sequencer_address, - class_commitment, event_commitment, state_commitment, - storage_commitment, transaction_commitment, starknet_version, transaction_count, @@ -705,10 +674,8 @@ mod tests { strk_l2_gas_price: GasPrice(36), sequencer_address: sequencer_address_bytes!(b"sequencer address genesis"), starknet_version: StarknetVersion::default(), - class_commitment, event_commitment: event_commitment_bytes!(b"event commitment genesis"), state_commitment: StateCommitment::calculate(storage_commitment, class_commitment), - storage_commitment, transaction_commitment: transaction_commitment_bytes!(b"tx commitment genesis"), transaction_count: 37, event_count: 40, @@ -717,6 +684,7 @@ mod tests { state_diff_commitment: state_diff_commitment!("12"), state_diff_length: 12, }; + let header1 = genesis .child_builder() .timestamp(BlockTimestamp::new_or_panic(12)) @@ -726,9 +694,10 @@ mod tests { .strk_l2_gas_price(GasPrice(37)) .sequencer_address(sequencer_address_bytes!(b"sequencer address 1")) .event_commitment(event_commitment_bytes!(b"event commitment 1")) - .class_commitment(class_commitment_bytes!(b"class commitment 1")) - .storage_commitment(storage_commitment_bytes!(b"storage commitment 1")) - .calculated_state_commitment() + .calculated_state_commitment( + storage_commitment_bytes!(b"storage commitment 1"), + class_commitment_bytes!(b"class commitment 1"), + ) .transaction_commitment(transaction_commitment_bytes!(b"tx commitment 1")) .l1_da_mode(L1DataAvailabilityMode::Calldata) .receipt_commitment(receipt_commitment_bytes!(b"block 1 receipt commitment")) @@ -743,9 +712,10 @@ mod tests { .timestamp(BlockTimestamp::new_or_panic(15)) .sequencer_address(sequencer_address_bytes!(b"sequencer address 2")) .event_commitment(event_commitment_bytes!(b"event commitment 2")) - .class_commitment(class_commitment_bytes!(b"class commitment 2")) - .storage_commitment(storage_commitment_bytes!(b"storage commitment 2")) - .calculated_state_commitment() + .calculated_state_commitment( + storage_commitment_bytes!(b"storage commitment 2"), + class_commitment_bytes!(b"class commitment 2"), + ) .transaction_commitment(transaction_commitment_bytes!(b"tx commitment 2")) .l1_da_mode(L1DataAvailabilityMode::Blob) .receipt_commitment(receipt_commitment_bytes!(b"block 2 receipt commitment")) diff --git a/crates/storage/src/connection/state_update.rs b/crates/storage/src/connection/state_update.rs index b263dd5b45..aa99cf022e 100644 --- a/crates/storage/src/connection/state_update.rs +++ b/crates/storage/src/connection/state_update.rs @@ -20,7 +20,6 @@ use pathfinder_common::{ StateCommitment, StateUpdate, StorageAddress, - StorageCommitment, StorageValue, }; @@ -266,8 +265,12 @@ impl Transaction<'_> { ) -> anyhow::Result> { use const_format::formatcp; - const PREFIX: &str = r"SELECT b1.number, b1.hash, b1.storage_commitment, b1.class_commitment, b2.storage_commitment, b2.class_commitment FROM block_headers b1 - LEFT OUTER JOIN block_headers b2 ON b2.number = b1.number - 1"; + const PREFIX: &str = r" + SELECT b1.number, b1.hash, b1.state_commitment, b2.state_commitment + FROM block_headers b1 + LEFT OUTER JOIN block_headers b2 + ON b2.number = b1.number - 1 + "; const LATEST: &str = formatcp!("{PREFIX} ORDER BY b1.number DESC LIMIT 1"); const NUMBER: &str = formatcp!("{PREFIX} WHERE b1.number = ?"); @@ -276,19 +279,9 @@ impl Transaction<'_> { let handle_row = |row: &rusqlite::Row<'_>| { let number = row.get_block_number(0)?; let hash = row.get_block_hash(1)?; - let storage_commitment = row.get_storage_commitment(2)?; - let class_commitment = row.get_class_commitment(3)?; + let state_commitment = row.get_state_commitment(2)?; // The genesis block would not have a value. - let parent_storage_commitment = - row.get_optional_storage_commitment(4)?.unwrap_or_default(); - let parent_class_commitment = row.get_optional_class_commitment(5)?.unwrap_or_default(); - - let state_commitment = StateCommitment::calculate(storage_commitment, class_commitment); - let parent_state_commitment = if parent_storage_commitment == StorageCommitment::ZERO { - StateCommitment::ZERO - } else { - StateCommitment::calculate(parent_storage_commitment, parent_class_commitment) - }; + let parent_state_commitment = row.get_optional_state_commitment(3)?.unwrap_or_default(); Ok((number, hash, state_commitment, parent_state_commitment)) }; diff --git a/crates/storage/src/fake.rs b/crates/storage/src/fake.rs index 36736dec64..a2160ae1c8 100644 --- a/crates/storage/src/fake.rs +++ b/crates/storage/src/fake.rs @@ -524,8 +524,6 @@ pub mod generate { ) .unwrap(); let state_commitment = StateCommitment::calculate(storage_commitment, class_commitment); - header.header.storage_commitment = storage_commitment; - header.header.class_commitment = class_commitment; header.header.state_commitment = state_commitment; state_update.state_commitment = state_commitment; } diff --git a/crates/storage/src/params.rs b/crates/storage/src/params.rs index 2a82e08754..00ca536395 100644 --- a/crates/storage/src/params.rs +++ b/crates/storage/src/params.rs @@ -197,18 +197,11 @@ pub trait RowExt { Ok(self.get_optional_felt(index)?.map(CasmHash)) } - fn get_optional_storage_commitment( + fn get_optional_state_commitment( &self, index: Index, - ) -> rusqlite::Result> { - Ok(self.get_optional_felt(index)?.map(StorageCommitment)) - } - - fn get_optional_class_commitment( - &self, - index: Index, - ) -> rusqlite::Result> { - Ok(self.get_optional_felt(index)?.map(ClassCommitment)) + ) -> rusqlite::Result> { + Ok(self.get_optional_felt(index)?.map(StateCommitment)) } fn get_block_number(&self, index: Index) -> rusqlite::Result { @@ -269,16 +262,6 @@ pub trait RowExt { .unwrap_or_default()) } - fn get_class_commitment( - &self, - index: Index, - ) -> rusqlite::Result { - Ok(self - .get_optional_felt(index)? - .map(ClassCommitment) - .unwrap_or_default()) - } - fn get_contract_address( &self, index: Index, @@ -357,7 +340,6 @@ pub trait RowExt { row_felt_wrapper!(get_class_hash, ClassHash); row_felt_wrapper!(get_state_commitment, StateCommitment); row_felt_wrapper!(get_state_diff_commitment, StateDiffCommitment); - row_felt_wrapper!(get_storage_commitment, StorageCommitment); row_felt_wrapper!(get_sequencer_address, SequencerAddress); row_felt_wrapper!(get_contract_root, ContractRoot); row_felt_wrapper!(get_contract_nonce, ContractNonce); diff --git a/crates/storage/src/schema.rs b/crates/storage/src/schema.rs index eca98647e4..562ad4d61a 100644 --- a/crates/storage/src/schema.rs +++ b/crates/storage/src/schema.rs @@ -26,6 +26,7 @@ mod revision_0063; mod revision_0064; mod revision_0065; mod revision_0066; +mod revision_0067; pub(crate) use base::base_schema; @@ -60,6 +61,7 @@ pub fn migrations() -> &'static [MigrationFn] { revision_0064::migrate, revision_0065::migrate, revision_0066::migrate, + revision_0067::migrate, ] } diff --git a/crates/storage/src/schema/revision_0067.rs b/crates/storage/src/schema/revision_0067.rs new file mode 100644 index 0000000000..2e6bc6efa9 --- /dev/null +++ b/crates/storage/src/schema/revision_0067.rs @@ -0,0 +1,15 @@ +use anyhow::Context; + +pub(crate) fn migrate(tx: &rusqlite::Transaction<'_>) -> anyhow::Result<()> { + tracing::info!( + "Removing storage_commitment and class_commitment columns from block_headers table" + ); + + tx.execute_batch( + r" + ALTER TABLE block_headers DROP COLUMN storage_commitment; + ALTER TABLE block_headers DROP COLUMN class_commitment; + ", + ) + .context("Removing storage_commitment and class_commitment columns from block_headers table") +} diff --git a/crates/storage/src/test_utils.rs b/crates/storage/src/test_utils.rs index 8c36f41e86..ab0a0d0a13 100644 --- a/crates/storage/src/test_utils.rs +++ b/crates/storage/src/test_utils.rs @@ -38,9 +38,7 @@ pub(crate) fn create_blocks(block_numbers: &[usize]) -> Vec { BlockHeader::builder() .number(BlockNumber::GENESIS + block_number as u64) .timestamp(BlockTimestamp::new_or_panic(i as u64 + 500)) - .class_commitment(class_commitment) - .storage_commitment(storage_commitment) - .calculated_state_commitment() + .calculated_state_commitment(storage_commitment, class_commitment) .eth_l1_gas_price(GasPrice::from(i as u64)) .sequencer_address(SequencerAddress(index_as_felt)) .transaction_commitment(TransactionCommitment(index_as_felt))