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

chore: extra data #13410

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion book/cli/reth/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ TxPool:
[default: 200]

Builder:
--builder.extradata <EXTRADATA>
--builder.extradata <EXTRA_DATA>
Block extra data set by the payload builder

[default: reth/<VERSION>/<OS>]
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ pub fn validate_4844_header_standalone<H: BlockHeader>(header: &H) -> Result<(),
Ok(())
}

/// Validates the header's extradata according to the beacon consensus rules.
/// Validates the header's extra data according to the beacon consensus rules.
///
/// From yellow paper: extraData: An arbitrary byte array containing data relevant to this block.
/// This must be 32 bytes or fewer; formally Hx.
#[inline]
pub fn validate_header_extradata<H: BlockHeader>(header: &H) -> Result<(), ConsensusError> {
let extradata_len = header.extra_data().len();
if extradata_len > MAXIMUM_EXTRA_DATA_SIZE {
Err(ConsensusError::ExtraDataExceedsMax { len: extradata_len })
pub fn validate_header_extra_data<H: BlockHeader>(header: &H) -> Result<(), ConsensusError> {
let extra_data_len = header.extra_data().len();
if extra_data_len > MAXIMUM_EXTRA_DATA_SIZE {
Err(ConsensusError::ExtraDataExceedsMax { len: extra_data_len })
} else {
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ethereum/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_consensus_common::validation::{
validate_4844_header_standalone, validate_against_parent_4844,
validate_against_parent_eip1559_base_fee, validate_against_parent_hash_number,
validate_against_parent_timestamp, validate_block_pre_execution, validate_body_against_header,
validate_header_base_fee, validate_header_extradata, validate_header_gas,
validate_header_base_fee, validate_header_extra_data, validate_header_gas,
};
use reth_primitives::{BlockWithSenders, NodePrimitives, Receipt, SealedBlock, SealedHeader};
use reth_primitives_traits::{
Expand Down Expand Up @@ -234,8 +234,8 @@ where
// Block validation with respect to the parent should ensure that the block timestamp
// is greater than its parent timestamp.

// validate header extradata for all networks post merge
validate_header_extradata(header)?;
// validate header extra data for all networks post merge
validate_header_extra_data(header)?;

// mixHash is used instead of difficulty inside EVM
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty
Expand All @@ -256,7 +256,7 @@ where
})
}

validate_header_extradata(header)?;
validate_header_extra_data(header)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl EthereumPayloadBuilder {
let conf = ctx.payload_builder_config();
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
evm_config,
EthereumBuilderConfig::new(conf.extradata_bytes()).with_gas_limit(conf.gas_limit()),
EthereumBuilderConfig::new(conf.extra_data_bytes()).with_gas_limit(conf.gas_limit()),
);

let payload_job_config = BasicPayloadJobGeneratorConfig::default()
Expand Down
26 changes: 13 additions & 13 deletions crates/node/core/src/args/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::{borrow::Cow, ffi::OsStr, time::Duration};
#[command(next_help_heading = "Builder")]
pub struct PayloadBuilderArgs {
/// Block extra data set by the payload builder.
#[arg(long = "builder.extradata", value_parser = ExtradataValueParser::default(), default_value_t = default_extra_data())]
pub extradata: String,
#[arg(long = "builder.extradata", value_parser = ExtraDataValueParser::default(), default_value_t = default_extra_data())]
pub extra_data: String,

/// Target gas limit for built blocks.
#[arg(long = "builder.gaslimit", default_value_t = ETHEREUM_BLOCK_GAS_LIMIT, value_name = "GAS_LIMIT")]
Expand All @@ -40,7 +40,7 @@ pub struct PayloadBuilderArgs {
impl Default for PayloadBuilderArgs {
fn default() -> Self {
Self {
extradata: default_extra_data(),
extra_data: default_extra_data(),
gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
interval: Duration::from_secs(1),
deadline: SLOT_DURATION,
Expand All @@ -50,8 +50,8 @@ impl Default for PayloadBuilderArgs {
}

impl PayloadBuilderConfig for PayloadBuilderArgs {
fn extradata(&self) -> Cow<'_, str> {
self.extradata.as_str().into()
fn extra_data(&self) -> Cow<'_, str> {
self.extra_data.as_str().into()
}

fn interval(&self) -> Duration {
Expand All @@ -73,9 +73,9 @@ impl PayloadBuilderConfig for PayloadBuilderArgs {

#[derive(Clone, Debug, Default)]
#[non_exhaustive]
struct ExtradataValueParser;
struct ExtraDataValueParser;

impl TypedValueParser for ExtradataValueParser {
impl TypedValueParser for ExtraDataValueParser {
type Value = String;

fn parse_ref(
Expand Down Expand Up @@ -130,23 +130,23 @@ mod tests {

#[test]
fn test_default_extra_data() {
let extradata = default_extra_data();
let extra_data = default_extra_data();
let args = CommandParser::<PayloadBuilderArgs>::parse_from([
"reth",
"--builder.extradata",
extradata.as_str(),
extra_data.as_str(),
])
.args;
assert_eq!(args.extradata, extradata);
assert_eq!(args.extra_data, extra_data);
}

#[test]
fn test_invalid_extradata() {
let extradata = "x".repeat(MAXIMUM_EXTRA_DATA_SIZE + 1);
fn test_invalid_extra_data() {
let extra_data = "x".repeat(MAXIMUM_EXTRA_DATA_SIZE + 1);
let args = CommandParser::<PayloadBuilderArgs>::try_parse_from([
"reth",
"--builder.extradata",
extradata.as_str(),
extra_data.as_str(),
]);
assert!(args.is_err());
}
Expand Down
8 changes: 4 additions & 4 deletions crates/node/core/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::{borrow::Cow, time::Duration};
/// [`PayloadBuilderArgs`](crate::args::PayloadBuilderArgs) type.
pub trait PayloadBuilderConfig {
/// Block extra data set by the payload builder.
fn extradata(&self) -> Cow<'_, str>;
fn extra_data(&self) -> Cow<'_, str>;

/// Returns the extradata as bytes.
fn extradata_bytes(&self) -> Bytes {
self.extradata().as_bytes().to_vec().into()
/// Returns the extra data as bytes.
fn extra_data_bytes(&self) -> Bytes {
self.extra_data().as_bytes().to_vec().into()
}

/// The interval at which the job should build a new payload after the last.
Expand Down
6 changes: 3 additions & 3 deletions crates/node/core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ mod tests {
use super::*;

#[test]
fn assert_extradata_less_32bytes() {
let extradata = default_extra_data();
assert!(extradata.len() <= 32, "extradata must be less than 32 bytes: {extradata}")
fn assert_extra_data_less_32bytes() {
let extra_data = default_extra_data();
assert!(extra_data.len() <= 32, "extra data must be less than 32 bytes: {extra_data}")
}
}
2 changes: 1 addition & 1 deletion crates/optimism/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub struct OpChainSpec {
}

impl OpChainSpec {
/// Extracts the Holcene 1599 parameters from the encoded extradata from the parent header.
/// Extracts the Holocene 1599 parameters from the encoded extra data from the parent header.
///
/// Caution: Caller must ensure that holocene is active in the parent header.
///
Expand Down
6 changes: 3 additions & 3 deletions crates/optimism/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_consensus_common::validation::{
validate_against_parent_4844, validate_against_parent_eip1559_base_fee,
validate_against_parent_hash_number, validate_against_parent_timestamp,
validate_body_against_header, validate_cancun_gas, validate_header_base_fee,
validate_header_extradata, validate_header_gas, validate_shanghai_withdrawals,
validate_header_extra_data, validate_header_gas, validate_shanghai_withdrawals,
};
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_forks::OpHardforks;
Expand Down Expand Up @@ -170,8 +170,8 @@ impl HeaderValidator for OpBeaconConsensus {
// Block validation with respect to the parent should ensure that the block timestamp
// is greater than its parent timestamp.

// validate header extradata for all networks post merge
validate_header_extradata(header)?;
// validate header extra data for all networks post merge
validate_header_extra_data(header)?;

// mixHash is used instead of difficulty inside EVM
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives-traits/src/header/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
pub enum HeaderError {
/// Represents an error when the block difficulty is too large.
LargeDifficulty,
/// Represents an error when the block extradata is too large.
/// Represents an error when the block extra data is too large.
LargeExtraData,
}
2 changes: 1 addition & 1 deletion examples/custom-payload-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
payload_job_config,
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(ctx.chain_spec()),
EthereumBuilderConfig::new(conf.extradata_bytes()),
EthereumBuilderConfig::new(conf.extra_data_bytes()),
),
);

Expand Down
Loading