From a3594952e07de0b322fdb83e30ca31b672cb848e Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Tue, 7 Jan 2025 18:26:15 -0500 Subject: [PATCH] refactor(katana): remove starknet version from chainspec (#2875) The protocol version isn't exactly being used (for what it's meant to be) except for putting it into the block header when building blocks. So, semantically it does nothing, and also it doesn't make sense to include it in the chain spec anyway. For now, we're removing it and replace all of its references with a constant. --- Cargo.lock | 2 +- crates/katana/chain-spec/src/lib.rs | 19 +++---------------- crates/katana/core/src/backend/mod.rs | 7 ++++--- crates/katana/core/src/backend/storage.rs | 2 -- .../katana/core/src/service/block_producer.rs | 3 ++- crates/katana/rpc/rpc/src/starknet/mod.rs | 7 ++++--- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4682e8743f..8b98d0f88a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8467,7 +8467,7 @@ dependencies = [ [[package]] name = "katana-chain-spec" -version = "1.0.9" +version = "1.0.10" dependencies = [ "alloy-primitives", "anyhow", diff --git a/crates/katana/chain-spec/src/lib.rs b/crates/katana/chain-spec/src/lib.rs index 229d1c4bea..155acd98f4 100644 --- a/crates/katana/chain-spec/src/lib.rs +++ b/crates/katana/chain-spec/src/lib.rs @@ -22,7 +22,7 @@ use katana_primitives::genesis::json::GenesisJson; use katana_primitives::genesis::Genesis; use katana_primitives::state::StateUpdatesWithClasses; use katana_primitives::utils::split_u256; -use katana_primitives::version::{ProtocolVersion, CURRENT_STARKNET_VERSION}; +use katana_primitives::version::CURRENT_STARKNET_VERSION; use katana_primitives::{eth, Felt}; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; @@ -42,9 +42,6 @@ pub struct ChainSpec { /// The chain fee token contract. pub fee_contracts: FeeContracts, - // TODO: Maybe remove? Doesn't seem like this should belong here. - pub version: ProtocolVersion, - /// The chain's settlement layer configurations. /// /// This is optional if the chain is on development mode. @@ -111,13 +108,7 @@ impl ChainSpec { let genesis_json: GenesisJson = serde_json::from_reader(BufReader::new(file))?; let genesis = Genesis::try_from(genesis_json)?; - Ok(Self { - genesis, - id: cs.id, - version: cs.version, - settlement: cs.settlement, - fee_contracts: cs.fee_contracts, - }) + Ok(Self { genesis, id: cs.id, settlement: cs.settlement, fee_contracts: cs.fee_contracts }) } pub fn store>(self, path: P) -> anyhow::Result<()> { @@ -127,7 +118,6 @@ impl ChainSpec { let stored = ChainSpecFile { id: self.id, - version: self.version, genesis: genesis_path, settlement: self.settlement, fee_contracts: self.fee_contracts, @@ -145,7 +135,7 @@ impl ChainSpec { pub fn block(&self) -> Block { let header = Header { state_diff_length: 0, - protocol_version: self.version.clone(), + protocol_version: CURRENT_STARKNET_VERSION, number: self.genesis.number, timestamp: self.genesis.timestamp, events_count: 0, @@ -218,7 +208,6 @@ impl Default for ChainSpec { struct ChainSpecFile { id: ChainId, fee_contracts: FeeContracts, - version: ProtocolVersion, #[serde(skip_serializing_if = "Option::is_none")] settlement: Option, genesis: PathBuf, @@ -250,7 +239,6 @@ lazy_static! { genesis, fee_contracts, settlement: None, - version: CURRENT_STARKNET_VERSION, } }; } @@ -468,7 +456,6 @@ mod tests { ]; let chain_spec = ChainSpec { id: ChainId::SEPOLIA, - version: CURRENT_STARKNET_VERSION, genesis: Genesis { classes, allocations: BTreeMap::from(allocations.clone()), diff --git a/crates/katana/core/src/backend/mod.rs b/crates/katana/core/src/backend/mod.rs index 43aab2929e..1e08a27da4 100644 --- a/crates/katana/core/src/backend/mod.rs +++ b/crates/katana/core/src/backend/mod.rs @@ -10,9 +10,10 @@ use katana_primitives::block::{ use katana_primitives::da::L1DataAvailabilityMode; use katana_primitives::env::BlockEnv; use katana_primitives::receipt::{Event, ReceiptWithTxHash}; -use katana_primitives::state::{compute_state_diff_hash, StateUpdates}; +use katana_primitives::state::{StateUpdates, compute_state_diff_hash}; use katana_primitives::transaction::{TxHash, TxWithHash}; -use katana_primitives::{address, ContractAddress, Felt}; +use katana_primitives::version::CURRENT_STARKNET_VERSION; +use katana_primitives::{ContractAddress, Felt, address}; use katana_provider::traits::block::{BlockHashProvider, BlockWriter}; use katana_provider::traits::trie::TrieWriter; use katana_trie::compute_merkle_root; @@ -174,7 +175,7 @@ impl Backend { parent_hash, number: block_env.number, timestamp: block_env.timestamp, - protocol_version: self.chain_spec.version.clone(), + protocol_version: CURRENT_STARKNET_VERSION, sequencer_address: block_env.sequencer_address, l1_gas_prices: block_env.l1_gas_prices, l1_data_gas_prices: block_env.l1_data_gas_prices, diff --git a/crates/katana/core/src/backend/storage.rs b/crates/katana/core/src/backend/storage.rs index 0f10d60b14..04f199ef1b 100644 --- a/crates/katana/core/src/backend/storage.rs +++ b/crates/katana/core/src/backend/storage.rs @@ -9,7 +9,6 @@ use katana_primitives::block::{ use katana_primitives::da::L1DataAvailabilityMode; use katana_primitives::hash::{self, StarkHash}; use katana_primitives::state::StateUpdatesWithClasses; -use katana_primitives::version::ProtocolVersion; use katana_provider::providers::db::DbProvider; use katana_provider::providers::fork::ForkedProvider; use katana_provider::traits::block::{BlockProvider, BlockWriter}; @@ -160,7 +159,6 @@ impl Blockchain { let block_num = forked_block.block_number; chain.id = chain_id.into(); - chain.version = ProtocolVersion::parse(&forked_block.starknet_version)?; // adjust the genesis to match the forked block chain.genesis.timestamp = forked_block.timestamp; diff --git a/crates/katana/core/src/service/block_producer.rs b/crates/katana/core/src/service/block_producer.rs index 848ae60789..80dd670d63 100644 --- a/crates/katana/core/src/service/block_producer.rs +++ b/crates/katana/core/src/service/block_producer.rs @@ -15,6 +15,7 @@ use katana_primitives::da::L1DataAvailabilityMode; use katana_primitives::receipt::Receipt; use katana_primitives::trace::TxExecInfo; use katana_primitives::transaction::{ExecutableTxWithHash, TxHash, TxWithHash}; +use katana_primitives::version::CURRENT_STARKNET_VERSION; use katana_provider::error::ProviderError; use katana_provider::traits::block::{BlockHashProvider, BlockNumberProvider}; use katana_provider::traits::env::BlockEnvProvider; @@ -578,7 +579,7 @@ impl InstantBlockProducer { parent_hash, number: block_env.number, timestamp: block_env.timestamp, - protocol_version: backend.chain_spec.version.clone(), + protocol_version: CURRENT_STARKNET_VERSION, 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/rpc/rpc/src/starknet/mod.rs b/crates/katana/rpc/rpc/src/starknet/mod.rs index 3828b2c332..68649a2c6d 100644 --- a/crates/katana/rpc/rpc/src/starknet/mod.rs +++ b/crates/katana/rpc/rpc/src/starknet/mod.rs @@ -16,6 +16,7 @@ use katana_primitives::da::L1DataAvailabilityMode; use katana_primitives::env::BlockEnv; use katana_primitives::event::MaybeForkedContinuationToken; use katana_primitives::transaction::{ExecutableTxWithHash, TxHash, TxWithHash}; +use katana_primitives::version::CURRENT_STARKNET_VERSION; use katana_primitives::Felt; use katana_provider::error::ProviderError; use katana_provider::traits::block::{BlockHashProvider, BlockIdReader, BlockNumberProvider}; @@ -623,7 +624,7 @@ where parent_hash: latest_hash, timestamp: block_env.timestamp, sequencer_address: block_env.sequencer_address, - protocol_version: this.inner.backend.chain_spec.version.clone(), + protocol_version: CURRENT_STARKNET_VERSION, }; // TODO(kariy): create a method that can perform this filtering for us @@ -689,7 +690,7 @@ where timestamp: block_env.timestamp, l1_da_mode: L1DataAvailabilityMode::Calldata, sequencer_address: block_env.sequencer_address, - protocol_version: this.inner.backend.chain_spec.version.clone(), + protocol_version: CURRENT_STARKNET_VERSION, }; let receipts = executor @@ -753,7 +754,7 @@ where number: block_env.number, parent_hash: latest_hash, timestamp: block_env.timestamp, - protocol_version: this.inner.backend.chain_spec.version.clone(), + protocol_version: CURRENT_STARKNET_VERSION, sequencer_address: block_env.sequencer_address, };