chore: extra data (#13410)

This commit is contained in:
Roman Krasiuk
2024-12-16 04:58:36 +01:00
committed by GitHub
parent 091c5499ba
commit f36e369021
11 changed files with 37 additions and 37 deletions

View File

@ -508,7 +508,7 @@ TxPool:
[default: 200] [default: 200]
Builder: Builder:
--builder.extradata <EXTRADATA> --builder.extradata <EXTRA_DATA>
Block extra data set by the payload builder Block extra data set by the payload builder
[default: reth/<VERSION>/<OS>] [default: reth/<VERSION>/<OS>]

View File

@ -213,15 +213,15 @@ pub fn validate_4844_header_standalone<H: BlockHeader>(header: &H) -> Result<(),
Ok(()) 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. /// From yellow paper: extraData: An arbitrary byte array containing data relevant to this block.
/// This must be 32 bytes or fewer; formally Hx. /// This must be 32 bytes or fewer; formally Hx.
#[inline] #[inline]
pub fn validate_header_extradata<H: BlockHeader>(header: &H) -> Result<(), ConsensusError> { pub fn validate_header_extra_data<H: BlockHeader>(header: &H) -> Result<(), ConsensusError> {
let extradata_len = header.extra_data().len(); let extra_data_len = header.extra_data().len();
if extradata_len > MAXIMUM_EXTRA_DATA_SIZE { if extra_data_len > MAXIMUM_EXTRA_DATA_SIZE {
Err(ConsensusError::ExtraDataExceedsMax { len: extradata_len }) Err(ConsensusError::ExtraDataExceedsMax { len: extra_data_len })
} else { } else {
Ok(()) Ok(())
} }

View File

@ -19,7 +19,7 @@ use reth_consensus_common::validation::{
validate_4844_header_standalone, validate_against_parent_4844, validate_4844_header_standalone, validate_against_parent_4844,
validate_against_parent_eip1559_base_fee, validate_against_parent_hash_number, validate_against_parent_eip1559_base_fee, validate_against_parent_hash_number,
validate_against_parent_timestamp, validate_block_pre_execution, validate_body_against_header, 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::{BlockWithSenders, NodePrimitives, Receipt, SealedBlock, SealedHeader};
use reth_primitives_traits::{ use reth_primitives_traits::{
@ -234,8 +234,8 @@ where
// Block validation with respect to the parent should ensure that the block timestamp // Block validation with respect to the parent should ensure that the block timestamp
// is greater than its parent timestamp. // is greater than its parent timestamp.
// validate header extradata for all networks post merge // validate header extra data for all networks post merge
validate_header_extradata(header)?; validate_header_extra_data(header)?;
// mixHash is used instead of difficulty inside EVM // mixHash is used instead of difficulty inside EVM
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty // https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty
@ -256,7 +256,7 @@ where
}) })
} }
validate_header_extradata(header)?; validate_header_extra_data(header)?;
} }
Ok(()) Ok(())

View File

