feat(engine): payload cancun fields (#4010)

This commit is contained in:
erik
2023-08-01 11:25:10 -04:00
committed by GitHub
parent 9430800d2e
commit bfbad261ec
6 changed files with 39 additions and 13 deletions

View File

@ -268,9 +268,9 @@ impl StorageInner {
mix_hash: Default::default(),
nonce: 0,
base_fee_per_gas,
extra_data: Default::default(),
blob_gas_used: None,
excess_blob_gas: None,
extra_data: Default::default(),
};
header.transactions_root = if transactions.is_empty() {

View File

@ -786,9 +786,9 @@ where
gas_limit: block_gas_limit,
difficulty: U256::ZERO,
gas_used: 0,
extra_data: extra_data.into(),
blob_gas_used: None,
excess_blob_gas: None,
extra_data: extra_data.into(),
};
let block = Block { header, body: vec![], ommers: vec![], withdrawals };

View File

@ -239,6 +239,12 @@ pub struct Header {
/// Withdrawals root hash added by EIP-4895 and is ignored in legacy headers.
#[serde(skip_serializing_if = "Option::is_none")]
pub withdrawals_root: Option<H256>,
/// Blob gas used
#[serde(rename = "blobGasUsed", skip_serializing_if = "Option::is_none")]
pub blob_gas_used: Option<U64>,
/// Excess blob gas
#[serde(rename = "excessBlobGas", skip_serializing_if = "Option::is_none")]
pub excess_blob_gas: Option<U64>,
}
// === impl Header ===
@ -268,9 +274,8 @@ impl Header {
base_fee_per_gas,
extra_data,
withdrawals_root,
// TODO: add header fields to the rpc header
blob_gas_used: _,
excess_blob_gas: _,
blob_gas_used,
excess_blob_gas,
},
hash,
} = primitive_header;
@ -294,6 +299,8 @@ impl Header {
mix_hash,
nonce: Some(nonce.to_be_bytes().into()),
base_fee_per_gas: base_fee_per_gas.map(U256::from),
blob_gas_used: blob_gas_used.map(U64::from),
excess_blob_gas: excess_blob_gas.map(U64::from),
}
}
}
@ -423,6 +430,8 @@ mod tests {
mix_hash: H256::from_low_u64_be(14),
nonce: Some(H64::from_low_u64_be(15)),
base_fee_per_gas: Some(U256::from(20)),
blob_gas_used: None,
excess_blob_gas: None,
},
total_difficulty: Some(U256::from(100000)),
uncles: vec![H256::from_low_u64_be(17)],
@ -461,6 +470,8 @@ mod tests {
mix_hash: H256::from_low_u64_be(14),
nonce: Some(H64::from_low_u64_be(15)),
base_fee_per_gas: Some(U256::from(20)),
blob_gas_used: None,
excess_blob_gas: None,
},
total_difficulty: Some(U256::from(100000)),
uncles: vec![H256::from_low_u64_be(17)],

View File

