Skip to content

Add make command for op-rbuilder image and switch to nightly fmt #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
toolchain:
- stable
- nightly
features:
- ""
steps:
@@ -32,6 +32,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain }}
components: "rustfmt,clippy"

# https://github.com/swatinem/rust-cache
- name: Run Swatinem/rust-cache@v2
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -28,9 +28,13 @@ build: ## Build (debug version)
cargo build --features "$(FEATURES)"

.PHONY: docker-image-rbuilder
docker-image-rubilder: ## Build a rbuilder Docker image
docker-image-rbuilder: ## Build a rbuilder Docker image
docker build --platform linux/amd64 --target rbuilder-runtime --build-arg FEATURES="$(FEATURES)" . -t rbuilder

.PHONY: docker-image-op-rbuilder
docker-image-op-rbuilder: ## Build a rbuilder Docker image
docker build --platform linux/amd64 --target rbuilder-runtime --build-arg FEATURES="$(FEATURES)" --file Dockerfile.op-rbuilder . -t op-rbuilder

.PHONY: docker-image-test-relay
docker-image-test-relay: ## Build a test relay Docker image
docker build --platform linux/amd64 --target test-relay-runtime --build-arg FEATURES="$(FEATURES)" . -t test-relay
@@ -39,9 +43,9 @@ docker-image-test-relay: ## Build a test relay Docker image

.PHONY: lint
lint: ## Run the linters
cargo fmt -- --check
cargo clippy --features "$(FEATURES)" -- -D warnings
cargo clippy -p op-rbuilder --features "$(FEATURES)" -- -D warnings
cargo +nightly fmt -- --check
cargo +nightly clippy --features "$(FEATURES)" -- -D warnings
cargo +nightly clippy -p op-rbuilder --features "$(FEATURES)" -- -D warnings

.PHONY: test
test: ## Run the tests for rbuilder and op-rbuilder
@@ -54,10 +58,10 @@ lt: lint test ## Run "lint" and "test"

.PHONY: fmt
fmt: ## Format the code
cargo fmt
cargo fix --allow-staged
cargo clippy --features "$(FEATURES)" --fix --allow-staged
cargo clippy -p op-rbuilder --features "$(FEATURES)" --fix --allow-staged
cargo +nightly fmt
cargo +nightly fix --allow-staged
cargo +nightly clippy --features "$(FEATURES)" --fix --allow-staged
cargo +nightly clippy -p op-rbuilder --features "$(FEATURES)" --fix --allow-staged

.PHONY: bench
bench: ## Run benchmarks
2 changes: 2 additions & 0 deletions crates/eth-sparse-mpt/src/reth_sparse_trie/hash.rs
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ pub enum RootHashError {
HashingAccountsTrie { err: ErrSparseNodeNotFound },
}

