Skip to content

Commit

Permalink
ensure proposer's gas limit preferences are respected
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Apr 28, 2024
1 parent 765a3e7 commit 16f9f21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mev-build-rs/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn make_attributes_for_proposer(
let proposal = ProposalAttributes {
builder_fee_recipient,
builder_signer,
suggested_gas_limit: proposer.gas_limit,
proposer_gas_limit: proposer.gas_limit,
proposer_fee_recipient: proposer.fee_recipient,
};
let mut attributes = attributes.clone();
Expand Down
7 changes: 3 additions & 4 deletions mev-build-rs/src/payload/builder_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn payload_id_with_bytes(
}

if let Some(proposal) = proposal {
hasher.update(proposal.suggested_gas_limit.to_be_bytes());
hasher.update(proposal.proposer_gas_limit.to_be_bytes());
hasher.update(proposal.proposer_fee_recipient.as_slice());
}

Expand All @@ -52,7 +52,7 @@ pub fn mix_proposal_into_payload_id(
hasher.update(payload_id);

hasher.update(proposal.builder_fee_recipient.as_slice());
hasher.update(proposal.suggested_gas_limit.to_be_bytes());
hasher.update(proposal.proposer_gas_limit.to_be_bytes());
hasher.update(proposal.proposer_fee_recipient.as_slice());

let out = hasher.finalize();
Expand All @@ -65,8 +65,7 @@ pub struct ProposalAttributes {
pub builder_fee_recipient: Address,
// TODO: move to payload builder
pub builder_signer: Arc<LocalWallet>,
// TODO: ensure this is being used, and mapped to correct value
pub suggested_gas_limit: u64,
pub proposer_gas_limit: u64,
pub proposer_fee_recipient: Address,
}

Expand Down
25 changes: 19 additions & 6 deletions mev-build-rs/src/payload/job_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@ use crate::{
utils::payload_job::PayloadTaskGuard,
};
use ethereum_consensus::clock::duration_until;
use mev_rs::compute_preferred_gas_limit;
use reth::{
api::PayloadBuilderAttributes,
payload::{self, database::CachedReads, error::PayloadBuilderError},
primitives::{BlockNumberOrTag, Bytes, ChainSpec, B256},
primitives::{BlockNumberOrTag, Bytes, ChainSpec, B256, U256},
providers::{BlockReaderIdExt, BlockSource, CanonStateNotification, StateProviderFactory},
tasks::TaskSpawner,
transaction_pool::TransactionPool,
};
use reth_basic_payload_builder::{PayloadConfig, PrecachedState};
use std::{sync::Arc, time::Duration};

fn apply_gas_limit<P>(config: &mut PayloadConfig<P>, gas_limit: u64) {
config.initialized_block_env.gas_limit = U256::from(gas_limit);
}

#[derive(Debug, Clone)]
pub struct PayloadJobGeneratorConfig {
pub extradata: Bytes,
// TODO: remove or use?
// NOTE: currently ignored, see: https://github.com/paradigmxyz/reth/issues/7948
pub _max_gas_limit: u64,
pub interval: Duration,
pub deadline: Duration,
Expand Down Expand Up @@ -105,21 +110,29 @@ where
block.seal(attributes.parent())
};

let until = if attributes.proposal.is_some() {
self.job_deadline(attributes.timestamp())
let (until, gas_limit) = if let Some(proposal) = attributes.proposal.as_ref() {
let until = self.job_deadline(attributes.timestamp());
let gas_limit =
compute_preferred_gas_limit(proposal.proposer_gas_limit, parent_block.gas_limit);
(until, Some(gas_limit))
} else {
// If there is no attached proposal, then terminate the payload job immediately
tokio::time::Instant::now()
let until = tokio::time::Instant::now();
(until, None)
};
let deadline = Box::pin(tokio::time::sleep_until(until));

let config = PayloadConfig::new(
let mut config = PayloadConfig::new(
Arc::new(parent_block),
self.config.extradata.clone(),
attributes,
Arc::clone(&self.chain_spec),
);

if let Some(gas_limit) = gas_limit {
apply_gas_limit(&mut config, gas_limit);
}

let cached_reads = self.maybe_pre_cached(config.parent_block.hash());

Ok(PayloadJob {
Expand Down

0 comments on commit 16f9f21

Please sign in to comment.