Merge pull request #3920 from realbigsean/fix-and-loosen-execution-block-decoding

Fix and loosen execution block decoding
This commit is contained in:
realbigsean 2023-01-27 18:10:47 +01:00 committed by GitHub
commit c0bdc1d120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 22 deletions

View File

@ -1026,25 +1026,28 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
//FIXME(sean) avoid the clone by comparing refs to headers (`as_execution_payload_header` method ?) //FIXME(sean) avoid the clone by comparing refs to headers (`as_execution_payload_header` method ?)
let full_payload: FullPayload<T::EthSpec> = execution_payload.clone().into(); let full_payload: FullPayload<T::EthSpec> = execution_payload.clone().into();
// Verify payload integrity. //FIXME(sean) we're not decoding blobs txs correctly yet
let header_from_payload = full_payload.to_execution_payload_header(); if !matches!(execution_payload, ExecutionPayload::Eip4844(_)) {
if header_from_payload != execution_payload_header { // Verify payload integrity.
for txn in execution_payload.transactions() { let header_from_payload = full_payload.to_execution_payload_header();
debug!( if header_from_payload != execution_payload_header {
self.log, for txn in execution_payload.transactions() {
"Reconstructed txn"; debug!(
"bytes" => format!("0x{}", hex::encode(&**txn)), self.log,
); "Reconstructed txn";
} "bytes" => format!("0x{}", hex::encode(&**txn)),
);
}
return Err(Error::InconsistentPayloadReconstructed { return Err(Error::InconsistentPayloadReconstructed {
slot: blinded_block.slot(), slot: blinded_block.slot(),
exec_block_hash, exec_block_hash,
canonical_payload_root: execution_payload_header.tree_hash_root(), canonical_payload_root: execution_payload_header.tree_hash_root(),
reconstructed_payload_root: header_from_payload.tree_hash_root(), reconstructed_payload_root: header_from_payload.tree_hash_root(),
canonical_transactions_root: execution_payload_header.transactions_root(), canonical_transactions_root: execution_payload_header.transactions_root(),
reconstructed_transactions_root: header_from_payload.transactions_root(), reconstructed_transactions_root: header_from_payload.transactions_root(),
}); });
}
} }
// Add the payload to the block to form a full block. // Add the payload to the block to form a full block.

View File

@ -36,12 +36,15 @@ impl<T: EthSpec> ExecutionLayer<T> {
None None
}; };
let rlp_excess_data_gas = payload.excess_data_gas().ok();
// Construct the block header. // Construct the block header.
let exec_block_header = ExecutionBlockHeader::from_payload( let exec_block_header = ExecutionBlockHeader::from_payload(
payload, payload,
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_excess_data_gas.copied(),
); );
// Hash the RLP encoding of the block header. // Hash the RLP encoding of the block header.
@ -81,6 +84,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(excess_data_gas) = &header.excess_data_gas {
rlp_header_stream.append(excess_data_gas);
}
rlp_header_stream.finalize_unbounded_list(); rlp_header_stream.finalize_unbounded_list();
rlp_header_stream.out().into() rlp_header_stream.out().into()
} }

View File

@ -31,8 +31,7 @@ use tokio::sync::mpsc::{self, Receiver, Sender};
use tokio::time::error::Error as TimeError; use tokio::time::error::Error as TimeError;
use tokio_util::time::delay_queue::{DelayQueue, Key as DelayKey}; use tokio_util::time::delay_queue::{DelayQueue, Key as DelayKey};
use types::{ use types::{
Attestation, EthSpec, Hash256, LightClientOptimisticUpdate, SignedAggregateAndProof, Attestation, EthSpec, Hash256, LightClientOptimisticUpdate, SignedAggregateAndProof, SubnetId,
SubnetId,
}; };
const TASK_NAME: &str = "beacon_processor_reprocess_queue"; const TASK_NAME: &str = "beacon_processor_reprocess_queue";

View File

@ -25,8 +25,9 @@ use metastruct::metastruct;
/// Credit to Reth for the type definition. /// Credit to Reth for the type definition.
#[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,
))))] excess_data_gas
)),))]
pub struct ExecutionBlockHeader { pub struct ExecutionBlockHeader {
pub parent_hash: Hash256, pub parent_hash: Hash256,
pub ommers_hash: Hash256, pub ommers_hash: Hash256,
@ -45,6 +46,7 @@ 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>,
} }
impl ExecutionBlockHeader { impl ExecutionBlockHeader {
@ -53,6 +55,7 @@ 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>,
) -> 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.
@ -74,6 +77,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,
excess_data_gas: rlp_excess_data_gas,
} }
} }
} }