Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added EIP-4788, receipts root and state root fields to Block (#4570).
  • Loading branch information
ricmoo committed Feb 6, 2024
1 parent cac1da1 commit c5f126f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs.wrm/links/specs.txt
Expand Up @@ -31,6 +31,7 @@ link-eip-2098 [EIP-2098](https://eips.ethereum.org/EIPS/eip-2098)
link-eip-2304 [EIP-2304](https://eips.ethereum.org/EIPS/eip-2304)
link-eip-2718 [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718)
link-eip-2930 [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)
link-eip-4788 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4788)
link-eip-4844 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)

# Open Standards
Expand Down
11 changes: 11 additions & 0 deletions src.ts/_tests/blockchain-data.ts
Expand Up @@ -28,6 +28,10 @@ export interface TestBlockchainBlock {
baseFeePerGas?: bigint;
blobGasUsed?: bigint;
excessBlobGas?: bigint;

parentBeaconBlockRoot?: string;
stateRoot?: string;
receiptsRoot?: string;
}

export interface TestBlockchainTransaction {
Expand Down Expand Up @@ -135,6 +139,8 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
gasUsed: BigInt("0"),
miner: "0x5088D623ba0fcf0131E0897a91734A4D83596AA0",
extraData: "0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34",
stateRoot: '0x76ab0b899e8387436ff2658e2988f83cbf1af1590b9fe9feca3714f8d1824940',
receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
transactions: [ ]
},
{
Expand All @@ -150,6 +156,8 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
miner: "0x2A20380DcA5bC24D052acfbf79ba23e988ad0050",
extraData: "0x706f6f6c696e2e636f6d21f7092f019bb92a76",
baseFeePerGas: BigInt("40911884304"),
stateRoot: '0xd08663f630cfcf2d7d8fe4d52f7685ad09798b7e6150cabea5eeceb1d89e11c2',
receiptsRoot: '0x473e83ec3df279f44c4fc6da50fe1d0c5a18f1929b90de8917bdcdb88a132750',
transactions: [
"0x1c3a398933db10634631f54b435c40c8805c13f12bbac7c3dab858ca44213fa2",
"0xd98947cbdd892cc7f679c903903e6d18a5c5afb19e94437beba79372ad71c347",
Expand Down Expand Up @@ -188,6 +196,7 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
test: "eip-4844-BLob-block",
hash: "0xa76eb2ed547798d6010f599902788136f0cd289e2c6df5bbf5242e36e356124d",
parentHash: "0x2b579cb7224abdbe7a66c76380d60329bba41d95d225feb80ca1a78cf83a5124",
parentBeaconBlockRoot: '0xa05d27aa9c2f3d57943ca86134a08f6f7852ad5e9dbe360f86b466e2f0ed7bb5',
number: 5198187,
timestamp: 1706801700,
nonce: "0x0000000000000000",
Expand All @@ -199,6 +208,8 @@ export const testBlock: Record<TestBlockchainNetwork, Array<TestBlockchainBlock>
extraData: "0x",
blobGasUsed: BigInt("524288"),
excessBlobGas: BigInt("79691776"),
stateRoot: '0xa78ad0e0f5d2b3383fdb13f4ad0523723816863556be3a5414536862f4d217df',
receiptsRoot: '0xa254ed337328248b77011c70c2b85d6575f965f2fe65ed233c27e3750c0b7170',
transactions: [
"0xe8a096a98cd7b8d783cbb30687c3adc8e59f1e9563c0454623cc8af59f8bcab1",
"0x5aac2d50b15e177e8edaae4819e989650a6cdb335dd8924b5a7a7ed1675d15e7",
Expand Down
5 changes: 5 additions & 0 deletions src.ts/providers/format.ts
Expand Up @@ -111,6 +111,8 @@ export function formatLog(value: any): LogParams {
const _formatBlock = object({
hash: allowNull(formatHash),
parentHash: formatHash,
parentBeaconBlockRoot: allowNull(formatHash, null),

number: getNumber,

timestamp: getNumber,
Expand All @@ -120,6 +122,9 @@ const _formatBlock = object({
gasLimit: getBigInt,
gasUsed: getBigInt,

stateRoot: allowNull(formatHash, null),
receiptsRoot: allowNull(formatHash, null),

blobGasUsed: allowNull(getBigInt, null),
excessBlobGas: allowNull(getBigInt, null),

Expand Down
17 changes: 17 additions & 0 deletions src.ts/providers/formatting.ts
Expand Up @@ -38,6 +38,12 @@ export interface BlockParams {
*/
parentHash: string;

/**
* The hash tree root of the parent beacon block for the given
* execution block. See [[link-eip-4788]].
*/
parentBeaconBlockRoot?: null | string;

/**
* A random sequence provided during the mining process for
* proof-of-work networks.
Expand Down Expand Up @@ -88,6 +94,17 @@ export interface BlockParams {
*/
baseFeePerGas: null | bigint;

/**
* The root hash for the global state after applying changes
* in this block.
*/
stateRoot?: null | string;

/**
* The hash of the transaction receipts trie.
*/
receiptsRoot?: null | string;

/**
* The list of transactions in the block.
*/
Expand Down
28 changes: 26 additions & 2 deletions src.ts/providers/provider.ts
Expand Up @@ -436,6 +436,12 @@ export class Block implements BlockParams, Iterable<string> {
*/
readonly parentHash!: string;

/**
* The hash tree root of the parent beacon block for the given
* execution block. See [[link-eip-4788]].
*/
parentBeaconBlockRoot!: null | string;

/**
* The nonce.
*
Expand Down Expand Up @@ -466,6 +472,18 @@ export class Block implements BlockParams, Iterable<string> {
*/
readonly gasUsed!: bigint;


/**
* The root hash for the global state after applying changes
* in this block.
*/
readonly stateRoot!: null | string;

/**
* The hash of the transaction receipts trie.
*/
readonly receiptsRoot!: null | string;

/**
* The total amount of blob gas consumed by the transactions
* within the block. See [[link-eip-4844]].
Expand Down Expand Up @@ -524,6 +542,7 @@ export class Block implements BlockParams, Iterable<string> {
timestamp: block.timestamp,

parentHash: block.parentHash,
parentBeaconBlockRoot: block.parentBeaconBlockRoot,

nonce: block.nonce,
difficulty: block.difficulty,
Expand All @@ -535,7 +554,10 @@ export class Block implements BlockParams, Iterable<string> {
miner: block.miner,
extraData: block.extraData,

baseFeePerGas: getValue(block.baseFeePerGas)
baseFeePerGas: getValue(block.baseFeePerGas),

stateRoot: block.stateRoot,
receiptsRoot: block.receiptsRoot,
});
}

Expand Down Expand Up @@ -578,7 +600,8 @@ export class Block implements BlockParams, Iterable<string> {
toJSON(): any {
const {
baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash,
miner, nonce, number, parentHash, timestamp, transactions
miner, nonce, number, parentHash, parentBeaconBlockRoot,
stateRoot, receiptsRoot, timestamp, transactions
} = this;

return {
Expand All @@ -591,6 +614,7 @@ export class Block implements BlockParams, Iterable<string> {
blobGasUsed: toJson(this.blobGasUsed),
excessBlobGas: toJson(this.excessBlobGas),
hash, miner, nonce, number, parentHash, timestamp,
parentBeaconBlockRoot, stateRoot, receiptsRoot,
transactions,
};
}
Expand Down

0 comments on commit c5f126f

Please sign in to comment.