Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make 'extra data' for builder conform to spec #51

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use reth_payload_builder::{
PayloadJob, PayloadJobGenerator,
};
use reth_primitives::{
constants::{BEACON_NONCE, EMPTY_OMMER_ROOT},
constants::{BEACON_NONCE, EMPTY_OMMER_ROOT, MAXIMUM_EXTRA_DATA_SIZE},
proofs, Block, BlockNumber, Bytes, ChainSpec, Header, IntoRecoveredTransaction, Receipt,
SealedHeader, TransactionSigned, TransactionSignedEcRecovered, U256,
};
Expand Down Expand Up @@ -116,7 +116,7 @@ struct UnpackagedPayload<S: StateProvider> {
block_env: BlockEnv,
state: Arc<State<S>>,
post_state: PostState,
extra_data: u128,
extra_data: Bytes,
txs: Vec<TransactionSigned>,
bundles: HashSet<BundleId>,
cumulative_gas_used: u64,
Expand All @@ -136,6 +136,13 @@ impl<S: StateProvider> UnpackagedPayload<S> {
let withdrawals_root = proofs::calculate_withdrawals_root(&self.attributes.withdrawals);
let state_root = self.state.state().state_root(self.post_state)?;

if self.extra_data.len() > MAXIMUM_EXTRA_DATA_SIZE {
return Err(PayloadBuilderError::Internal(RethError::Custom(
"Unpackaged Payload extradata size exceeds MAXIMUM_EXTRA_DATA_SIZE bytes limit"
.into(),
)));
}

let header = Header {
parent_hash: self.attributes.parent,
ommers_hash: EMPTY_OMMER_ROOT,
Expand All @@ -155,7 +162,7 @@ impl<S: StateProvider> UnpackagedPayload<S> {
base_fee_per_gas: Some(base_fee),
blob_gas_used: None,
excess_blob_gas: None,
extra_data: self.extra_data.to_le_bytes().into(),
extra_data: self.extra_data,
};

let block = Block {
Expand Down Expand Up @@ -184,7 +191,7 @@ struct Payload {
#[derive(Clone, Debug)]
struct PayloadAttributes {
inner: PayloadBuilderAttributes,
extra_data: u128,
extra_data: Bytes,
chirag-bgh marked this conversation as resolved.
Show resolved Hide resolved
wallet: LocalWallet,
}

Expand Down Expand Up @@ -423,15 +430,15 @@ where
#[derive(Clone, Debug)]
pub struct BuilderConfig {
pub deadline: Duration,
pub extra_data: u128,
pub extra_data: Bytes,
pub wallet: LocalWallet,
}

pub struct Builder<Client, Pool> {
chain: Arc<ChainSpec>,
deadline: Duration,
wallet: LocalWallet,
extra_data: u128,
extra_data: Bytes,
client: Arc<Client>,
pool: Arc<Pool>,
bundle_pool: Arc<Mutex<BundlePool>>,
Expand Down Expand Up @@ -552,9 +559,16 @@ where
)));
}

// extra data must be less than 32 bytes
if self.extra_data.len() > MAXIMUM_EXTRA_DATA_SIZE {
return Err(PayloadBuilderError::Internal(RethError::Custom(
"extradata size exceeds MAXIMUM_EXTRA_DATA_SIZE bytes limit".into(),
)));
}

let attributes = PayloadAttributes {
inner: attributes,
extra_data: self.extra_data,
extra_data: self.extra_data.clone(),
wallet: self.wallet.clone(),
};

Expand Down Expand Up @@ -645,6 +659,13 @@ where
let mut txs = Vec::new();
let mut bundle_ids = HashSet::new();

// extra data must be less than 32 bytes
if config.attributes.extra_data.len() > MAXIMUM_EXTRA_DATA_SIZE {
return Err(PayloadBuilderError::Internal(RethError::Custom(
"extradata size exceeds MAXIMUM_EXTRA_DATA_SIZE bytes limit".into(),
)));
}

// execute bundles
for (id, bundle) in bundles {
// check gas for entire bundle
Expand Down