-
Notifications
You must be signed in to change notification settings - Fork 76
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
1 parent
df6cc54
commit 96c8c5b
Showing
11 changed files
with
178 additions
and
88 deletions.
There are no files selected for viewing
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
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
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,42 @@ | ||
use crate::reth_builder::{build::Build, error::Error}; | ||
use async_trait::async_trait; | ||
use ethereum_consensus::clock::{Clock, SystemTimeProvider}; | ||
use std::time::Duration; | ||
|
||
pub enum Bid { | ||
Continue, | ||
Done, | ||
} | ||
|
||
#[async_trait] | ||
pub trait Bidder { | ||
async fn bid_for(&self, build: &Build) -> Result<Option<Bid>, Error>; | ||
} | ||
|
||
/// `DeadlineBidder` submits the best payload *once* at the `deadline` | ||
/// expressed as a `Duration` *before* the start of the build's target slot. | ||
/// | ||
/// For example, if the `deadline` is 1 second, then the bidder will return | ||
/// a value to bid one second before the start of the build's target slot. | ||
pub struct DeadlineBidder { | ||
clock: Clock<SystemTimeProvider>, | ||
deadline: Duration, | ||
} | ||
|
||
impl DeadlineBidder { | ||
pub fn new(clock: Clock<SystemTimeProvider>, deadline: Duration) -> Self { | ||
Self { clock, deadline } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Bidder for DeadlineBidder { | ||
async fn bid_for(&self, build: &Build) -> Result<Option<Bid>, Error> { | ||
let slot = build.context.slot; | ||
let target = self.clock.duration_until_slot(slot); | ||
let duration = target - self.deadline; | ||
tokio::time::sleep(duration).await; | ||
|
||
Ok(Some(Bid::Done)) | ||
} | ||
} |
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
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
Oops, something went wrong.