mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: extra data (#13410)
This commit is contained in:
2
book/cli/reth/node.md
vendored
2
book/cli/reth/node.md
vendored
@ -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>]
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
|
||||
@ -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::{
|
||||
@ -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
|
||||
@ -256,7 +256,7 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
validate_header_extradata(header)?;
|
||||
validate_header_extra_data(header)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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")]
|
||||
@ -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,
|
||||
@ -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 {
|
||||
@ -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(
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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}")
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
///
|
||||
|
||||
@ -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;
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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()),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user