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

Retrieve all transaction receipts for a block in one request #6646

Merged
merged 8 commits into from
Dec 10, 2024

Conversation

Wetitpig
Copy link
Contributor

@Wetitpig Wetitpig commented Feb 29, 2024

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Most advanced CI tests are deferred until PR approval, but you could:

  • locally run all unit tests via: ./gradlew build
  • locally run all acceptance tests via: ./gradlew acceptanceTest
  • locally run all integration tests via: ./gradlew integrationTest
  • locally run all reference tests via: ./gradlew ethereum:referenceTests:referenceTests

PR description

  1. Retrieve all transaction receipts in a block in 1 call to blockchain query instead of a call for each transaction in a block
  2. Calculate transaction fee reward for miner based on effectivePriorityFeePerGas instead of effectiveGasPrice because baseFee would be burnt.

@Wetitpig
Copy link
Contributor Author

My node on snap sync shows static block reward as 0 even at genesis block of ETH mainnet.
Not sure if the protocol specification was purged as part of the state or simply a bug.

@Wetitpig Wetitpig force-pushed the receiptLoop branch 3 times, most recently from 89ea57c to 4341667 Compare March 1, 2024 10:42
@Wetitpig Wetitpig marked this pull request as ready for review March 2, 2024 02:25
@Wetitpig Wetitpig force-pushed the receiptLoop branch 4 times, most recently from 8d61d3e to ef71f57 Compare March 6, 2024 03:35
@Wetitpig Wetitpig force-pushed the receiptLoop branch 2 times, most recently from 6c1a93d to 027d056 Compare March 19, 2024 10:24
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

I think the changes make sense. Would like a test for the new method on BlockchainQueries, think other changes are covered already.

@macfarla
Copy link
Contributor

My node on snap sync shows static block reward as 0 even at genesis block of ETH mainnet. Not sure if the protocol specification was purged as part of the state or simply a bug.

is this comment related to this change or a separate issue?

@Wetitpig
Copy link
Contributor Author

My node on snap sync shows static block reward as 0 even at genesis block of ETH mainnet. Not sure if the protocol specification was purged as part of the state or simply a bug.

is this comment related to this change or a separate issue?

Separate issue. Incidentally discovered when testing the RPC method.

@macfarla
Copy link
Contributor

My node on snap sync shows static block reward as 0 even at genesis block of ETH mainnet. Not sure if the protocol specification was purged as part of the state or simply a bug.

is this comment related to this change or a separate issue?

Separate issue. Incidentally discovered when testing the RPC method.

ok - can you open an issue with more info if we need to look into it? thanks!

@macfarla
Copy link
Contributor

@Wetitpig this PR needs updating with latest main - I don't have permission to update your branch

@Wetitpig Wetitpig force-pushed the receiptLoop branch 2 times, most recently from 2844cfa to 0a67874 Compare March 22, 2024 07:32
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

@Wetitpig can you add a test for BlockchainQueries. transactionReceiptsByBlockHash

@jframe
Copy link
Contributor

jframe commented Jun 10, 2024

@ahamlat Would you mind having a look at this changes and see if they make sense?

@ahamlat
Copy link
Contributor

ahamlat commented Jul 2, 2024

Yes, these changes make sens here. I suggested this modification in this discord thread : https://discord.com/channels/905194001349627914/905205502940696607/1156154204981821500
@Wetitpig Could you give a clear description of the PR, then I can review the changes ?

@Wetitpig
Copy link
Contributor Author

Wetitpig commented Jul 3, 2024

Yes, these changes make sens here. I suggested this modification in this discord thread : https://discord.com/channels/905194001349627914/905205502940696607/1156154204981821500
@Wetitpig Could you give a clear description of the PR, then I can review the changes ?

Thanks.
I was trying to reorganize the step in which transaction receipts are retrieved, such that transaction receipts in one single block are retrieved in a batch if all of them are required.
Currently they are retrieved one by one with block height and transaction index, even if the transactions originate from the same block.

