Skip to content

Commit c477ab0

Browse files
committed
verioned constant overrides refactor
1 parent 67c9947 commit c477ab0

File tree

26 files changed

+230
-139
lines changed

26 files changed

+230
-139
lines changed

bin/katana/src/cli/init/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,7 @@ impl RollupArgs {
247247

248248
// At the moment, the fee token is limited to a predefined token.
249249
let fee_contracts = FeeContracts::default();
250-
let versioned_constants_overrides = None;
251-
let chain_spec = rollup::ChainSpec {
252-
id,
253-
genesis,
254-
settlement,
255-
fee_contracts,
256-
versioned_constants_overrides,
257-
};
250+
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contracts };
258251

259252
if let Some(path) = self.output_path {
260253
let dir = ChainConfigDir::create(path)?;
@@ -392,14 +385,7 @@ impl SovereignArgs {
392385

393386
// At the moment, the fee token is limited to a predefined token.
394387
let fee_contracts = FeeContracts::default();
395-
let versioned_constants_overrides = None;
396-
let chain_spec = rollup::ChainSpec {
397-
id,
398-
genesis,
399-
settlement,
400-
fee_contracts,
401-
versioned_constants_overrides,
402-
};
388+
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contracts };
403389

404390
if let Some(path) = self.output_path {
405391
let dir = ChainConfigDir::create(path)?;

crates/chain-spec/src/dev.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use katana_primitives::chain::ChainId;
1515
use katana_primitives::class::ClassHash;
1616
use katana_primitives::contract::ContractAddress;
1717
use katana_primitives::da::L1DataAvailabilityMode;
18-
use katana_primitives::env::VersionedConstantsOverrides;
1918
use katana_primitives::state::StateUpdatesWithClasses;
2019
use katana_primitives::utils::split_u256;
2120
use katana_primitives::version::StarknetVersion;
@@ -37,8 +36,6 @@ pub struct ChainSpec {
3736
pub fee_contracts: FeeContracts,
3837

3938
pub settlement: Option<SettlementLayer>,
40-
41-
pub versioned_constants_overrides: Option<VersionedConstantsOverrides>,
4239
}
4340

4441
//////////////////////////////////////////////////////////////
@@ -140,7 +137,6 @@ lazy_static! {
140137
genesis,
141138
fee_contracts,
142139
settlement: None,
143-
versioned_constants_overrides: None,
144140
}
145141
};
146142
}
@@ -328,7 +324,6 @@ mod tests {
328324
strk: DEFAULT_STRK_FEE_TOKEN_ADDRESS,
329325
},
330326
settlement: None,
331-
versioned_constants_overrides: None,
332327
};
333328

334329
// setup expected storage values

crates/chain-spec/src/full_node.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use katana_genesis::Genesis;
2+
use katana_primitives::chain::ChainId;
3+
use lazy_static::lazy_static;
4+
5+
use crate::{FeeContracts, SettlementLayer};
6+
7+
/// The full node chain specification.
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
pub struct ChainSpec {
10+
/// The network chain id.
11+
pub id: ChainId,
12+
13+
/// The chain's genesis states.
14+
pub genesis: Genesis,
15+
16+
/// The chain fee token contract.
17+
pub fee_contracts: FeeContracts,
18+
19+
/// The chain's settlement layer configurations (if any).
20+
pub settlement: Option<SettlementLayer>,
21+
}
22+
23+
//////////////////////////////////////////////////////////////
24+
// ChainSpec implementations
25+
//////////////////////////////////////////////////////////////
26+
27+
impl ChainSpec {
28+
/// Creates a new [`ChainSpec`] for Starknet mainnet.
29+
pub fn mainnet() -> Self {
30+
MAINNET.clone()
31+
}
32+
33+
/// Creates a new [`ChainSpec`] for Starknet sepolia testnet.
34+
pub fn sepolia() -> Self {
35+
SEPOLIA.clone()
36+
}
37+
}
38+
39+
//////////////////////////////////////////////////////////////
40+
// Predefined ChainSpec instances
41+
//////////////////////////////////////////////////////////////
42+
43+
lazy_static! {
44+
/// Starknet mainnet chain specification.
45+
pub static ref MAINNET: ChainSpec = ChainSpec {
46+
id: ChainId::MAINNET,
47+
genesis: Genesis::default(),
48+
fee_contracts: FeeContracts {
49+
eth: katana_genesis::constant::DEFAULT_ETH_FEE_TOKEN_ADDRESS,
50+
strk: katana_genesis::constant::DEFAULT_STRK_FEE_TOKEN_ADDRESS,
51+
},
52+
settlement: None,
53+
};
54+
55+
/// Starknet sepolia testnet chain specification.
56+
pub static ref SEPOLIA: ChainSpec = ChainSpec {
57+
id: ChainId::SEPOLIA,
58+
genesis: Genesis::default(),
59+
fee_contracts: FeeContracts {
60+
eth: katana_genesis::constant::DEFAULT_ETH_FEE_TOKEN_ADDRESS,
61+
strk: katana_genesis::constant::DEFAULT_STRK_FEE_TOKEN_ADDRESS,
62+
},
63+
settlement: None,
64+
};
65+
}

