Skip to content

Commit 351f6ce

Browse files
blockifier_reexecution: allow custom chain id
1 parent 802fd8b commit 351f6ce

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

crates/blockifier_reexecution/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ The blockier reexecution crate is intended to verify blockifier changes do not b
77
## CLI Commands
88
Using the different CLI commands, it is possible to run reexecution tests in different modes, to download (permisionless) files for offline reexecution from the GC bucket, and to upload (permissioned) files for offline reexecution to the GC bucket.
99

10+
### Chain ID Option
11+
Commands that use RPC (`rpc-test`, `reexecute-single-tx`, `write-to-file`) accept an optional `-c/--chain-id` argument. If not provided, the chain ID is guessed from the node URL.
12+
13+
Standard chain IDs:
14+
- `SN_MAIN` - Mainnet
15+
- `SN_SEPOLIA` - Sepolia testnet
16+
- `SN_INTEGRATION_SEPOLIA` - Integration Sepolia
17+
18+
Custom chain IDs are also supported for private/custom networks:
19+
```
20+
cargo run --bin blockifier_reexecution rpc-test -n <node_url> -b <block_number> -c MY_CUSTOM_CHAIN
21+
```
22+
1023
### Reexecution Modes
1124

1225
Reexecution can be run via CLI in the following modes:

crates/blockifier_reexecution/src/state_reader/cli.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,24 @@ pub struct BlockifierReexecutionCliArgs {
2020
pub command: Command,
2121
}
2222

23-
#[derive(clap::ValueEnum, Clone, Debug)]
24-
pub enum SupportedChainId {
25-
Mainnet,
26-
Testnet,
27-
Integration,
28-
}
29-
30-
impl From<SupportedChainId> for ChainId {
31-
fn from(chain_id: SupportedChainId) -> Self {
32-
match chain_id {
33-
SupportedChainId::Mainnet => Self::Mainnet,
34-
SupportedChainId::Testnet => Self::Sepolia,
35-
SupportedChainId::Integration => Self::IntegrationSepolia,
36-
}
37-
}
38-
}
39-
4023
#[derive(Clone, Debug, Args)]
4124
pub struct RpcArgs {
4225
/// Node url.
4326
#[clap(long, short = 'n')]
4427
pub node_url: String,
4528

4629
/// Optional chain ID (if not provided, it will be guessed from the node url).
30+
/// Standard chain IDs: SN_MAIN, SN_SEPOLIA, SN_INTEGRATION_SEPOLIA.
31+
/// Custom chain IDs are also supported.
4732
#[clap(long, short = 'c')]
48-
pub chain_id: Option<SupportedChainId>,
33+
pub chain_id: Option<ChainId>,
4934
}
5035

5136
impl RpcArgs {
5237
pub fn parse_chain_id(&self) -> ChainId {
5338
self.chain_id
5439
.clone()
55-
.map(ChainId::from)
56-
.unwrap_or(guess_chain_id_from_node_url(self.node_url.as_str()).unwrap())
40+
.unwrap_or_else(|| guess_chain_id_from_node_url(self.node_url.as_str()).unwrap())
5741
}
5842
}
5943

crates/blockifier_reexecution/src/state_reader/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use blockifier::blockifier::config::ContractClassManagerConfig;
1010
use blockifier::context::{ChainInfo, FeeTokenAddresses};
1111
use blockifier::execution::contract_class::{CompiledClassV0, CompiledClassV1};
1212
use blockifier::state::cached_state::{CachedState, CommitmentStateDiff, StateMaps};
13+
use blockifier::state::contract_class_manager::ContractClassManager;
1314
use blockifier::state::global_cache::CompiledClasses;
1415
use blockifier::state::state_api::{StateReader, StateResult};
15-
use blockifier::state::contract_class_manager::ContractClassManager;
1616
use indexmap::IndexMap;
1717
use pretty_assertions::assert_eq;
1818
use serde::{Deserialize, Serialize};

crates/starknet_api/src/core.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ impl std::fmt::Display for ChainId {
8181
}
8282
}
8383

84+
impl std::str::FromStr for ChainId {
85+
type Err = std::convert::Infallible;
86+
87+
fn from_str(s: &str) -> Result<Self, Self::Err> {
88+
Ok(Self::from(s.to_owned()))
89+
}
90+
}
91+
8492
impl ChainId {
8593
pub fn as_hex(&self) -> String {
8694
format!("0x{}", hex::encode(self.to_string()))

0 commit comments

Comments
 (0)