@ -256,7 +256,7 @@ impl EthereumPayloadBuilder {
let conf = ctx.payload_builder_config(); let conf = ctx.payload_builder_config();
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new( let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
evm_config, 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() let payload_job_config = BasicPayloadJobGeneratorConfig::default()

View File

@ -13,8 +13,8 @@ use std::{borrow::Cow, ffi::OsStr, time::Duration};
#[command(next_help_heading = "Builder")] #[command(next_help_heading = "Builder")]
pub struct PayloadBuilderArgs { pub struct PayloadBuilderArgs {
/// Block extra data set by the payload builder. /// Block extra data set by the payload builder.
#[arg(long = "builder.extradata", value_parser = ExtradataValueParser::default(), default_value_t = default_extra_data())] #[arg(long = "builder.extradata", value_parser = ExtraDataValueParser::default(), default_value_t = default_extra_data())]
pub extradata: String, pub extra_data: String,
/// Target gas limit for built blocks. /// Target gas limit for built blocks.
#[arg(long = "builder.gaslimit", default_value_t = ETHEREUM_BLOCK_GAS_LIMIT, value_name = "GAS_LIMIT")] #[arg(long = "builder.gaslimit", default_value_t = ETHEREUM_BLOCK_GAS_LIMIT, value_name = "GAS_LIMIT")]
@ -40,7 +40,7 @@ pub struct PayloadBuilderArgs {
impl Default for PayloadBuilderArgs { impl Default for PayloadBuilderArgs {
fn default() -> Self { fn default() -> Self {
Self { Self {
extradata: default_extra_data(), extra_data: default_extra_data(),
gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
interval: Duration::from_secs(1), interval: Duration::from_secs(1),
deadline: SLOT_DURATION, deadline: SLOT_DURATION,
@ -50,8 +50,8 @@ impl Default for PayloadBuilderArgs {
} }
impl PayloadBuilderConfig for PayloadBuilderArgs { impl PayloadBuilderConfig for PayloadBuilderArgs {
fn extradata(&self) -> Cow<'_, str> { fn extra_data(&self) -> Cow<'_, str> {
self.extradata.as_str().into() self.extra_data.as_str().into()
} }
fn interval(&self) -> Duration { fn interval(&self) -> Duration {
@ -73,9 +73,9 @@ impl PayloadBuilderConfig for PayloadBuilderArgs {
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
#[non_exhaustive] #[non_exhaustive]
struct ExtradataValueParser; struct ExtraDataValueParser;
impl TypedValueParser for ExtradataValueParser { impl TypedValueParser for ExtraDataValueParser {
type Value = String; type Value = String;
fn parse_ref( fn parse_ref(
@ -130,23 +130,23 @@ mod tests {
#[test] #[test]
fn test_default_extra_data() { fn test_default_extra_data() {
let extradata = default_extra_data(); let extra_data = default_extra_data();
let args = CommandParser::<PayloadBuilderArgs>::parse_from([ let args = CommandParser::<PayloadBuilderArgs>::parse_from([
"reth", "reth",
"--builder.extradata", "--builder.extradata",
extradata.as_str(), extra_data.as_str(),
]) ])
.args; .args;
assert_eq!(args.extradata, extradata); assert_eq!(args.extra_data, extra_data);
} }
#[test] #[test]
fn test_invalid_extradata() { fn test_invalid_extra_data() {
let extradata = "x".repeat(MAXIMUM_EXTRA_DATA_SIZE + 1); let extra_data = "x".repeat(MAXIMUM_EXTRA_DATA_SIZE + 1);
let args = CommandParser::<PayloadBuilderArgs>::try_parse_from([ let args = CommandParser::<PayloadBuilderArgs>::try_parse_from([
"reth", "reth",
"--builder.extradata", "--builder.extradata",
extradata.as_str(), extra_data.as_str(),
]); ]);
assert!(args.is_err()); assert!(args.is_err());
} }

View File

@ -11,11 +11,11 @@ use std::{borrow::Cow, time::Duration};
/// [`PayloadBuilderArgs`](crate::args::PayloadBuilderArgs) type. /// [`PayloadBuilderArgs`](crate::args::PayloadBuilderArgs) type.
pub trait PayloadBuilderConfig { pub trait PayloadBuilderConfig {
/// Block extra data set by the payload builder. /// Block extra data set by the payload builder.
fn extradata(&self) -> Cow<'_, str>; fn extra_data(&self) -> Cow<'_, str>;
/// Returns the extradata as bytes. /// Returns the extra data as bytes.
fn extradata_bytes(&self) -> Bytes { fn extra_data_bytes(&self) -> Bytes {
self.extradata().as_bytes().to_vec().into() self.extra_data().as_bytes().to_vec().into()
} }
/// The interval at which the job should build a new payload after the last. /// The interval at which the job should build a new payload after the last.

View File

@ -149,8 +149,8 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn assert_extradata_less_32bytes() { fn assert_extra_data_less_32bytes() {
let extradata = default_extra_data(); let extra_data = default_extra_data();
assert!(extradata.len() <= 32, "extradata must be less than 32 bytes: {extradata}") assert!(extra_data.len() <= 32, "extra data must be less than 32 bytes: {extra_data}")
} }
} }

View File

@ -193,7 +193,7 @@ pub struct OpChainSpec {
} }
impl 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. /// Caution: Caller must ensure that holocene is active in the parent header.
/// ///

View File

@ -19,7 +19,7 @@ use reth_consensus_common::validation::{
validate_against_parent_4844, validate_against_parent_eip1559_base_fee, validate_against_parent_4844, validate_against_parent_eip1559_base_fee,
validate_against_parent_hash_number, validate_against_parent_timestamp, validate_against_parent_hash_number, validate_against_parent_timestamp,
validate_body_against_header, validate_cancun_gas, validate_header_base_fee, 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_chainspec::OpChainSpec;
use reth_optimism_forks::OpHardforks; use reth_optimism_forks::OpHardforks;
@ -170,8 +170,8 @@ impl HeaderValidator for OpBeaconConsensus {
// Block validation with respect to the parent should ensure that the block timestamp // Block validation with respect to the parent should ensure that the block timestamp
// is greater than its parent timestamp. // is greater than its parent timestamp.
// validate header extradata for all networks post merge // validate header extra data for all networks post merge
validate_header_extradata(header)?; validate_header_extra_data(header)?;
// mixHash is used instead of difficulty inside EVM // mixHash is used instead of difficulty inside EVM
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty // https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty

View File

@ -3,6 +3,6 @@
pub enum HeaderError { pub enum HeaderError {
/// Represents an error when the block difficulty is too large. /// Represents an error when the block difficulty is too large.
LargeDifficulty, LargeDifficulty,
/// Represents an error when the block extradata is too large. /// Represents an error when the block extra data is too large.
LargeExtraData, LargeExtraData,
} }

View File

@ -67,7 +67,7 @@ where
payload_job_config, payload_job_config,
reth_ethereum_payload_builder::EthereumPayloadBuilder::new( reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(ctx.chain_spec()), EthEvmConfig::new(ctx.chain_spec()),
EthereumBuilderConfig::new(conf.extradata_bytes()), EthereumBuilderConfig::new(conf.extra_data_bytes()),
), ),
); );