crates/chain-spec/src/lib.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use katana_genesis::Genesis;
22
use katana_primitives::block::BlockNumber;
33
use katana_primitives::chain::ChainId;
4-
use katana_primitives::env::VersionedConstantsOverrides;
54
use katana_primitives::{eth, ContractAddress};
65
use serde::{Deserialize, Serialize};
76
use url::Url;
87

98
pub mod dev;
9+
pub mod full_node;
1010
pub mod rollup;
1111

1212
#[derive(Debug, Clone, PartialEq, Eq)]
1313
pub enum ChainSpec {
1414
Dev(dev::ChainSpec),
1515
Rollup(rollup::ChainSpec),
16+
FullNode(full_node::ChainSpec),
1617
}
1718

1819
//////////////////////////////////////////////////////////////
@@ -25,38 +26,45 @@ impl ChainSpec {
2526
Self::Dev(dev::DEV.clone())
2627
}
2728

29+
/// Creates a new [`ChainSpec`] for Starknet mainnet.
30+
pub fn mainnet() -> Self {
31+
Self::FullNode(full_node::ChainSpec::mainnet())
32+
}
33+
34+
/// Creates a new [`ChainSpec`] for Starknet sepolia testnet.
35+
pub fn sepolia() -> Self {
36+
Self::FullNode(full_node::ChainSpec::sepolia())
37+
}
38+
2839
pub fn id(&self) -> ChainId {
2940
match self {
3041
Self::Dev(spec) => spec.id,
3142
Self::Rollup(spec) => spec.id,
43+
Self::FullNode(spec) => spec.id,
3244
}
3345
}
3446

3547
pub fn genesis(&self) -> &Genesis {
3648
match self {
3749
Self::Dev(spec) => &spec.genesis,
3850
Self::Rollup(spec) => &spec.genesis,
51+
Self::FullNode(spec) => &spec.genesis,
3952
}
4053
}
4154

4255
pub fn settlement(&self) -> Option<&SettlementLayer> {
4356
match self {
4457
Self::Dev(spec) => spec.settlement.as_ref(),
4558
Self::Rollup(spec) => Some(&spec.settlement),
59+
Self::FullNode(spec) => spec.settlement.as_ref(),
4660
}
4761
}
4862

4963
pub fn fee_contracts(&self) -> &FeeContracts {
5064
match self {
5165
Self::Dev(spec) => &spec.fee_contracts,
5266
Self::Rollup(spec) => &spec.fee_contracts,
53-
}
54-
}
55-
56-
pub fn versioned_constants_overrides(&self) -> Option<&VersionedConstantsOverrides> {
57-
match self {
58-
Self::Dev(spec) => spec.versioned_constants_overrides.as_ref(),
59-
Self::Rollup(spec) => spec.versioned_constants_overrides.as_ref(),
67+
Self::FullNode(spec) => &spec.fee_contracts,
6068
}
6169
}
6270
}
@@ -73,6 +81,12 @@ impl From<rollup::ChainSpec> for ChainSpec {
7381
}
7482
}
7583

84+
impl From<full_node::ChainSpec> for ChainSpec {
85+
fn from(spec: full_node::ChainSpec) -> Self {
86+
Self::FullNode(spec)
87+
}
88+
}
89+
7690
impl Default for ChainSpec {
7791
fn default() -> Self {
7892
Self::dev()

crates/chain-spec/src/rollup/file.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ pub fn read(dir: &ChainConfigDir) -> Result<ChainSpec, Error> {
8787
id: chain_spec.id,
8888
settlement: chain_spec.settlement,
8989
fee_contracts: chain_spec.fee_contract.into(),
90-
versioned_constants_overrides: None,
9190
})
9291
}
9392

