Skip to content

Commit

Permalink
feat: pass parent beacon block root to payload builder (paradigmxyz#4425
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alessandromazza98 authored Sep 4, 2023
1 parent b32562f commit d9334ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ where
difficulty: U256::ZERO,
gas_used: cumulative_gas_used,
extra_data: extra_data.into(),
parent_beacon_block_root: None,
parent_beacon_block_root: attributes.parent_beacon_block_root,
blob_gas_used,
excess_blob_gas,
};
Expand Down Expand Up @@ -906,7 +906,7 @@ where
blob_gas_used: None,
excess_blob_gas: None,
extra_data: extra_data.into(),
parent_beacon_block_root: None,
parent_beacon_block_root: attributes.parent_beacon_block_root,
};

let block = Block { header, body: vec![], ommers: vec![], withdrawals };
Expand Down
6 changes: 6 additions & 0 deletions crates/payload/builder/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub struct PayloadBuilderAttributes {
pub prev_randao: H256,
/// Withdrawals for the generated payload
pub withdrawals: Vec<Withdrawal>,
/// Root of the parent beacon block
pub parent_beacon_block_root: Option<H256>,
}

// === impl PayloadBuilderAttributes ===
Expand All @@ -146,6 +148,7 @@ impl PayloadBuilderAttributes {
suggested_fee_recipient: attributes.suggested_fee_recipient,
prev_randao: attributes.prev_randao,
withdrawals: attributes.withdrawals.unwrap_or_default(),
parent_beacon_block_root: attributes.parent_beacon_block_root,
}
}

Expand Down Expand Up @@ -204,6 +207,9 @@ pub(crate) fn payload_id(parent: &H256, attributes: &PayloadAttributes) -> Paylo
withdrawals.encode(&mut buf);
hasher.update(buf);
}
if let Some(parent_beacon_block) = attributes.parent_beacon_block_root {
hasher.update(parent_beacon_block);
}
let out = hasher.finalize();
PayloadId::new(out.as_slice()[..8].try_into().expect("sufficient length"))
}

0 comments on commit d9334ee

Please sign in to comment.