Skip to content

Commit

Permalink
misc fixes, logging adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Sep 7, 2023
1 parent 45881d3 commit c0a3de6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ extra_data = "hello world"
execution_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
bidding_deadline_ms = 1000
bid_percent = 0.9
subsidy_gwei = 1000000000 # 1 eth
subsidy_gwei = 100000000 # 0.1 eth
jwt_secret_path = "/secrets/jwt.hex"
1 change: 1 addition & 0 deletions mev-build-rs/src/reth_builder/bidder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Bidder for DeadlineBidder {
let slot = build.context.slot;
let target = self.clock.duration_until_slot(slot);
let duration = target.checked_sub(self.deadline).unwrap_or_default();
tracing::trace!(duration = ?duration, "waiting to submit bid");
tokio::time::sleep(duration).await;

Ok(Some(Bid::Done))
Expand Down
1 change: 1 addition & 0 deletions mev-build-rs/src/reth_builder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn make_submission(
Ok(SignedBidSubmission { message, execution_payload, signature })
}

// TODO: drop unnecessary things...
#[derive(Debug, Clone)]
pub struct BuildContext {
pub slot: Slot,
Expand Down
14 changes: 7 additions & 7 deletions mev-build-rs/src/reth_builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use std::{
use tokio::sync::mpsc;
use tokio_stream::{wrappers::ReceiverStream, Stream};

// All builds are cancelled this many seconds into their target slot.
const BUILD_DEADLINE_MS: u64 = 2000;
// All builds are given this long (in milliseconds) to execute.
const BUILD_DEADLINE_MS: u64 = 14000;

/// `Builder` builds blocks for proposers registered to connected relays.
#[derive(Clone)]
Expand Down Expand Up @@ -202,6 +202,7 @@ impl<Pool, Client> Builder<Pool, Client> {

pub fn stop_build(&self, id: &BuildIdentifier) {
if let Some(build) = self.build_for(id) {
tracing::trace!(id = %id, "stopping build");
build.stop()
}
}
Expand All @@ -217,7 +218,7 @@ impl<Pool, Client> Builder<Pool, Client> {
// TODO: make calls concurrently
for index in &context.relays {
let relay = &self.relays[*index];
tracing::info!(id = ?id, proposer_payment = ?signed_submission.message.value, builder_payment = ?builder_payment, relay = ?relay, bid = ?signed_submission, "submitting bid");
tracing::info!(id = ?id, proposer_payment = ?signed_submission.message.value, builder_payment = ?builder_payment, relay = ?relay, bid_trace = ?signed_submission.message, "submitting bid");
match relay.submit_bid(&signed_submission).await {
Ok(_) => tracing::info!(id = ?id, relay = ?relay, "successfully submitted bid"),
Err(err) => {
Expand Down Expand Up @@ -389,9 +390,8 @@ impl<Pool: TransactionPool, Client: StateProviderFactory + BlockReaderIdExt> Bui
if self.builds_tx.blocking_send(id.clone()).is_err() {
tracing::warn!(id = ?id, "could not send build to stream of builds, listeners will ignore");
}
let deadline = self.clock.duration_until_slot(build.context.slot) +
Duration::from_millis(BUILD_DEADLINE_MS);
let deadline = Instant::now() + deadline;
let deadline = Instant::now() + Duration::from_millis(BUILD_DEADLINE_MS);
tracing::trace!(id = ?id, slot = ?build.context.slot, "starting build");
loop {
if Instant::now() > deadline {
return Ok(())
Expand All @@ -406,7 +406,7 @@ impl<Pool: TransactionPool, Client: StateProviderFactory + BlockReaderIdExt> Bui
state.payload_with_payments = payload_with_payments;
}
Ok(BuildOutcome::Worse { threshold, provided }) => {
tracing::info!(
tracing::trace!(
threshold = ?threshold,
provided = ?provided,
"discarding built payload that did not exceed current value"
Expand Down
15 changes: 14 additions & 1 deletion mev-build-rs/src/reth_builder/payload_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

/// Payload building logic is heavily inspired by
/// the `reth-basic-payload-builder` package in the `reth` codebase.
use crate::reth_builder::{
Expand Down Expand Up @@ -187,6 +189,18 @@ struct ExecutionContext<'a> {
revenue: U256,
}

impl<'a> fmt::Debug for ExecutionContext<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ExecutionContext")
.field("build", &self.build)
.field("cumulative_gas_used", &self.cumulative_gas_used)
.field("total_fees", &self.total_fees)
.field("total_payment", &self.total_payment)
.field("reveneu", &self.revenue)
.finish()
}
}

impl<'a> ExecutionContext<'a> {
fn try_from<P: reth_provider::StateProviderFactory>(
context: &'a BuildContext,
Expand Down Expand Up @@ -269,7 +283,6 @@ pub fn build_payload<
}

context.compute_payment_from_fees();

let payment_tx = construct_payment_tx(&mut context)?;

context.extend_transaction(payment_tx)?;
Expand Down
11 changes: 7 additions & 4 deletions mev-build-rs/src/reth_builder/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::reth_builder::{
bidder::{Bid, Bidder},
builder::{Builder, PayloadAttributesProcessingOutcome},
error::Error as BuilderError,
};
use ethereum_consensus::{
clock::{Clock, SystemTimeProvider},
Expand Down Expand Up @@ -148,7 +149,7 @@ impl<

while let Some(id) = builds.next().await {
let build = builder.build_for(&id).expect("only asking for existing builds");
tracing::trace!(id = ?id, "starting bidding");
tracing::trace!(id = ?id, slot = ?build.context.slot, "starting bidding");
// TODO: spawn in another context
// TODO: constrain bidders to finite lifetime
loop {
Expand Down Expand Up @@ -192,14 +193,16 @@ impl<
let builder = builder.clone();
let id = build_identifier.clone();
tokio::task::spawn_blocking(move || {
tracing::trace!(id = ?id, "starting build");
if let Err(err) = builder.start_build(&id) {
tracing::warn!(id = ?id, err = ?err, "failed to progress build");
}
});
}
Ok(PayloadAttributesProcessingOutcome::Duplicate(attrs)) => {
tracing::trace!(attrs = ?attrs, "skipping processing of duplicate payload attributes")
Ok(PayloadAttributesProcessingOutcome::Duplicate(_)) => {
tracing::trace!("skipping processing of duplicate payload attributes")
}
Err(BuilderError::NoRegisteredValidatorsForSlot(slot)) => {
tracing::trace!(slot = ?slot, "no registered validator");
}
Err(err) => {
tracing::warn!(err = ?err, "could not process payload attributes");
Expand Down

0 comments on commit c0a3de6

Please sign in to comment.