#[expect(clippy::result_large_err)]
impl EthSparseTries {
pub fn calculate_root_hash(
&mut self,
@@ -172,6 +173,7 @@ impl EthSparseTries {
}
}

#[expect(clippy::result_large_err)]
fn hash_storage_trie(
storage_trie: &mut DiffTrie,
account: &Bytes,
7 changes: 5 additions & 2 deletions crates/eth-sparse-mpt/src/reth_sparse_trie/mod.rs
Original file line number Diff line number Diff line change
@@ -6,8 +6,10 @@ use reth_provider::{
providers::ConsistentDbView, BlockReader, DatabaseProviderFactory, ExecutionOutcome,
StateCommitmentProvider,
};
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::{
sync::Arc,
time::{Duration, Instant},
};

pub mod change_set;
pub mod hash;
@@ -75,6 +77,7 @@ impl ChangedAccountData {
}
}

#[expect(clippy::result_large_err)]
/// Prefetches data
pub fn prefetch_tries_for_accounts<'a, Provider>(
consistent_db_view: ConsistentDbView<Provider>,
Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@ use crate::{
sparse_mpt::{AddNodeError, FixedTrie},
utils::HashMap,
};
use alloy_primitives::Bytes;
use alloy_primitives::B256;
use alloy_primitives::{Bytes, B256};
use alloy_trie::Nibbles;

/// SparseTrieSharedCache is a storage for fetched parts of the ethereum tries
44 changes: 23 additions & 21 deletions crates/op-rbuilder/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
use futures_util::Future;
use futures_util::FutureExt;
use reth::providers::BlockReaderIdExt;
use reth::{providers::StateProviderFactory, tasks::TaskSpawner};
use reth_basic_payload_builder::HeaderForPayload;
use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadConfig};
use reth_node_api::PayloadBuilderAttributes;
use reth_node_api::PayloadKind;
use reth_payload_builder::PayloadJobGenerator;
use reth_payload_builder::{KeepPayloadJobAlive, PayloadBuilderError, PayloadJob};
use futures_util::{Future, FutureExt};
use reth::{
providers::{BlockReaderIdExt, StateProviderFactory},
tasks::TaskSpawner,
};
use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, HeaderForPayload, PayloadConfig};
use reth_node_api::{PayloadBuilderAttributes, PayloadKind};
use reth_payload_builder::{
KeepPayloadJobAlive, PayloadBuilderError, PayloadJob, PayloadJobGenerator,
};
use reth_payload_primitives::BuiltPayload;
use reth_primitives_traits::HeaderTy;
use reth_revm::cached::CachedReads;
use std::sync::{Arc, Mutex};
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use tokio::sync::oneshot;
use tokio::sync::Notify;
use tokio::time::Duration;
use tokio::time::Sleep;
use std::{
sync::{Arc, Mutex},
time::{SystemTime, UNIX_EPOCH},
};
use tokio::{
sync::{oneshot, Notify},
time::{Duration, Sleep},
};
use tokio_util::sync::CancellationToken;
use tracing::info;

