add data gas used and update excess data gas to u64

This commit is contained in:
realbigsean
2023-06-07 11:03:49 -04:00
parent e6b0754f06
commit 6970f7a19f
8 changed files with 99 additions and 73 deletions

View File

@@ -36,6 +36,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
None None
}; };
let rlp_data_gas_used = payload.data_gas_used().ok();
let rlp_excess_data_gas = payload.excess_data_gas().ok(); let rlp_excess_data_gas = payload.excess_data_gas().ok();
// Construct the block header. // Construct the block header.
@@ -44,6 +45,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
KECCAK_EMPTY_LIST_RLP.as_fixed_bytes().into(), KECCAK_EMPTY_LIST_RLP.as_fixed_bytes().into(),
rlp_transactions_root, rlp_transactions_root,
rlp_withdrawals_root, rlp_withdrawals_root,
rlp_data_gas_used.copied(),
rlp_excess_data_gas.copied(), rlp_excess_data_gas.copied(),
); );
@@ -84,6 +86,9 @@ pub fn rlp_encode_block_header(header: &ExecutionBlockHeader) -> Vec<u8> {
if let Some(withdrawals_root) = &header.withdrawals_root { if let Some(withdrawals_root) = &header.withdrawals_root {
rlp_header_stream.append(withdrawals_root); rlp_header_stream.append(withdrawals_root);
} }
if let Some(data_gas_used) = &header.data_gas_used {
rlp_header_stream.append(data_gas_used);
}
if let Some(excess_data_gas) = &header.excess_data_gas { if let Some(excess_data_gas) = &header.excess_data_gas {
rlp_header_stream.append(excess_data_gas); rlp_header_stream.append(excess_data_gas);
} }
@@ -133,6 +138,7 @@ mod test {
nonce: Hash64::zero(), nonce: Hash64::zero(),
base_fee_per_gas: 0x036b_u64.into(), base_fee_per_gas: 0x036b_u64.into(),
withdrawals_root: None, withdrawals_root: None,
data_gas_used: None,
excess_data_gas: None, excess_data_gas: None,
}; };
let expected_rlp = "f90200a0e0a94a7a3c9617401586b1a27025d2d9671332d22d540e0af72b069170380f2aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0ec3c94b18b8a1cff7d60f8d258ec723312932928626b4c9355eb4ab3568ec7f7a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000000000088000000000000000082036b"; let expected_rlp = "f90200a0e0a94a7a3c9617401586b1a27025d2d9671332d22d540e0af72b069170380f2aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0ec3c94b18b8a1cff7d60f8d258ec723312932928626b4c9355eb4ab3568ec7f7a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000000000088000000000000000082036b";
@@ -162,6 +168,7 @@ mod test {
nonce: Hash64::zero(), nonce: Hash64::zero(),
base_fee_per_gas: 0x036b_u64.into(), base_fee_per_gas: 0x036b_u64.into(),
withdrawals_root: None, withdrawals_root: None,
data_gas_used: None,
excess_data_gas: None, excess_data_gas: None,
}; };
let expected_rlp = "f901fda0927ca537f06c783a3a2635b8805eef1c8c2124f7444ad4a3389898dd832f2dbea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0e97859b065bd8dbbb4519c7cb935024de2484c2b7f881181b4360492f0b06b82a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000002000088000000000000000082036b"; let expected_rlp = "f901fda0927ca537f06c783a3a2635b8805eef1c8c2124f7444ad4a3389898dd832f2dbea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ba5e000000000000000000000000000000000000a0e97859b065bd8dbbb4519c7cb935024de2484c2b7f881181b4360492f0b06b82a050f738580ed699f0469702c7ccc63ed2e51bc034be9479b7bff4e68dee84accfa029b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800188016345785d8a00008301553482079e42a0000000000000000000000000000000000000000000000000000000000002000088000000000000000082036b";
@@ -192,6 +199,7 @@ mod test {
nonce: Hash64::zero(), nonce: Hash64::zero(),
base_fee_per_gas: 0x34187b238_u64.into(), base_fee_per_gas: 0x34187b238_u64.into(),
withdrawals_root: None, withdrawals_root: None,
data_gas_used: None,
excess_data_gas: None, excess_data_gas: None,
}; };
let expected_hash = let expected_hash =

View File

