Skip to content

Commit 460a958

Browse files
committed
anvil: Add --celo flag
1 parent 0e7eca2 commit 460a958

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

crates/anvil/src/cmd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ impl NodeArgs {
279279
.with_max_persisted_states(self.max_persisted_states)
280280
.with_optimism(self.evm.optimism)
281281
.with_odyssey(self.evm.odyssey)
282+
.with_celo(self.evm.celo)
282283
.with_disable_default_create2_deployer(self.evm.disable_default_create2_deployer)
283284
.with_slots_in_an_epoch(self.slots_in_an_epoch)
284285
.with_memory_limit(self.evm.memory_limit)
@@ -599,6 +600,10 @@ pub struct AnvilEvmArgs {
599600
/// Enable Odyssey features
600601
#[arg(long, alias = "alphanet")]
601602
pub odyssey: bool,
603+
604+
/// Run a Celo chain
605+
#[arg(long)]
606+
pub celo: bool,
602607
}
603608

604609
/// Resolves an alias passed as fork-url to the matching url defined in the rpc_endpoints section

crates/anvil/src/config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub struct NodeConfig {
194194
pub precompile_factory: Option<Arc<dyn PrecompileFactory>>,
195195
/// Enable Odyssey features.
196196
pub odyssey: bool,
197+
/// Enable Celo features.
198+
pub celo: bool,
197199
/// Do not print log messages.
198200
pub silent: bool,
199201
/// The path where states are cached.
@@ -489,6 +491,7 @@ impl Default for NodeConfig {
489491
memory_limit: None,
490492
precompile_factory: None,
491493
odyssey: false,
494+
celo: false,
492495
silent: false,
493496
cache_path: None,
494497
}
@@ -1007,6 +1010,17 @@ impl NodeConfig {
10071010
self
10081011
}
10091012

1013+
/// Sets whether to enable Celo support
1014+
#[must_use]
1015+
pub fn with_celo(mut self, celo: bool) -> Self {
1016+
self.celo = celo;
1017+
if celo {
1018+
// Celo requires Optimism support
1019+
self.enable_optimism = true;
1020+
}
1021+
self
1022+
}
1023+
10101024
/// Makes the node silent to not emit anything on stdout
10111025
#[must_use]
10121026
pub fn silent(self) -> Self {
@@ -1061,6 +1075,7 @@ impl NodeConfig {
10611075
..Default::default()
10621076
},
10631077
self.enable_optimism,
1078+
self.celo,
10641079
);
10651080

10661081
let fees = FeeManager::new(

crates/anvil/src/eth/backend/env.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ pub struct Env {
1010
pub evm_env: EvmEnv,
1111
pub tx: OpTransaction<TxEnv>,
1212
pub is_optimism: bool,
13+
pub is_celo: bool,
1314
}
1415

1516
/// Helper container type for [`EvmEnv`] and [`OpTransaction<TxEnv>`].
1617
impl Env {
17-
pub fn new(cfg: CfgEnv, block: BlockEnv, tx: OpTransaction<TxEnv>, is_optimism: bool) -> Self {
18-
Self { evm_env: EvmEnv { cfg_env: cfg, block_env: block }, tx, is_optimism }
18+
pub fn new(
19+
cfg: CfgEnv,
20+
block: BlockEnv,
21+
tx: OpTransaction<TxEnv>,
22+
is_optimism: bool,
23+
is_celo: bool,
24+
) -> Self {
25+
Self { evm_env: EvmEnv { cfg_env: cfg, block_env: block }, tx, is_optimism, is_celo }
1926
}
2027
}
2128

crates/anvil/src/eth/backend/executor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub struct TransactionExecutor<'a, Db: ?Sized, V: TransactionValidator> {
120120
pub enable_steps_tracing: bool,
121121
pub odyssey: bool,
122122
pub optimism: bool,
123+
pub celo: bool,
123124
pub print_logs: bool,
124125
pub print_traces: bool,
125126
/// Recorder used for decoding traces, used together with print_traces
@@ -264,7 +265,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> TransactionExecutor<'_, DB, V> {
264265
tx_env.enveloped_tx = Some(alloy_rlp::encode(&tx.transaction.transaction).into());
265266
}
266267

267-
Env::new(self.cfg_env.clone(), self.block_env.clone(), tx_env, self.optimism)
268+
Env::new(self.cfg_env.clone(), self.block_env.clone(), tx_env, self.optimism, self.celo)
268269
}
269270
}
270271

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,11 @@ impl Backend {
835835
self.env.read().is_optimism
836836
}
837837

838+
/// Returns true if Celo features are active
839+
pub fn is_celo(&self) -> bool {
840+
self.env.read().is_celo
841+
}
842+
838843
/// Returns [`BlobParams`] corresponding to the current spec.
839844
pub fn blob_params(&self) -> BlobParams {
840845
let spec_id = self.env.read().evm_env.cfg_env.spec;
@@ -1266,6 +1271,7 @@ impl Backend {
12661271
precompile_factory: self.precompile_factory.clone(),
12671272
odyssey: self.odyssey,
12681273
optimism: self.is_optimism(),
1274+
celo: self.is_celo(),
12691275
blob_params: self.blob_params(),
12701276
};
12711277

@@ -1353,6 +1359,7 @@ impl Backend {
13531359
odyssey: self.odyssey,
13541360
precompile_factory: self.precompile_factory.clone(),
13551361
optimism: self.is_optimism(),
1362+
celo: self.is_celo(),
13561363
blob_params: self.blob_params(),
13571364
};
13581365
let executed_tx = executor.execute();
@@ -2710,6 +2717,7 @@ impl Backend {
27102717
precompile_factory: self.precompile_factory.clone(),
27112718
odyssey: self.odyssey,
27122719
optimism: self.is_optimism(),
2720+
celo: self.is_celo(),
27132721
blob_params: self.blob_params(),
27142722
};
27152723

crates/anvil/src/evm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ mod tests {
149149
..Default::default()
150150
},
151151
is_optimism: true,
152+
is_celo: false,
152153
};
153154

154155
let mut chain = L1BlockInfo::default();

0 commit comments

Comments
 (0)