@@ -355,7 +354,6 @@ mod tests {
355354
eth: ContractAddress::default(),
356355
strk: ContractAddress::default(),
357356
},
358-
versioned_constants_overrides: None,
359357
settlement: SettlementLayer::Starknet {
360358
block: 0,
361359
id: ChainId::default(),

crates/chain-spec/src/rollup/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use katana_genesis::Genesis;
22
use katana_primitives::block::{ExecutableBlock, GasPrices, PartialHeader};
33
use katana_primitives::chain::ChainId;
44
use katana_primitives::da::L1DataAvailabilityMode;
5-
use katana_primitives::env::VersionedConstantsOverrides;
65
use katana_primitives::version::CURRENT_STARKNET_VERSION;
76

87
mod file;
@@ -27,8 +26,6 @@ pub struct ChainSpec {
2726

2827
/// The chain's settlement layer configurations.
2928
pub settlement: SettlementLayer,
30-
31-
pub versioned_constants_overrides: Option<VersionedConstantsOverrides>,
3229
}
3330

3431
//////////////////////////////////////////////////////////////

crates/cli/src/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ PREDEPLOYED CONTRACTS
130130
cs.fee_contracts.strk, DEFAULT_LEGACY_ERC20_CLASS_HASH,
131131
);
132132
}
133+
134+
ChainSpec::FullNode(..) => {}
133135
}
134136

135137
println!(

crates/core/src/backend/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ impl<EF: ExecutorFactory> Backend<EF> {
7676
match self.chain_spec.as_ref() {
7777
ChainSpec::Dev(cs) => self.init_dev_genesis(cs),
7878
ChainSpec::Rollup(cs) => self.init_rollup_genesis(cs),
79+
ChainSpec::FullNode(_) => {
80+
// Full nodes sync from the network, so we skip genesis initialization
81+
info!("Full node mode: genesis initialization skipped, will sync from network");
82+
Ok(())
83+
}
7984
}
8085
}
8186

crates/core/src/service/block_producer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<EF: ExecutorFactory> IntervalBlockProducer<EF> {
263263
let validator = TxValidator::new(
264264
state,
265265
flags.clone(),
266-
cfg.clone(),
266+
cfg.cloned(),
267267
block_env,
268268
permit.clone(),
269269
backend.chain_spec.clone(),
@@ -591,7 +591,7 @@ impl<EF: ExecutorFactory> InstantBlockProducer<EF> {
591591
let validator = TxValidator::new(
592592
state,
593593
flags.clone(),
594-
cfg.clone(),
594+
cfg.cloned(),
595595
block_env,
596596
permit.clone(),
597597
backend.chain_spec.clone(),

crates/core/tests/backend.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use url::Url;
2121

2222
fn executor(chain_spec: Arc<ChainSpec>) -> BlockifierFactory {
2323
BlockifierFactory::new(
24-
VersionedConstantsOverrides {
25-
validate_max_n_steps: u32::MAX,
26-
invoke_tx_max_n_steps: u32::MAX,
27-
max_recursion_depth: usize::MAX,
28-
},
24+
Some(VersionedConstantsOverrides {
25+
validate_max_n_steps: Some(u32::MAX),
26+
invoke_tx_max_n_steps: Some(u32::MAX),
27+
max_recursion_depth: Some(usize::MAX),
28+
}),
2929
Default::default(),
3030
BlockLimits::default(),
3131
ClassCache::new().unwrap(),
@@ -72,13 +72,7 @@ fn rollup_chain_spec() -> rollup::ChainSpec {
7272
rpc_url: Url::parse("http://localhost:5050").unwrap(),
7373
};
7474

75-
rollup::ChainSpec {
76-
id,
77-
genesis,
78-
settlement,
79-
fee_contracts,
80-
versioned_constants_overrides: None,
81-
}
75+
rollup::ChainSpec { id, genesis, settlement, fee_contracts }
8276
}
8377

8478
#[rstest]

0 commit comments

Comments
 (0)