@@ -189,8 +189,11 @@ pub struct ExecutionBlockWithTransactions<T: EthSpec> {
#[superstruct(only(Capella, Deneb))] #[superstruct(only(Capella, Deneb))]
pub withdrawals: Vec<JsonWithdrawal>, pub withdrawals: Vec<JsonWithdrawal>,
#[superstruct(only(Deneb))] #[superstruct(only(Deneb))]
#[serde(with = "serde_utils::u256_hex_be")] #[serde(with = "serde_utils::u64_hex_be")]
pub excess_data_gas: Uint256, pub data_gas_used: u64,
#[superstruct(only(Deneb))]
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_data_gas: u64,
} }
impl<T: EthSpec> TryFrom<ExecutionPayload<T>> for ExecutionBlockWithTransactions<T> { impl<T: EthSpec> TryFrom<ExecutionPayload<T>> for ExecutionBlockWithTransactions<T> {
@@ -267,6 +270,7 @@ impl<T: EthSpec> TryFrom<ExecutionPayload<T>> for ExecutionBlockWithTransactions
.into_iter() .into_iter()
.map(|withdrawal| withdrawal.into()) .map(|withdrawal| withdrawal.into())
.collect(), .collect(),
data_gas_used: block.data_gas_used,
excess_data_gas: block.excess_data_gas, excess_data_gas: block.excess_data_gas,
}), }),
}; };
@@ -509,6 +513,7 @@ impl<E: EthSpec> ExecutionPayloadBodyV1<E> {
block_hash: header.block_hash, block_hash: header.block_hash,
transactions: self.transactions, transactions: self.transactions,
withdrawals, withdrawals,
data_gas_used: header.data_gas_used,
excess_data_gas: header.excess_data_gas, excess_data_gas: header.excess_data_gas,
})) }))
} else { } else {

View File

@@ -99,8 +99,11 @@ pub struct JsonExecutionPayload<T: EthSpec> {
#[superstruct(only(V2, V3))] #[superstruct(only(V2, V3))]
pub withdrawals: VariableList<JsonWithdrawal, T::MaxWithdrawalsPerPayload>, pub withdrawals: VariableList<JsonWithdrawal, T::MaxWithdrawalsPerPayload>,
#[superstruct(only(V3))] #[superstruct(only(V3))]
#[serde(with = "serde_utils::u256_hex_be")] #[serde(with = "serde_utils::u64_hex_be")]
pub excess_data_gas: Uint256, pub data_gas_used: u64,
#[superstruct(only(V3))]
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_data_gas: u64,
} }
impl<T: EthSpec> From<ExecutionPayloadMerge<T>> for JsonExecutionPayloadV1<T> { impl<T: EthSpec> From<ExecutionPayloadMerge<T>> for JsonExecutionPayloadV1<T> {
@@ -172,6 +175,7 @@ impl<T: EthSpec> From<ExecutionPayloadDeneb<T>> for JsonExecutionPayloadV3<T> {
.map(Into::into) .map(Into::into)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into(), .into(),
data_gas_used: payload.data_gas_used,
excess_data_gas: payload.excess_data_gas, excess_data_gas: payload.excess_data_gas,
} }
} }
@@ -256,6 +260,7 @@ impl<T: EthSpec> From<JsonExecutionPayloadV3<T>> for ExecutionPayloadDeneb<T> {
.map(Into::into) .map(Into::into)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into(), .into(),
data_gas_used: payload.data_gas_used,
excess_data_gas: payload.excess_data_gas, excess_data_gas: payload.excess_data_gas,
} }
} }

View File

@@ -1856,6 +1856,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
block_hash: deneb_block.block_hash, block_hash: deneb_block.block_hash,
transactions: convert_transactions(deneb_block.transactions)?, transactions: convert_transactions(deneb_block.transactions)?,
withdrawals, withdrawals,
data_gas_used: deneb_block.data_gas_used,
excess_data_gas: deneb_block.excess_data_gas, excess_data_gas: deneb_block.excess_data_gas,
}) })
} }

View File

