-
Notifications
You must be signed in to change notification settings - Fork 892
/
payload.rs
557 lines (504 loc) · 23.7 KB
/
payload.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
use reth_primitives::{
constants::{MAXIMUM_EXTRA_DATA_SIZE, MIN_PROTOCOL_BASE_FEE_U256},
proofs::{self, EMPTY_LIST_HASH},
Address, Block, Bloom, Bytes, Header, SealedBlock, TransactionSigned, UintTryTo, Withdrawal,
H256, H64, U256, U64,
};
use reth_rlp::Decodable;
use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};
/// The execution payload body response that allows for `null` values.
pub type ExecutionPayloadBodiesV1 = Vec<Option<ExecutionPayloadBodyV1>>;
/// And 8-byte identifier for an execution payload.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub struct PayloadId(H64);
// === impl PayloadId ===
impl PayloadId {
/// Creates a new payload id from the given identifier.
pub fn new(id: [u8; 8]) -> Self {
Self(H64::from(id))
}
}
impl std::fmt::Display for PayloadId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
/// This structure maps for the return value of `engine_getPayload` of the beacon chain spec, for
/// both V2 and V3.
///
/// See also:
/// <https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#engine_getpayloadv2>
/// <https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#engine_getpayloadv3>
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExecutionPayloadEnvelope {
/// Execution payload, which could be either V1 or V2
///
/// V1 (_NO_ withdrawals) MUST be returned if the payload timestamp is lower than the Shanghai
/// timestamp
///
/// V2 (_WITH_ withdrawals) MUST be returned if the payload timestamp is greater or equal to
/// the Shanghai timestamp
#[serde(rename = "executionPayload")]
pub payload: ExecutionPayload,
/// The expected value to be received by the feeRecipient in wei
#[serde(rename = "blockValue")]
pub block_value: U256,
//
// // TODO(mattsse): for V3
// #[serde(rename = "blobsBundle", skip_serializing_if = "Option::is_none")]
// pub blobs_bundle: Option<BlobsBundleV1>,
/// Introduced in V3, this represents a suggestion from the execution layer if the payload
/// should be used instead of an externally provided one.
#[serde(rename = "shouldOverrideBuilder", skip_serializing_if = "Option::is_none")]
pub should_override_builder: Option<bool>,
}
impl ExecutionPayloadEnvelope {
/// Returns the [ExecutionPayload] for the `engine_getPayloadV1` endpoint
pub fn into_v1_payload(mut self) -> ExecutionPayload {
// ensure withdrawals are removed
self.payload.withdrawals.take();
self.payload
}
}
/// This structure maps on the ExecutionPayload structure of the beacon chain spec.
///
/// See also: <https://github.com/ethereum/execution-apis/blob/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine/paris.md#executionpayloadv1>
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExecutionPayload {
pub parent_hash: H256,
pub fee_recipient: Address,
pub state_root: H256,
pub receipts_root: H256,
pub logs_bloom: Bloom,
pub prev_randao: H256,
pub block_number: U64,
pub gas_limit: U64,
pub gas_used: U64,
pub timestamp: U64,
pub extra_data: Bytes,
pub base_fee_per_gas: U256,
pub block_hash: H256,
pub transactions: Vec<Bytes>,
/// Array of [`Withdrawal`] enabled with V2
/// See <https://github.com/ethereum/execution-apis/blob/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine/shanghai.md#executionpayloadv2>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub withdrawals: Option<Vec<Withdrawal>>,
/// Array of [`U64`] representing blob gas used, enabled with V3
/// See <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#ExecutionPayloadV3>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blob_gas_used: Option<U64>,
/// Array of [`U64`] representing excess blob gas, enabled with V3
/// See <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#ExecutionPayloadV3>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub excess_blob_gas: Option<U64>,
}
impl From<SealedBlock> for ExecutionPayload {
fn from(value: SealedBlock) -> Self {
let transactions = value
.body
.iter()
.map(|tx| {
let mut encoded = Vec::new();
tx.encode_enveloped(&mut encoded);
encoded.into()
})
.collect();
ExecutionPayload {
parent_hash: value.parent_hash,
fee_recipient: value.beneficiary,
state_root: value.state_root,
receipts_root: value.receipts_root,
logs_bloom: value.logs_bloom,
prev_randao: value.mix_hash,
block_number: value.number.into(),
gas_limit: value.gas_limit.into(),
gas_used: value.gas_used.into(),
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,
}
}
}
impl ExecutionPayload {
/// Tries to create a new block from the given payload and optional parent beacon block root.
/// Perform additional validation of `extra_data` and `base_fee_per_gas` fields.
///
/// NOTE: The log bloom is assumed to be validated during serialization.
/// NOTE: Empty ommers, nonce and difficulty values are validated upon computing block hash and
/// comparing the value with `payload.block_hash`.
///
/// See <https://github.com/ethereum/go-ethereum/blob/79a478bb6176425c2400e949890e668a3d9a3d05/core/beacon/types.go#L145>
pub fn try_into_sealed_block(
self,
parent_beacon_block_root: Option<H256>,
) -> Result<SealedBlock, PayloadError> {
if self.extra_data.len() > MAXIMUM_EXTRA_DATA_SIZE {
return Err(PayloadError::ExtraData(self.extra_data))
}
if self.base_fee_per_gas < MIN_PROTOCOL_BASE_FEE_U256 {
return Err(PayloadError::BaseFee(self.base_fee_per_gas))
}
let transactions = self
.transactions
.iter()
.map(|tx| TransactionSigned::decode(&mut tx.as_ref()))
.collect::<Result<Vec<_>, _>>()?;
let transactions_root = proofs::calculate_transaction_root(&transactions);
let withdrawals_root =
self.withdrawals.as_ref().map(|w| proofs::calculate_withdrawals_root(w));
let header = Header {
parent_hash: self.parent_hash,
beneficiary: self.fee_recipient,
state_root: self.state_root,
transactions_root,
receipts_root: self.receipts_root,
withdrawals_root,
parent_beacon_block_root,
logs_bloom: self.logs_bloom,
number: self.block_number.as_u64(),
gas_limit: self.gas_limit.as_u64(),
gas_used: self.gas_used.as_u64(),
timestamp: self.timestamp.as_u64(),
mix_hash: self.prev_randao,
base_fee_per_gas: Some(
self.base_fee_per_gas
.uint_try_to()
.map_err(|_| PayloadError::BaseFee(self.base_fee_per_gas))?,
),
blob_gas_used: self.blob_gas_used.map(|blob_gas_used| blob_gas_used.as_u64()),
excess_blob_gas: self.excess_blob_gas.map(|excess_blob_gas| excess_blob_gas.as_u64()),
extra_data: self.extra_data,
// Defaults
ommers_hash: EMPTY_LIST_HASH,
difficulty: Default::default(),
nonce: Default::default(),
}
.seal_slow();
if self.block_hash != header.hash() {
return Err(PayloadError::BlockHash {
execution: header.hash(),
consensus: self.block_hash,
})
}
Ok(SealedBlock {
header,
body: transactions,
withdrawals: self.withdrawals,
ommers: Default::default(),
})
}
}
/// This includes all bundled blob related data of an executed payload.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlobsBundleV1 {
pub commitments: Vec<Bytes>,
pub proofs: Vec<Bytes>,
pub blobs: Vec<Bytes>,
}
/// Error that can occur when handling payloads.
#[derive(thiserror::Error, Debug)]
pub enum PayloadError {
/// Invalid payload extra data.
#[error("Invalid payload extra data: {0}")]
ExtraData(Bytes),
/// 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 {
/// The block hash computed from the payload.
execution: H256,
/// The block hash provided with the payload.
consensus: H256,
},
/// Encountered decoding error.
#[error(transparent)]
Decode(#[from] reth_rlp::DecodeError),
}
impl PayloadError {
/// Returns `true` if the error is caused by invalid extra data.
pub fn is_block_hash_mismatch(&self) -> bool {
matches!(self, PayloadError::BlockHash { .. })
}
}
/// This structure contains a body of an execution payload.
///
/// See also: <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#executionpayloadbodyv1>
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExecutionPayloadBodyV1 {
/// Enveloped encoded transactions.
pub transactions: Vec<Bytes>,
/// All withdrawals in the block.
///
/// Will always be `None` if pre shanghai.
pub withdrawals: Option<Vec<Withdrawal>>,
}
impl From<Block> for ExecutionPayloadBodyV1 {
fn from(value: Block) -> Self {
let transactions = value.body.into_iter().map(|tx| {
let mut out = Vec::new();
tx.encode_enveloped(&mut out);
out.into()
});
ExecutionPayloadBodyV1 {
transactions: transactions.collect(),
withdrawals: value.withdrawals,
}
}
}
/// This structure contains the attributes required to initiate a payload build process in the
/// context of an `engine_forkchoiceUpdated` call.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PayloadAttributes {
pub timestamp: U64,
pub prev_randao: H256,
pub suggested_fee_recipient: Address,
/// Array of [`Withdrawal`] enabled with V2
/// See <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#payloadattributesv2>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub withdrawals: Option<Vec<Withdrawal>>,
/// Root of the parent beacon block enabled with V3.
///
/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#payloadattributesv3>
#[serde(default, skip_serializing_if = "Option::is_none")]
pub parent_beacon_block_root: Option<H256>,
}
/// This structure contains the result of processing a payload or fork choice update.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PayloadStatus {
#[serde(flatten)]
pub status: PayloadStatusEnum,
/// Hash of the most recent valid block in the branch defined by payload and its ancestors
pub latest_valid_hash: Option<H256>,
}
impl PayloadStatus {
pub fn new(status: PayloadStatusEnum, latest_valid_hash: Option<H256>) -> Self {
Self { status, latest_valid_hash }
}
pub fn from_status(status: PayloadStatusEnum) -> Self {
Self { status, latest_valid_hash: None }
}
pub fn with_latest_valid_hash(mut self, latest_valid_hash: H256) -> Self {
self.latest_valid_hash = Some(latest_valid_hash);
self
}
pub fn maybe_latest_valid_hash(mut self, latest_valid_hash: Option<H256>) -> Self {
self.latest_valid_hash = latest_valid_hash;
self
}
/// Returns true if the payload status is syncing.
pub fn is_syncing(&self) -> bool {
self.status.is_syncing()
}
/// Returns true if the payload status is valid.
pub fn is_valid(&self) -> bool {
self.status.is_valid()
}
/// Returns true if the payload status is invalid.
pub fn is_invalid(&self) -> bool {
self.status.is_invalid()
}
}
impl std::fmt::Display for PayloadStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"PayloadStatus {{status: {}, latestValidHash: {:?} }}",
self.status, self.latest_valid_hash
)
}
}
impl Serialize for PayloadStatus {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(3))?;
map.serialize_entry("status", self.status.as_str())?;
map.serialize_entry("latestValidHash", &self.latest_valid_hash)?;
map.serialize_entry("validationError", &self.status.validation_error())?;
map.end()
}
}
impl From<PayloadError> for PayloadStatusEnum {
fn from(error: PayloadError) -> Self {
PayloadStatusEnum::Invalid { validation_error: error.to_string() }
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PayloadStatusEnum {
/// VALID is returned by the engine API in the following calls:
/// - newPayload: if the payload was already known or was just validated and executed
/// - forkchoiceUpdate: if the chain accepted the reorg (might ignore if it's stale)
Valid,
/// INVALID is returned by the engine API in the following calls:
/// - newPayload: if the payload failed to execute on top of the local chain
/// - forkchoiceUpdate: if the new head is unknown, pre-merge, or reorg to it fails
Invalid {
#[serde(rename = "validationError")]
validation_error: String,
},
/// SYNCING is returned by the engine API in the following calls:
/// - newPayload: if the payload was accepted on top of an active sync
/// - forkchoiceUpdate: if the new head was seen before, but not part of the chain
Syncing,
/// ACCEPTED is returned by the engine API in the following calls:
/// - newPayload: if the payload was accepted, but not processed (side chain)
Accepted,
}
impl PayloadStatusEnum {
/// Returns the string representation of the payload status.
pub fn as_str(&self) -> &'static str {
match self {
PayloadStatusEnum::Valid => "VALID",
PayloadStatusEnum::Invalid { .. } => "INVALID",
PayloadStatusEnum::Syncing => "SYNCING",
PayloadStatusEnum::Accepted => "ACCEPTED",
}
}
/// Returns the validation error if the payload status is invalid.
pub fn validation_error(&self) -> Option<&str> {
match self {
PayloadStatusEnum::Invalid { validation_error } => Some(validation_error),
_ => None,
}
}
/// Returns true if the payload status is syncing.
pub fn is_syncing(&self) -> bool {
matches!(self, PayloadStatusEnum::Syncing)
}
/// Returns true if the payload status is valid.
pub fn is_valid(&self) -> bool {
matches!(self, PayloadStatusEnum::Valid)
}
/// Returns true if the payload status is invalid.
pub fn is_invalid(&self) -> bool {
matches!(self, PayloadStatusEnum::Invalid { .. })
}
}
impl std::fmt::Display for PayloadStatusEnum {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PayloadStatusEnum::Invalid { validation_error } => {
f.write_str(self.as_str())?;
f.write_str(": ")?;
f.write_str(validation_error.as_str())
}
_ => f.write_str(self.as_str()),
}
}
}
/// Various errors that can occur when validating a payload or forkchoice update.
///
/// This is intended for the [PayloadStatusEnum::Invalid] variant.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum PayloadValidationError {
/// Thrown when a forkchoice update's head links to a previously rejected payload.
#[error("links to previously rejected block")]
LinksToRejectedPayload,
/// Thrown when a new payload contains a wrong block number.
#[error("invalid block number")]
InvalidBlockNumber,
/// Thrown when a new payload contains a wrong state root
#[error("invalid merkle root: (remote: {remote:?} local: {local:?})")]
InvalidStateRoot {
/// The state root of the payload we received from remote (CL)
remote: H256,
/// The state root of the payload that we computed locally.
local: H256,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serde_payload_status() {
let s = r#"{"status":"SYNCING","latestValidHash":null,"validationError":null}"#;
let status: PayloadStatus = serde_json::from_str(s).unwrap();
assert_eq!(status.status, PayloadStatusEnum::Syncing);
assert!(status.latest_valid_hash.is_none());
assert!(status.status.validation_error().is_none());
assert_eq!(serde_json::to_string(&status).unwrap(), s);
let full = s;
let s = r#"{"status":"SYNCING","latestValidHash":null}"#;
let status: PayloadStatus = serde_json::from_str(s).unwrap();
assert_eq!(status.status, PayloadStatusEnum::Syncing);
assert!(status.latest_valid_hash.is_none());
assert!(status.status.validation_error().is_none());
assert_eq!(serde_json::to_string(&status).unwrap(), full);
}
#[test]
fn serde_payload_status_error_deserialize() {
let s = r#"{"status":"INVALID","latestValidHash":null,"validationError":"Failed to decode block"}"#;
let q = PayloadStatus {
latest_valid_hash: None,
status: PayloadStatusEnum::Invalid {
validation_error: "Failed to decode block".to_string(),
},
};
assert_eq!(q, serde_json::from_str(s).unwrap());
let s = r#"{"status":"INVALID","latestValidHash":null,"validationError":"links to previously rejected block"}"#;
let q = PayloadStatus {
latest_valid_hash: None,
status: PayloadStatusEnum::Invalid {
validation_error: PayloadValidationError::LinksToRejectedPayload.to_string(),
},
};
assert_eq!(q, serde_json::from_str(s).unwrap());
let s = r#"{"status":"INVALID","latestValidHash":null,"validationError":"invalid block number"}"#;
let q = PayloadStatus {
latest_valid_hash: None,
status: PayloadStatusEnum::Invalid {
validation_error: PayloadValidationError::InvalidBlockNumber.to_string(),
},
};
assert_eq!(q, serde_json::from_str(s).unwrap());
let s = r#"{"status":"INVALID","latestValidHash":null,"validationError":
"invalid merkle root: (remote: 0x3f77fb29ce67436532fee970e1add8f5cc80e8878c79b967af53b1fd92a0cab7 local: 0x603b9628dabdaadb442a3bb3d7e0360efc110e1948472909230909f1690fed17)"}"#;
let q = PayloadStatus {
latest_valid_hash: None,
status: PayloadStatusEnum::Invalid {
validation_error: PayloadValidationError::InvalidStateRoot {
remote: "0x3f77fb29ce67436532fee970e1add8f5cc80e8878c79b967af53b1fd92a0cab7"
.parse()
.unwrap(),
local: "0x603b9628dabdaadb442a3bb3d7e0360efc110e1948472909230909f1690fed17"
.parse()
.unwrap(),
}
.to_string(),
},
};
similar_asserts::assert_eq!(q, serde_json::from_str(s).unwrap());
}
#[test]
fn serde_roundtrip_legacy_txs_payload() {
// pulled from hive tests - modified with 4844 fields
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"],"blobGasUsed":"0xb10b","excessBlobGas":"0xb10b"}"#;
let payload: ExecutionPayload = serde_json::from_str(s).unwrap();
assert_eq!(serde_json::to_string(&payload).unwrap(), s);
}
#[test]
fn serde_roundtrip_enveloped_txs_payload() {
// pulled from hive tests - modified with 4844 fields
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"],"blobGasUsed":"0xb10b","excessBlobGas":"0xb10b"}"#;
let payload: ExecutionPayload = serde_json::from_str(s).unwrap();
assert_eq!(serde_json::to_string(&payload).unwrap(), s);
}
}