Skip to content

Commit

Permalink
refactor(katana): remove starknet version from chainspec (#2875)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kariy committed Jan 21, 2025
1 parent b9ba1af commit 437f6ba
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
19 changes: 3 additions & 16 deletions crates/katana/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 should only be optional if the chain is in development mode.
Expand Down Expand Up @@ -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<P: AsRef<Path>>(self, path: P) -> anyhow::Result<()> {
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<SettlementLayer>,
genesis: PathBuf,
Expand Down Expand Up @@ -250,7 +239,6 @@ lazy_static! {
genesis,
fee_contracts,
settlement: None,
version: CURRENT_STARKNET_VERSION,
}
};
}
Expand Down Expand Up @@ -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()),
Expand Down
7 changes: 4 additions & 3 deletions crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,7 +175,7 @@ impl<EF: ExecutorFactory> Backend<EF> {
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,
Expand Down
2 changes: 0 additions & 2 deletions crates/katana/core/src/backend/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion crates/katana/core/src/service/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -578,7 +579,7 @@ impl<EF: ExecutorFactory> InstantBlockProducer<EF> {
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(),
Expand Down
7 changes: 4 additions & 3 deletions crates/katana/rpc/rpc/src/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
};

Expand Down

0 comments on commit 437f6ba

Please sign in to comment.