Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benches/benches/build_block_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fn create_payload_block(genesis_block: &Block, store: &Store) -> (Block, u64) {
version: 3,
elasticity_multiplier: 1,
gas_ceil: DEFAULT_BUILDER_GAS_CEIL,
target_gas_limit: None,
};
let id = payload_args.id();
let block = create_payload(&payload_args, store, Bytes::new()).unwrap();
Expand Down
46 changes: 45 additions & 1 deletion crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ pub struct BuildPayloadArgs {
pub version: u8,
pub elasticity_multiplier: u64,
pub gas_ceil: u64,
/// CL-provided target gas limit (EIP-7783, Amsterdam). When `Some`, takes
/// precedence over `gas_ceil` for `calc_gas_limit`. `None` falls back to
/// the builder's `gas_ceil`.
pub target_gas_limit: Option<u64>,
}

#[derive(Debug, Error)]
Expand All @@ -117,6 +121,9 @@ impl BuildPayloadArgs {
if let Some(beacon_root) = self.beacon_root {
hasher.update(beacon_root);
}
if let Some(target_gas_limit) = self.target_gas_limit {
hasher.update(target_gas_limit.to_be_bytes());
}
let res = &mut hasher.finalize()[..8];
res[0] = self.version;
Ok(u64::from_be_bytes(res.try_into().map_err(|_| {
Expand All @@ -137,7 +144,8 @@ pub fn create_payload(
.ok_or_else(|| ChainError::ParentNotFound)?;
let chain_config = storage.get_chain_config();
let fork = chain_config.fork(args.timestamp);
let gas_limit = calc_gas_limit(parent_block.gas_limit, args.gas_ceil);
let desired_gas_limit = args.target_gas_limit.unwrap_or(args.gas_ceil);
let gas_limit = calc_gas_limit(parent_block.gas_limit, desired_gas_limit);
let excess_blob_gas = chain_config
.get_fork_blob_schedule(args.timestamp)
.map(|schedule| calc_excess_blob_gas(&parent_block, schedule, fork));
Expand Down Expand Up @@ -1072,3 +1080,39 @@ impl PartialOrd for HeadTransaction {
Some(self.cmp(other))
}
}

#[cfg(test)]
mod tests {
use super::*;

fn base_args() -> BuildPayloadArgs {
BuildPayloadArgs {
parent: BlockHash::zero(),
timestamp: 1_700_000_000,
fee_recipient: Address::zero(),
random: H256::zero(),
withdrawals: None,
beacon_root: None,
slot_number: Some(42),
version: 4,
elasticity_multiplier: 2,
gas_ceil: 30_000_000,
target_gas_limit: None,
}
}

#[test]
fn payload_id_includes_target_gas_limit() {
let a = base_args();
let mut b = base_args();
b.target_gas_limit = Some(36_000_000);
assert_ne!(a.id().unwrap(), b.id().unwrap());
}

#[test]
fn payload_id_stable_when_target_unchanged() {
let a = base_args();
let b = base_args();
assert_eq!(a.id().unwrap(), b.id().unwrap());
}
}
1 change: 1 addition & 0 deletions crates/l2/sequencer/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl BlockProducer {
version,
elasticity_multiplier: self.elasticity_multiplier,
gas_ceil: self.block_gas_limit,
target_gas_limit: None,
};
let payload = create_payload(&args, &self.store, Bytes::new())?;

Expand Down
8 changes: 5 additions & 3 deletions crates/networking/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ jemalloc_pprof = { version = "0.8.0", optional = true, features = [
] }
spawned-rt.workspace = true
spawned-concurrency.workspace = true
futures.workspace = true

# EIP-8025 dependencies (optional)
libssz-merkle = { workspace = true, optional = true }
libssz-types = { workspace = true, optional = true }
# Engine REST/SSZ (execution-apis PR #764)
libssz.workspace = true
libssz-derive.workspace = true
libssz-types.workspace = true

# Clients
envy = "0.4.2"
Expand Down
20 changes: 12 additions & 8 deletions crates/networking/rpc/engine/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fn parse(
Ok((forkchoice_state, payload_attributes))
}

async fn handle_forkchoice(
pub(crate) async fn handle_forkchoice(
fork_choice_state: &ForkChoiceState,
context: RpcApiContext,
version: usize,
Expand Down Expand Up @@ -382,7 +382,7 @@ async fn handle_forkchoice(
}
}

fn validate_attributes_v1(
pub(crate) fn validate_attributes_v1(
attributes: &PayloadAttributesV3,
head_block: &BlockHeader,
) -> Result<(), RpcErr> {
Expand All @@ -392,7 +392,7 @@ fn validate_attributes_v1(
validate_timestamp(attributes, head_block)
}

fn validate_attributes_v2(
pub(crate) fn validate_attributes_v2(
attributes: &PayloadAttributesV3,
head_block: &BlockHeader,
) -> Result<(), RpcErr> {
Expand All @@ -402,7 +402,7 @@ fn validate_attributes_v2(
validate_timestamp(attributes, head_block)
}

fn validate_attributes_v2_pre_shanghai(
pub(crate) fn validate_attributes_v2_pre_shanghai(
attributes: &PayloadAttributesV3,
head_block: &BlockHeader,
) -> Result<(), RpcErr> {
Expand All @@ -412,7 +412,7 @@ fn validate_attributes_v2_pre_shanghai(
validate_timestamp(attributes, head_block)
}

fn validate_attributes_v3(
pub(crate) fn validate_attributes_v3(
attributes: &PayloadAttributesV3,
head_block: &BlockHeader,
context: &RpcApiContext,
Expand Down Expand Up @@ -448,7 +448,7 @@ fn validate_timestamp(
Ok(())
}

async fn build_payload(
pub(crate) async fn build_payload(
attributes: &PayloadAttributesV3,
context: RpcApiContext,
fork_choice_state: &ForkChoiceState,
Expand All @@ -465,6 +465,7 @@ async fn build_payload(
version,
elasticity_multiplier: ELASTICITY_MULTIPLIER,
gas_ceil: context.gas_ceil,
target_gas_limit: None,
};
let payload_id = args
.id()
Expand Down Expand Up @@ -514,7 +515,7 @@ fn parse_v4(
Ok((forkchoice_state, payload_attributes))
}

fn validate_attributes_v4(
pub(crate) fn validate_attributes_v4(
attributes: &PayloadAttributesV4,
head_block: &BlockHeader,
context: &RpcApiContext,
Expand Down Expand Up @@ -551,7 +552,7 @@ fn validate_timestamp_v4(
Ok(())
}

async fn build_payload_v4(
pub(crate) async fn build_payload_v4(
attributes: &PayloadAttributesV4,
context: RpcApiContext,
fork_choice_state: &ForkChoiceState,
Expand All @@ -567,6 +568,9 @@ async fn build_payload_v4(
version: 4,
elasticity_multiplier: ELASTICITY_MULTIPLIER,
gas_ceil: context.gas_ceil,
// Collapse the EIP-7783 0-sentinel to `None`; see the field doc on
// `PayloadAttributesV4::target_gas_limit`.
target_gas_limit: attributes.target_gas_limit.filter(|&v| v != 0),
};
let payload_id = args
.id()
Expand Down
7 changes: 6 additions & 1 deletion crates/networking/rpc/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl RpcHandler for ExchangeCapabilitiesRequest {
}

async fn handle(&self, _context: RpcApiContext) -> Result<Value, RpcErr> {
Ok(json!(CAPABILITIES))
// Per execution-apis PR #764, advertise both JSON-RPC method names and
// the SSZ REST endpoint identifiers we support so the CL can pick the
// binary transport per endpoint.
let mut all: Vec<&str> = CAPABILITIES.to_vec();
all.extend_from_slice(crate::engine_rest::SSZ_REST_CAPABILITIES);
Ok(json!(all))
}
}
Loading
Loading