private BlockReceiptsResult getBlockReceiptsResult(final Hash blockHash) {
final List<TransactionReceiptResult> receiptList =
blockchainQueries
.get()
.blockByHash(blockHash)
.transactionReceiptsByBlockHash(blockHash, protocolSchedule)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why you didn't use DefaultBlockchain.getTxReceipts here ?

@ahamlat
Copy link
Contributor

ahamlat commented Jul 3, 2024

With DefaultBlockchain.getTxReceipts, the block receipts are retrieved in one go. Also, keep in mind that DefaultBlockchain.getTxReceipts uses the cache to retrieved the receipts if --cache-last-blocks=n is enabled. With this flag, Besu caches blockchain data while importing blocks.

@macfarla macfarla added the Stale label Dec 3, 2024
@macfarla
Copy link
Contributor

macfarla commented Dec 3, 2024

@Wetitpig are you still engaged on this PR? it's marked as stale and will be closed in 2 weeks if no activity

@Wetitpig Wetitpig force-pushed the receiptLoop branch 3 times, most recently from dfa9af0 to 5e8e86a Compare December 7, 2024 15:40
@Wetitpig Wetitpig requested a review from macfarla December 7, 2024 15:42
@Wetitpig
Copy link
Contributor Author

Wetitpig commented Dec 7, 2024

Tests have been written for transactionReceiptsByBlockHash, but they have not been run to see if they would pass.

The BlockchainQueries.getblockchain() did not get replaced, because the transactionReceiptsByBlockHash method is required for calculating the effective priority gas used.

@macfarla macfarla dismissed their stale review December 8, 2024 23:04

the test I requested has been added

Copy link
Contributor

@ahamlat ahamlat left a comment

Choose a reason for hiding this comment

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

Nice work @Wetitpig
I confirmed that :

  • eth_getBlockReceipts is much faster especially when using --cache-last-blocks=512 (from ~500ms to ~50 ms)
  • eth_getMinerDataByBlockHash is much faster as well with -cache-last-blocks=512 (from ~500ms to ~50 ms)
  • eth_getMinerDataByBlockHash netBlockReward returns the block reward without the burned fees (see example below)

eth_getMinerDataByBlockHash for block 21363910
Before this PR
netBlockReward = 0.198194985313316095

{"jsonrpc":"2.0","id":1,"result":{"netBlockReward":"0x00000000000000000000000000000000000000000000000002c02149ffdd2cff","staticBlockReward":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionFee":"0x00000000000000000000000000000000000000000000000002c02149ffdd2cff","uncleInclusionReward":"0x0000000000000000000000000000000000000000000000000000000000000000","uncleRewards":[],"coinbase":"0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97","extraData":"0x546974616e2028746974616e6275696c6465722e78797a29","difficulty":"0x0000000000000000000000000000000000000000000000000000000000000000","totalDifficulty":"0x000000000000000000000000000000000000000000000c70d815d562d3cfa955"}}

After this PR
netBlockReward = 0.026228768668364131

{"jsonrpc":"2.0","id":1,"result":{"netBlockReward":"0x000000000000000000000000000000000000000000000000005d2eed175fad63","staticBlockReward":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionFee":"0x000000000000000000000000000000000000000000000000005d2eed175fad63","uncleInclusionReward":"0x0000000000000000000000000000000000000000000000000000000000000000","uncleRewards":[],"coinbase":"0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97","extraData":"0x546974616e2028746974616e6275696c6465722e78797a29","difficulty":"0x0000000000000000000000000000000000000000000000000000000000000000","totalDifficulty":"0x000000000000000000000000000000000000000000000c70d815d562d3cfa955"}}

@Wetitpig Wetitpig force-pushed the receiptLoop branch 2 times, most recently from 47ad5a5 to 535de72 Compare December 9, 2024 15:54
@ahamlat ahamlat assigned Wetitpig and unassigned ahamlat Dec 9, 2024
@macfarla
Copy link
Contributor

macfarla commented Dec 9, 2024

@Wetitpig there are some unit and other tests failing - compile errors. you should be able to run these tests locally

CHANGELOG.md Outdated
@@ -67,6 +67,7 @@
- Add histogram to Prometheus metrics system [#7944](https://github.com/hyperledger/besu/pull/7944)
- Improve newPayload and FCU logs [#7961](https://github.com/hyperledger/besu/pull/7961)
- Proper support for `pending` block tag when calling `eth_estimateGas` and `eth_createAccessList` [#7951](https://github.com/hyperledger/besu/pull/7951)
- Retrieve all transaction receipts for a block in one request [#6646](https://github.com/hyperledger/besu/pull/6646)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should move up to the "Unreleased" section

Signed-off-by: Wetitpig <[email protected]>
@macfarla macfarla merged commit 4435f75 into hyperledger:main Dec 10, 2024
43 checks passed
@Wetitpig Wetitpig deleted the receiptLoop branch December 10, 2024 13:06
daniellehrner pushed a commit to daniellehrner/besu that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants