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

Merge main into verkle #8332

Open
wants to merge 136 commits into
base: verkle
Choose a base branch
from

Conversation

matkt
Copy link
Contributor

@matkt matkt commented Feb 19, 2025

PR description

Fixed Issue(s)

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

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

garyschulte and others added 30 commits December 21, 2024 19:42
* prague fee market for blob gas

Signed-off-by: garyschulte <garyschulte@gmail.com>

* Fix wiring and unit test

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>

---------

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
This EIP was removed and equivalent functionality replaced by EIP-7840.

---

Revert "Rename targetBlobCount to targetBlobsPerBlock (hyperledger#7981)"

This reverts commit 1671306.

Revert "EIP-7742: Add target_blob_count to block header (hyperledger#7808)"

This reverts commit f855d5b.

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
* Reimplement EthereumNodeRecord and remove dependency on tuweni-devp2p
* Refactor EthereumNodeRecord for DNSDaemon
* Update EthereumNodeRecord to use Besu RLP
* additional unit tests
* Convert ENR to Java record
* regenerate equals and hashcode for enr record
---------

Signed-off-by: Usman Saleem <usman@usmans.info>
* Update HISTORY_STORAGE_ADDRESS and HISTORY_SERVE_WINDOW for EIP-2935

hyperledger#8061

* Update HISTORY_STORAGE_ADDRESS and genesis code in tests.

Even for unrelated tests, this has a knock-on impact on the state root due to the history storage account being created when the BlockHashProcessor runs for block 1

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
* 7311: Add PeerTask system for use in future PRs

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Clean up some warnings

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add feature toggle for enabling use of the peertask system where available

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove log used for testing, apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add private constructor to PeerTaskFeatureToggle to prevent instantiation

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Switch to logging a warning instead of throwing an exception when initializing PeerTaskFeatureToggle multiple times

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update javadoc to match previous commit

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix broken BesuCommandTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: add class

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move PeerTaskFeatureToggle to more appropriate location

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: add X prefix to peertask-system-enabled

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move --Xpeertask-system-enabled out of BesuCommand and make hidden

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add GetReceiptsFromPeerTask

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move isPeerTaskSystemEnabled to SynchronizerOptions

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix javadoc issue

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix javadoc issue

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move PeerTaskFeatureToggleTestHelper to TestUtil and fix RunnerTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove PeerTaskFeatureToggle in favor of including isPeerTaskSystemEnabled in SynchronizerConfiguration

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Adjust to the removal of PeerTaskFeatureToggle and use SynchronizerConfiguration to get the toggle instead

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Reduce timeout in PeerTaskRequestSender to 5s

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Refactor PeerManager to be an interface

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix up compile errors after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix MetricsAcceptanceTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix MetricsAcceptanceTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix DownloadReceiptsStep when using peer task system

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rename PeerManager to PeerSelector

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Reword PeerSelector javadoc to avoid implementation details

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use ConcurrentHashMap in DefaultPeerSelector

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Reword trace log in DefaultPeerSelector

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove unused imports

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use a 1 second delay between retries in PeerTaskExecutor to match old implementation

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add testGetPeerButNoPeerMatchesFilter to DefaultPeerSelectorTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add testGetPeerButNoPeerMatchesFilter to DefaultPeerSelectorTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix MetricsAcceptanceTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix MetricsAcceptanceTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Modify PeerTaskExecutor metric to include response time from peer

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use SubProtocol instead of subprotocol name string in PeerTask

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: rename timing context to ignored to prevent intellij warnings

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use constants for number of retries

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Convert PeerTaskExecutorResult to a record

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rename PeerTaskBehavior to PeerTaskRetryBehavior

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move peer selection logic to PeerSelector

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix up everything broken after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Attempt to improve performance of peer task system in pipeline

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: fix compile check

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix broken workflow

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Reduce logging in JsonRpcExecutor to trace level

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: More changes in DownloadReceiptsStep

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rework DownloadReceiptsStep

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Make changes as discussed in walkthrough meeting

Remove DefaultPeerSelector, make EthPeers implement PeerSelector interface, and add PeerTask.getPeerRequirementFilter

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update after merge and make discussed changes from walkthrough discussion

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Change to regular HashMap

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove runtime exception again

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rename getPeerTaskBehavior to getPeerTaskRetryBehavior

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rename getPeerTaskBehavior to getPeerTaskRetryBehavior

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rework PeerTaskExecutor retry system to be 0-based

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix up compile errors after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix broken DownloadReceiptsStepTest test

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move GetReceipts to services worker for parallelism

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Refactor peer task system usage in DownloadReceiptsStep to better match old system

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove unused async methods in PeerTaskExecutor

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Return Optional<EthPeer> in PeerSelector.getPeer and utilise existing peer selection behavior in EthPeers

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Redo getPeer again to include hasAvailableRequestCapacity check

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add protocol spec supplier to GetReceiptsFromPeerTask

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rework getPeer again to use LEAST_TO_MOST_BUSY comparator

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Import PeerNotConnected class instead of using fully qualified class name

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Change to specifying retry counts in PeerTask instead of behavior enums

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: clean up after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: clean up after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix up javadoc

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add additional metrics to PeerTaskExecutor

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add Predicate to PeerTask to check for partial success

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix incorrect name on isPartialSuccessTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Implement isPartialSuccess and add unit tests

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add partialSuccessCounter and inflightRequestGauge in PeerTaskExecutor

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Also filter by whether a peer is fully validated

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove unneeded throws in RunnerTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix up inflight requests gauge in PeerTaskExecutor

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update plugin api hash

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update plugin api hash

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add javadoc to LabelledGauge.isLabelsObserved

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update plugin-api hash

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update changelog

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Handle headers with no receipts as a special case in DownloadReceiptsStep

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Complete merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use taskName instead of className for labelNames

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use snake_case for metric names

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use _total metric name suffix

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: rework partial success handling

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Update GetReceiptsFromPeerTask with partialSuccess changes

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Add default implementation to LabelledGauge.isLabelsObserved

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix broken unit test

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Rename parseResponse to processResponse

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* add possibility to use the new peer task system when downloading the bodies

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>

* fix loop

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>

* 7311: Wrap peer task system usage in ethScheduler call to match other usages

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* small fixes

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>

* update API change

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>

* spotless

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>

* 7311: apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Move check for empty trie hash into GetReceiptsFromPeerTask and update unit test to test for this functionality

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix compile issue after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Remove BodyValidator and update code and test to match

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix up pre-fill and add test to test failure scenario

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Use ProtocolSchedule.anyMatch to find if any ProtocolSpecs are PoS, remove new usages of currentProtocolSpecSupplier

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Only attempt to remove headers on successful requests

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7311: Fix broken stuff after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* spotless

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>

* Fix up compile errors after merge

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Add PeerTaskExecutor usage for GetBodies in DownloadHeaderSequenceTask

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Add PeerTaskExecutor usage for GetBodies in ForwardSyncStep and apply spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Allow custom retries against other peers in GetBodiesFromPeerTask

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Fix infinite loop in CheckPointSyncChainDownloaderTest

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* spotless

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Update CompleteBlocksWithPeerTask.getBlocks to retrieveBlocksFromPeers and add javadoc

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* Add javadoc to GetBodiesFromPeerTask

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

* 7582: Simplify withdrawals validation

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
* implement the proposed gas changes for bls / eip-2537 for pectra-devnet-5
* disable eip-2537 testing until we have new artifacts that reflect pectra gas costs

