diff --git a/Cargo.toml b/Cargo.toml index 3930d3c7..38405842 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,9 @@ lto = "fat" codegen-units = 1 incremental = false +[workspace.lints.rust] +unreachable_pub = "warn" + [workspace.dependencies] reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.7.0" } reth-chain-state = { git = "https://github.com/paradigmxyz/reth", tag = "v1.7.0" } diff --git a/crates/op-rbuilder/Cargo.toml b/crates/op-rbuilder/Cargo.toml index a7c22586..3d31df46 100644 --- a/crates/op-rbuilder/Cargo.toml +++ b/crates/op-rbuilder/Cargo.toml @@ -8,6 +8,9 @@ homepage.workspace = true repository.workspace = true default-run = "op-rbuilder" +[lints] +workspace = true + [dependencies] reth.workspace = true reth-optimism-node.workspace = true diff --git a/crates/op-rbuilder/src/args/playground.rs b/crates/op-rbuilder/src/args/playground.rs index c4cf2470..3ef24c1d 100644 --- a/crates/op-rbuilder/src/args/playground.rs +++ b/crates/op-rbuilder/src/args/playground.rs @@ -50,7 +50,7 @@ use url::{Host, Url}; use super::Cli; -pub struct PlaygroundOptions { +pub(super) struct PlaygroundOptions { /// Sets node.chain in NodeCommand pub chain: Arc, @@ -78,7 +78,7 @@ pub struct PlaygroundOptions { impl PlaygroundOptions { /// Creates a new `PlaygroundOptions` instance with the specified genesis path. - pub fn new(path: &Path) -> Result { + pub(super) fn new(path: &Path) -> Result { if !path.exists() { return Err(eyre!( "Playground data directory {} does not exist", @@ -112,7 +112,7 @@ impl PlaygroundOptions { }) } - pub fn apply(self, cli: Cli) -> Cli { + pub(super) fn apply(self, cli: Cli) -> Cli { let mut cli = cli; let Commands::Node(ref mut node) = cli.command else { // playground defaults are only relevant if running the node commands. diff --git a/crates/op-rbuilder/src/builders/builder_tx.rs b/crates/op-rbuilder/src/builders/builder_tx.rs index 3dcb8984..80c73c83 100644 --- a/crates/op-rbuilder/src/builders/builder_tx.rs +++ b/crates/op-rbuilder/src/builders/builder_tx.rs @@ -12,7 +12,7 @@ pub trait BuilderTx { // Scaffolding for how to construct the end of block builder transaction // This will be the regular end of block transaction without the TEE key #[derive(Clone)] -pub struct StandardBuilderTx { +pub(super) struct StandardBuilderTx { #[allow(dead_code)] pub signer: Option, } diff --git a/crates/op-rbuilder/src/builders/context.rs b/crates/op-rbuilder/src/builders/context.rs index 7863d441..8129b9f5 100644 --- a/crates/op-rbuilder/src/builders/context.rs +++ b/crates/op-rbuilder/src/builders/context.rs @@ -50,7 +50,7 @@ use crate::{ /// Container type that holds all necessities to build a new payload. #[derive(Debug)] -pub struct OpPayloadBuilderCtx { +pub(super) struct OpPayloadBuilderCtx { /// The type that knows how to perform system calls and configure the evm. pub evm_config: OpEvmConfig, /// The DA config for the payload builder @@ -79,41 +79,41 @@ pub struct OpPayloadBuilderCtx { impl OpPayloadBuilderCtx { /// Returns the parent block the payload will be build on. - pub fn parent(&self) -> &SealedHeader { + pub(super) fn parent(&self) -> &SealedHeader { &self.config.parent_header } /// Returns the builder attributes. - pub const fn attributes(&self) -> &OpPayloadBuilderAttributes { + pub(super) const fn attributes(&self) -> &OpPayloadBuilderAttributes { &self.config.attributes } /// Returns the withdrawals if shanghai is active. - pub fn withdrawals(&self) -> Option<&Withdrawals> { + pub(super) fn withdrawals(&self) -> Option<&Withdrawals> { self.chain_spec .is_shanghai_active_at_timestamp(self.attributes().timestamp()) .then(|| &self.attributes().payload_attributes.withdrawals) } /// Returns the block gas limit to target. - pub fn block_gas_limit(&self) -> u64 { + pub(super) fn block_gas_limit(&self) -> u64 { self.attributes() .gas_limit .unwrap_or(self.evm_env.block_env.gas_limit) } /// Returns the block number for the block. - pub fn block_number(&self) -> u64 { + pub(super) fn block_number(&self) -> u64 { as_u64_saturated!(self.evm_env.block_env.number) } /// Returns the current base fee - pub fn base_fee(&self) -> u64 { + pub(super) fn base_fee(&self) -> u64 { self.evm_env.block_env.basefee } /// Returns the current blob gas price. - pub fn get_blob_gasprice(&self) -> Option { + pub(super) fn get_blob_gasprice(&self) -> Option { self.evm_env .block_env .blob_gasprice() @@ -123,7 +123,7 @@ impl OpPayloadBuilderCtx { /// Returns the blob fields for the header. /// /// This will always return `Some(0)` after ecotone. - pub fn blob_fields(&self) -> (Option, Option) { + pub(super) fn blob_fields(&self) -> (Option, Option) { // OP doesn't support blobs/EIP-4844. // https://specs.optimism.io/protocol/exec-engine.html#ecotone-disable-blob-transactions // Need [Some] or [None] based on hardfork to match block hash. @@ -137,7 +137,7 @@ impl OpPayloadBuilderCtx { /// Returns the extra data for the block. /// /// After holocene this extracts the extradata from the paylpad - pub fn extra_data(&self) -> Result { + pub(super) fn extra_data(&self) -> Result { if self.is_holocene_active() { self.attributes() .get_holocene_extra_data( @@ -152,52 +152,52 @@ impl OpPayloadBuilderCtx { } /// Returns the current fee settings for transactions from the mempool - pub fn best_transaction_attributes(&self) -> BestTransactionsAttributes { + pub(super) fn best_transaction_attributes(&self) -> BestTransactionsAttributes { BestTransactionsAttributes::new(self.base_fee(), self.get_blob_gasprice()) } /// Returns the unique id for this payload job. - pub fn payload_id(&self) -> PayloadId { + pub(super) fn payload_id(&self) -> PayloadId { self.attributes().payload_id() } /// Returns true if regolith is active for the payload. - pub fn is_regolith_active(&self) -> bool { + pub(super) fn is_regolith_active(&self) -> bool { self.chain_spec .is_regolith_active_at_timestamp(self.attributes().timestamp()) } /// Returns true if ecotone is active for the payload. - pub fn is_ecotone_active(&self) -> bool { + pub(super) fn is_ecotone_active(&self) -> bool { self.chain_spec .is_ecotone_active_at_timestamp(self.attributes().timestamp()) } /// Returns true if canyon is active for the payload. - pub fn is_canyon_active(&self) -> bool { + pub(super) fn is_canyon_active(&self) -> bool { self.chain_spec .is_canyon_active_at_timestamp(self.attributes().timestamp()) } /// Returns true if holocene is active for the payload. - pub fn is_holocene_active(&self) -> bool { + pub(super) fn is_holocene_active(&self) -> bool { self.chain_spec .is_holocene_active_at_timestamp(self.attributes().timestamp()) } /// Returns true if isthmus is active for the payload. - pub fn is_isthmus_active(&self) -> bool { + pub(super) fn is_isthmus_active(&self) -> bool { self.chain_spec .is_isthmus_active_at_timestamp(self.attributes().timestamp()) } /// Returns the chain id - pub fn chain_id(&self) -> u64 { + pub(super) fn chain_id(&self) -> u64 { self.chain_spec.chain_id() } /// Returns the builder signer - pub fn builder_signer(&self) -> Option { + pub(super) fn builder_signer(&self) -> Option { self.builder_signer } } @@ -236,7 +236,7 @@ impl OpPayloadBuilderCtx { } /// Executes all sequencer transactions that are included in the payload attributes. - pub fn execute_sequencer_transactions( + pub(super) fn execute_sequencer_transactions( &self, state: &mut State, ) -> Result, PayloadBuilderError> @@ -325,7 +325,7 @@ impl OpPayloadBuilderCtx { /// Executes the given best transactions and updates the execution info. /// /// Returns `Ok(Some(())` if the job was cancelled. - pub fn execute_best_transactions( + pub(super) fn execute_best_transactions( &self, info: &mut ExecutionInfo, state: &mut State, @@ -567,7 +567,7 @@ impl OpPayloadBuilderCtx { Ok(None) } - pub fn add_builder_tx( + pub(super) fn add_builder_tx( &self, info: &mut ExecutionInfo, state: &mut State, @@ -628,7 +628,7 @@ impl OpPayloadBuilderCtx { /// Calculates EIP 2718 builder transaction size // TODO: this function could be improved, ideally we shouldn't take mut ref to db and maybe // it's possible to do this without db at all - pub fn estimate_builder_tx_da_size( + pub(super) fn estimate_builder_tx_da_size( &self, state: &mut State, builder_tx_gas: u64, @@ -656,7 +656,7 @@ impl OpPayloadBuilderCtx { } } -pub fn estimate_gas_for_builder_tx(input: Vec) -> u64 { +pub(super) fn estimate_gas_for_builder_tx(input: Vec) -> u64 { // Count zero and non-zero bytes let (zero_bytes, nonzero_bytes) = input.iter().fold((0, 0), |(zeros, nonzeros), &byte| { if byte == 0 { @@ -678,7 +678,7 @@ pub fn estimate_gas_for_builder_tx(input: Vec) -> u64 { } /// Creates signed builder tx to Address::ZERO and specified message as input -pub fn signed_builder_tx( +pub(super) fn signed_builder_tx( state: &mut State, builder_tx_gas: u64, message: Vec, diff --git a/crates/op-rbuilder/src/builders/flashblocks/best_txs.rs b/crates/op-rbuilder/src/builders/flashblocks/best_txs.rs index b2108aa7..3d4021c7 100644 --- a/crates/op-rbuilder/src/builders/flashblocks/best_txs.rs +++ b/crates/op-rbuilder/src/builders/flashblocks/best_txs.rs @@ -6,7 +6,7 @@ use tracing::debug; use crate::tx::MaybeFlashblockFilter; -pub struct BestFlashblocksTxs +pub(super) struct BestFlashblocksTxs where T: PoolTransaction, I: PayloadTransactions, @@ -23,7 +23,7 @@ where T: PoolTransaction, I: PayloadTransactions, { - pub fn new(inner: I) -> Self { + pub(super) fn new(inner: I) -> Self { Self { inner, current_flashblock_number: 0, @@ -33,13 +33,13 @@ where /// Replaces current iterator with new one. We use it on new flashblock building, to refresh /// priority boundaries - pub fn refresh_iterator(&mut self, inner: I, current_flashblock_number: u64) { + pub(super) fn refresh_iterator(&mut self, inner: I, current_flashblock_number: u64) { self.inner = inner; self.current_flashblock_number = current_flashblock_number; } /// Remove transaction from next iteration and it already in the state - pub fn mark_commited(&mut self, txs: Vec) { + pub(super) fn mark_commited(&mut self, txs: Vec) { self.commited_transactions.extend(txs); } } diff --git a/crates/op-rbuilder/src/builders/flashblocks/config.rs b/crates/op-rbuilder/src/builders/flashblocks/config.rs index 702566be..a3122f52 100644 --- a/crates/op-rbuilder/src/builders/flashblocks/config.rs +++ b/crates/op-rbuilder/src/builders/flashblocks/config.rs @@ -65,7 +65,7 @@ impl TryFrom for FlashblocksConfig { } } -pub trait FlashBlocksConfigExt { +pub(super) trait FlashBlocksConfigExt { fn flashblocks_per_block(&self) -> u64; } diff --git a/crates/op-rbuilder/src/builders/flashblocks/payload.rs b/crates/op-rbuilder/src/builders/flashblocks/payload.rs index 3fc6fca2..6117dd6e 100644 --- a/crates/op-rbuilder/src/builders/flashblocks/payload.rs +++ b/crates/op-rbuilder/src/builders/flashblocks/payload.rs @@ -70,36 +70,36 @@ struct FlashblocksExtraCtx { impl OpPayloadBuilderCtx { /// Returns the current flashblock index - pub fn flashblock_index(&self) -> u64 { + pub(crate) fn flashblock_index(&self) -> u64 { self.extra_ctx.flashblock_index } /// Returns the target flashblock count - pub fn target_flashblock_count(&self) -> u64 { + pub(crate) fn target_flashblock_count(&self) -> u64 { self.extra_ctx.target_flashblock_count } /// Increments the flashblock index - pub fn increment_flashblock_index(&mut self) -> u64 { + pub(crate) fn increment_flashblock_index(&mut self) -> u64 { self.extra_ctx.flashblock_index += 1; self.extra_ctx.flashblock_index } /// Sets the target flashblock count - pub fn set_target_flashblock_count(&mut self, target_flashblock_count: u64) -> u64 { + pub(crate) fn set_target_flashblock_count(&mut self, target_flashblock_count: u64) -> u64 { self.extra_ctx.target_flashblock_count = target_flashblock_count; self.extra_ctx.target_flashblock_count } /// Returns if the flashblock is the last one - pub fn is_last_flashblock(&self) -> bool { + pub(crate) fn is_last_flashblock(&self) -> bool { self.flashblock_index() == self.target_flashblock_count() - 1 } } /// Optimism's payload builder #[derive(Debug, Clone)] -pub struct OpPayloadBuilder { +pub(super) struct OpPayloadBuilder { /// The type responsible for creating the evm. pub evm_config: OpEvmConfig, /// The transaction pool @@ -125,7 +125,7 @@ pub struct OpPayloadBuilder { impl OpPayloadBuilder { /// `OpPayloadBuilder` constructor. - pub fn new( + pub(super) fn new( evm_config: OpEvmConfig, pool: Pool, client: Client, @@ -646,7 +646,7 @@ where } /// Sends built payload via payload builder handle broadcast channel to the engine - pub fn send_payload_to_engine(&self, payload: OpBuiltPayload) { + pub(super) fn send_payload_to_engine(&self, payload: OpBuiltPayload) { // Send built payload as created one match self.payload_builder_handle.get() { Some(handle) => { @@ -666,7 +666,7 @@ where /// Spawn task that will send new flashblock level cancel token in steady intervals (first interval /// may vary if --flashblocks.dynamic enabled) - pub fn spawn_timer_task( + pub(super) fn spawn_timer_task( &self, block_cancel: CancellationToken, fb_cancel_token_tx: Sender>, @@ -713,7 +713,7 @@ where /// Calculate number of flashblocks. /// If dynamic is enabled this function will take time drift into the account. - pub fn calculate_flashblocks(&self, timestamp: u64) -> (u64, Duration) { + pub(super) fn calculate_flashblocks(&self, timestamp: u64) -> (u64, Duration) { if self.config.specific.fixed { return ( self.config.flashblocks_per_block(), diff --git a/crates/op-rbuilder/src/builders/flashblocks/wspub.rs b/crates/op-rbuilder/src/builders/flashblocks/wspub.rs index cf8c485c..944edb91 100644 --- a/crates/op-rbuilder/src/builders/flashblocks/wspub.rs +++ b/crates/op-rbuilder/src/builders/flashblocks/wspub.rs @@ -28,7 +28,7 @@ use crate::metrics::OpRBuilderMetrics; /// updates about new flashblocks. It maintains a count of sent messages and active subscriptions. /// /// This is modelled as a `futures::Sink` that can be used to send `FlashblocksPayloadV1` messages. -pub struct WebSocketPublisher { +pub(super) struct WebSocketPublisher { sent: Arc, subs: Arc, term: watch::Sender, @@ -36,7 +36,7 @@ pub struct WebSocketPublisher { } impl WebSocketPublisher { - pub fn new(addr: SocketAddr, metrics: Arc) -> io::Result { + pub(super) fn new(addr: SocketAddr, metrics: Arc) -> io::Result { let (pipe, _) = broadcast::channel(100); let (term, _) = watch::channel(false); @@ -61,7 +61,7 @@ impl WebSocketPublisher { }) } - pub fn publish(&self, payload: &FlashblocksPayloadV1) -> io::Result { + pub(super) fn publish(&self, payload: &FlashblocksPayloadV1) -> io::Result { // Serialize the payload to a UTF-8 string // serialize only once, then just copy around only a pointer // to the serialized data for each subscription. diff --git a/crates/op-rbuilder/src/builders/generator.rs b/crates/op-rbuilder/src/builders/generator.rs index c7793083..be9bd89f 100644 --- a/crates/op-rbuilder/src/builders/generator.rs +++ b/crates/op-rbuilder/src/builders/generator.rs @@ -34,7 +34,7 @@ use tracing::info; /// /// Generic parameters `Pool` and `Client` represent the transaction pool and /// Ethereum client types. -pub trait PayloadBuilder: Send + Sync + Clone { +pub(super) trait PayloadBuilder: Send + Sync + Clone { /// The payload attributes type to accept for building. type Attributes: PayloadBuilderAttributes; /// The type of the built payload. @@ -61,7 +61,7 @@ pub trait PayloadBuilder: Send + Sync + Clone { /// The generator type that creates new jobs that builds empty blocks. #[derive(Debug)] -pub struct BlockPayloadJobGenerator { +pub(super) struct BlockPayloadJobGenerator { /// The client that can interact with the chain. client: Client, /// How to spawn building tasks @@ -87,7 +87,7 @@ pub struct BlockPayloadJobGenerator { impl BlockPayloadJobGenerator { /// Creates a new [EmptyBlockPayloadJobGenerator] with the given config and custom /// [PayloadBuilder] - pub fn with_builder( + pub(super) fn with_builder( client: Client, executor: Tasks, config: BasicPayloadJobGeneratorConfig, @@ -238,7 +238,7 @@ use std::{ }; /// A [PayloadJob] that builds empty blocks. -pub struct BlockPayloadJob +pub(super) struct BlockPayloadJob where Builder: PayloadBuilder, { @@ -296,7 +296,7 @@ where } } -pub struct BuildArguments { +pub(super) struct BuildArguments { /// Previously cached disk reads pub cached_reads: CachedReads, /// How to configure the payload. @@ -313,7 +313,7 @@ where Builder::Attributes: Unpin + Clone, Builder::BuiltPayload: Unpin + Clone, { - pub fn spawn_build_job(&mut self) { + pub(super) fn spawn_build_job(&mut self) { let builder = self.builder.clone(); let payload_config = self.config.clone(); let cell = self.cell.clone(); @@ -367,12 +367,12 @@ where } // A future that resolves when a payload becomes available in the BlockCell -pub struct ResolvePayload { +pub(super) struct ResolvePayload { future: WaitForValue, } impl ResolvePayload { - pub fn new(future: WaitForValue) -> Self { + pub(super) fn new(future: WaitForValue) -> Self { Self { future } } } @@ -389,39 +389,39 @@ impl Future for ResolvePayload { } #[derive(Clone)] -pub struct BlockCell { +pub(super) struct BlockCell { inner: Arc>>, notify: Arc, } impl BlockCell { - pub fn new() -> Self { + pub(super) fn new() -> Self { Self { inner: Arc::new(Mutex::new(None)), notify: Arc::new(Notify::new()), } } - pub fn set(&self, value: T) { + pub(super) fn set(&self, value: T) { let mut inner = self.inner.lock().unwrap(); *inner = Some(value); self.notify.notify_one(); } - pub fn get(&self) -> Option { + pub(super) fn get(&self) -> Option { let inner = self.inner.lock().unwrap(); inner.clone() } // Return a future that resolves when value is set - pub fn wait_for_value(&self) -> WaitForValue { + pub(super) fn wait_for_value(&self) -> WaitForValue { WaitForValue { cell: self.clone() } } } #[derive(Clone)] // Future that resolves when a value is set in BlockCell -pub struct WaitForValue { +pub(super) struct WaitForValue { cell: BlockCell, } diff --git a/crates/op-rbuilder/src/builders/standard/payload.rs b/crates/op-rbuilder/src/builders/standard/payload.rs index c61fc32e..daebf7dd 100644 --- a/crates/op-rbuilder/src/builders/standard/payload.rs +++ b/crates/op-rbuilder/src/builders/standard/payload.rs @@ -336,7 +336,7 @@ where /// And finally /// 5. build the block: compute all roots (txs, state) #[derive(derive_more::Debug)] -pub struct OpBuilder<'a, Txs> { +pub(super) struct OpBuilder<'a, Txs> { /// Yields the best transaction to include if transactions from the mempool are allowed. best: Box Txs + 'a>, } @@ -351,14 +351,14 @@ impl<'a, Txs> OpBuilder<'a, Txs> { /// Holds the state after execution #[derive(Debug)] -pub struct ExecutedPayload { +pub(super) struct ExecutedPayload { /// Tracked execution info pub info: ExecutionInfo, } impl OpBuilder<'_, Txs> { /// Executes the payload and returns the outcome. - pub fn execute( + pub(super) fn execute( self, state: &mut State, ctx: &OpPayloadBuilderCtx, @@ -466,7 +466,7 @@ impl OpBuilder<'_, Txs> { } /// Builds the payload on top of the state. - pub fn build( + pub(super) fn build( self, mut state: State, ctx: OpPayloadBuilderCtx, diff --git a/crates/op-rbuilder/src/gas_limiter/metrics.rs b/crates/op-rbuilder/src/gas_limiter/metrics.rs index e009b221..f7898657 100644 --- a/crates/op-rbuilder/src/gas_limiter/metrics.rs +++ b/crates/op-rbuilder/src/gas_limiter/metrics.rs @@ -7,7 +7,7 @@ use crate::gas_limiter::error::GasLimitError; #[derive(Metrics, Clone)] #[metrics(scope = "op_rbuilder.gas_limiter")] -pub struct GasLimiterMetrics { +pub(super) struct GasLimiterMetrics { /// Transactions rejected by gas limits Labeled by reason: "per_address", /// "global", "burst" pub rejections: Counter, @@ -23,7 +23,11 @@ pub struct GasLimiterMetrics { } impl GasLimiterMetrics { - pub fn record_gas_check(&self, check_result: &Result, duration: Duration) { + pub(super) fn record_gas_check( + &self, + check_result: &Result, + duration: Duration, + ) { if let Ok(created_new_bucket) = check_result { if *created_new_bucket { self.active_address_count.increment(1); @@ -35,7 +39,7 @@ impl GasLimiterMetrics { self.check_time.record(duration); } - pub fn record_refresh(&self, removed_addresses: usize, duration: Duration) { + pub(super) fn record_refresh(&self, removed_addresses: usize, duration: Duration) { self.active_address_count .decrement(removed_addresses as f64); self.refresh_duration.record(duration); diff --git a/crates/op-rbuilder/src/monitor_tx_pool.rs b/crates/op-rbuilder/src/monitor_tx_pool.rs index 4554c5e6..a9cbbae6 100644 --- a/crates/op-rbuilder/src/monitor_tx_pool.rs +++ b/crates/op-rbuilder/src/monitor_tx_pool.rs @@ -5,7 +5,7 @@ use moka::future::Cache; use reth_transaction_pool::{AllTransactionsEvents, FullTransactionEvent}; use tracing::info; -pub async fn monitor_tx_pool( +pub(crate) async fn monitor_tx_pool( mut new_transactions: AllTransactionsEvents, reverted_cache: Cache, ) {