Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added EIP-4844 Headers for BlockHeaderOutput. Issue: 6933 #6937

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { decodeSignedTransaction } from './utils/decode_signed_transaction.js';
import {
accountSchema,
blockSchema,
blockHeaderSchema,
feeHistorySchema,
logSchema,
transactionReceiptSchema,
Expand Down Expand Up @@ -257,7 +258,7 @@ export async function getBlock<ReturnFormat extends DataFormat>(
hydrated,
);
}
return format(blockSchema, response as unknown as Block, returnFormat);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you would want to edit blockSchema and add the new properties there, not editing blockHeaderSchema and just using blockSchema

Copy link
Contributor Author

@ymonye ymonye Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you would want to edit blockSchema and add the new properties there, not editing blockHeaderSchema and just using blockSchema

Ok, yeah I'd noticed both the withdrawals & withdrawalsRoot properties only appear under blockHeaderSchema, in the schemas.ts file. When I call getBlock() on web3.js v1.9, it outputs both of those properties. This is why I'd assumed getBlock() probably needed blockHeaderSchema defined within v4's rpc_method_wrappers.ts file instead of blockSchema, and thought it was a typo.

Should blockSchema & blockHeaderSchema have identical properties then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea its a bit confusing, It seems like blockSchema needs to also have updated properties of withdrawals and withdrawalsRoot. blockHeaderSchema is only being used for subscriptions. We may need to update the blockHeaderSchema as well, if you want to check and confirm result of a subscription the result you can also edit blockheaderSchema, otherwise you can focus on just updating blockSchema

Copy link
Contributor Author

@ymonye ymonye Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've updated both blockSchema & blockHeaderSchema in schemas.ts, with blockHeaderSchema retaining the below author & excessDataGas properties while missing from blockSchema. Please let me know if blockSchema should also have these.

blockSchema & blockHeaderSchema also have different nested arrays for the transactions property, and were left as originally found.

author: {
   format: 'bytes32',
},
excessDataGas: {
   format: 'uint',
},

The BlockOutput & BlockHeaderOutput interfaces in eth_types.ts were also updated accordingly.

Under eth_types.ts, I'd noticed a number of properties are formatted as either bigint | number or Numbers, whether they are defined under BlockOutput or BlockHeaderOutput.

For example: totalDifficulty in BlockOutput:
readonly totalDifficulty?: bigint | number;

Whereas in BlockHeaderOutput, totalDifficulty is formatted as:
readonly totalDifficulty?: Numbers;

I'm unsure if it should be one or the other, but I've left as-is. Also the extra properties: author & excessDataGas were not added to the BlockOutput interface, as they are not present in blockSchema. However I did add everything else from BlockHeaderOutput interface into BlockOutput, while formatting the ones with Numbers as bigint | number. Please advise if that was the correct move.

Also, let me know if those author & excessDataGase properites should also be present across blockSchema/blockHeaderSchema & BlockOutput/BlockHeaderOutput.

yarn.lock had its changes reverted, as well as rpc_method_wrappers.ts.

Copy link
Contributor Author

@ymonye ymonye Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it appears the 'newHeads' & 'newBlockHeaders' subscriptions only return formatted data from the BlockBase interface in eth_types.ts, and not from the BlockHeaderOutput interface.

https://docs.web3js.org/api/web3-eth/class/NewHeadsSubscription

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a note here so I don't forget after sleep. Looks like more parameters are missing from v4.6 yet present in v1.9, outside the scope of EIP-4844 changes, specifically across other eth_* functions. I'll do a much proper rundown thru the next couple of days, likely into the weekend.

For ex: the id parameter is missing in the logs array, from eth_getTransactionReceipt. Example below from an ETH mainnet request:

web3 v4.6:
{"address":"0xb584d4be1a5470ca1a8778e9b86c81e165204599","blockHash":"0x47c58ebbaaff9a9a9ee60d74029224df7cac63b5c09972d4306e7500d8078b55","blockNumber":"19529894","data":"0x0000000000000000000000000000000000000000000000000000022ecb25c000","logIndex":"469","removed":false,"topics":["0x90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15","0x0000000000000000000000000a25e45792fef9fb600a81f0d7ac4ab9e893fc71","0x0000000000000000000000000000000000000000000000000000000000000064"],"transactionHash":"0xe2bad713807549fe3bb0bf0a69dce0ddc634c8dbec655660ea038279ef5bdb91","transactionIndex":"170"}

web3 v1.9:
{"address":"0xb584D4bE1A5470CA1a8778E9B86c81e165204599","blockHash":"0x47c58ebbaaff9a9a9ee60d74029224df7cac63b5c09972d4306e7500d8078b55","blockNumber":19529894,"data":"0x0000000000000000000000000000000000000000000000000000022ecb25c000","id":"log_ff3f9ddd","logIndex":469,"removed":false,"topics":["0x90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15","0x0000000000000000000000000a25e45792fef9fb600a81f0d7ac4ab9e893fc71","0x0000000000000000000000000000000000000000000000000000000000000064"],"transactionHash":"0xe2bad713807549fe3bb0bf0a69dce0ddc634c8dbec655660ea038279ef5bdb91","transactionIndex":170}

return format(blockHeaderSchema, response as unknown as Block, returnFormat);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-eth/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ export const withdrawalsSchema = {
export const blockHeaderSchema = {
type: 'object',
properties: {
blobGasUsed: {
format: 'uint',
},
excessBlobGas: {
format: 'uint',
},
parentBeaconBlockRoot: {
format: 'bytes32',
},
author: {
format: 'bytes32',
},
Expand Down
3 changes: 3 additions & 0 deletions packages/web3-types/src/eth_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export interface Withdrawals {
}

export interface BlockHeaderOutput {
readonly blobGasUsed?: Numbers;
readonly excessBlobGas?: Numbers;
readonly parentBeaconBlockRoot?: HexString32Bytes;
readonly hash?: HexString32Bytes;
readonly parentHash?: HexString32Bytes;
readonly receiptsRoot?: HexString32Bytes;
Expand Down
Loading
Loading