Signed-off-by: garyschulte <garyschulte@gmail.com>
… txpool (hyperledger#8018)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
…rtBlock calls (hyperledger#8096)

Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
…for Pectra (hyperledger#8101)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
…edger#8091)

* Refactor BlockHashOperation block height check into Operation

Refactor the 4 different places block height is checked across Besu into
the BlockHashOperation. Add support to make the lookback range
configurable in the BlockHashLookup interface, but default it to 256.

Signed-off-by: Danno Ferrin <danno@numisight.com>

* spotless

Signed-off-by: Danno Ferrin <danno@numisight.com>

* javadoc

Signed-off-by: Danno Ferrin <danno@numisight.com>

* Update Unit Tests to use the operation.

Signed-off-by: Danno Ferrin <danno@numisight.com>

* Update Unit Tests to use the operation.

Signed-off-by: Danno Ferrin <danno@numisight.com>

---------

Signed-off-by: Danno Ferrin <danno@numisight.com>
* Add head execution time metric during new payload execution
* Change the metric value only if the block was executed sucessfully

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
* add workflow to verify artifacts

Signed-off-by: Joshua Fernandes <joshua.fernandes@consensys.net>

* curate list of artifacts based on PR review

Signed-off-by: Joshua Fernandes <joshua.fernandes@consensys.net>

* make the artifacts list simple

Signed-off-by: Joshua Fernandes <joshua.fernandes@consensys.net>

---------

Signed-off-by: Joshua Fernandes <joshua.fernandes@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
…8116)

Support authorizationList parsing in reference tests for execution-spec-tests
Allow zero chainId

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
…dger#8099)

Collect trielog rolling exceptions and display upon state root mismatch

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
- Change debug_traceBlockByNumber implementation by using a pipeline
- Change the defaults to match Geth and Nethermind defaults
- Improve general performance
- Add unit tests

Signed-off-by: Ameziane H. <ameziane.hamlat@consensys.net>
* exclude empty requests from requests hash

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Exclude empty requests and prepend request type byte in engine_getPayloadV4

Fixes ethereum/execution-apis#599 change to EIP-7685

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>

* fix test

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fix prague tests: change request hash, reorder json elements

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fix extracting of request for new payload

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fix test by fixing request object creation

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* spotless

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* set request type to only one byte, fixed creation of request list in T8nExecutor

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fix expected json output to exclude empty requests

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
…lculator (hyperledger#8106)

* move gas refund calculation from MainnetTransactionProcessor to RefundCalculator

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fix MainnetTransactionProcessorTest

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* add test for FrontierRefundCalculator

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* add test for FrontierRefundCalculator

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* add PragueRefundCalculator dummy

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* move refund logic to gas calculator, delete RefundCalculator

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
* Update ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/Endpoint.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Vaidik <vaidikbhardwaj00@gmail.com>

* loopback address
* use constant

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Vaidik <vaidikbhardwaj00@gmail.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
…hyperledger#8115)

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
* upcoming breaking changes for various deprecated bonsai CLI options

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

* order

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Update the EXTCALL account creation detection to match legacy call
detection.

Signed-off-by: Danno Ferrin <danno@numisight.com>
* first draft for 7702 changes for pectra-devnet5

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* spotless, javadoc

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fixed get code in call operations

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* allow code delegation chain id to be up to 2^256-1

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* set code for delegated accounts correctly in the initialFrame of the tx processing

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* delegated accounts return empty bytes for the code if the target does not exist

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
Implements EIP-7623 (increase calldata cost)

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
* default target gas limit for holesky

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Co-authored-by: Justin Florentine <justin+github@florentine.us>
…er#8133)

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
daniellehrner and others added 7 commits February 18, 2025 14:15
* increase mainnet gas limit to 36M, remove unused gas limit calculator from BesuControllerBuilder

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* gas limit in SystemCallProcessor is independent of the block gas limit

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* update test to reflect gas limit increase from 30M -> 36M

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* remove unused gas limit check from previous commit

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* moved the target gas limit constant for testnets to the same class as the one for mainnet

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fix tests

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
* update some deprecated references

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

* change order of params to eliminate deprecation warning

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Use fixtures_develop which contains Pectra test fixtures.

Unignore the BLS execution-spec-tests, but keep ignoring the older reference tests version

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
@matkt matkt force-pushed the verkle-branch/merge-main branch from ae4feed to 36fbcdd Compare February 20, 2025 09:51
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
@matkt
Copy link
Contributor Author

matkt commented Feb 20, 2025

Tried and this PR is syncing the current devnet

@matkt matkt marked this pull request as ready for review February 20, 2025 13:54
@matkt matkt added the verkle label Feb 20, 2025
+ (transaction.getAccessList().map(gasCalculator::accessListGasCost).orElse(0L))
+ gasCalculator.delegateCodeGasCost(transaction.codeDelegationListSize());
// TODO VERKLE FIX CALCULATION ON VALIDATION+
// gasCalculator.computeAccessEventsCost(accessWitness, transaction);
Copy link
Contributor

Choose a reason for hiding this comment

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

Removal of comments, intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's an old comment we added before your refactoring of the gascost . it seems to be useless to keep it now

* @return the full world state, if available
*/
private Optional<MutableWorldState> getFullWorldStateFromHead(final Hash blockHash) {
// TODO begin remove before merging on main
Optional<BlockHeader> blockHeader = blockchain.getBlockHeader(blockHash);
if (blockHeader.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this if check present? it does not exist on my merge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a temporary code we have on verkle to trigger a rollback and rollfoward for each block when we are syncing and testing that everything is working correctly

private long cost(final MessageFrame frame, final long blockNumber) {
final UInt256 key = UInt256.valueOf(blockNumber % BLOCKHASH_SERVE_WINDOW);
long gas = frame.getAccessWitness().touchAndChargeStorageLoad(contractAddress, key);
public Address getContractAddress() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this method used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes seems to be useless I removed it

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
@@ -81,10 +81,10 @@
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe146098573615156028575f545f5260205ff35b36606014156101445760115f54600182026001905f5b5f82111560595781019083028483029004916001019190603e565b90939004341061014457600154600101600155600354806004026004013381556001015f35815560010160203581556001016040359055600101600355005b6003546002548082038060011160ac575060015b5f5b81811460f15780607402838201600402600401805490600101805490600101805490600101549260601b84529083601401528260340152906054015260010160ae565b9101809214610103579060025561010e565b90505f6002555f6003555b5f548061049d141561011d57505f5b6001546001828201116101325750505f610138565b01600190035b5f555f6001556074025ff35b5f5ffd",
"storage": {}
},
"0xfffffffffffffffffffffffffffffffffffffffe": {
"0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc": {
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't seem correct, we are using 0xff...fe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will not be a problem because PragueBlockHashProcessor still use the correct with my modification . Now Eip7709BlockHashProcessor.java will have it's own address value and will not override the one from Prague

@@ -173,12 +173,12 @@
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe146098573615156028575f545f5260205ff35b36606014156101445760115f54600182026001905f5b5f82111560595781019083028483029004916001019190603e565b90939004341061014457600154600101600155600354806004026004013381556001015f35815560010160203581556001016040359055600101600355005b6003546002548082038060011160ac575060015b5f5b81811460f15780607402838201600402600401805490600101805490600101805490600101549260601b84529083601401528260340152906054015260010160ae565b9101809214610103579060025561010e565b90505f6002555f6003555b5f548061049d141561011d57505f5b6001546001828201116101325750505f610138565b01600190035b5f555f6001556074025ff35b5f5ffd",
"storage": {}
},
"0xfffffffffffffffffffffffffffffffffffffffe": {
"0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc": {
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't seem correct, we are using 0xff...fe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will not be a problem because PragueBlockHashProcessor still use the correct with my modification . Now Eip7709BlockHashProcessor.java will have it's own address value and will not override the one from Prague

@@ -63,14 +63,14 @@
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
"storage": {}
},
"0xfffffffffffffffffffffffffffffffffffffffe": {
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500",
"0x0000f90827f1c53a10cb7a02335b175320002935": {
Copy link
Contributor

Choose a reason for hiding this comment

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

again not 0xfffffffffffffffffffffffffffffffffffffffe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will not be a problem because PragueBlockHashProcessor still use the correct with my modification . Now Eip7709BlockHashProcessor.java will have it's own address value and will not override the one from Prague

"balance": "0x0",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500",
"nonce": "0x1",
"0x0000f90827f1c53a10cb7a02335b175320002935": {
Copy link
Contributor

Choose a reason for hiding this comment

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

again not 0xfffffffffffffffffffffffffffffffffffffffe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will not be a problem because PragueBlockHashProcessor still use the correct with my modification . Now Eip7709BlockHashProcessor.java will have it's own address value and will not override the one from Prague

"comment": "Increase the MAX_EFFECTIVE_BALANCE",
"nonce": "0x01",
"balance": "0x00",
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd",
"storage": {}
},
"0xfffffffffffffffffffffffffffffffffffffffe": {
"0x0000f90827f1c53a10cb7a02335b175320002935": {
Copy link
Contributor

Choose a reason for hiding this comment

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

again not 0xfffffffffffffffffffffffffffffffffffffffe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will not be a problem because PragueBlockHashProcessor still use the correct with my modification . Now Eip7709BlockHashProcessor.java will have it's own address value and will not override the one from Prague

"nonce":"0x1"
},
"0x0c15f14308530b7cdb8460094bbb9cc28b9aaaaa": {
"0x00000961ef480eb55e80d19ad83579a64c007002": {
Copy link
Contributor

Choose a reason for hiding this comment

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

again not 0xfffffffffffffffffffffffffffffffffffffffe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will not be a problem because PragueBlockHashProcessor still use the correct with my modification . Now Eip7709BlockHashProcessor.java will have it's own address value and will not override the one from Prague

new MainnetBlockHeaderFunctions());
new MainnetBlockHeaderFunctions(),
null // execution witnesses
);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra new line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -104,8 +105,8 @@ public static Collection<Object[]> generateTestParametersForConfig(final String[
public static void executeTest(final BlockchainReferenceTestCase testCase) {
final BlockHeader genesisBlockHeader = testCase.getGenesisBlockHeader();
final MutableWorldState worldState =
testCase.getWorldStateArchive()
.getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash())
testCase.getWorldStateArchive()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spacing

|| soughtBlock >= currentBlockNumber
|| soughtBlock < (currentBlockNumber - blockHashLookup.getLookback())) {
frame.pushStackItem(Bytes32.ZERO);
return new OperationResult(cost, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

if you do return, why do you need the else?
copy pasting my version:

    // If the sought block is negative, a future block, the current block, or not in the
    // lookback window, zero is returned.
    if (soughtBlock < 0
        || soughtBlock >= currentBlockNumber
        || soughtBlock < (currentBlockNumber - blockHashLookup.getLookback())) {
      frame.pushStackItem(Bytes32.ZERO);
      return new OperationResult(cost, null);
    }

    final long remainingGas = frame.getRemainingGas();
    final Hash blockHash = blockHashLookup.apply(frame, soughtBlock);
    final long lookupCost = remainingGas - frame.getRemainingGas();
    // give lookupCost back as it will be taken after
    frame.incrementRemainingGas(lookupCost);
    if (blockHash == null) {
      return new OperationResult(cost + lookupCost, ExceptionalHaltReason.INSUFFICIENT_GAS);
    }
    frame.pushStackItem(blockHash);

    return new OperationResult(cost + lookupCost, null);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes we can remove it

return null;
}
frame.decrementRemainingGas(lookupCost);
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry you need to put this back before the check for OOG. I remembered the reason I did it this way - if you fail on OOG you want to be able to report exactly by how much have you failed on, so you need to decrement the gas cost here from the frame so you can get it correctly on the other side upon returning the failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a rollback of this modification

Signed-off-by: Karim Taam <karim.t2am@gmail.com>
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class Eip7709BlockHashLookupTest {
class Eip7709BlockHashLookupTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer the version that was there in the verkle branch, reason: I reworked these tests while implementing the gas costs so the version on the verkle branch is more up to date:

class Eip7709BlockHashLookupTest {
  private static final long BLOCKHASH_SERVE_WINDOW = 160;
  private static final Address STORAGE_ADDRESS = Address.fromHexString("0x0");
  private static final long HISTORY_SERVE_WINDOW = 200L;
  private static final int CURRENT_BLOCK_NUMBER =
      Math.toIntExact(HISTORY_SERVE_WINDOW + BLOCKHASH_SERVE_WINDOW / 2);
  private List<BlockHeader> headers;
  private BlockHashLookup lookup;
  private MessageFrame frame;
  private WorldUpdater worldUpdater;

  @BeforeEach
  void setUp() {
    headers = new ArrayList<>();
    worldUpdater = createWorldUpdater(0, CURRENT_BLOCK_NUMBER);
    lookup =
        new Eip7709BlockHashLookup(STORAGE_ADDRESS, HISTORY_SERVE_WINDOW, BLOCKHASH_SERVE_WINDOW);
    frame = createMessageFrame(CURRENT_BLOCK_NUMBER, worldUpdater, Long.MAX_VALUE);
  }

  private WorldUpdater createWorldUpdater(final int fromBlockNumber, final int toBlockNumber) {
    WorldUpdater worldUpdaterMock = mock(WorldUpdater.class);
    SimpleAccount contractAccount = spy(new SimpleAccount(STORAGE_ADDRESS, 0, Wei.ZERO));
    when(worldUpdaterMock.get(STORAGE_ADDRESS)).thenReturn(contractAccount);
    BlockHeader parentHeader = null;
    for (int i = fromBlockNumber; i < toBlockNumber; i++) {
      final BlockHeader header = createHeader(i, parentHeader);
      headers.add(header);
      contractAccount.setStorageValue(
          UInt256.valueOf(i % HISTORY_SERVE_WINDOW), UInt256.fromBytes(header.getHash()));
      parentHeader = header;
    }
    return worldUpdaterMock;
  }

  private MessageFrame createMessageFrame(
      final long currentBlockNumber, final WorldUpdater worldUpdater, final long remainingGas) {
    final MessageFrame messageFrame = mock(MessageFrame.class);
    final BlockValues blockValues = mock(BlockValues.class);
    when(blockValues.getNumber()).thenReturn(currentBlockNumber);
    when(messageFrame.getBlockValues()).thenReturn(blockValues);
    when(messageFrame.getBlockHashLookup()).thenReturn(lookup);
    when(messageFrame.getWorldUpdater()).thenReturn(worldUpdater);
    when(messageFrame.getRemainingGas()).thenReturn(remainingGas);
    when(messageFrame.getAccessWitness()).thenReturn(NoopAccessWitness.get());
    return messageFrame;
  }

  @Test
  void shouldGetHashOfImmediateParent() {
    assertHashForBlockNumber(CURRENT_BLOCK_NUMBER - 1);
  }

  @Test
  void shouldGetHashOfMaxBlocksBehind() {
    assertHashForBlockNumber(Math.toIntExact(CURRENT_BLOCK_NUMBER - BLOCKHASH_SERVE_WINDOW));
  }

  @Test
  void shouldReturnZeroHashWhenSystemContractNotExists() {
    worldUpdater = new SimpleWorld();
    frame = createMessageFrame(CURRENT_BLOCK_NUMBER, worldUpdater, Long.MAX_VALUE);
    assertThat(lookup.apply(frame, CURRENT_BLOCK_NUMBER - 1L)).isEqualTo(Hash.ZERO);
  }

  @Test
  @SuppressWarnings("ReturnValueIgnored")
  void shouldDecrementRemainingGasFromFrame() {
    AccessWitness accessWitness = mock(AccessWitness.class);
    when(accessWitness.touchAndChargeStorageLoad(any(), any())).thenReturn(100L);
    frame = createMessageFrame(CURRENT_BLOCK_NUMBER, worldUpdater, 200L);
    when(frame.getAccessWitness()).thenReturn(accessWitness);
    lookup.apply(frame, CURRENT_BLOCK_NUMBER - 1L);
    verify(frame).decrementRemainingGas(eq(100L));
    verify(frame).getAccessWitness();
    verify(frame).getRemainingGas();
    verify(frame).getWorldUpdater();
    verifyNoMoreInteractions(frame);
  }

  @Test
  void insufficientGasReturnsNullBlockHash() {
    worldUpdater = new SimpleWorld();
    AccessWitness accessWitness = mock(AccessWitness.class);
    when(accessWitness.touchAndChargeStorageLoad(any(), any())).thenReturn(100L);
    frame = createMessageFrame(CURRENT_BLOCK_NUMBER, worldUpdater, 1L);
    when(frame.getAccessWitness()).thenReturn(accessWitness);
    final Hash blockHash = lookup.apply(frame, CURRENT_BLOCK_NUMBER - 1L);
    assertThat(blockHash).isNull();
  }

  @Test
  void shouldReturnZeroHashWhenParentBlockNotInContract() {
    worldUpdater = createWorldUpdater(CURRENT_BLOCK_NUMBER - 10, CURRENT_BLOCK_NUMBER);
    frame = createMessageFrame(CURRENT_BLOCK_NUMBER, worldUpdater, Long.MAX_VALUE);
    lookup =
        new Eip7709BlockHashLookup(STORAGE_ADDRESS, HISTORY_SERVE_WINDOW, BLOCKHASH_SERVE_WINDOW);
    assertHashForBlockNumber(CURRENT_BLOCK_NUMBER - 20, Hash.ZERO);
  }

  @Test
  void shouldCacheBlockHashes() {
    worldUpdater = createWorldUpdater(0, CURRENT_BLOCK_NUMBER);
    frame = createMessageFrame(CURRENT_BLOCK_NUMBER, worldUpdater, Long.MAX_VALUE);
    final Account account = worldUpdater.get(STORAGE_ADDRESS);
    clearInvocations(account);

    int blockNumber1 = CURRENT_BLOCK_NUMBER - 1;
    int blockNumber2 = CURRENT_BLOCK_NUMBER - 4;
    int blockNumber3 = CURRENT_BLOCK_NUMBER - 5;
    assertHashForBlockNumber(blockNumber1);
    assertHashForBlockNumber(blockNumber1);
    assertHashForBlockNumber(blockNumber2);
    assertHashForBlockNumber(blockNumber3);
    assertHashForBlockNumber(blockNumber3);
    assertHashForBlockNumber(blockNumber3);

    verify(account, times(1))
        .getStorageValue(eq(UInt256.valueOf(blockNumber1 % HISTORY_SERVE_WINDOW)));
    verify(account, times(1))
        .getStorageValue(eq(UInt256.valueOf(blockNumber2 % HISTORY_SERVE_WINDOW)));
    verify(account, times(1))
        .getStorageValue(eq(UInt256.valueOf(blockNumber3 % HISTORY_SERVE_WINDOW)));
    verifyNoMoreInteractions(account);
  }

  @Test
  void shouldGetHashWhenParentIsGenesis() {
    worldUpdater = createWorldUpdater(0, 1);
    frame = createMessageFrame(1, worldUpdater, Long.MAX_VALUE);
    lookup =
        new Eip7709BlockHashLookup(STORAGE_ADDRESS, HISTORY_SERVE_WINDOW, BLOCKHASH_SERVE_WINDOW);
    assertHashForBlockNumber(0);
  }

  @Test
  void shouldReturnZeroWhenRequestedBlockEqualToImportingBlock() {
    assertHashForBlockNumber(CURRENT_BLOCK_NUMBER, Hash.ZERO);
  }

  @Test
  void shouldReturnZeroWhenRequestedBlockAheadOfCurrent() {
    assertHashForBlockNumber(CURRENT_BLOCK_NUMBER + 1, Hash.ZERO);
    assertHashForBlockNumber(CURRENT_BLOCK_NUMBER + 20, Hash.ZERO);
  }

  @Test
  void shouldReturnZeroWhenRequestedBlockTooFarBehindCurrent() {
    assertHashForBlockNumber(
        Math.toIntExact(CURRENT_BLOCK_NUMBER - BLOCKHASH_SERVE_WINDOW - 1), Hash.ZERO);
    assertHashForBlockNumber(2, Hash.ZERO);
  }

  private void assertHashForBlockNumber(final int blockNumber) {
    assertHashForBlockNumber(blockNumber, headers.get(blockNumber).getHash());
  }

  private void assertHashForBlockNumber(final int blockNumber, final Hash hash) {
    clearInvocations(frame);

    BlockHashOperation op = new BlockHashOperation(new CancunGasCalculator());
    when(frame.popStackItem()).thenReturn(Bytes.ofUnsignedInt(blockNumber));

    op.execute(frame, null);

    verify(frame).pushStackItem(hash);
  }

  private BlockHeader createHeader(final long blockNumber, final BlockHeader parentHeader) {
    return new BlockHeaderTestFixture()
        .number(blockNumber)
        .parentHash(parentHeader != null ? parentHeader.getHash() : Hash.EMPTY)
        .buildHeader();
  }
}

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.