Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(katana): remove starknet version from chainspec #2875

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -23,7 +23,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 @@ -43,9 +43,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.
Expand Down Expand Up @@ -112,13 +109,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 @@ -128,7 +119,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 @@ -146,7 +136,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 @@ -214,7 +204,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 @@ -246,7 +235,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
3 changes: 2 additions & 1 deletion crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use katana_primitives::env::BlockEnv;
use katana_primitives::receipt::{Event, ReceiptWithTxHash};
use katana_primitives::state::{compute_state_diff_hash, StateUpdates};
use katana_primitives::transaction::{TxHash, TxWithHash};
use katana_primitives::version::CURRENT_STARKNET_VERSION;
use katana_primitives::Felt;
use katana_provider::traits::block::{BlockHashProvider, BlockWriter};
use katana_provider::traits::trie::TrieWriter;
Expand Down Expand Up @@ -138,7 +139,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 @@ -613,7 +614,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 @@ -679,7 +680,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 @@ -743,7 +744,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
Loading