Skip to content

Commit cf80ef4

Browse files
authored
refactor: simplify --dev setup (#16662)
1 parent 6d5b0ef commit cf80ef4

File tree

7 files changed

+59
-265
lines changed

7 files changed

+59
-265
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/engine/local/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,12 @@ exclude.workspace = true
1111
[dependencies]
1212
# reth
1313
reth-chainspec.workspace = true
14-
reth-consensus.workspace = true
1514
reth-engine-primitives.workspace = true
16-
reth-engine-service.workspace = true
17-
reth-engine-tree.workspace = true
18-
reth-node-types.workspace = true
19-
reth-evm.workspace = true
2015
reth-ethereum-engine-primitives.workspace = true
2116
reth-payload-builder.workspace = true
2217
reth-payload-primitives.workspace = true
2318
reth-provider.workspace = true
24-
reth-prune.workspace = true
2519
reth-transaction-pool.workspace = true
26-
reth-stages-api.workspace = true
2720

2821
# alloy
2922
alloy-consensus.workspace = true
@@ -50,5 +43,4 @@ op = [
5043
"dep:op-alloy-rpc-types-engine",
5144
"dep:reth-optimism-chainspec",
5245
"reth-payload-primitives/op",
53-
"reth-evm/op",
5446
]

crates/engine/local/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
pub mod miner;
1212
pub mod payload;
13-
pub mod service;
1413

15-
pub use miner::MiningMode;
14+
pub use miner::{LocalMiner, MiningMode};
1615
pub use payload::LocalPayloadAttributesBuilder;
17-
pub use service::LocalEngineService;

crates/engine/local/src/miner.rs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use alloy_primitives::{TxHash, B256};
55
use alloy_rpc_types_engine::ForkchoiceState;
66
use eyre::OptionExt;
77
use futures_util::{stream::Fuse, StreamExt};
8-
use reth_engine_primitives::BeaconEngineMessage;
8+
use reth_engine_primitives::BeaconConsensusEngineHandle;
99
use reth_payload_builder::PayloadBuilderHandle;
1010
use reth_payload_primitives::{
1111
BuiltPayload, EngineApiMessageVersion, PayloadAttributesBuilder, PayloadKind, PayloadTypes,
@@ -18,10 +18,7 @@ use std::{
1818
task::{Context, Poll},
1919
time::{Duration, UNIX_EPOCH},
2020
};
21-
use tokio::{
22-
sync::{mpsc::UnboundedSender, oneshot},
23-
time::Interval,
24-
};
21+
use tokio::time::Interval;
2522
use tokio_stream::wrappers::ReceiverStream;
2623
use tracing::error;
2724

@@ -78,7 +75,7 @@ pub struct LocalMiner<T: PayloadTypes, B> {
7875
/// The payload attribute builder for the engine
7976
payload_attributes_builder: B,
8077
/// Sender for events to engine.
81-
to_engine: UnboundedSender<BeaconEngineMessage<T>>,
78+
to_engine: BeaconConsensusEngineHandle<T>,
8279
/// The mining mode for the engine
8380
mode: MiningMode,
8481
/// The payload builder for the engine
@@ -95,31 +92,28 @@ where
9592
B: PayloadAttributesBuilder<<T as PayloadTypes>::PayloadAttributes>,
9693
{
9794
/// Spawns a new [`LocalMiner`] with the given parameters.
98-
pub fn spawn_new(
95+
pub fn new(
9996
provider: impl BlockReader,
10097
payload_attributes_builder: B,
101-
to_engine: UnboundedSender<BeaconEngineMessage<T>>,
98+
to_engine: BeaconConsensusEngineHandle<T>,
10299
mode: MiningMode,
103100
payload_builder: PayloadBuilderHandle<T>,
104-
) {
101+
) -> Self {
105102
let latest_header =
106103
provider.sealed_header(provider.best_block_number().unwrap()).unwrap().unwrap();
107104

108-
let miner = Self {
105+
Self {
109106
payload_attributes_builder,
110107
to_engine,
111108
mode,
112109
payload_builder,
113110
last_timestamp: latest_header.timestamp(),
114111
last_block_hashes: vec![latest_header.hash()],
115-
};
116-
117-
// Spawn the miner
118-
tokio::spawn(miner.run());
112+
}
119113
}
120114

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

157151
/// Sends a FCU to the engine.
158152
async fn update_forkchoice_state(&self) -> eyre::Result<()> {
159-
let (tx, rx) = oneshot::channel();
160-
self.to_engine.send(BeaconEngineMessage::ForkchoiceUpdated {
161-
state: self.forkchoice_state(),
162-
payload_attrs: None,
163-
tx,
164-
version: EngineApiMessageVersion::default(),
165-
})?;
166-
167-
let res = rx.await??;
168-
if !res.forkchoice_status().is_valid() {
153+
let res = self
154+
.to_engine
155+
.fork_choice_updated(self.forkchoice_state(), None, EngineApiMessageVersion::default())
156+
.await?;
157+
158+
if !res.is_valid() {
169159
eyre::bail!("Invalid fork choice update")
170160
}
171161

@@ -183,16 +173,16 @@ where
183173
.as_secs(),
184174
);
185175

186-
let (tx, rx) = oneshot::channel();
187-
self.to_engine.send(BeaconEngineMessage::ForkchoiceUpdated {
188-
state: self.forkchoice_state(),
189-
payload_attrs: Some(self.payload_attributes_builder.build(timestamp)),
190-
tx,
191-
version: EngineApiMessageVersion::default(),
192-
})?;
176+
let res = self
177+
.to_engine
178+
.fork_choice_updated(
179+
self.forkchoice_state(),
180+
Some(self.payload_attributes_builder.build(timestamp)),
181+
EngineApiMessageVersion::default(),
182+
)
183+
.await?;
193184

194-
let res = rx.await??.await?;
195-
if !res.payload_status.is_valid() {
185+
if !res.is_valid() {
196186
eyre::bail!("Invalid payload status")
197187
}
198188

@@ -206,11 +196,8 @@ where
206196

207197
let block = payload.block();
208198

209-
let (tx, rx) = oneshot::channel();
210199
let payload = T::block_to_payload(payload.block().clone());
211-
self.to_engine.send(BeaconEngineMessage::NewPayload { payload, tx })?;
212-
213-
let res = rx.await??;
200+
let res = self.to_engine.new_payload(payload).await?;
214201

215202
if !res.is_valid() {
216203
eyre::bail!("Invalid payload")

crates/engine/local/src/payload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! The implementation of the [`PayloadAttributesBuilder`] for the
2-
//! [`LocalEngineService`](super::service::LocalEngineService).
2+
//! [`LocalMiner`](super::LocalMiner).
33
44
use alloy_primitives::{Address, B256};
55
use reth_chainspec::EthereumHardforks;

crates/engine/local/src/service.rs

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)