Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions crates/engine/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@ exclude.workspace = true
[dependencies]
# reth
reth-chainspec.workspace = true
reth-consensus.workspace = true
reth-engine-primitives.workspace = true
reth-engine-service.workspace = true
reth-engine-tree.workspace = true
reth-node-types.workspace = true
reth-evm.workspace = true
reth-ethereum-engine-primitives.workspace = true
reth-payload-builder.workspace = true
reth-payload-primitives.workspace = true
reth-provider.workspace = true
reth-prune.workspace = true
reth-transaction-pool.workspace = true
reth-stages-api.workspace = true

# alloy
alloy-consensus.workspace = true
Expand All @@ -50,5 +43,4 @@ op = [
"dep:op-alloy-rpc-types-engine",
"dep:reth-optimism-chainspec",
"reth-payload-primitives/op",
"reth-evm/op",
]
4 changes: 1 addition & 3 deletions crates/engine/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

pub mod miner;
pub mod payload;
pub mod service;

pub use miner::MiningMode;
pub use miner::{LocalMiner, MiningMode};
pub use payload::LocalPayloadAttributesBuilder;
pub use service::LocalEngineService;
63 changes: 25 additions & 38 deletions crates/engine/local/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy_primitives::{TxHash, B256};
use alloy_rpc_types_engine::ForkchoiceState;
use eyre::OptionExt;
use futures_util::{stream::Fuse, StreamExt};
use reth_engine_primitives::BeaconEngineMessage;
use reth_engine_primitives::BeaconConsensusEngineHandle;
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, PayloadAttributesBuilder, PayloadKind, PayloadTypes,
Expand All @@ -18,10 +18,7 @@ use std::{
task::{Context, Poll},
time::{Duration, UNIX_EPOCH},
};
use tokio::{
sync::{mpsc::UnboundedSender, oneshot},
time::Interval,
};
use tokio::time::Interval;
use tokio_stream::wrappers::ReceiverStream;
use tracing::error;

Expand Down Expand Up @@ -78,7 +75,7 @@ pub struct LocalMiner<T: PayloadTypes, B> {
/// The payload attribute builder for the engine
payload_attributes_builder: B,
/// Sender for events to engine.
to_engine: UnboundedSender<BeaconEngineMessage<T>>,
to_engine: BeaconConsensusEngineHandle<T>,
/// The mining mode for the engine
mode: MiningMode,
/// The payload builder for the engine
Expand All @@ -95,31 +92,28 @@ where
B: PayloadAttributesBuilder<<T as PayloadTypes>::PayloadAttributes>,
{
/// Spawns a new [`LocalMiner`] with the given parameters.
pub fn spawn_new(
pub fn new(
provider: impl BlockReader,
payload_attributes_builder: B,
to_engine: UnboundedSender<BeaconEngineMessage<T>>,
to_engine: BeaconConsensusEngineHandle<T>,
mode: MiningMode,
payload_builder: PayloadBuilderHandle<T>,
) {
) -> Self {
let latest_header =
provider.sealed_header(provider.best_block_number().unwrap()).unwrap().unwrap();

let miner = Self {
Self {
payload_attributes_builder,
to_engine,
mode,
payload_builder,
last_timestamp: latest_header.timestamp(),
last_block_hashes: vec![latest_header.hash()],
};

// Spawn the miner
tokio::spawn(miner.run());
}
}

/// Runs the [`LocalMiner`] in a loop, polling the miner and building payloads.
async fn run(mut self) {
pub async fn run(mut self) {
let mut fcu_interval = tokio::time::interval(Duration::from_secs(1));
loop {
tokio::select! {
Expand Down Expand Up @@ -156,16 +150,12 @@ where

/// Sends a FCU to the engine.
async fn update_forkchoice_state(&self) -> eyre::Result<()> {
let (tx, rx) = oneshot::channel();
self.to_engine.send(BeaconEngineMessage::ForkchoiceUpdated {
state: self.forkchoice_state(),
payload_attrs: None,
tx,
version: EngineApiMessageVersion::default(),
})?;

let res = rx.await??;
if !res.forkchoice_status().is_valid() {
let res = self
.to_engine
.fork_choice_updated(self.forkchoice_state(), None, EngineApiMessageVersion::default())
.await?;

if !res.is_valid() {
eyre::bail!("Invalid fork choice update")
}

Expand All @@ -183,16 +173,16 @@ where
.as_secs(),
);

let (tx, rx) = oneshot::channel();
self.to_engine.send(BeaconEngineMessage::ForkchoiceUpdated {
state: self.forkchoice_state(),
payload_attrs: Some(self.payload_attributes_builder.build(timestamp)),
tx,
version: EngineApiMessageVersion::default(),
})?;
let res = self
.to_engine
.fork_choice_updated(
self.forkchoice_state(),
Some(self.payload_attributes_builder.build(timestamp)),
EngineApiMessageVersion::default(),
)
.await?;

let res = rx.await??.await?;
if !res.payload_status.is_valid() {
if !res.is_valid() {
eyre::bail!("Invalid payload status")
}

Expand All @@ -206,11 +196,8 @@ where

let block = payload.block();

let (tx, rx) = oneshot::channel();
let payload = T::block_to_payload(payload.block().clone());
self.to_engine.send(BeaconEngineMessage::NewPayload { payload, tx })?;

let res = rx.await??;
let res = self.to_engine.new_payload(payload).await?;

if !res.is_valid() {
eyre::bail!("Invalid payload")
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/local/src/payload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The implementation of the [`PayloadAttributesBuilder`] for the
//! [`LocalEngineService`](super::service::LocalEngineService).
//! [`LocalMiner`](super::LocalMiner).

use alloy_primitives::{Address, B256};
use reth_chainspec::EthereumHardforks;
Expand Down
163 changes: 0 additions & 163 deletions crates/engine/local/src/service.rs

This file was deleted.

Loading
Loading