fix: allow withdrawal root past shanghai (#1437)

This commit is contained in:
Dan Cline
2023-02-17 15:41:24 -05:00
committed by GitHub
parent 01b8c8b815
commit 5c2f96ed65

View File

@@ -50,7 +50,9 @@ pub fn validate_header_standalone(
header.withdrawals_root.is_none()
{
return Err(Error::WithdrawalsRootMissing)
} else if header.withdrawals_root.is_some() {
} else if !chain_spec.fork(Hardfork::Shanghai).active_at_timestamp(header.timestamp) &&
header.withdrawals_root.is_some()
{
return Err(Error::WithdrawalsRootUnexpected)
}
@@ -334,7 +336,7 @@ pub fn validate_header_regarding_parent(
/// If we already know the block.
/// If parent is known
///
/// Returns parent block header
/// Returns parent block header
pub fn validate_block_regarding_chain<PROV: HeaderProvider>(
block: &SealedBlock,
provider: &PROV,
@@ -638,4 +640,20 @@ mod tests {
Err(Error::WithdrawalIndexInvalid { .. })
);
}
#[test]
fn shanghai_block_zero_withdrawals() {
// ensures that if shanghai is activated, and we include a block with a withdrawals root,
// that the header is valid
let chain_spec = ChainSpecBuilder::mainnet().shanghai_activated().build();
let header = Header {
base_fee_per_gas: Some(1337u64.into()),
withdrawals_root: Some(proofs::calculate_withdrawals_root(&[])),
..Default::default()
}
.seal_slow();
assert_eq!(validate_header_standalone(&header, &chain_spec), Ok(()));
}
}