@@ -424,14 +425,15 @@ mod tests {
use reth::tasks::TokioTaskExecutor;
use reth_chain_state::ExecutedBlockWithTrieUpdates;
use reth_node_api::NodePrimitives;
use reth_optimism_payload_builder::payload::OpPayloadBuilderAttributes;
use reth_optimism_payload_builder::OpPayloadPrimitives;
use reth_optimism_payload_builder::{payload::OpPayloadBuilderAttributes, OpPayloadPrimitives};
use reth_optimism_primitives::OpPrimitives;
use reth_primitives::SealedBlock;
use reth_provider::test_utils::MockEthProvider;
use reth_testing_utils::generators::{random_block_range, BlockRangeParams};
use tokio::task;
use tokio::time::{sleep, Duration};
use tokio::{
task,
time::{sleep, Duration},
};

#[tokio::test]
async fn test_block_cell_wait_for_value() {
5 changes: 2 additions & 3 deletions crates/op-rbuilder/src/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::future::Future;
use std::path::Path;
use std::{
fs::{File, OpenOptions},
future::Future,
io,
io::prelude::*,
path::PathBuf,
path::{Path, PathBuf},
process::{Child, Command},
time::{Duration, SystemTime},
};
3 changes: 1 addition & 2 deletions crates/op-rbuilder/src/main.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@ use clap::Parser;
use monitoring::Monitoring;
use reth::providers::CanonStateSubscriptions;
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_node::node::OpAddOnsBuilder;
use reth_optimism_node::OpNode;
use reth_optimism_node::{node::OpAddOnsBuilder, OpNode};

#[cfg(feature = "flashblocks")]
use payload_builder::CustomOpPayloadBuilder;
5 changes: 4 additions & 1 deletion crates/op-rbuilder/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use reth_metrics::{metrics::Counter, metrics::Gauge, metrics::Histogram, Metrics};
use reth_metrics::{
metrics::{Counter, Gauge, Histogram},
Metrics,
};

/// op-rbuilder metrics
#[derive(Metrics, Clone)]
3 changes: 1 addition & 2 deletions crates/op-rbuilder/src/tester/mod.rs
Original file line number Diff line number Diff line change
@@ -18,8 +18,7 @@ use reth_node_api::{EngineTypes, PayloadTypes};
use reth_optimism_node::OpEngineTypes;
use reth_payload_builder::PayloadId;
use reth_rpc_layer::{AuthClientLayer, AuthClientService, JwtSecret};
use rollup_boost::Flashblocks;
use rollup_boost::FlashblocksService;
use rollup_boost::{Flashblocks, FlashblocksService};
use serde_json::Value;
use std::{
str::FromStr,
Original file line number Diff line number Diff line change
@@ -16,11 +16,11 @@ use super::{OrderPriority, SimulatedOrderSink};
/// Order must implement BlockOrdersOrder which has priority(). This priority is used to sort the simulated orders.
/// Usage:
/// - Add new order (a little bit complex):
/// ALWAYS BE SURE THAT YOU CALLED update_onchain_nonces and updated the current state of all the needed nonces by the order
/// call insert_order
/// ALWAYS BE SURE THAT YOU CALLED update_onchain_nonces and updated the current state of all the needed nonces by the order
/// call insert_order
/// - Get best order to execute
/// call pop_order to get the best order
/// if the order is executed call update_onchain_nonces to update all the changed nonces.
/// call pop_order to get the best order
/// if the order is executed call update_onchain_nonces to update all the changed nonces.
/// - Remove orders: remove_orders. This is useful if we think this orders are no really good (failed to execute to often)
#[derive(Debug, Clone)]
pub struct PrioritizedOrderStore<OrderPriorityType> {
Original file line number Diff line number Diff line change
@@ -55,11 +55,13 @@ pub trait BlockBuildingHelper: Send + Sync {
/// This is the maximum profit that can reach the final fee recipient (max bid!).
/// Maximum payout_tx_value value to pass to finalize_block.
/// The main reason to get an error is if profit is so low that we can't pay the payout tx (that would mean negative block value!).
#[expect(clippy::result_large_err)]
fn true_block_value(&self) -> Result<U256, BlockBuildingHelperError>;

/// Eats the BlockBuildingHelper since once it's finished you should not use it anymore.
/// payout_tx_value: If Some, added at the end of the block from coinbase to the final fee recipient.
/// This only works if can_add_payout_tx.
#[expect(clippy::result_large_err)]
fn finalize_block(
self: Box<Self>,
local_ctx: &mut ThreadBlockBuildingContext,
@@ -94,6 +96,7 @@ impl Clone for BiddableUnfinishedBlock {
}

impl BiddableUnfinishedBlock {
#[expect(clippy::result_large_err)]
pub fn new(block: Box<dyn BlockBuildingHelper>) -> Result<Self, BlockBuildingHelperError> {
let true_block_value = block.true_block_value()?;
Ok(Self {
@@ -185,7 +188,7 @@ impl BlockBuildingHelperFromProvider {
/// - Query fee_recipient_balance_start.
/// - pre_block_call.
/// - Estimate payout tx cost.
#[allow(clippy::too_many_arguments)]
#[expect(clippy::result_large_err)]
pub fn new(
state_provider: Arc<dyn StateProvider>,
building_ctx: BlockBuildingContext,
@@ -272,6 +275,7 @@ impl BlockBuildingHelperFromProvider {
}

/// Inserts payout tx if necessary and updates built_block_trace.
#[expect(clippy::result_large_err)]
fn finalize_block_execution(
&mut self,
local_ctx: &mut ThreadBlockBuildingContext,
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::building::ThreadBlockBuildingContext;
use crate::live_builder::simulation::SimulatedOrderCommand;
use crate::primitives::SimValue;
use crate::provider::RootHasher;
use crate::roothash::RootHashError;
use crate::{
building::{
BlockBuildingContext, BuiltBlockTrace, CriticalCommitOrderError, ExecutionError,
ExecutionResult,
ExecutionResult, ThreadBlockBuildingContext,
},
primitives::SimulatedOrder,
live_builder::simulation::SimulatedOrderCommand,
primitives::{SimValue, SimulatedOrder},
provider::RootHasher,
roothash::RootHashError,
};
use alloy_primitives::B256;
use alloy_primitives::U256;
use alloy_primitives::{B256, U256};
use reth::providers::ExecutionOutcome;
use reth_primitives::SealedBlock;
use time::OffsetDateTime;
Original file line number Diff line number Diff line change
@@ -15,8 +15,7 @@ use super::{
simulation_cache::SharedSimulationCache, ConflictGroup, ConflictResolutionResultPerGroup,
ConflictTask, GroupId, ResolutionResult, TaskPriority,
};
use crate::building::BlockBuildingContext;
use crate::provider::StateProviderFactory;
use crate::{building::BlockBuildingContext, provider::StateProviderFactory};

pub type TaskQueue = Arc<SegQueue<ConflictTask>>;

Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ impl ConflictTaskGenerator {
self.add_processed_groups(&new_group, &mut processed_groups);

// Remove all subset groups
if new_group.conflicting_group_ids.len() > 0 {
if !new_group.conflicting_group_ids.is_empty() {
self.remove_conflicting_subset_groups(&new_group);
}
}
3 changes: 2 additions & 1 deletion crates/rbuilder/src/building/mod.rs
Original file line number Diff line number Diff line change
@@ -635,6 +635,7 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
}

/// returns (requests, withdrawals_root)
#[expect(clippy::result_large_err)]
pub fn process_requests(
&self,
state: &mut BlockState,
@@ -697,7 +698,7 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
}

/// Mostly based on reth's (v1.2) default_ethereum_payload_builder.
#[allow(clippy::too_many_arguments)]
#[expect(clippy::result_large_err)]
pub fn finalize(
self,
state: &mut BlockState,
1 change: 1 addition & 0 deletions crates/rbuilder/src/building/sim.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ use std::{
};
use tracing::{error, trace};

#[expect(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum OrderSimResult {
Success(SimulatedOrder, Vec<(Address, u64)>),
Original file line number Diff line number Diff line change
@@ -6,8 +6,10 @@ use time::{error, OffsetDateTime};
use tracing::{error, info, warn};

use super::interfaces::LandedBlockInfo;
use crate::provider::StateProviderFactory;
use crate::telemetry::{add_subsidy_value, inc_subsidized_blocks};
use crate::{
provider::StateProviderFactory,
telemetry::{add_subsidy_value, inc_subsidized_blocks},
};

/// Allows to monitor the evolution of our wallet for the landed blocks.
/// It's useful for bidders to detect profit and subsidies.
2 changes: 1 addition & 1 deletion crates/rbuilder/src/live_builder/config.rs
Original file line number Diff line number Diff line change
@@ -62,8 +62,8 @@ use reth_primitives::StaticFileSegment;
use reth_provider::StaticFileProviderFactory;
use serde::Deserialize;
use serde_with::{serde_as, OneOrMany};
use std::collections::HashMap;
use std::{
collections::HashMap,
fmt::Debug,
path::{Path, PathBuf},
str::FromStr,
17 changes: 12 additions & 5 deletions crates/rbuilder/src/live_builder/order_input/mod.rs
Original file line number Diff line number Diff line change
@@ -11,14 +11,20 @@ use self::{
orderpool::{OrderPool, OrderPoolSubscriptionId},
replaceable_order_sink::ReplaceableOrderSink,
};
use crate::primitives::{serialize::CancelShareBundle, BundleReplacementData, Order};
use crate::provider::StateProviderFactory;
use crate::telemetry::{set_current_block, set_ordepool_count};
use crate::{
primitives::{serialize::CancelShareBundle, BundleReplacementData, Order},
provider::StateProviderFactory,
telemetry::{set_current_block, set_ordepool_count},
};
use alloy_consensus::Header;
use jsonrpsee::RpcModule;
use parking_lot::Mutex;
use std::{net::Ipv4Addr, path::PathBuf, sync::Arc, time::Duration};
use std::{path::Path, time::Instant};
use std::{
net::Ipv4Addr,
path::{Path, PathBuf},
sync::Arc,
time::{Duration, Instant},
};
use tokio::{sync::mpsc, task::JoinHandle};
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, info, trace, warn};
@@ -165,6 +171,7 @@ impl OrderInputConfig {
}

/// Commands we can get from RPC or mempool fetcher.
#[expect(clippy::large_enum_variant)]
#[derive(Debug, Clone)]
pub enum ReplaceableOrderPoolCommand {
/// New or update order
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ impl Drop for OrderPrinter {
}

///////////////////////

#[expect(clippy::large_enum_variant)]
#[derive(Debug, Clone)]
pub enum OrderPoolCommand {
//OrderSink::insert_order
Loading