Skip to content

Commit

Permalink
chore: enforce more lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jan 20, 2024
1 parent eb629fd commit c88d0c7
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 33 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
//! - `js-tracer`: Enables a JavaScript tracer implementation. This pulls in extra dependencies
//! (such as `boa`, `tokio` and `serde_json`).

#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

/// An inspector implementation for an EIP2930 Accesslist
Expand Down
4 changes: 2 additions & 2 deletions src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use maybe_owned::MaybeOwnedInspector;
/// - Block: Hook on block execution
/// - BlockWithIndex: Hook on block execution transaction index
/// - Transaction: Hook on a specific transaction hash
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Copy)]
pub enum Hook {
#[default]
/// No hook.
Expand Down Expand Up @@ -73,7 +73,7 @@ impl InspectorStack {
}

/// Configuration for the inspectors.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, Copy)]
pub struct InspectorStackConfig {
/// Enable revm inspector printer.
/// In execution this will print opcode level traces directly to console.
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) enum PushTraceKind {

impl PushTraceKind {
#[inline]
fn is_attach_to_parent(&self) -> bool {
const fn is_attach_to_parent(&self) -> bool {
matches!(self, PushTraceKind::PushAndAttachToParent)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ where
/// The value is obvious for most opcodes, but SWAP* and DUP* are a bit weird,
/// and we handle those as they are handled in parity vmtraces.
/// For reference: <https://github.com/ledgerwatch/erigon/blob/9b74cf0384385817459f88250d1d9c459a18eab1/turbo/jsonrpc/trace_adhoc.go#L451>
pub(crate) fn stack_push_count(step_op: OpCode) -> usize {
pub(crate) const fn stack_push_count(step_op: OpCode) -> usize {
let step_op = step_op.get();
match step_op {
opcode::PUSH0..=opcode::PUSH32 => 1,
Expand Down
20 changes: 10 additions & 10 deletions src/tracing/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,36 +100,36 @@ impl TracingInspectorConfig {
/// Configure whether calls to precompiles should be ignored.
///
/// If set to `true`, calls to precompiles without value transfers will be ignored.
pub fn set_exclude_precompile_calls(mut self, exclude_precompile_calls: bool) -> Self {
pub const fn set_exclude_precompile_calls(mut self, exclude_precompile_calls: bool) -> Self {
self.exclude_precompile_calls = exclude_precompile_calls;
self
}

/// Configure whether individual opcode level steps should be recorded
pub fn set_steps(mut self, record_steps: bool) -> Self {
pub const fn set_steps(mut self, record_steps: bool) -> Self {
self.record_steps = record_steps;
self
}

/// Configure whether the tracer should record memory snapshots
pub fn set_memory_snapshots(mut self, record_memory_snapshots: bool) -> Self {
pub const fn set_memory_snapshots(mut self, record_memory_snapshots: bool) -> Self {
self.record_memory_snapshots = record_memory_snapshots;
self
}

/// Configure how the tracer should record stack snapshots
pub fn set_stack_snapshots(mut self, record_stack_snapshots: StackSnapshotType) -> Self {
pub const fn set_stack_snapshots(mut self, record_stack_snapshots: StackSnapshotType) -> Self {
self.record_stack_snapshots = record_stack_snapshots;
self
}

/// Sets state diff recording to true.
pub fn with_state_diffs(self) -> Self {
pub const fn with_state_diffs(self) -> Self {
self.set_steps_and_state_diffs(true)
}

/// Configure whether the tracer should record state diffs
pub fn set_state_diffs(mut self, record_state_diff: bool) -> Self {
pub const fn set_state_diffs(mut self, record_state_diff: bool) -> Self {
self.record_state_diff = record_state_diff;
self
}
Expand All @@ -138,14 +138,14 @@ impl TracingInspectorConfig {
///
/// This is a convenience method for setting both [TracingInspectorConfig::set_steps] and
/// [TracingInspectorConfig::set_state_diffs] since tracking state diffs requires steps tracing.
pub fn set_steps_and_state_diffs(mut self, steps_and_diffs: bool) -> Self {
pub const fn set_steps_and_state_diffs(mut self, steps_and_diffs: bool) -> Self {
self.record_steps = steps_and_diffs;
self.record_state_diff = steps_and_diffs;
self
}

/// Configure whether the tracer should record logs
pub fn set_record_logs(mut self, record_logs: bool) -> Self {
pub const fn set_record_logs(mut self, record_logs: bool) -> Self {
self.record_logs = record_logs;
self
}
Expand All @@ -165,13 +165,13 @@ pub enum StackSnapshotType {
impl StackSnapshotType {
/// Returns true if this is the [StackSnapshotType::Full] variant
#[inline]
pub fn is_full(self) -> bool {
pub const fn is_full(self) -> bool {
matches!(self, Self::Full)
}

/// Returns true if this is the [StackSnapshotType::Pushes] variant
#[inline]
pub fn is_pushes(self) -> bool {
pub const fn is_pushes(self) -> bool {
matches!(self, Self::Pushes)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/fourbyte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct FourByteInspector {

impl FourByteInspector {
/// Returns the map of SELECTOR to number of occurrences entries
pub fn inner(&self) -> &HashMap<(Selector, usize), u64> {
pub const fn inner(&self) -> &HashMap<(Selector, usize), u64> {
&self.inner
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ impl JsInspector {
}

/// Returns the config object.
pub fn config(&self) -> &serde_json::Value {
pub const fn config(&self) -> &serde_json::Value {
&self.config
}

/// Returns the transaction context.
pub fn transaction_context(&self) -> &TransactionContext {
pub const fn transaction_context(&self) -> &TransactionContext {
&self.transaction_context
}

Expand Down Expand Up @@ -264,7 +264,7 @@ impl JsInspector {
output: output_bytes.unwrap_or_default(),
time: env.block.timestamp.to_string(),
intrinsic_gas: 0,
transaction_ctx: self.transaction_context.clone(),
transaction_ctx: self.transaction_context,
};
let ctx = ctx.into_js_object(&mut self.ctx)?;
let db = db.into_js_object(&mut self.ctx)?;
Expand Down Expand Up @@ -572,7 +572,7 @@ where

/// Contains some contextual infos for a transaction execution that is made available to the JS
/// object.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct TransactionContext {
/// Hash of the block the tx is contained within.
///
Expand All @@ -590,19 +590,19 @@ pub struct TransactionContext {

impl TransactionContext {
/// Sets the block hash.
pub fn with_block_hash(mut self, block_hash: B256) -> Self {
pub const fn with_block_hash(mut self, block_hash: B256) -> Self {
self.block_hash = Some(block_hash);
self
}

/// Sets the index of the transaction within a block.
pub fn with_tx_index(mut self, tx_index: usize) -> Self {
pub const fn with_tx_index(mut self, tx_index: usize) -> Self {
self.tx_index = Some(tx_index);
self
}

/// Sets the hash of the transaction.
pub fn with_tx_hash(mut self, tx_hash: B256) -> Self {
pub const fn with_tx_hash(mut self, tx_hash: B256) -> Self {
self.tx_hash = Some(tx_hash);
self
}
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ impl TracingInspector {
}

/// Returns the config of the inspector.
pub fn config(&self) -> &TracingInspectorConfig {
pub const fn config(&self) -> &TracingInspectorConfig {
&self.config
}

/// Gets a reference to the recorded call traces.
pub fn get_traces(&self) -> &CallTraceArena {
pub const fn get_traces(&self) -> &CallTraceArena {
&self.traces
}

Expand Down
2 changes: 1 addition & 1 deletion src/tracing/opcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct OpcodeCountInspector {
impl OpcodeCountInspector {
/// Returns the opcode counter
#[inline]
pub fn count(&self) -> usize {
pub const fn count(&self) -> usize {
self.count
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl CallTraceNode {
/// Returns the call context's execution address
///
/// See `Inspector::call` impl of [TracingInspector](crate::tracing::TracingInspector)
pub fn execution_address(&self) -> Address {
pub const fn execution_address(&self) -> Address {
if self.trace.kind.is_delegate() {
self.trace.caller
} else {
Expand Down Expand Up @@ -391,19 +391,19 @@ pub enum CallKind {
impl CallKind {
/// Returns true if the call is a create
#[inline]
pub fn is_any_create(&self) -> bool {
pub const fn is_any_create(&self) -> bool {
matches!(self, CallKind::Create | CallKind::Create2)
}

/// Returns true if the call is a delegate of some sorts
#[inline]
pub fn is_delegate(&self) -> bool {
pub const fn is_delegate(&self) -> bool {
matches!(self, CallKind::DelegateCall | CallKind::CallCode)
}

/// Returns true if the call is [CallKind::StaticCall].
#[inline]
pub fn is_static_call(&self) -> bool {
pub const fn is_static_call(&self) -> bool {
matches!(self, CallKind::StaticCall)
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@ pub(crate) struct CallTraceStepStackItem<'a> {
}

/// Ordering enum for calls and logs
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogCallOrder {
/// Contains the index of the corresponding log
Log(usize),
Expand Down Expand Up @@ -573,14 +573,14 @@ impl CallTraceStep {

/// Returns true if the step is a STOP opcode
#[inline]
pub(crate) fn is_stop(&self) -> bool {
pub(crate) const fn is_stop(&self) -> bool {
matches!(self.op.get(), opcode::STOP)
}

/// Returns true if the step is a call operation, any of
/// CALL, CALLCODE, DELEGATECALL, STATICCALL, CREATE, CREATE2
#[inline]
pub(crate) fn is_calllike_op(&self) -> bool {
pub(crate) const fn is_calllike_op(&self) -> bool {
matches!(
self.op.get(),
opcode::CALL
Expand All @@ -594,7 +594,7 @@ impl CallTraceStep {

// Returns true if the status code is an error or revert, See [InstructionResult::Revert]
#[inline]
pub(crate) fn is_error(&self) -> bool {
pub(crate) const fn is_error(&self) -> bool {
self.status as u8 >= InstructionResult::Revert as u8
}

Expand Down

0 comments on commit c88d0c7

Please sign in to comment.