builder gas limit & some refactoring (#6583)

* Cache gas_limit

* Payload Parameters Refactor

* Enforce Proposer Gas Limit

* Fixed and Added New Tests

* Fix Beacon Chain Tests
This commit is contained in:
ethDreamer
2024-12-15 21:43:58 -08:00
committed by GitHub
parent 11e1d5bf14
commit 86891e6d0f
14 changed files with 598 additions and 243 deletions

View File

@@ -1,5 +1,5 @@
use crate::test_utils::{DEFAULT_BUILDER_PAYLOAD_VALUE_WEI, DEFAULT_JWT_SECRET};
use crate::{Config, ExecutionLayer, PayloadAttributes};
use crate::{Config, ExecutionLayer, PayloadAttributes, PayloadParameters};
use eth2::types::{BlobsBundle, BlockId, StateId, ValidatorId};
use eth2::{BeaconNodeHttpClient, Timeouts, CONSENSUS_VERSION_HEADER};
use fork_choice::ForkchoiceUpdateParameters;
@@ -54,6 +54,10 @@ impl Operation {
}
}
pub fn mock_builder_extra_data<E: EthSpec>() -> types::VariableList<u8, E::MaxExtraDataBytes> {
"mock_builder".as_bytes().to_vec().into()
}
#[derive(Debug)]
// We don't use the string value directly, but it's used in the Debug impl which is required by `warp::reject::Reject`.
struct Custom(#[allow(dead_code)] String);
@@ -72,6 +76,8 @@ pub trait BidStuff<E: EthSpec> {
fn set_withdrawals_root(&mut self, withdrawals_root: Hash256);
fn sign_builder_message(&mut self, sk: &SecretKey, spec: &ChainSpec) -> Signature;
fn stamp_payload(&mut self);
}
impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
@@ -203,6 +209,29 @@ impl<E: EthSpec> BidStuff<E> for BuilderBid<E> {
let message = self.signing_root(domain);
sk.sign(message)
}
// this helps differentiate a builder block from a regular block
fn stamp_payload(&mut self) {
let extra_data = mock_builder_extra_data::<E>();
match self.to_mut().header_mut() {
ExecutionPayloadHeaderRefMut::Bellatrix(header) => {
header.extra_data = extra_data;
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
}
ExecutionPayloadHeaderRefMut::Capella(header) => {
header.extra_data = extra_data;
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
}
ExecutionPayloadHeaderRefMut::Deneb(header) => {
header.extra_data = extra_data;
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
}
ExecutionPayloadHeaderRefMut::Electra(header) => {
header.extra_data = extra_data;
header.block_hash = ExecutionBlockHash::from_root(header.tree_hash_root());
}
}
}
}
#[derive(Clone)]
@@ -286,6 +315,7 @@ impl<E: EthSpec> MockBuilder<E> {
while let Some(op) = guard.pop() {
op.apply(bid);
}
bid.stamp_payload();
}
}
@@ -413,11 +443,12 @@ pub fn serve<E: EthSpec>(
let block = head.data.message();
let head_block_root = block.tree_hash_root();
let head_execution_hash = block
let head_execution_payload = block
.body()
.execution_payload()
.map_err(|_| reject("pre-merge block"))?
.block_hash();
.map_err(|_| reject("pre-merge block"))?;
let head_execution_hash = head_execution_payload.block_hash();
let head_gas_limit = head_execution_payload.gas_limit();
if head_execution_hash != parent_hash {
return Err(reject("head mismatch"));
}
@@ -529,14 +560,24 @@ pub fn serve<E: EthSpec>(
finalized_hash: Some(finalized_execution_hash),
};
let proposer_gas_limit = builder
.val_registration_cache
.read()
.get(&pubkey)
.map(|v| v.message.gas_limit);
let payload_parameters = PayloadParameters {
parent_hash: head_execution_hash,
parent_gas_limit: head_gas_limit,
proposer_gas_limit,
payload_attributes: &payload_attributes,
forkchoice_update_params: &forkchoice_update_params,
current_fork: fork,
};
let payload_response_type = builder
.el
.get_full_payload_caching(
head_execution_hash,
&payload_attributes,
forkchoice_update_params,
fork,
)
.get_full_payload_caching(payload_parameters)
.await
.map_err(|_| reject("couldn't get payload"))?;
@@ -648,8 +689,6 @@ pub fn serve<E: EthSpec>(
}
};
message.set_gas_limit(cached_data.gas_limit);
builder.apply_operations(&mut message);
let mut signature =