Skip to content

Commit 8aaf762

Browse files
committed
chore: fmt and fix lints
1 parent 3d3a78e commit 8aaf762

File tree

17 files changed

+266
-585
lines changed

17 files changed

+266
-585
lines changed

crates/op-rbuilder/src/args/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ impl CliExt for Cli {
6969
/// Returns the type of builder implementation that the node is started
7070
/// with. Currently supports `Standard` and `Flashblocks` modes.
7171
fn builder_mode(&self) -> BuilderMode {
72-
if let Commands::Node(ref node_command) = self.command {
73-
if node_command.ext.flashblocks.enabled {
74-
return BuilderMode::Flashblocks;
75-
}
72+
if let Commands::Node(ref node_command) = self.command &&
73+
node_command.ext.flashblocks.enabled
74+
{
75+
return BuilderMode::Flashblocks;
7676
}
7777
BuilderMode::Standard
7878
}

crates/op-rbuilder/src/args/playground.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ impl PlaygroundOptions {
8080
/// Creates a new `PlaygroundOptions` instance with the specified genesis path.
8181
pub(super) fn new(path: &Path) -> Result<Self> {
8282
if !path.exists() {
83-
return Err(eyre!(
84-
"Playground data directory {} does not exist",
85-
path.display()
86-
));
83+
return Err(eyre!("Playground data directory {} does not exist", path.display()));
8784
}
8885

8986
let chain = OpChainSpecParser::parse(&existing_path(path, "l2-genesis.json")?)?;
@@ -127,9 +124,8 @@ impl PlaygroundOptions {
127124
// either via the command line or an environment variable. Otherwise, don't
128125
// override the user provided values.
129126
let matches = Cli::command().get_matches();
130-
let matches = matches
131-
.subcommand_matches("node")
132-
.expect("validated that we are in the node command");
127+
let matches =
128+
matches.subcommand_matches("node").expect("validated that we are in the node command");
133129

134130
if matches.value_source("chain").is_default() {
135131
node.chain = self.chain;
@@ -223,9 +219,7 @@ fn extract_chain_block_time(basepath: &Path) -> Result<Duration> {
223219

224220
fn extract_deterministic_p2p_key(basepath: &Path) -> Result<SecretKey> {
225221
let key = read_to_string(existing_path(basepath, "enode-key-1.txt")?)?;
226-
Ok(SecretKey::from_slice(
227-
&hex::decode(key).map_err(|e| eyre!("Invalid hex key: {e}"))?,
228-
)?)
222+
Ok(SecretKey::from_slice(&hex::decode(key).map_err(|e| eyre!("Invalid hex key: {e}"))?)?)
229223
}
230224

231225
fn read_docker_compose(basepath: &Path) -> Result<serde_yaml::Value> {
@@ -238,9 +232,7 @@ fn extract_service_command_flag(basepath: &Path, service: &str, flag: &str) -> R
238232
let docker_compose = read_docker_compose(basepath)?;
239233
let args = docker_compose["services"][service]["command"]
240234
.as_sequence()
241-
.ok_or(eyre!(
242-
"docker-compose.yaml is missing command line arguments for {service}"
243-
))?
235+
.ok_or(eyre!("docker-compose.yaml is missing command line arguments for {service}"))?
244236
.iter()
245237
.map(|s| {
246238
s.as_str().ok_or_else(|| {
@@ -254,9 +246,8 @@ fn extract_service_command_flag(basepath: &Path, service: &str, flag: &str) -> R
254246
.position(|arg| *arg == flag)
255247
.ok_or_else(|| eyre!("docker_compose: {flag} not found on {service} service"))?;
256248

257-
let value = args
258-
.get(index + 1)
259-
.ok_or_else(|| eyre!("docker_compose: {flag} value not found"))?;
249+
let value =
250+
args.get(index + 1).ok_or_else(|| eyre!("docker_compose: {flag} value not found"))?;
260251

261252
Ok(value.to_string())
262253
}
@@ -274,9 +265,7 @@ fn extract_trusted_peer_port(basepath: &Path) -> Result<u16> {
274265
// command line arguments used to start the op-geth service
275266

276267
let Some(opgeth_args) = docker_compose["services"]["op-geth"]["command"][1].as_str() else {
277-
return Err(eyre!(
278-
"docker-compose.yaml is missing command line arguments for op-geth"
279-
));
268+
return Err(eyre!("docker-compose.yaml is missing command line arguments for op-geth"));
280269
};
281270

282271
let opgeth_args = opgeth_args.split_whitespace().collect::<Vec<_>>();
@@ -289,16 +278,12 @@ fn extract_trusted_peer_port(basepath: &Path) -> Result<u16> {
289278
.get(port_param_position + 1)
290279
.ok_or_else(|| eyre!("docker_compose: --port value not found"))?;
291280

292-
let port_value = port_value
293-
.parse::<u16>()
294-
.map_err(|e| eyre!("Invalid port value: {e}"))?;
281+
let port_value = port_value.parse::<u16>().map_err(|e| eyre!("Invalid port value: {e}"))?;
295282

296283
// now we need to find the external port of the op-geth service from the docker-compose.yaml
297284
// ports mapping used to start the op-geth service
298285
let Some(opgeth_ports) = docker_compose["services"]["op-geth"]["ports"].as_sequence() else {
299-
return Err(eyre!(
300-
"docker-compose.yaml is missing ports mapping for op-geth"
301-
));
286+
return Err(eyre!("docker-compose.yaml is missing ports mapping for op-geth"));
302287
};
303288
let ports_mapping = opgeth_ports
304289
.iter()

crates/op-rbuilder/src/builders/builder_tx.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ pub trait BuilderTransactions<ExtraCtx: Debug + Default = ()>: Debug {
8585
db: &mut State<impl Database>,
8686
) -> Result<Vec<BuilderTransactionCtx>, BuilderTransactionError> {
8787
{
88-
let mut evm = builder_ctx
89-
.evm_config
90-
.evm_with_env(&mut *db, builder_ctx.evm_env.clone());
88+
let mut evm =
89+
builder_ctx.evm_config.evm_with_env(&mut *db, builder_ctx.evm_env.clone());
9190

9291
let mut invalid: HashSet<Address> = HashSet::new();
9392

@@ -109,7 +108,8 @@ pub trait BuilderTransactions<ExtraCtx: Debug + Default = ()>: Debug {
109108
continue;
110109
}
111110

112-
// Add gas used by the transaction to cumulative gas used, before creating the receipt
111+
// Add gas used by the transaction to cumulative gas used, before creating the
112+
// receipt
113113
let gas_used = result.gas_used();
114114
info.cumulative_gas_used += gas_used;
115115

@@ -127,8 +127,7 @@ pub trait BuilderTransactions<ExtraCtx: Debug + Default = ()>: Debug {
127127

128128
// Append sender and transaction to the respective lists
129129
info.executed_senders.push(builder_tx.signed_tx.signer());
130-
info.executed_transactions
131-
.push(builder_tx.signed_tx.clone().into_inner());
130+
info.executed_transactions.push(builder_tx.signed_tx.clone().into_inner());
132131
}
133132

134133
// Release the db reference by dropping evm
@@ -151,9 +150,7 @@ pub trait BuilderTransactions<ExtraCtx: Debug + Default = ()>: Debug {
151150
.with_bundle_prestate(db.bundle_state.clone())
152151
.with_bundle_update()
153152
.build();
154-
let mut evm = ctx
155-
.evm_config
156-
.evm_with_env(&mut simulation_state, ctx.evm_env.clone());
153+
let mut evm = ctx.evm_config.evm_with_env(&mut simulation_state, ctx.evm_env.clone());
157154

158155
for builder_tx in builder_txs {
159156
let ResultAndState { state, .. } = evm

crates/op-rbuilder/src/builders/context.rs

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
9393

9494
/// Returns the block gas limit to target.
9595
pub(super) fn block_gas_limit(&self) -> u64 {
96-
self.attributes()
97-
.gas_limit
98-
.unwrap_or(self.evm_env.block_env.gas_limit)
96+
self.attributes().gas_limit.unwrap_or(self.evm_env.block_env.gas_limit)
9997
}
10098

10199
/// Returns the block number for the block.
@@ -110,10 +108,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
110108

111109
/// Returns the current blob gas price.
112110
pub(super) fn get_blob_gasprice(&self) -> Option<u64> {
113-
self.evm_env
114-
.block_env
115-
.blob_gasprice()
116-
.map(|gasprice| gasprice as u64)
111+
self.evm_env.block_env.blob_gasprice().map(|gasprice| gasprice as u64)
117112
}
118113

119114
/// Returns the blob fields for the header.
@@ -123,11 +118,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
123118
// OP doesn't support blobs/EIP-4844.
124119
// https://specs.optimism.io/protocol/exec-engine.html#ecotone-disable-blob-transactions
125120
// Need [Some] or [None] based on hardfork to match block hash.
126-
if self.is_ecotone_active() {
127-
(Some(0), Some(0))
128-
} else {
129-
(None, None)
130-
}
121+
if self.is_ecotone_active() { (Some(0), Some(0)) } else { (None, None) }
131122
}
132123

133124
/// Returns the extra data for the block.
@@ -159,32 +150,27 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
159150

160151
/// Returns true if regolith is active for the payload.
161152
pub(super) fn is_regolith_active(&self) -> bool {
162-
self.chain_spec
163-
.is_regolith_active_at_timestamp(self.attributes().timestamp())
153+
self.chain_spec.is_regolith_active_at_timestamp(self.attributes().timestamp())
164154
}
165155

166156
/// Returns true if ecotone is active for the payload.
167157
pub(super) fn is_ecotone_active(&self) -> bool {
168-
self.chain_spec
169-
.is_ecotone_active_at_timestamp(self.attributes().timestamp())
158+
self.chain_spec.is_ecotone_active_at_timestamp(self.attributes().timestamp())
170159
}
171160

172161
/// Returns true if canyon is active for the payload.
173162
pub(super) fn is_canyon_active(&self) -> bool {
174-
self.chain_spec
175-
.is_canyon_active_at_timestamp(self.attributes().timestamp())
163+
self.chain_spec.is_canyon_active_at_timestamp(self.attributes().timestamp())
176164
}
177165

178166
/// Returns true if holocene is active for the payload.
179167
pub(super) fn is_holocene_active(&self) -> bool {
180-
self.chain_spec
181-
.is_holocene_active_at_timestamp(self.attributes().timestamp())
168+
self.chain_spec.is_holocene_active_at_timestamp(self.attributes().timestamp())
182169
}
183170

184171
/// Returns true if isthmus is active for the payload.
185172
pub(super) fn is_isthmus_active(&self) -> bool {
186-
self.chain_spec
187-
.is_isthmus_active_at_timestamp(self.attributes().timestamp())
173+
self.chain_spec.is_isthmus_active_at_timestamp(self.attributes().timestamp())
188174
}
189175

190176
/// Returns the chain id
@@ -247,12 +233,9 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
247233
// purely for the purposes of utilizing the `evm_config.tx_env`` function.
248234
// Deposit transactions do not have signatures, so if the tx is a deposit, this
249235
// will just pull in its `from` address.
250-
let sequencer_tx = sequencer_tx
251-
.value()
252-
.try_clone_into_recovered()
253-
.map_err(|_| {
254-
PayloadBuilderError::other(OpPayloadBuilderError::TransactionEcRecoverFailed)
255-
})?;
236+
let sequencer_tx = sequencer_tx.value().try_clone_into_recovered().map_err(|_| {
237+
PayloadBuilderError::other(OpPayloadBuilderError::TransactionEcRecoverFailed)
238+
})?;
256239

257240
// Cache the depositor account prior to the state transition for the deposit nonce.
258241
//
@@ -339,12 +322,8 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
339322

340323
// Remove once we merge Reth 1.4.4
341324
// Fixed in https://github.com/paradigmxyz/reth/pull/16514
342-
self.metrics
343-
.da_block_size_limit
344-
.set(block_da_limit.map_or(-1.0, |v| v as f64));
345-
self.metrics
346-
.da_tx_size_limit
347-
.set(tx_da_limit.map_or(-1.0, |v| v as f64));
325+
self.metrics.da_block_size_limit.set(block_da_limit.map_or(-1.0, |v| v as f64));
326+
self.metrics.da_tx_size_limit.set(tx_da_limit.map_or(-1.0, |v| v as f64));
348327

349328
let block_attr = BlockConditionalAttributes {
350329
number: self.block_number(),
@@ -361,9 +340,11 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
361340
let tx_hash = tx.tx_hash();
362341

363342
// exclude reverting transaction if:
364-
// - the transaction comes from a bundle (is_some) and the hash **is not** in reverted hashes
365-
// Note that we need to use the Option to signal whether the transaction comes from a bundle,
366-
// otherwise, we would exclude all transactions that are not in the reverted hashes.
343+
// - the transaction comes from a bundle (is_some) and the hash **is not** in reverted
344+
// hashes
345+
// Note that we need to use the Option to signal whether the transaction comes from a
346+
// bundle, otherwise, we would exclude all transactions that are not in the
347+
// reverted hashes.
367348
let is_bundle_tx = reverted_hashes.is_some();
368349
let exclude_reverting_txs =
369350
is_bundle_tx && !reverted_hashes.unwrap().contains(&tx_hash);
@@ -382,19 +363,20 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
382363
num_txs_considered += 1;
383364

384365
// TODO: ideally we should get this from the txpool stream
385-
if let Some(conditional) = conditional
386-
&& !conditional.matches_block_attributes(&block_attr)
366+
if let Some(conditional) = conditional &&
367+
!conditional.matches_block_attributes(&block_attr)
387368
{
388369
best_txs.mark_invalid(tx.signer(), tx.nonce());
389370
continue;
390371
}
391372

392-
// TODO: remove this condition and feature once we are comfortable enabling interop for everything
373+
// TODO: remove this condition and feature once we are comfortable enabling interop for
374+
// everything
393375
if cfg!(feature = "interop") {
394-
// We skip invalid cross chain txs, they would be removed on the next block update in
395-
// the maintenance job
396-
if let Some(interop) = interop
397-
&& !is_valid_interop(interop, self.config.attributes.timestamp())
376+
// We skip invalid cross chain txs, they would be removed on the next block update
377+
// in the maintenance job
378+
if let Some(interop) = interop &&
379+
!is_valid_interop(interop, self.config.attributes.timestamp())
398380
{
399381
log_txn(TxnExecutionResult::InteropFailed);
400382
best_txs.mark_invalid(tx.signer(), tx.nonce());
@@ -455,21 +437,15 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
455437
}
456438
};
457439

458-
self.metrics
459-
.tx_simulation_duration
460-
.record(tx_simulation_start_time.elapsed());
440+
self.metrics.tx_simulation_duration.record(tx_simulation_start_time.elapsed());
461441
self.metrics.tx_byte_size.record(tx.inner().size() as f64);
462442
num_txs_simulated += 1;
463443

464444
// Run the per-address gas limiting before checking if the tx has
465445
// reverted or not, as this is a check against maliciously searchers
466446
// sending txs that are expensive to compute but always revert.
467447
let gas_used = result.gas_used();
468-
if self
469-
.address_gas_limiter
470-
.consume_gas(tx.signer(), gas_used)
471-
.is_err()
472-
{
448+
if self.address_gas_limiter.consume_gas(tx.signer(), gas_used).is_err() {
473449
log_txn(TxnExecutionResult::MaxGasUsageExceeded);
474450
best_txs.mark_invalid(tx.signer(), tx.nonce());
475451
continue;
@@ -495,12 +471,12 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
495471

496472
// add gas used by the transaction to cumulative gas used, before creating the
497473
// receipt
498-
if let Some(max_gas_per_txn) = self.max_gas_per_txn {
499-
if gas_used > max_gas_per_txn {
500-
log_txn(TxnExecutionResult::MaxGasUsageExceeded);
501-
best_txs.mark_invalid(tx.signer(), tx.nonce());
502-
continue;
503-
}
474+
if let Some(max_gas_per_txn) = self.max_gas_per_txn &&
475+
gas_used > max_gas_per_txn
476+
{
477+
log_txn(TxnExecutionResult::MaxGasUsageExceeded);
478+
best_txs.mark_invalid(tx.signer(), tx.nonce());
479+
continue;
504480
}
505481

506482
info.cumulative_gas_used += gas_used;

0 commit comments

Comments
 (0)