@@ -518,67 +518,61 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
block_hash: ExecutionBlockHash::zero(), block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(), transactions: vec![].into(),
}), }),
PayloadAttributes::V2(pa) => { PayloadAttributes::V2(pa) => match self.get_fork_at_timestamp(pa.timestamp) {
match self.get_fork_at_timestamp(pa.timestamp) { ForkName::Merge => ExecutionPayload::Merge(ExecutionPayloadMerge {
ForkName::Merge => ExecutionPayload::Merge(ExecutionPayloadMerge { parent_hash: forkchoice_state.head_block_hash,
parent_hash: forkchoice_state.head_block_hash, fee_recipient: pa.suggested_fee_recipient,
fee_recipient: pa.suggested_fee_recipient, receipts_root: Hash256::repeat_byte(42),
receipts_root: Hash256::repeat_byte(42), state_root: Hash256::repeat_byte(43),
state_root: Hash256::repeat_byte(43), logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].into(), prev_randao: pa.prev_randao,
prev_randao: pa.prev_randao, block_number: parent.block_number() + 1,
block_number: parent.block_number() + 1, gas_limit: GAS_LIMIT,
gas_limit: GAS_LIMIT, gas_used: GAS_USED,
gas_used: GAS_USED, timestamp: pa.timestamp,
timestamp: pa.timestamp, extra_data: "block gen was here".as_bytes().to_vec().into(),
extra_data: "block gen was here".as_bytes().to_vec().into(), base_fee_per_gas: Uint256::one(),
base_fee_per_gas: Uint256::one(), block_hash: ExecutionBlockHash::zero(),
block_hash: ExecutionBlockHash::zero(), transactions: vec![].into(),
transactions: vec![].into(), }),
}), ForkName::Capella => ExecutionPayload::Capella(ExecutionPayloadCapella {
ForkName::Capella => { parent_hash: forkchoice_state.head_block_hash,
ExecutionPayload::Capella(ExecutionPayloadCapella { fee_recipient: pa.suggested_fee_recipient,
parent_hash: forkchoice_state.head_block_hash, receipts_root: Hash256::repeat_byte(42),
fee_recipient: pa.suggested_fee_recipient, state_root: Hash256::repeat_byte(43),
receipts_root: Hash256::repeat_byte(42), logs_bloom: vec![0; 256].into(),
state_root: Hash256::repeat_byte(43), prev_randao: pa.prev_randao,
logs_bloom: vec![0; 256].into(), block_number: parent.block_number() + 1,
prev_randao: pa.prev_randao, gas_limit: GAS_LIMIT,
block_number: parent.block_number() + 1, gas_used: GAS_USED,
gas_limit: GAS_LIMIT, timestamp: pa.timestamp,
gas_used: GAS_USED, extra_data: "block gen was here".as_bytes().to_vec().into(),
timestamp: pa.timestamp, base_fee_per_gas: Uint256::one(),
extra_data: "block gen was here".as_bytes().to_vec().into(), block_hash: ExecutionBlockHash::zero(),
base_fee_per_gas: Uint256::one(), transactions: vec![].into(),
block_hash: ExecutionBlockHash::zero(), withdrawals: pa.withdrawals.clone().into(),
transactions: vec![].into(), }),
withdrawals: pa.withdrawals.clone().into(), ForkName::Deneb => ExecutionPayload::Deneb(ExecutionPayloadDeneb {
}) parent_hash: forkchoice_state.head_block_hash,
} fee_recipient: pa.suggested_fee_recipient,
ForkName::Deneb => { receipts_root: Hash256::repeat_byte(42),
ExecutionPayload::Deneb(ExecutionPayloadDeneb { state_root: Hash256::repeat_byte(43),
parent_hash: forkchoice_state.head_block_hash, logs_bloom: vec![0; 256].into(),
fee_recipient: pa.suggested_fee_recipient, prev_randao: pa.prev_randao,
receipts_root: Hash256::repeat_byte(42), block_number: parent.block_number() + 1,
state_root: Hash256::repeat_byte(43), gas_limit: GAS_LIMIT,
logs_bloom: vec![0; 256].into(), gas_used: GAS_USED,
prev_randao: pa.prev_randao, timestamp: pa.timestamp,
block_number: parent.block_number() + 1, extra_data: "block gen was here".as_bytes().to_vec().into(),
gas_limit: GAS_LIMIT, base_fee_per_gas: Uint256::one(),
gas_used: GAS_USED, block_hash: ExecutionBlockHash::zero(),
timestamp: pa.timestamp, transactions: vec![].into(),
extra_data: "block gen was here".as_bytes().to_vec().into(), withdrawals: pa.withdrawals.clone().into(),
base_fee_per_gas: Uint256::one(), data_gas_used: 0,
block_hash: ExecutionBlockHash::zero(), excess_data_gas: 0,
transactions: vec![].into(), }),
withdrawals: pa.withdrawals.clone().into(), _ => unreachable!(),
// FIXME(deneb) maybe this should be set to something? },
excess_data_gas: Uint256::one(),
})
}
_ => unreachable!(),
}
}
}; };
match execution_payload.fork_name() { match execution_payload.fork_name() {

View File

@@ -26,6 +26,7 @@ use metastruct::metastruct;
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[metastruct(mappings(map_execution_block_header_fields_except_withdrawals(exclude( #[metastruct(mappings(map_execution_block_header_fields_except_withdrawals(exclude(
withdrawals_root, withdrawals_root,
data_gas_used,
excess_data_gas excess_data_gas
)),))] )),))]
pub struct ExecutionBlockHeader { pub struct ExecutionBlockHeader {
@@ -46,7 +47,8 @@ pub struct ExecutionBlockHeader {
pub nonce: Hash64, pub nonce: Hash64,
pub base_fee_per_gas: Uint256, pub base_fee_per_gas: Uint256,
pub withdrawals_root: Option<Hash256>, pub withdrawals_root: Option<Hash256>,
pub excess_data_gas: Option<Uint256>, pub data_gas_used: Option<u64>,
pub excess_data_gas: Option<u64>,
} }
impl ExecutionBlockHeader { impl ExecutionBlockHeader {
@@ -55,7 +57,8 @@ impl ExecutionBlockHeader {
rlp_empty_list_root: Hash256, rlp_empty_list_root: Hash256,
rlp_transactions_root: Hash256, rlp_transactions_root: Hash256,
rlp_withdrawals_root: Option<Hash256>, rlp_withdrawals_root: Option<Hash256>,
rlp_excess_data_gas: Option<Uint256>, rlp_data_gas_used: Option<u64>,
rlp_excess_data_gas: Option<u64>,
) -> Self { ) -> Self {
// Most of these field mappings are defined in EIP-3675 except for `mixHash`, which is // Most of these field mappings are defined in EIP-3675 except for `mixHash`, which is
// defined in EIP-4399. // defined in EIP-4399.
@@ -77,6 +80,7 @@ impl ExecutionBlockHeader {
nonce: Hash64::zero(), nonce: Hash64::zero(),
base_fee_per_gas: payload.base_fee_per_gas(), base_fee_per_gas: payload.base_fee_per_gas(),
withdrawals_root: rlp_withdrawals_root, withdrawals_root: rlp_withdrawals_root,
data_gas_used: rlp_data_gas_used,
excess_data_gas: rlp_excess_data_gas, excess_data_gas: rlp_excess_data_gas,
} }
} }

View File

@@ -84,9 +84,13 @@ pub struct ExecutionPayload<T: EthSpec> {
#[superstruct(only(Capella, Deneb))] #[superstruct(only(Capella, Deneb))]
pub withdrawals: Withdrawals<T>, pub withdrawals: Withdrawals<T>,
#[superstruct(only(Deneb))] #[superstruct(only(Deneb))]
#[serde(with = "serde_utils::quoted_u256")] #[serde(with = "serde_utils::quoted_u64")]
#[superstruct(getter(copy))] #[superstruct(getter(copy))]
pub excess_data_gas: Uint256, pub data_gas_used: u64,
#[superstruct(only(Deneb))]
#[serde(with = "serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub excess_data_gas: u64,
} }
impl<'a, T: EthSpec> ExecutionPayloadRef<'a, T> { impl<'a, T: EthSpec> ExecutionPayloadRef<'a, T> {

View File

@@ -78,9 +78,13 @@ pub struct ExecutionPayloadHeader<T: EthSpec> {
#[superstruct(getter(copy))] #[superstruct(getter(copy))]
pub withdrawals_root: Hash256, pub withdrawals_root: Hash256,
#[superstruct(only(Deneb))] #[superstruct(only(Deneb))]
#[serde(with = "serde_utils::quoted_u256")] #[serde(with = "serde_utils::quoted_u64")]
#[superstruct(getter(copy))] #[superstruct(getter(copy))]
pub excess_data_gas: Uint256, pub data_gas_used: u64,
#[superstruct(only(Deneb))]
#[serde(with = "serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub excess_data_gas: u64,
} }
impl<T: EthSpec> ExecutionPayloadHeader<T> { impl<T: EthSpec> ExecutionPayloadHeader<T> {
@@ -151,8 +155,8 @@ impl<T: EthSpec> ExecutionPayloadHeaderCapella<T> {
block_hash: self.block_hash, block_hash: self.block_hash,
transactions_root: self.transactions_root, transactions_root: self.transactions_root,
withdrawals_root: self.withdrawals_root, withdrawals_root: self.withdrawals_root,
// TODO: verify if this is correct data_gas_used: 0,
excess_data_gas: Uint256::zero(), excess_data_gas: 0,
} }
} }
} }
@@ -217,6 +221,7 @@ impl<'a, T: EthSpec> From<&'a ExecutionPayloadDeneb<T>> for ExecutionPayloadHead
block_hash: payload.block_hash, block_hash: payload.block_hash,
transactions_root: payload.transactions.tree_hash_root(), transactions_root: payload.transactions.tree_hash_root(),
withdrawals_root: payload.withdrawals.tree_hash_root(), withdrawals_root: payload.withdrawals.tree_hash_root(),
data_gas_used: payload.data_gas_used,
excess_data_gas: payload.excess_data_gas, excess_data_gas: payload.excess_data_gas,
} }
} }