@ -79,6 +79,8 @@ pub struct ExecutionPayload {
pub timestamp: U64,
pub extra_data: Bytes,
pub base_fee_per_gas: U256,
pub blob_gas_used: Option<U64>,
pub excess_blob_gas: Option<U64>,
pub block_hash: H256,
pub transactions: Vec<Bytes>,
/// Array of [`Withdrawal`] enabled with V2
@ -111,6 +113,8 @@ impl From<SealedBlock> for ExecutionPayload {
timestamp: value.timestamp.into(),
extra_data: value.extra_data.clone(),
base_fee_per_gas: U256::from(value.base_fee_per_gas.unwrap_or_default()),
blob_gas_used: value.blob_gas_used.map(U64::from),
excess_blob_gas: value.excess_blob_gas.map(U64::from),
block_hash: value.hash(),
transactions,
withdrawals: value.withdrawals,
@ -167,14 +171,15 @@ impl TryFrom<ExecutionPayload> for SealedBlock {
.uint_try_to()
.map_err(|_| PayloadError::BaseFee(payload.base_fee_per_gas))?,
),
blob_gas_used: payload.blob_gas_used.map(|blob_gas_used| blob_gas_used.as_u64()),
excess_blob_gas: payload
.excess_blob_gas
.map(|excess_blob_gas| excess_blob_gas.as_u64()),
extra_data: payload.extra_data,
// Defaults
ommers_hash: EMPTY_LIST_HASH,
difficulty: Default::default(),
nonce: Default::default(),
// TODO: add conversion once ExecutionPayload has 4844 fields
blob_gas_used: None,
excess_blob_gas: None,
}
.seal_slow();
@ -211,6 +216,12 @@ pub enum PayloadError {
/// Invalid payload base fee.
#[error("Invalid payload base fee: {0}")]
BaseFee(U256),
/// Invalid payload base fee.
#[error("Invalid payload blob gas used: {0}")]
BlobGasUsed(U256),
/// Invalid payload base fee.
#[error("Invalid payload excess blob gas: {0}")]
ExcessBlobGas(U256),
/// Invalid payload block hash.
#[error("blockhash mismatch, want {consensus}, got {execution}")]
BlockHash {
@ -519,7 +530,7 @@ mod tests {
#[test]
fn serde_roundtrip_legacy_txs_payload() {
// pulled from hive tests
let s = r#"{"parentHash":"0x67ead97eb79b47a1638659942384143f36ed44275d4182799875ab5a87324055","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x4e3c608a9f2e129fccb91a1dae7472e78013b8e654bccc8d224ce3d63ae17006","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0x44bb4b98c59dbb726f96ffceb5ee028dcbe35b9bba4f9ffd56aeebf8d1e4db62","blockNumber":"0x1","gasLimit":"0x2fefd8","gasUsed":"0xa860","timestamp":"0x1235","extraData":"0x8b726574682f76302e312e30","baseFeePerGas":"0x342770c0","blockHash":"0x5655011482546f16b2312ef18e9fad03d6a52b1be95401aea884b222477f9e64","transactions":["0xf865808506fc23ac00830124f8940000000000000000000000000000000000000316018032a044b25a8b9b247d01586b3d59c71728ff49c9b84928d9e7fa3377ead3b5570b5da03ceac696601ff7ee6f5fe8864e2998db9babdf5eeba1a0cd5b4d44b3fcbd181b"]}"#;
let s = r#"{"parentHash":"0x67ead97eb79b47a1638659942384143f36ed44275d4182799875ab5a87324055","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x4e3c608a9f2e129fccb91a1dae7472e78013b8e654bccc8d224ce3d63ae17006","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0x44bb4b98c59dbb726f96ffceb5ee028dcbe35b9bba4f9ffd56aeebf8d1e4db62","blockNumber":"0x1","gasLimit":"0x2fefd8","gasUsed":"0xa860","timestamp":"0x1235","extraData":"0x8b726574682f76302e312e30","baseFeePerGas":"0x342770c0","blobGasUsed":null,"excessBlobGas":null,"blockHash":"0x5655011482546f16b2312ef18e9fad03d6a52b1be95401aea884b222477f9e64","transactions":["0xf865808506fc23ac00830124f8940000000000000000000000000000000000000316018032a044b25a8b9b247d01586b3d59c71728ff49c9b84928d9e7fa3377ead3b5570b5da03ceac696601ff7ee6f5fe8864e2998db9babdf5eeba1a0cd5b4d44b3fcbd181b"]}"#;
let payload: ExecutionPayload = serde_json::from_str(s).unwrap();
assert_eq!(serde_json::to_string(&payload).unwrap(), s);
}
@ -527,7 +538,7 @@ mod tests {
#[test]
fn serde_roundtrip_enveloped_txs_payload() {
// pulled from hive tests
let s = r#"{"parentHash":"0x67ead97eb79b47a1638659942384143f36ed44275d4182799875ab5a87324055","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x76a03cbcb7adce07fd284c61e4fa31e5e786175cefac54a29e46ec8efa28ea41","receiptsRoot":"0x4e3c608a9f2e129fccb91a1dae7472e78013b8e654bccc8d224ce3d63ae17006","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0x028111cb7d25918386a69656b3d17b2febe95fd0f11572c1a55c14f99fdfe3df","blockNumber":"0x1","gasLimit":"0x2fefd8","gasUsed":"0xa860","timestamp":"0x1235","extraData":"0x8b726574682f76302e312e30","baseFeePerGas":"0x342770c0","blockHash":"0xa6f40ed042e61e88e76125dede8fff8026751ea14454b68fb534cea99f2b2a77","transactions":["0xf865808506fc23ac00830124f8940000000000000000000000000000000000000316018032a044b25a8b9b247d01586b3d59c71728ff49c9b84928d9e7fa3377ead3b5570b5da03ceac696601ff7ee6f5fe8864e2998db9babdf5eeba1a0cd5b4d44b3fcbd181b"]}"#;
let s = r#"{"parentHash":"0x67ead97eb79b47a1638659942384143f36ed44275d4182799875ab5a87324055","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x76a03cbcb7adce07fd284c61e4fa31e5e786175cefac54a29e46ec8efa28ea41","receiptsRoot":"0x4e3c608a9f2e129fccb91a1dae7472e78013b8e654bccc8d224ce3d63ae17006","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0x028111cb7d25918386a69656b3d17b2febe95fd0f11572c1a55c14f99fdfe3df","blockNumber":"0x1","gasLimit":"0x2fefd8","gasUsed":"0xa860","timestamp":"0x1235","extraData":"0x8b726574682f76302e312e30","baseFeePerGas":"0x342770c0","blobGasUsed":null,"excessBlobGas":null,"blockHash":"0xa6f40ed042e61e88e76125dede8fff8026751ea14454b68fb534cea99f2b2a77","transactions":["0xf865808506fc23ac00830124f8940000000000000000000000000000000000000316018032a044b25a8b9b247d01586b3d59c71728ff49c9b84928d9e7fa3377ead3b5570b5da03ceac696601ff7ee6f5fe8864e2998db9babdf5eeba1a0cd5b4d44b3fcbd181b"]}"#;
let payload: ExecutionPayload = serde_json::from_str(s).unwrap();
assert_eq!(serde_json::to_string(&payload).unwrap(), s);
}

View File

@ -142,9 +142,9 @@ impl PendingBlockEnv {
gas_limit: block_gas_limit,
difficulty: U256::ZERO,
gas_used: cumulative_gas_used,
extra_data: Default::default(),
blob_gas_used: None,
excess_blob_gas: None,
extra_data: Default::default(),
};
// seal the block

View File

@ -78,6 +78,10 @@ pub struct Header {
pub base_fee_per_gas: Option<JsonU256>,
/// Withdrawals root.
pub withdrawals_root: Option<H256>,
/// Blob gas used.
pub blob_gas_used: Option<JsonU256>,
/// Excess blob gas.
pub excess_blob_gas: Option<JsonU256>,
}
impl From<Header> for SealedHeader {
@ -100,8 +104,8 @@ impl From<Header> for SealedHeader {
parent_hash: value.parent_hash,
logs_bloom: value.bloom,
withdrawals_root: value.withdrawals_root,
blob_gas_used: None,
excess_blob_gas: None,
blob_gas_used: value.blob_gas_used.map(|v| v.0.to::<u64>()),
excess_blob_gas: value.excess_blob_gas.map(|v| v.0.to::<u64>()),
};
header.seal(value.hash)
}