-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
478 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[package] | ||
name = "reth-engine-local" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
exclude.workspace = true | ||
|
||
[dependencies] | ||
# reth | ||
reth-beacon-consensus.workspace = true | ||
reth-engine-tree.workspace = true | ||
reth-node-types.workspace = true | ||
reth-payload-builder.workspace = true | ||
reth-payload-primitives.workspace = true | ||
reth-primitives.workspace = true | ||
reth-provider.workspace = true | ||
reth-prune.workspace = true | ||
reth-transaction-pool.workspace = true | ||
reth-stages-api.workspace = true | ||
|
||
# async | ||
tokio.workspace = true | ||
tokio-stream.workspace = true | ||
futures-util.workspace = true | ||
|
||
# misc | ||
eyre.workspace = true | ||
tracing.workspace = true | ||
|
||
[dev-dependencies] | ||
reth-chainspec.workspace = true | ||
reth-chain-state.workspace = true | ||
reth-config.workspace = true | ||
reth-db = { workspace = true, features = ["test-utils"] } | ||
reth-ethereum-engine-primitives.workspace = true | ||
reth-exex-test-utils.workspace = true | ||
reth-payload-builder = { workspace = true, features = ["test-utils"] } | ||
reth-provider = { workspace = true, features = ["test-utils"] } | ||
reth-rpc-types.workspace = true | ||
reth-tracing.workspace = true | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! A local engine service that can be used to drive a dev chain. | ||
pub mod miner; | ||
pub mod service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Contains the implementation of the mining mode for the local engine. | ||
|
||
use futures_util::{stream::Fuse, StreamExt}; | ||
use reth_primitives::TxHash; | ||
use reth_transaction_pool::TransactionPool; | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
time::Duration, | ||
}; | ||
use tokio::time::Interval; | ||
use tokio_stream::wrappers::ReceiverStream; | ||
|
||
/// A mining mode for the local dev engine. | ||
#[derive(Debug)] | ||
pub enum MiningMode { | ||
/// In this mode a block is built as soon as | ||
/// a valid transaction reaches the pool. | ||
Instant(Fuse<ReceiverStream<TxHash>>), | ||
/// In this mode a block is built at a fixed interval. | ||
Interval(Interval), | ||
} | ||
|
||
impl MiningMode { | ||
/// Constructor for a [`MiningMode::Instant`] | ||
pub fn instant<Pool: TransactionPool>(pool: Pool) -> Self { | ||
let rx = pool.pending_transactions_listener(); | ||
Self::Instant(ReceiverStream::new(rx).fuse()) | ||
} | ||
|
||
/// Constructor for a [`MiningMode::Interval`] | ||
pub fn interval(duration: Duration) -> Self { | ||
let start = tokio::time::Instant::now() + duration; | ||
Self::Interval(tokio::time::interval_at(start, duration)) | ||
} | ||
} | ||
|
||
impl Future for MiningMode { | ||
type Output = (); | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.get_mut(); | ||
match this { | ||
Self::Instant(rx) => { | ||
// drain all transactions notifications | ||
if let Poll::Ready(Some(_)) = rx.poll_next_unpin(cx) { | ||
return Poll::Ready(()) | ||
} | ||
Poll::Pending | ||
} | ||
Self::Interval(interval) => { | ||
if interval.poll_tick(cx).is_ready() { | ||
return Poll::Ready(()) | ||
} | ||
Poll::Pending | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.