Skip to content

Commit c5f126f

Browse files
committed
Added EIP-4788, receipts root and state root fields to Block (#4570).
1 parent cac1da1 commit c5f126f

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

docs.wrm/links/specs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ link-eip-2098 [EIP-2098](https://eips.ethereum.org/EIPS/eip-2098)
3131
link-eip-2304 [EIP-2304](https://eips.ethereum.org/EIPS/eip-2304)
3232
link-eip-2718 [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718)
3333
link-eip-2930 [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)
34+
link-eip-4788 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4788)
3435
link-eip-4844 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)
3536

3637
# Open Standards

src.ts/_tests/blockchain-data.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export interface TestBlockchainBlock {
2828
baseFeePerGas?: bigint;
2929
blobGasUsed?: bigint;
3030
excessBlobGas?: bigint;
31+
32+
parentBeaconBlockRoot?: string;
33+
stateRoot?: string;
34+
receiptsRoot?: string;
3135
}
3236

3337
export interface TestBlockchainTransaction {
@@ -135,6 +139,8 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
135139
gasUsed: BigInt("0"),
136140
miner: "0x5088D623ba0fcf0131E0897a91734A4D83596AA0",
137141
extraData: "0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34",
142+
stateRoot: '0x76ab0b899e8387436ff2658e2988f83cbf1af1590b9fe9feca3714f8d1824940',
143+
receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
138144
transactions: [ ]
139145
},
140146
{
@@ -150,6 +156,8 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
150156
miner: "0x2A20380DcA5bC24D052acfbf79ba23e988ad0050",
151157
extraData: "0x706f6f6c696e2e636f6d21f7092f019bb92a76",
152158
baseFeePerGas: BigInt("40911884304"),
159+
stateRoot: '0xd08663f630cfcf2d7d8fe4d52f7685ad09798b7e6150cabea5eeceb1d89e11c2',
160+
receiptsRoot: '0x473e83ec3df279f44c4fc6da50fe1d0c5a18f1929b90de8917bdcdb88a132750',
153161
transactions: [
154162
"0x1c3a398933db10634631f54b435c40c8805c13f12bbac7c3dab858ca44213fa2",
155163
"0xd98947cbdd892cc7f679c903903e6d18a5c5afb19e94437beba79372ad71c347",
@@ -188,6 +196,7 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
188196
test: "eip-4844-BLob-block",
189197
hash: "0xa76eb2ed547798d6010f599902788136f0cd289e2c6df5bbf5242e36e356124d",
190198
parentHash: "0x2b579cb7224abdbe7a66c76380d60329bba41d95d225feb80ca1a78cf83a5124",
199+
parentBeaconBlockRoot: '0xa05d27aa9c2f3d57943ca86134a08f6f7852ad5e9dbe360f86b466e2f0ed7bb5',
191200
number: 5198187,
192201
timestamp: 1706801700,
193202
nonce: "0x0000000000000000",
@@ -199,6 +208,8 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
199208
extraData: "0x",
200209
blobGasUsed: BigInt("524288"),
201210
excessBlobGas: BigInt("79691776"),
211+
stateRoot: '0xa78ad0e0f5d2b3383fdb13f4ad0523723816863556be3a5414536862f4d217df',
212+
receiptsRoot: '0xa254ed337328248b77011c70c2b85d6575f965f2fe65ed233c27e3750c0b7170',
202213
transactions: [
203214
"0xe8a096a98cd7b8d783cbb30687c3adc8e59f1e9563c0454623cc8af59f8bcab1",
204215
"0x5aac2d50b15e177e8edaae4819e989650a6cdb335dd8924b5a7a7ed1675d15e7",

src.ts/providers/format.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export function formatLog(value: any): LogParams {
111111
const _formatBlock = object({
112112
hash: allowNull(formatHash),
113113
parentHash: formatHash,
114+
parentBeaconBlockRoot: allowNull(formatHash, null),
115+
114116
number: getNumber,
115117

116118
timestamp: getNumber,
@@ -120,6 +122,9 @@ const _formatBlock = object({
120122
gasLimit: getBigInt,
121123
gasUsed: getBigInt,
122124

125+
stateRoot: allowNull(formatHash, null),
126+
receiptsRoot: allowNull(formatHash, null),
127+
123128
blobGasUsed: allowNull(getBigInt, null),
124129
excessBlobGas: allowNull(getBigInt, null),
125130

src.ts/providers/formatting.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export interface BlockParams {
3838
*/
3939
parentHash: string;
4040

41+
/**
42+
* The hash tree root of the parent beacon block for the given
43+
* execution block. See [[link-eip-4788]].
44+
*/
45+
parentBeaconBlockRoot?: null | string;
46+
4147
/**
4248
* A random sequence provided during the mining process for
4349
* proof-of-work networks.
@@ -88,6 +94,17 @@ export interface BlockParams {
8894
*/
8995
baseFeePerGas: null | bigint;
9096

97+
/**
98+
* The root hash for the global state after applying changes
99+
* in this block.
100+
*/
101+
stateRoot?: null | string;
102+
103+
/**
104+
* The hash of the transaction receipts trie.
105+
*/
106+
receiptsRoot?: null | string;
107+
91108
/**
92109
* The list of transactions in the block.
93110
*/

src.ts/providers/provider.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ export class Block implements BlockParams, Iterable<string> {
436436
*/
437437
readonly parentHash!: string;
438438

439+
/**
440+
* The hash tree root of the parent beacon block for the given
441+
* execution block. See [[link-eip-4788]].
442+
*/
443+
parentBeaconBlockRoot!: null | string;
444+
439445
/**
440446
* The nonce.
441447
*
@@ -466,6 +472,18 @@ export class Block implements BlockParams, Iterable<string> {
466472
*/
467473
readonly gasUsed!: bigint;
468474

475+
476+
/**
477+
* The root hash for the global state after applying changes
478+
* in this block.
479+
*/
480+
readonly stateRoot!: null | string;
481+
482+
/**
483+
* The hash of the transaction receipts trie.
484+
*/
485+
readonly receiptsRoot!: null | string;
486+
469487
/**
470488
* The total amount of blob gas consumed by the transactions
471489
* within the block. See [[link-eip-4844]].
@@ -524,6 +542,7 @@ export class Block implements BlockParams, Iterable<string> {
524542
timestamp: block.timestamp,
525543

526544
parentHash: block.parentHash,
545+
parentBeaconBlockRoot: block.parentBeaconBlockRoot,
527546

528547
nonce: block.nonce,
529548
difficulty: block.difficulty,
@@ -535,7 +554,10 @@ export class Block implements BlockParams, Iterable<string> {
535554
miner: block.miner,
536555
extraData: block.extraData,
537556

538-
baseFeePerGas: getValue(block.baseFeePerGas)
557+
baseFeePerGas: getValue(block.baseFeePerGas),
558+
559+
stateRoot: block.stateRoot,
560+
receiptsRoot: block.receiptsRoot,
539561
});
540562
}
541563

@@ -578,7 +600,8 @@ export class Block implements BlockParams, Iterable<string> {
578600
toJSON(): any {
579601
const {
580602
baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash,
581-
miner, nonce, number, parentHash, timestamp, transactions
603+
miner, nonce, number, parentHash, parentBeaconBlockRoot,
604+
stateRoot, receiptsRoot, timestamp, transactions
582605
} = this;
583606

584607
return {
@@ -591,6 +614,7 @@ export class Block implements BlockParams, Iterable<string> {
591614
blobGasUsed: toJson(this.blobGasUsed),
592615
excessBlobGas: toJson(this.excessBlobGas),
593616
hash, miner, nonce, number, parentHash, timestamp,
617+
parentBeaconBlockRoot, stateRoot, receiptsRoot,
594618
transactions,
595619
};
596620
}

0 commit comments

Comments
 (0)