baseFee as Wei instead of long (#3065)

* [Config] convert baseFee from long to wei

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/3143/head
fab-10 3 years ago committed by GitHub
parent 7713199e96
commit 43e67e0be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 94
      CHANGELOG.md
  2. 2
      config/build.gradle
  3. 10
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java
  4. 4
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  5. 9
      config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java
  6. 8
      config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java
  7. 6
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java
  8. 2
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueBlockHashing.java
  9. 2
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java
  10. 40
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java
  11. 22
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java
  12. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/FeeHistory.java
  13. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java
  14. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionReceiptWithMetadata.java
  15. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionWithMetadata.java
  16. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java
  17. 10
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java
  18. 7
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java
  19. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java
  20. 11
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java
  21. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java
  22. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResultTest.java
  23. 4
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java
  24. 4
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java
  25. 11
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java
  26. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java
  27. 7
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java
  28. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java
  29. 27
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java
  30. 25
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/feemarket/BaseFee.java
  31. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/feemarket/CoinbaseFeePriceCalculator.java
  32. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/feemarket/TransactionPriceCalculator.java
  33. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java
  34. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/EthHash.java
  35. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java
  36. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java
  37. 7
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/BaseFeeMarket.java
  38. 7
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FeeMarket.java
  39. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/LegacyFeeMarket.java
  40. 48
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/LondonFeeMarket.java
  41. 14
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/BaseFeeMarketBlockHeaderGasPriceValidationRule.java
  42. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRule.java
  43. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java
  44. 8
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java
  45. 7
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java
  46. 4
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java
  47. 25
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/feemarket/BaseFeeMarketBaseFeeTest.java
  48. 5
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/feemarket/BaseFeeMarketTest.java
  49. 6
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/feemarket/CoinbaseFeePriceCalculatorTest.java
  50. 18
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/feemarket/TransactionPriceCalculatorTest.java
  51. 6
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidatorTest.java
  52. 3
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasherTest.java
  53. 12
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java
  54. 8
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/BaseFeeMarketBlockHeaderGasPriceValidationRuleTest.java
  55. 5
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/EIP1559Helper.java
  56. 11
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/GasLimitRangeAndDeltaValidationRuleTest.java
  57. 3
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java
  58. 8
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java
  59. 9
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/operations/BaseFeeOperationTest.java
  60. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolReplacementRule.java
  61. 24
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionReplacementByFeeMarketRule.java
  62. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionReplacementByGasPriceRule.java
  63. 21
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/BaseFeePendingTransactionsSorter.java
  64. 12
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingMultiTypesTransactionsTest.java
  65. 42
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionReplacementRulesTest.java
  66. 3
      ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/BlockchainReferenceTestCaseSpec.java
  67. 4
      ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java
  68. 3
      ethereum/retesteth/src/test/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParamsTest.java
  69. 18
      ethereum/rlp/src/test/java/org/hyperledger/besu/ethereum/rlp/BytesValueRLPOutputTest.java
  70. 4
      evm/src/main/java/org/hyperledger/besu/evm/frame/BlockValues.java
  71. 14
      evm/src/main/java/org/hyperledger/besu/evm/operation/BaseFeeOperation.java
  72. 3
      evm/src/test/java/org/hyperledger/besu/evm/toy/ToyBlockValues.java
  73. 2
      plugin-api/build.gradle
  74. 2
      plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java

@ -1,5 +1,13 @@
# Changelog
## <Next RC>
### Additions and Improvements
- Represent baseFee as Wei instead of long accordingly to the spec [#2785] (https://github.com/hyperledger/besu/issues/2785)
### <Next RC> Breaking Changes
- Plugin API: BlockHeader.getBaseFee() method now returns an optional Wei instead of an optional Long
## 21.10.3
### Additions and Improvements
@ -40,7 +48,7 @@ SHA256: 4b96d4d10c0c6128dc67333c8600e927ea135b4db5e5f74688a0753260b7b985
### Bug Fixes
- Do not change the sender balance, but set gas fee to zero, when simulating a transaction without enforcing balance checks. [#2454](https://github.com/hyperledger/besu/pull/2454)
- Ensure genesis block has the default base fee if london is at block 0 [#2920](https://github.com/hyperledger/besu/pull/2920)
- Ensure genesis block has the default base fee if london is at block 0 [#2920](https://github.com/hyperledger/besu/pull/2920)
- Fixes the exit condition for loading a BonsaiPersistedWorldState for a sibling block of the last one persisted [#2967](https://github.com/hyperledger/besu/pull/2967)
### Early Access Features
@ -122,7 +130,7 @@ SHA256: 536612e5e4d7a5e7a582f729f01ba591ba68cc389e8379fea3571ed85322ff51
## 21.7.4
### Additions and Improvements
- Upgrade Gradle to 7.2, which supports building with Java 17 [#2761](https://github.com/hyperledger/besu/pull/2376)
- Upgrade Gradle to 7.2, which supports building with Java 17 [#2761](https://github.com/hyperledger/besu/pull/2376)
### Bug Fixes
- Set an idle timeout for metrics connections, to clean up ports when no longer used [\#2748](https://github.com/hyperledger/besu/pull/2748)
@ -188,14 +196,14 @@ sha256sum 83fc44e39a710a95d8b6cbbbf04010dea76122bafcc633a993cd15304905a402
## 21.7.0
### Additions and Improvements
This release contains the activation blocks for London across all supported testnets. They are:
This release contains the activation blocks for London across all supported testnets. They are:
* Ropsten 10_499_401 (24 Jun 2021)
* Goerli 5_062_605 (30 Jun 2021)
* Rinkeby 8_897_988 (7 Jul 2021)
* Mainnet 12_965_000 (4 Aug 2021)
- eip-1559 changes: accept transactions which have maxFeePerGas below current baseFee [\#2374](https://github.com/hyperledger/besu/pull/2374)
- Introduced transitions for IBFT2 block rewards [\#1977](https://github.com/hyperledger/besu/pull/1977)
- Change Ethstats's status from experimental feature to stable. [\#2405](https://github.com/hyperledger/besu/pull/2405)
- Introduced transitions for IBFT2 block rewards [\#1977](https://github.com/hyperledger/besu/pull/1977)
- Change Ethstats's status from experimental feature to stable. [\#2405](https://github.com/hyperledger/besu/pull/2405)
- Fixed disabling of native libraries for secp256k1 and altBn128. [\#2163](https://github.com/hyperledger/besu/pull/2163)
- eth_feeHistory API for wallet providers [\#2466](https://github.com/hyperledger/besu/pull/2466)
@ -231,8 +239,8 @@ sha256sum 7bc97c359386cad84d449f786dc0a8ed8728616b6704ce473c63f1d94af3a9ef
### Additions and Improvements
- eip-1559 changes: accept transactions which have maxFeePerGas below current baseFee [\#2374](https://github.com/hyperledger/besu/pull/2374)
- Introduced transitions for IBFT2 block rewards [\#1977](https://github.com/hyperledger/besu/pull/1977)
- Change Ethstats's status from experimental feature to stable. [\#2405](https://github.com/hyperledger/besu/pull/2405)
- Introduced transitions for IBFT2 block rewards [\#1977](https://github.com/hyperledger/besu/pull/1977)
- Change Ethstats's status from experimental feature to stable. [\#2405](https://github.com/hyperledger/besu/pull/2405)
- Fixed disabling of native libraries for secp256k1 and altBn128. [\#2163](https://github.com/hyperledger/besu/pull/2163)
@ -241,7 +249,7 @@ sha256sum 7bc97c359386cad84d449f786dc0a8ed8728616b6704ce473c63f1d94af3a9ef
- Updated `eth_sendRawTransaction` to return an error when maxPriorityFeePerGas exceeds maxFeePerGas [\#2424](https://github.com/hyperledger/besu/pull/2424)
### Early Access Features
This release contains the activation blocks for London across all supported testnets. They are:
This release contains the activation blocks for London across all supported testnets. They are:
* Ropsten 10_499_401 (24 Jun 2021)
* Goerli 5_062_605 (30 Jun 2021)
* Rinkeby 8_897_988 (7 Jul 2021)
@ -302,7 +310,7 @@ sha256: f415c9b67d26819caeb9940324b2b1b9ce6e872c9181052739438545e84e2531
- Added ACCESS_LIST transactions to the list of transactions using legacy gas pricing for 1559 [\#2239](https://github.com/hyperledger/besu/pull/2239)
- Reduced logging level of public key decoding failure of malformed packets. [\#2143](https://github.com/hyperledger/besu/pull/2143)
- Add 1559 parameters to json-rpc responses. [\#2222](https://github.com/hyperledger/besu/pull/2222)
- Add 1559 parameters to json-rpc responses. [\#2222](https://github.com/hyperledger/besu/pull/2222)
### Early Access Features
@ -388,7 +396,7 @@ https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/21.1.3/besu-21.1.3.z
### Important note: the 21.1.1 release contains an outdated version of the Berlin network upgrade. If you are using Besu on public Ethereum networks, you must upgrade to 21.1.2.
This release contains the activation blocks for Berlin across all supported testnets and the Ethereum mainnet. They are:
This release contains the activation blocks for Berlin across all supported testnets and the Ethereum mainnet. They are:
* Ropsten 9_812_189 (10 Mar 2021)
* Goerli 4_460_644 (17 Mar 2021)
* Rinkeby 8_290_928 (24 Mar 2021)
@ -396,7 +404,7 @@ This release contains the activation blocks for Berlin across all supported test
### Additions and Improvements
- Added option to set a limit for JSON-RPC connections
- Added option to set a limit for JSON-RPC connections
* HTTP connections `--rpc-http-max-active-connections` [\#1996](https://github.com/hyperledger/besu/pull/1996)
* WS connections `--rpc-ws-max-active-connections` [\#2006](https://github.com/hyperledger/besu/pull/2006)
- Added ASTOR testnet ETC support [\#2017](https://github.com/hyperledger/besu/pull/2017)
@ -418,7 +426,7 @@ https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/21.1.2/besu-21.1.2.z
### Important note: this release contains an outdated version of the Berlin network upgrade. If you are using Besu on public Ethereum networks, you must upgrade to 21.1.2.
This release contains the activation blocks for Berlin across all supported testnets and the Ethereum mainnet. They are:
This release contains the activation blocks for Berlin across all supported testnets and the Ethereum mainnet. They are:
* Ropsten 9_812_189 (10 Mar 2021)
* Goerli 4_460_644 (17 Mar 2021)
* Rinkeby 8_290_928 (24 Mar 2021)
@ -452,14 +460,14 @@ sha256: `c22a80a54e9fed864734b9fbd69a0a46840fd27ca5211648a3eaf8a955417218 `
## 21.1.0 Features
Features added between 20.10.0 to 21.1.0 include:
* Berlin Network Upgrade: this release contains the activation blocks for Berlin across all supported testnets and the Ethereum mainnet. They are:
* Berlin Network Upgrade: this release contains the activation blocks for Berlin across all supported testnets and the Ethereum mainnet. They are:
* Ropsten 9_812_189 (10 Mar 2021)
* Goerli 4_460_644 (17 Mar 2021)
* Rinkeby 8_290_928 (24 Mar 2021)
* Ethereum 12_244_000 (14 Apr 2021)
* Besu Launcher: Besu now has support for the [Quorum Mainnet Launcher](https://github.com/ConsenSys/quorum-mainnet-launcher) which makes it easy for users to configure and launch Besu on the Ethereum mainnet.
* Bonsai Tries: A new database format which reduces storage requirements and improves performance for access to recent state. _Note: only full sync is currently supported._
* Miner Data JSON-RPC: The `eth_getMinerDataByBlockHash` and `eth_getMinerDataByBlockNumber` endpoints return miner rewards and coinbase address for a given block.
* Miner Data JSON-RPC: The `eth_getMinerDataByBlockHash` and `eth_getMinerDataByBlockNumber` endpoints return miner rewards and coinbase address for a given block.
* EIP-1898 support: [The EIP](https://eips.ethereum.org/EIPS/eip-1898) adds `blockHash` to JSON-RPC methods which accept a default block parameter.
### Early Access Features
@ -518,7 +526,7 @@ sha256: `e4c8fe4007e3e5f7f2528cbf1eeb5457caf06536c974a6ff4305035ff5724476`
### Download link
Link removed because this release contains an outdated version of the Berlin network upgrade, which was changed on March 5, 2021 ([link](https://github.com/ethereum/pm/issues/263#issuecomment-791473406)). If you are using Besu on public Ethereum networks, you must upgrade to 21.1.1. sha256 hash left for reference.
Link removed because this release contains an outdated version of the Berlin network upgrade, which was changed on March 5, 2021 ([link](https://github.com/ethereum/pm/issues/263#issuecomment-791473406)). If you are using Besu on public Ethereum networks, you must upgrade to 21.1.1. sha256 hash left for reference.
sha256: `b0fe3942052b8fd43fc3025a298a6c701f9edae2e100f0c563a1c5a4ceef71f1`
@ -650,7 +658,7 @@ Prior versions of Besu would set the HTTP Status 400 Bad Request for JSON-RPC re
In Besu version 20.10, properly formatted requests that have valid parameters (count and content) will return a HTTP Status 200 OK, with an error field if an error occurred. For example, requesting an account that does not exist in the chain, or a block by hash that Besu does not have, will now return HTTP 200 OK responses. Unparsable requests, improperly formatted requests, or requests with invalid parameters will continue to return HTTP 400 Bad Request.
Users of Web3J should note that many calls will now return a result with the error field containing the message whereas before a call would throw an exception with the error message as the exception message.
Users of Web3J should note that many calls will now return a result with the error field containing the message whereas before a call would throw an exception with the error message as the exception message.
## 20.10.0 Additions and Improvements
@ -660,7 +668,7 @@ Users of Web3J should note that many calls will now return a result with the err
* Added support for the upcoming YOLOv2 ephemeral testnet and removed the flag for the deprecated YOLOv1 ephemeral testnet. [#1386](https://github.com/hyperledger/besu/pull/1386)
* Added `debug_standardTraceBlockToFile` JSON-RPC API. This API accepts a block hash and will replay the block. It returns a list of files containing the result of the trace (one file per transaction). [\#1392](https://github.com/hyperledger/besu/pull/1392)
* Added `debug_standardTraceBadBlockToFile` JSON-RPC API. This API is similar to `debug_standardTraceBlockToFile`, but can be used to obtain info about a block which has been rejected as invalid. [\#1403](https://github.com/hyperledger/besu/pull/1403)
* Added support for EIP-2929 to YOLOv2. [#1387](https://github.com/hyperledger/besu/pull/1387)
* Added support for EIP-2929 to YOLOv2. [#1387](https://github.com/hyperledger/besu/pull/1387)
* Added `--start-block` and `--end-block` to the `blocks import` subcommand [\#1399](https://github.com/hyperledger/besu/pull/1399)
* Added support for multi-tenancy when using the early access feature of [onchain privacy group management](https://besu.hyperledger.org/en/stable/Concepts/Privacy/Onchain-PrivacyGroups/)
* \[Reverted\] Fixed memory leak in eth/65 subprotocol behavior. It is now enabled by default. [\#1420](https://github.com/hyperledger/besu/pull/1420), [#1348](https://github.com/hyperledger/besu/pull/1348), [#1321](https://github.com/hyperledger/besu/pull/1321)
@ -768,7 +776,7 @@ To enhance control over permissions on the privacy group management contract:
the privacy group. In the default onchain privacy group management contract implementation, only the
owner can add and remove participants, and upgrade the management contract.
The onchain privacy support in the current version of the web3js-eea library (v0.9) will not be compatible with Besu v1.5.3. We are actively working on an upgrade to webj3-eea that will support these changes.
The onchain privacy support in the current version of the web3js-eea library (v0.9) will not be compatible with Besu v1.5.3. We are actively working on an upgrade to webj3-eea that will support these changes.
### Download link
https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/1.5.3/besu-1.5.3.zip
@ -789,7 +797,7 @@ sha256sum: `735cd511e1dae1590f2829d9535cb383aa8c526f059b3451859e5fcfccc48985`
* New docker images are being generated to use the latest version of OpenJDK (currently 14.0.1) with the tag suffix of `-openjdk-latest`, for example `1.5.2-openjdk-latest`.
* New docker images are being generated to use [GraalVM](https://www.graalvm.org/) with the tag suffix of `-graalvm`, for example `1.5.2-graalvm`.
* The existing images based on Java 11 are also being tagged with the suffix `-openjdk-11`, for example `1.5.2-openjdk-11`, as well as `1.5.2`.
* The existing images based on Java 11 are also being tagged with the suffix `-openjdk-11`, for example `1.5.2-openjdk-11`, as well as `1.5.2`.
The intent is that the major Java VM version or Java VM type shipped with the default docker images (`latest`, `1.5.x`, etc.) may be changed during future quarterly releases but will remain consistent within quarterly releases.
@ -1037,7 +1045,7 @@ Workaround - Limit the number of blocks queried by each `eth_getLogs` call.
a fix is completed for the [eth/65 known issue](KNOWN_ISSUES.md). [\#741](https://github.com/hyperledger/besu/pull/741)
- Resolve crashing NAT detectors on GKE. [\#731](https://github.com/hyperledger/besu/pull/731) fixes [\#507](https://github.com/hyperledger/besu/issues/507).
[Besu-Kubernetes Readme](https://github.com/PegaSysEng/besu-kubernetes/blob/master/README.md#network-topology-and-high-availability-requirements)
updated to reflect changes.
updated to reflect changes.
- Deal with quick service start failures [\#714](https://github.com/hyperledger/besu/pull/714) fixes [\#662](https://github.com/hyperledger/besu/issues/662)
### Known Issues
@ -1066,7 +1074,7 @@ The `eth/65` change is not [backwards compatible](https://github.com/hyperledger
This has the following impact:
* In a private network, nodes using the 1.4.3 client cannot interact with nodes using 1.4.2 or earlier
clients.
* On mainnet, synchronizing eventually stalls.
* On mainnet, synchronizing eventually stalls.
Workaround -> revert to v1.4.2.
@ -1091,7 +1099,7 @@ in 1.5.0 release. [\#639](https://github.com/hyperledger/besu/pull/639)
### Known Issues
#### Fast sync when running Besu on cloud providers
#### Fast sync when running Besu on cloud providers
A known [RocksDB issue](https://github.com/facebook/rocksdb/issues/6435) causes fast sync to fail
when running Besu on certain cloud providers. The following error is displayed repeatedly:
@ -1270,7 +1278,7 @@ If you have existing private transactions, see [migration details](docs/Private-
* Added [`priv_call`](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#priv_call) which invokes
a private contract function locally and does not change the private state.
* Besu has moved from an internal Bytes library to the [Apache Tuweni](https://tuweni.apache.org/) Bytes library.
* Besu has moved from an internal Bytes library to the [Apache Tuweni](https://tuweni.apache.org/) Bytes library.
This includes using the library in the Plugins API interfaces. [#295](https://github.com/hyperledger/besu/pull/295) and [#215](https://github.com/hyperledger/besu/pull/215)
### Early Access Features
@ -1602,7 +1610,7 @@ For compatibility with ETC Agharta upgrade, use 1.3.7 or later.
- Add `--target-gas-limit` command line option. [\#24](https://github.com/hyperledger/besu/pull/24)(thanks to new contributor [cfelde](https://github.com/cfelde))
- Allow private contracts to access public state. [\#9](https://github.com/hyperledger/besu/pull/9)
- Documentation updates include:
- Added [sample load balancer configurations](https://besu.hyperledger.org/en/latest/HowTo/Configure/Configure-HA/Sample-Configuration/)
- Added [sample load balancer configurations](https://besu.hyperledger.org/en/latest/HowTo/Configure/Configure-HA/Sample-Configuration/)
- Added [`retesteth`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Subcommands/#retesteth) subcommand
- Added [`debug_accountRange`](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#debug_accountrange) JSON-RPC API method
- Clarified purpose of [static nodes](https://besu.hyperledger.org/en/latest/HowTo/Find-and-Connect/Managing-Peers/#static-nodes)
@ -1686,7 +1694,7 @@ For compatibility with ETC Agharta upgrade, use 1.3.7 or later.
- [Added Responsible Disclosure policy](https://docs.pantheon.pegasys.tech/en/latest/Reference/Responsible-Disclosure/)
- [Added `blocks export` subcommand](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Subcommands/#export)
### Technical Improvements
### Technical Improvements
- Update the `pantheon blocks export` command usage [\#1887](https://github.com/PegaSysEng/pantheon/pull/1887) (thanks to [matkt](https://github.com/matkt))
- Stop Returning null for 'pending' RPC calls [\#1883](https://github.com/PegaSysEng/pantheon/pull/1883)
- Blake validation errors are hard errors [\#1882](https://github.com/PegaSysEng/pantheon/pull/1882)
@ -1876,7 +1884,7 @@ For compatibility with ETC Agharta upgrade, use 1.3.7 or later.
- Added content on [creating and managing privacy groups](https://besu.hyperledger.org/en/latest/Reference/web3js-eea-Methods/#createprivacygroup)
- Added content on [accessing private and privacy marker transactions](https://besu.hyperledger.org/en/latest/HowTo/Use-Privacy/Access-Private-Transactions/)
- Added content on [system requirements](https://besu.hyperledger.org/en/latest/HowTo/Get-Started/System-Requirements/)
- Added reference to [Besu role on Galaxy to deploy using Ansible](https://besu.hyperledger.org/en/latest/HowTo/Deploy/Ansible/).
- Added reference to [Besu role on Galaxy to deploy using Ansible](https://besu.hyperledger.org/en/latest/HowTo/Deploy/Ansible/).
### Technical Improvements
@ -2101,11 +2109,11 @@ Documentation updates include:
- Added Genesis file support for specifying the maximum stack size. [\#1431](https://github.com/PegaSysEng/pantheon/pull/1431)
- Included transaction details when subscribed to Pending transactions [\#1410](https://github.com/PegaSysEng/pantheon/pull/1410)
- Documentation updates include:
- [Added configuration items specified in the genesis file](https://besu.hyperledger.org/en/latest/Reference/Config-Items/#configuration-items)
- [Added configuration items specified in the genesis file](https://besu.hyperledger.org/en/latest/Reference/Config-Items/#configuration-items)
- [Added pending transaction details subscription](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/RPC-PubSub/#pending-transactionss)
- [Added Troubleshooting content](https://besu.hyperledger.org/en/latest/HowTo/Troubleshoot/Troubleshooting/)
- [Added Privacy Quickstart](https://besu.hyperledger.org/en/latest/Tutorials/Quickstarts/Privacy-Quickstart/)
- [Added privacy roadmap](https://github.com/hyperledger/besu/blob/master/ROADMAP.md)
- [Added Privacy Quickstart](https://besu.hyperledger.org/en/latest/Tutorials/Quickstarts/Privacy-Quickstart/)
- [Added privacy roadmap](https://github.com/hyperledger/besu/blob/master/ROADMAP.md)
### Technical Improvements
@ -2274,15 +2282,15 @@ Documentation updates include:
- Notify of dropped messages [\#1156](https://github.com/PegaSysEng/pantheon/pull/1156)
- Documentation updates include:
- Added [Permissioning Overview](https://besu.hyperledger.org/en/latest/Concepts/Permissioning/Permissioning-Overview/)
- Added content on [Network vs Node Configuration](https://besu.hyperledger.org/en/latest/HowTo/Configure/Using-Configuration-File/)
- Updated [RAM requirements](https://besu.hyperledger.org/en/latest/HowTo/Get-Started/System-Requirements/#ram)
- Added content on [Network vs Node Configuration](https://besu.hyperledger.org/en/latest/HowTo/Configure/Using-Configuration-File/)
- Updated [RAM requirements](https://besu.hyperledger.org/en/latest/HowTo/Get-Started/System-Requirements/#ram)
- Added [Privacy Overview](https://besu.hyperledger.org/en/latest/Concepts/Privacy/Privacy-Overview/) and [Processing Private Transactions](https://besu.hyperledger.org/en/latest/Concepts/Privacy/Private-Transaction-Processing/)
- Renaming of Ethstats Lite Explorer to [Ethereum Lite Explorer](https://besu.hyperledger.org/en/latest/HowTo/Deploy/Lite-Block-Explorer/#lite-block-explorer-documentation) (thanks to [tzapu](https://github.com/tzapu))
- Added content on using [Truffle with Besu](https://besu.hyperledger.org/en/latest/HowTo/Develop-Dapps/Truffle/)
- Added [`droppedPendingTransactions` RPC Pub/Sub subscription](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/RPC-PubSub/#dropped-transactions)
- Added [`eea_*` JSON-RPC API methods](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#eea-methods)
- Added [`eea_*` JSON-RPC API methods](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#eea-methods)
- Added [architecture diagram](https://besu.hyperledger.org/en/latest/Concepts/ArchitectureOverview/)
- Updated [permissioning CLI options](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#permissions-accounts-config-file-enabled) and [permissioned network tutorial](https://besu.hyperledger.org/en/stable/)
- Updated [permissioning CLI options](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#permissions-accounts-config-file-enabled) and [permissioned network tutorial](https://besu.hyperledger.org/en/stable/)
### Technical Improvements
@ -2349,18 +2357,18 @@ Documentation updates include:
- Added [Azure quickstart tutorial](https://besu.hyperledger.org/en/latest/Tutorials/Quickstarts/Azure-Private-Network-Quickstart/)
- Enabled copy button in code blocks
- Added [IBFT 1.0](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/QuorumIBFT/)
- Added section on using [Geth attach with Besu](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Using-JSON-RPC-API/#geth-console)
- Added section on using [Geth attach with Besu](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Using-JSON-RPC-API/#geth-console)
- Enabled the edit link doc site to ease external doc contributions
- Added [EthStats docs](https://besu.hyperledger.org/HowTo/Deploy/Lite-Network-Monitor/) (thanks to [baxy](https://github.com/baxy))
- Updated [Postman collection](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Authentication/#postman)
- Updated [Postman collection](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Authentication/#postman)
- Added [`metrics-category` CLI option](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#metrics-category)
- Added information on [block time and timeout settings](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/IBFT/#block-time) for IBFT 2.0
- Added [`admin_nodeInfo`](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#admin_nodeinfo)
- Added [permissions images](https://besu.hyperledger.org/en/latest/Concepts/Permissioning/Permissioning-Overview/)
- Added permissioning blog to [Resources](https://besu.hyperledger.org/en/latest/Reference/Resources/)
- Updated [Create Permissioned Network](https://besu.hyperledger.org/en/latest/Tutorials/Permissioning/Create-Permissioned-Network/) tutorial to use `export-address`
- Updated [Clique](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/Clique/) and [IBFT 2.0](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/IBFT/) docs to include complete genesis file
- Updated [Clique tutorial](https://besu.hyperledger.org/en/latest/Tutorials/Private-Network/Create-Private-Clique-Network/) to use `export-address` subcommand
- Updated [Clique](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/Clique/) and [IBFT 2.0](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/IBFT/) docs to include complete genesis file
- Updated [Clique tutorial](https://besu.hyperledger.org/en/latest/Tutorials/Private-Network/Create-Private-Clique-Network/) to use `export-address` subcommand
- Added IBFT 2.0 [future message configuration options](https://besu.hyperledger.org/en/latest/HowTo/Configure/Consensus-Protocols/IBFT/#optional-configuration-options)
### Technical Improvements
@ -2520,9 +2528,9 @@ Public key address export subcommand was missing in 1.0 release.
- Added rebind mitigation for Websockets. [\#905](https://github.com/PegaSysEng/pantheon/pull/905)
- Support genesis contract code [\#749](https://github.com/PegaSysEng/pantheon/pull/749) (thanks to [kziemianek](https://github.com/kziemianek)).
- Documentation updates include:
- Added details on [port configuration](https://besu.hyperledger.org/en/latest/HowTo/Find-and-Connect/Configuring-Ports/)
- Added details on [port configuration](https://besu.hyperledger.org/en/latest/HowTo/Find-and-Connect/Configuring-Ports/)
- Added [Resources page](https://besu.hyperledger.org/en/latest/Reference/Resources/) linking to Besu blog posts and webinars
- Added [JSON-RPC Authentication](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Authentication/)
- Added [JSON-RPC Authentication](https://besu.hyperledger.org/en/latest/HowTo/Interact/APIs/Authentication/)
- Added [tutorial to create permissioned network](https://besu.hyperledger.org/en/latest/Tutorials/Permissioning/Create-Permissioned-Network/)
- Added [Permissioning](https://besu.hyperledger.org/en/latest/Concepts/Permissioning/Permissioning-Overview/) content
- Added [Permissioning API methods](https://besu.hyperledger.org/en/latest/Reference/API-Methods/#permissioning-methods)
@ -2851,12 +2859,12 @@ To recover the node key and data directory from the Docker container:
Where `container` is the name or ID of the Docker container containing the Besu node.
The container can be running or stopped when you copy the key and data directory. If your node was
fully synchronized to MainNet, the data directory will be ~2TB.
fully synchronized to MainNet, the data directory will be ~2TB.
When restarting your node with the v0.8.4 Docker image:
* Save the node key in the [`key` file](https://besu.hyperledger.org/en/latest/Concepts/Node-Keys/#node-private-key) in the data
directory or specify the location using the [`--node-private-key` option](https://besu.hyperledger.org/en/stable/).
directory or specify the location using the [`--node-private-key` option](https://besu.hyperledger.org/en/stable/).
* Specify the `<destination_directory` as a [volume for the data directory](https://besu.hyperledger.org/en/stable/).
### Bug Fixes
@ -2877,7 +2885,7 @@ When restarting your node with the v0.8.4 Docker image:
- Added configurable refresh delay for SyncingSubscriptionService on start up [\#383](https://github.com/PegaSysEng/pantheon/pull/383)
- Added the Command Line Style Guide [\#530](https://github.com/PegaSysEng/pantheon/pull/530)
- Documentation updates include:
* Migrated to new [documentation site](https://docs.pantheon.pegasys.tech/en/latest/)
* Migrated to new [documentation site](https://docs.pantheon.pegasys.tech/en/latest/)
* Added [configuration file content](https://besu.hyperledger.org/en/stable/)
* Added [tutorial to create private network](https://besu.hyperledger.org/en/latest/Tutorials/Private-Network/Create-Private-Network/)
* Added content on [enabling non-default APIs](https://besu.hyperledger.org/en/latest/Reference/API-Methods/)
@ -2933,7 +2941,7 @@ From v0.8.3, incoming HTTP requests are only accepted from hostnames specified u
If using the URL `http://127.0.0.1` to make JSON-RPC calls, use `--host-whitelist` to specify the hostname `127.0.0.1` or update the hostname to `localhost`.
If your application publishes RPC ports, specify the hostnames when starting Besu. For example:
If your application publishes RPC ports, specify the hostnames when starting Besu. For example:
```bash
pantheon --host-whitelist=example.com

@ -28,6 +28,8 @@ jar {
}
dependencies {
implementation project(':datatypes')
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'org.apache.logging.log4j:log4j-api'

@ -17,6 +17,8 @@ package org.hyperledger.besu.config;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hyperledger.besu.config.JsonUtil.normalizeKeys;
import org.hyperledger.besu.datatypes.Wei;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@ -35,7 +37,7 @@ public class GenesisConfigFile {
public static final GenesisConfigFile DEFAULT =
new GenesisConfigFile(JsonUtil.createEmptyObjectNode());
public static final long BASEFEE_AT_GENESIS_DEFAULT_VALUE = 1000000000L;
public static final Wei BASEFEE_AT_GENESIS_DEFAULT_VALUE = Wei.of(1000000000L);
private final ObjectNode configRoot;
private GenesisConfigFile(final ObjectNode config) {
@ -137,12 +139,12 @@ public class GenesisConfigFile {
return parseLong("gasLimit", getFirstRequiredString("gaslimit", "gastarget"));
}
public Optional<Long> getBaseFeePerGas() {
public Optional<Wei> getBaseFeePerGas() {
return JsonUtil.getString(configRoot, "basefeepergas")
.map(baseFeeStr -> parseLong("baseFeePerGas", baseFeeStr));
.map(baseFeeStr -> Wei.of(parseLong("baseFeePerGas", baseFeeStr)));
}
public Optional<Long> getGenesisBaseFeePerGas() {
public Optional<Wei> getGenesisBaseFeePerGas() {
// if we have a base fee market at genesis, get either the configured baseFeePerGas, or the
// default
return getBaseFeePerGas()

@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.config;
import org.hyperledger.besu.datatypes.Wei;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
@ -81,7 +83,7 @@ public interface GenesisConfigOptions {
OptionalLong getArrowGlacierBlockNumber();
OptionalLong getBaseFeePerGas();
Optional<Wei> getBaseFeePerGas();
Optional<UInt256> getTerminalTotalDifficulty();

@ -17,6 +17,8 @@ package org.hyperledger.besu.config;
import static java.util.Collections.emptyMap;
import static java.util.Objects.isNull;
import org.hyperledger.besu.datatypes.Wei;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
@ -270,11 +272,12 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
}
@Override
public OptionalLong getBaseFeePerGas() {
public Optional<Wei> getBaseFeePerGas() {
return Optional.ofNullable(configOverrides.get("baseFeePerGas"))
.map(Long::parseLong)
.map(OptionalLong::of)
.orElse(OptionalLong.empty());
.map(Wei::of)
.map(Optional::of)
.orElse(Optional.empty());
}
@Override

@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.config;
import org.hyperledger.besu.datatypes.Wei;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
@ -41,7 +43,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong arrowGlacierBlockNumber = OptionalLong.empty();
private Optional<UInt256> terminalTotalDifficulty = Optional.empty();
private OptionalLong baseFeePerGas = OptionalLong.empty();
private Optional<Wei> baseFeePerGas = Optional.empty();
private OptionalLong classicForkBlock = OptionalLong.empty();
private OptionalLong ecip1015BlockNumber = OptionalLong.empty();
private OptionalLong diehardBlockNumber = OptionalLong.empty();
@ -194,7 +196,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
}
@Override
public OptionalLong getBaseFeePerGas() {
public Optional<Wei> getBaseFeePerGas() {
return baseFeePerGas;
}
@ -436,7 +438,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
}
public StubGenesisConfigOptions baseFeePerGas(final long baseFeeOverride) {
baseFeePerGas = OptionalLong.of(baseFeeOverride);
baseFeePerGas = Optional.of(Wei.of(baseFeeOverride));
return this;
}

@ -148,7 +148,7 @@ public class GenesisConfigFileTest {
GenesisConfigFile withBaseFeeAtGenesis =
GenesisConfigFile.fromConfig("{\"config\":{\"londonBlock\":0},\"baseFeePerGas\":\"0xa\"}");
assertThat(withBaseFeeAtGenesis.getBaseFeePerGas()).isPresent();
assertThat(withBaseFeeAtGenesis.getBaseFeePerGas().get()).isEqualTo(10L);
assertThat(withBaseFeeAtGenesis.getBaseFeePerGas().get().toLong()).isEqualTo(10L);
}
@Test
@ -167,7 +167,7 @@ public class GenesisConfigFileTest {
GenesisConfigFile withBaseFeeNotAtGenesis =
GenesisConfigFile.fromConfig("{\"config\":{\"londonBlock\":10},\"baseFeePerGas\":\"0xa\"}");
// specified baseFeePerGas:
assertThat(withBaseFeeNotAtGenesis.getBaseFeePerGas().get()).isEqualTo(10L);
assertThat(withBaseFeeNotAtGenesis.getBaseFeePerGas().get().toLong()).isEqualTo(10L);
// but no baseFeePerGas since london block is not at genesis:
assertThat(withBaseFeeNotAtGenesis.getGenesisBaseFeePerGas()).isNotPresent();
}
@ -176,7 +176,7 @@ public class GenesisConfigFileTest {
public void shouldOverrideConfigOptionsBaseFeeWhenSpecified() {
GenesisConfigOptions withOverrides =
EMPTY_CONFIG.getConfigOptions(Map.of("baseFeePerGas", "8"));
assertThat(withOverrides.getBaseFeePerGas().getAsLong()).isEqualTo(8L);
assertThat(withOverrides.getBaseFeePerGas().get().toLong()).isEqualTo(8L);
}
@Test

@ -92,7 +92,7 @@ public class CliqueBlockHashing {
out.writeBytes(extraDataSerializer.get());
out.writeBytes(header.getMixHash());
out.writeLong(header.getNonce());
header.getBaseFee().ifPresent(out::writeLongScalar);
header.getBaseFee().ifPresent(out::writeUInt256Scalar);
out.endList();
return out.encoded();
}

@ -141,7 +141,7 @@ public class CliqueProtocolScheduleTest {
// premature BaseFeeMarket block
BlockHeader emptyLondonBlock1 =
headerBuilder.baseFeePerGas(1000000000L).gasLimit(10000L).buildHeader();
headerBuilder.baseFeePerGas(Wei.of(1000000000L)).gasLimit(10000L).buildHeader();
// first BaseFeeMarket block
BlockHeader emptyLondonBlock2 =

@ -32,8 +32,6 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.STATE
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.TIMESTAMP;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.TOTAL_DIFFICULTY;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.TRANSACTION_ROOT;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
@ -94,7 +92,8 @@ public class JsonRpcResponseUtils {
final long gasUsed = unsignedLong(values.get(GAS_USED));
final long timestamp = unsignedLong(values.get(TIMESTAMP));
final long nonce = unsignedLong(values.get(NONCE));
final Long baseFee = values.containsKey(BASEFEE) ? unsignedLong(values.get(BASEFEE)) : null;
final Wei baseFee =
values.containsKey(BASEFEE) ? Wei.of(unsignedInt256(values.get(BASEFEE))) : null;
final Difficulty totalDifficulty = Difficulty.of(unsignedInt256(values.get(TOTAL_DIFFICULTY)));
final int size = unsignedInt(values.get(SIZE));
@ -148,7 +147,7 @@ public class JsonRpcResponseUtils {
final TransactionType transactionType,
final String blockHash,
final String blockNumber,
final Long baseFee,
final Wei baseFee,
final String fromAddress,
final String gas,
final String gasPrice,
@ -164,22 +163,16 @@ public class JsonRpcResponseUtils {
final String r,
final String s) {
final Transaction transaction = mock(Transaction.class);
when(transaction.getType()).thenReturn(transactionType);
when(transaction.getGasPrice()).thenReturn(Optional.of(Wei.fromHexString(gasPrice)));
when(transaction.getNonce()).thenReturn(unsignedLong(nonce));
when(transaction.getV()).thenReturn(bigInteger(v));
when(transaction.getR()).thenReturn(bigInteger(r));
when(transaction.getS()).thenReturn(bigInteger(s));
when(transaction.getHash()).thenReturn(hash(hash));
when(transaction.getTo()).thenReturn(Optional.ofNullable(address(toAddress)));
when(transaction.getSender()).thenReturn(address(fromAddress));
when(transaction.getPayload()).thenReturn(bytes(input));
when(transaction.getValue()).thenReturn(wei(value));
when(transaction.getGasLimit()).thenReturn(unsignedLong(gas));
when(transaction.getPublicKey()).thenReturn(Optional.ofNullable(publicKey));
when(transaction.getSignature())
.thenReturn(
final Transaction transaction =
new Transaction(
transactionType,
unsignedLong(nonce),
Optional.of(Wei.fromHexString(gasPrice)),
Optional.empty(),
Optional.empty(),
unsignedLong(gas),
Optional.ofNullable(address(toAddress)),
wei(value),
SignatureAlgorithmFactory.getInstance()
.createSignature(
Bytes.fromHexString(r).toUnsignedBigInteger(),
@ -187,7 +180,12 @@ public class JsonRpcResponseUtils {
Bytes.fromHexString(v)
.toUnsignedBigInteger()
.subtract(Transaction.REPLAY_UNPROTECTED_V_BASE)
.byteValueExact()));
.byteValueExact()),
bytes(input),
Optional.empty(),
address(fromAddress),
Optional.empty(),
Optional.of(bigInteger(v)));
return new TransactionCompleteResult(
new TransactionWithMetadata(

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import static java.util.stream.Collectors.toUnmodifiableList;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
@ -92,15 +93,15 @@ public class EthFeeHistory implements JsonRpcMethod {
.collect(toUnmodifiableList());
// we return the base fees for the blocks requested and 1 more because we can always compute it
final List<Long> explicitlyRequestedBaseFees =
final List<Wei> explicitlyRequestedBaseFees =
blockHeaders.stream()
.map(blockHeader -> blockHeader.getBaseFee().orElse(0L))
.map(blockHeader -> blockHeader.getBaseFee().orElse(Wei.ZERO))
.collect(toUnmodifiableList());
final long nextBlockNumber = resolvedHighestBlockNumber + 1;
final Long nextBaseFee =
final Wei nextBaseFee =
blockchain
.getBlockHeader(nextBlockNumber)
.map(blockHeader -> blockHeader.getBaseFee().orElse(0L))
.map(blockHeader -> blockHeader.getBaseFee().orElse(Wei.ZERO))
.orElseGet(
() ->
Optional.of(protocolSchedule.getByBlockNumber(nextBlockNumber).getFeeMarket())
@ -117,14 +118,14 @@ public class EthFeeHistory implements JsonRpcMethod {
lastBlockHeader.getGasUsed(),
feeMarket.targetGasUsed(lastBlockHeader));
})
.orElse(0L));
.orElse(Wei.ZERO));
final List<Double> gasUsedRatios =
blockHeaders.stream()
.map(blockHeader -> blockHeader.getGasUsed() / (double) blockHeader.getGasLimit())
.collect(toUnmodifiableList());
final Optional<List<List<Long>>> maybeRewards =
final Optional<List<List<Wei>>> maybeRewards =
maybeRewardPercentiles.map(
rewardPercentiles ->
LongStream.range(oldestBlock, oldestBlock + blockCount)
@ -150,17 +151,16 @@ public class EthFeeHistory implements JsonRpcMethod {
.build()));
}
private List<Long> computeRewards(final List<Double> rewardPercentiles, final Block block) {
private List<Wei> computeRewards(final List<Double> rewardPercentiles, final Block block) {
final List<Transaction> transactions = block.getBody().getTransactions();
if (transactions.isEmpty()) {
// all 0's for empty block
return LongStream.generate(() -> 0)
return Stream.generate(() -> Wei.ZERO)
.limit(rewardPercentiles.size())
.boxed()
.collect(toUnmodifiableList());
}
final Optional<Long> baseFee = block.getHeader().getBaseFee();
final Optional<Wei> baseFee = block.getHeader().getBaseFee();
// we need to get the gas used for the individual transactions and can't use the cumulative gas
// used because we're going to be reordering the transactions
@ -185,7 +185,7 @@ public class EthFeeHistory implements JsonRpcMethod {
// We need to weight the percentile of rewards by the gas used in the transaction.
// That's why we're keeping track of the cumulative gas used and checking to see which
// percentile markers we've passed
final ArrayList<Long> rewards = new ArrayList<>();
final ArrayList<Wei> rewards = new ArrayList<>();
int rewardPercentileIndex = 0;
long gasUsed = 0;
for (final Map.Entry<Transaction, Long> transactionAndGasUsed :

@ -16,6 +16,8 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;
import static java.util.stream.Collectors.toUnmodifiableList;
import org.hyperledger.besu.datatypes.Wei;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
@ -29,11 +31,11 @@ public interface FeeHistory {
long getOldestBlock();
List<Long> getBaseFeePerGas();
List<Wei> getBaseFeePerGas();
List<Double> getGasUsedRatio();
Optional<List<List<Long>>> getReward();
Optional<List<List<Wei>>> getReward();
@Value.Immutable
@Value.Style(allParameters = true)

@ -863,7 +863,7 @@ public class BlockchainQueries {
private List<TransactionWithMetadata> formatTransactions(
final List<Transaction> txs,
final long blockNumber,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Hash blockHash) {
final int count = txs.size();
final List<TransactionWithMetadata> result = new ArrayList<>(count);

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.api.query;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
@ -25,7 +26,7 @@ public class TransactionReceiptWithMetadata {
private final Hash transactionHash;
private final int transactionIndex;
private final long gasUsed;
private final Optional<Long> baseFee;
private final Optional<Wei> baseFee;
private final long blockNumber;
private final Hash blockHash;
private final Transaction transaction;
@ -36,7 +37,7 @@ public class TransactionReceiptWithMetadata {
final Hash transactionHash,
final int transactionIndex,
final long gasUsed,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Hash blockHash,
final long blockNumber) {
this.receipt = receipt;
@ -55,7 +56,7 @@ public class TransactionReceiptWithMetadata {
final Hash transactionHash,
final int transactionIndex,
final long gasUsed,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Hash blockHash,
final long blockNumber) {
return new TransactionReceiptWithMetadata(
@ -99,7 +100,7 @@ public class TransactionReceiptWithMetadata {
return gasUsed;
}
public Optional<Long> getBaseFee() {
public Optional<Wei> getBaseFee() {
return baseFee;
}
}

@ -17,6 +17,7 @@
package org.hyperledger.besu.ethereum.api.query;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import java.util.Optional;
@ -25,7 +26,7 @@ public class TransactionWithMetadata {
private final Transaction transaction;
private final Optional<Long> blockNumber;
private final Optional<Long> baseFee;
private final Optional<Wei> baseFee;
private final Optional<Hash> blockHash;
private final Optional<Integer> transactionIndex;
@ -40,7 +41,7 @@ public class TransactionWithMetadata {
public TransactionWithMetadata(
final Transaction transaction,
final long blockNumber,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Hash blockHash,
final int transactionIndex) {
this.transaction = transaction;
@ -58,7 +59,7 @@ public class TransactionWithMetadata {
return blockNumber;
}
public Optional<Long> getBaseFee() {
public Optional<Wei> getBaseFee() {
return baseFee;
}

@ -1698,7 +1698,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
final Transaction transaction,
final Integer index,
final Hash blockHash,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Long blockNumber) {
assertThat(Hash.fromHexString(result.getString("hash"))).isEqualTo(transaction.getHash());
assertThat(Long.decode(result.getString("nonce"))).isEqualByComparingTo(transaction.getNonce());

@ -226,7 +226,7 @@ public class EthCallTest {
@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToTrueWhenGasPriceIsZeroAfterEIP1559() {
JsonCallParameter callParameters = callParameter(Wei.ZERO, null, null);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(1L), true);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(Wei.ONE), true);
}
@Test
@ -238,24 +238,24 @@ public class EthCallTest {
@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToFalseWhenGasPriceIsNotZeroAfterEIP1559() {
JsonCallParameter callParameters = callParameter(Wei.ONE, null, null);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(1L), false);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(Wei.ONE), false);
}
@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToTrueWhenFeesAreZero() {
JsonCallParameter callParameters = callParameter(null, Wei.ZERO, Wei.ZERO);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(1L), true);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(Wei.ONE), true);
}
@Test
public void shouldAutoSelectIsAllowedExeceedingBalanceToFalseWhenFeesAreZero() {
JsonCallParameter callParameters = callParameter(null, Wei.ONE, Wei.ONE);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(1L), false);
internalAutoSelectIsAllowedExeecdBalance(callParameters, Optional.of(Wei.ONE), false);
}
private void internalAutoSelectIsAllowedExeecdBalance(
final JsonCallParameter callParameter,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final boolean isAllowedExeedingBalance) {
final JsonRpcRequestContext request = ethCallRequest(callParameter, "latest");

@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
@ -90,9 +91,9 @@ public class EthFeeHistoryTest {
FeeHistory.FeeHistoryResult.from(
ImmutableFeeHistory.builder()
.oldestBlock(10)
.baseFeePerGas(List.of(25496L, 28683L))
.baseFeePerGas(List.of(Wei.of(25496L), Wei.of(28683L)))
.gasUsedRatio(List.of(0.9999999992132459))
.reward(List.of(List.of(1524763764L)))
.reward(List.of(List.of(Wei.of(1524763764L))))
.build()));
}
@ -142,7 +143,7 @@ public class EthFeeHistoryTest {
final FeeHistory.FeeHistoryResult result =
(FeeHistory.FeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest(1, "latest")).getResult();
assertThat(Long.decode(result.getBaseFeePerGas().get(1)))
assertThat(Wei.fromHexString(result.getBaseFeePerGas().get(1)))
.isEqualTo(FeeMarket.london(11).getInitialBasefee());
}

@ -158,7 +158,7 @@ public class EthGasPriceTest {
0,
0,
Bytes.EMPTY,
0L,
Wei.ZERO,
Hash.EMPTY,
0,
null),
@ -194,7 +194,7 @@ public class EthGasPriceTest {
0,
0,
Bytes.EMPTY,
0L,
Wei.ZERO,
Hash.EMPTY,
0,
null),

@ -46,6 +46,7 @@ import java.util.Collections;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256s;
import org.junit.Test;
public class EthGetTransactionReceiptTest {
@ -185,7 +186,7 @@ public class EthGetTransactionReceiptTest {
when(blockchain.headBlockNumber()).thenReturn(1L);
final Transaction transaction1559 =
new BlockDataGenerator().transaction(TransactionType.EIP1559);
final long baseFee = 1L;
final Wei baseFee = Wei.ONE;
final TransactionReceiptWithMetadata transactionReceiptWithMetadata =
TransactionReceiptWithMetadata.create(
statusReceipt, transaction1559, hash, 1, 2, Optional.of(baseFee), blockHash, 4);
@ -199,10 +200,10 @@ public class EthGetTransactionReceiptTest {
(TransactionReceiptStatusResult) response.getResult();
assertThat(result.getStatus()).isEqualTo("0x1");
assertThat(Long.decode(result.getEffectiveGasPrice()))
assertThat(Wei.fromHexString(result.getEffectiveGasPrice()))
.isEqualTo(
Math.min(
baseFee + transaction1559.getMaxPriorityFeePerGas().get().toLong(),
transaction1559.getMaxFeePerGas().get().toLong()));
UInt256s.min(
baseFee.add(transaction1559.getMaxPriorityFeePerGas().get()),
transaction1559.getMaxFeePerGas().get()));
}
}

@ -22,6 +22,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
@ -109,7 +110,7 @@ public class EthGetUncleByBlockNumberAndIndexTest {
public void shouldReturnExpectedBlockResult() {
final JsonRpcRequestContext request =
getUncleByBlockNumberAndIndex(new Object[] {"0x1", "0x0"});
final BlockHeader header = blockHeaderTestFixture.baseFeePerGas(7L).buildHeader();
final BlockHeader header = blockHeaderTestFixture.baseFeePerGas(Wei.of(7L)).buildHeader();
final BlockResult expectedBlockResult = blockResult(header);
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, expectedBlockResult);

@ -45,7 +45,7 @@ public class TransactionCompleteResultTest {
.maxPriorityFeePerGas(Optional.of(Wei.ZERO))
.createTransaction(gen.generateKeyPair()),
0L,
Optional.of(7L),
Optional.of(Wei.of(7L)),
Hash.ZERO,
0));
@ -59,12 +59,12 @@ public class TransactionCompleteResultTest {
final Transaction transaction = gen.transaction(TransactionType.EIP1559);
TransactionCompleteResult tcr =
new TransactionCompleteResult(
new TransactionWithMetadata(transaction, 0L, Optional.of(7L), Hash.ZERO, 0));
new TransactionWithMetadata(transaction, 0L, Optional.of(Wei.of(7L)), Hash.ZERO, 0));
assertThat(tcr.getMaxFeePerGas()).isNotEmpty();
assertThat(tcr.getMaxPriorityFeePerGas()).isNotEmpty();
assertThat(tcr.getGasPrice()).isNotEmpty();
assertThat(tcr.getGasPrice())
.isEqualTo(Quantity.create(transaction.getEffectiveGasPrice(Optional.of(7L))));
.isEqualTo(Quantity.create(transaction.getEffectiveGasPrice(Optional.of(Wei.of(7L)))));
}
@Test
@ -73,7 +73,7 @@ public class TransactionCompleteResultTest {
final Transaction transaction = gen.transaction(TransactionType.FRONTIER);
TransactionCompleteResult tcr =
new TransactionCompleteResult(
new TransactionWithMetadata(transaction, 0L, Optional.of(7L), Hash.ZERO, 0));
new TransactionWithMetadata(transaction, 0L, Optional.of(Wei.of(7L)), Hash.ZERO, 0));
assertThat(tcr.getMaxFeePerGas()).isNull();
assertThat(tcr.getMaxPriorityFeePerGas()).isNull();
assertThat(tcr.getGasPrice()).isNotEmpty();

@ -266,7 +266,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
final BigInteger difficulty =
difficultyCalculator.nextDifficulty(timestamp, parentHeader, protocolContext);
final Long baseFee =
final Wei baseFee =
Optional.of(protocolSpec.getFeeMarket())
.filter(FeeMarket::implementsBaseFee)
.map(BaseFeeMarket.class::cast)
@ -274,7 +274,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
feeMarket ->
feeMarket.computeBaseFee(
newBlockNumber,
parentHeader.getBaseFee().orElse(0L),
parentHeader.getBaseFee().orElse(Wei.ZERO),
parentHeader.getGasUsed(),
feeMarket.targetGasUsed(parentHeader)))
.orElse(null);

@ -118,7 +118,7 @@ public class BlockTransactionSelectorTest {
.number(1)
.gasLimit(gasLimit)
.timestamp(Instant.now().toEpochMilli())
.baseFee(1L)
.baseFee(Wei.ONE)
.buildProcessableBlockHeader();
}
@ -342,7 +342,7 @@ public class BlockTransactionSelectorTest {
metricsSystem,
() -> {
final BlockHeader mockBlockHeader = mock(BlockHeader.class);
when(mockBlockHeader.getBaseFee()).thenReturn(Optional.of(1L));
when(mockBlockHeader.getBaseFee()).thenReturn(Optional.of(Wei.ONE));
return mockBlockHeader;
},
TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
@ -58,7 +59,7 @@ public class BlockHeader extends SealableBlockHeader
final long gasUsed,
final long timestamp,
final Bytes extraData,
final Long baseFee,
final Wei baseFee,
final Bytes32 mixHashOrRandom,
final long nonce,
final BlockHeaderFunctions blockHeaderFunctions,
@ -99,7 +100,7 @@ public class BlockHeader extends SealableBlockHeader
final long gasUsed,
final long timestamp,
final Bytes extraData,
final Long baseFee,
final Wei baseFee,
final Bytes32 mixHashOrRandom,
final long nonce,
final BlockHeaderFunctions blockHeaderFunctions) {
@ -217,7 +218,7 @@ public class BlockHeader extends SealableBlockHeader
out.writeBytes(mixHashOrRandom);
out.writeLong(nonce);
if (baseFee != null) {
out.writeLongScalar(baseFee);
out.writeUInt256Scalar(baseFee);
}
out.endList();
}
@ -240,7 +241,7 @@ public class BlockHeader extends SealableBlockHeader
final Bytes extraData = input.readBytes();
final Bytes32 mixHashOrRandom = input.readBytes32();
final long nonce = input.readLong();
final Long baseFee = !input.isEndOfCurrentList() ? input.readLongScalar() : null;
final Wei baseFee = !input.isEndOfCurrentList() ? Wei.of(input.readUInt256Scalar()) : null;
input.leaveList();
return new BlockHeader(
parentHash,
@ -320,7 +321,7 @@ public class BlockHeader extends SealableBlockHeader
pluginBlockHeader.getGasUsed(),
pluginBlockHeader.getTimestamp(),
pluginBlockHeader.getExtraData(),
pluginBlockHeader.getBaseFee().orElse(null),
pluginBlockHeader.getBaseFee().map(Wei::fromQuantity).orElse(null),
pluginBlockHeader.getRandom().orElse(null),
pluginBlockHeader.getNonce(),
blockHeaderFunctions);

@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkState;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
import java.time.Instant;
@ -57,7 +58,7 @@ public class BlockHeaderBuilder {
private Bytes extraData;
private Long baseFee = null;
private Wei baseFee = null;
private Bytes32 mixHashOrRandom = null;
@ -321,7 +322,7 @@ public class BlockHeaderBuilder {
return this;
}
public BlockHeaderBuilder baseFee(final Long baseFee) {
public BlockHeaderBuilder baseFee(final Wei baseFee) {
this.baseFee = baseFee;
return this;
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.frame.BlockValues;
import java.util.Optional;
@ -39,7 +40,7 @@ public class ProcessableBlockHeader implements BlockValues {
// The block creation timestamp (seconds since the unix epoch)
protected final long timestamp;
// base fee is included for post EIP-1559 blocks
protected final Long baseFee;
protected final Wei baseFee;
// random is included for post-merge blocks
protected final Bytes32 mixHashOrRandom;
@ -50,7 +51,7 @@ public class ProcessableBlockHeader implements BlockValues {
final long number,
final long gasLimit,
final long timestamp,
final Long baseFee,
final Wei baseFee,
final Bytes32 mixHashOrRandom) {
this.parentHash = parentHash;
this.coinbase = coinbase;
@ -135,7 +136,7 @@ public class ProcessableBlockHeader implements BlockValues {
* @return the optional long value for base fee
*/
@Override
public Optional<Long> getBaseFee() {
public Optional<Wei> getBaseFee() {
return Optional.ofNullable(baseFee);
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
import org.apache.tuweni.bytes.Bytes;
@ -51,7 +52,7 @@ public class SealableBlockHeader extends ProcessableBlockHeader {
final long gasUsed,
final long timestamp,
final Bytes extraData,
final Long baseFee,
final Wei baseFee,
final Bytes32 mixHashOrRandom) {
super(parentHash, coinbase, difficulty, number, gasLimit, timestamp, baseFee, mixHashOrRandom);
this.ommersHash = ommersHash;

@ -46,6 +46,7 @@ import java.util.stream.Stream;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import org.apache.tuweni.units.bigints.UInt256s;
/** An operation submitted by an external actor to be applied to the system. */
public class Transaction
@ -383,7 +384,7 @@ public class Transaction
* Boolean which indicates the transaction has associated cost data, whether gas price or 1559 fee
* market parameters.
*
* @return whether cost params are presetn
* @return whether cost params are present
*/
public boolean hasCostParams() {
return Arrays.asList(getGasPrice(), getMaxFeePerGas(), getMaxPriorityFeePerGas()).stream()
@ -392,22 +393,24 @@ public class Transaction
.anyMatch(q -> q.longValue() > 0L);
}
public long getEffectivePriorityFeePerGas(final Optional<Long> maybeBaseFee) {
public Wei getEffectivePriorityFeePerGas(final Optional<Wei> maybeBaseFee) {
return maybeBaseFee
.map(
baseFee -> {
if (getType().supports1559FeeMarket()) {
return Math.min(
getMaxPriorityFeePerGas().get().getAsBigInteger().longValue(),
getMaxFeePerGas().get().getAsBigInteger().longValue() - baseFee);
if (baseFee.greaterOrEqualThan(getMaxFeePerGas().get())) {
return Wei.ZERO;
}
return UInt256s.min(
getMaxPriorityFeePerGas().get(), getMaxFeePerGas().get().subtract(baseFee));
} else {
return getGasPrice().get().getValue().longValue() - baseFee;
if (baseFee.greaterOrEqualThan(getGasPrice().get())) {
return Wei.ZERO;
}
return getGasPrice().get().subtract(baseFee);
}
})
.map(
maybeNegativeEffectivePriorityFeePerGas ->
Math.max(0, maybeNegativeEffectivePriorityFeePerGas))
.orElseGet(() -> getGasPrice().map(Wei::getValue).map(Number::longValue).orElse(0L));
.orElseGet(() -> getGasPrice().orElse(Wei.ZERO));
}
/**
* Returns the transaction gas limit.
@ -1051,7 +1054,7 @@ public class Transaction
* @param baseFeePerGas optional baseFee from the block header, if we are post-london
* @return the effective gas price.
*/
public final Wei getEffectiveGasPrice(final Optional<Long> baseFeePerGas) {
return Wei.of(getEffectivePriorityFeePerGas(baseFeePerGas) + baseFeePerGas.orElse(0L));
public final Wei getEffectiveGasPrice(final Optional<Wei> baseFeePerGas) {
return getEffectivePriorityFeePerGas(baseFeePerGas).add(baseFeePerGas.orElse(Wei.ZERO));
}
}

@ -14,34 +14,35 @@
*/
package org.hyperledger.besu.ethereum.core.feemarket;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
public class BaseFee {
private final long value;
private final long delta;
private final long minNextValue;
private final long maxNextValue;
private final Wei value;
private final Wei delta;
private final Wei minNextValue;
private final Wei maxNextValue;
public BaseFee(final BaseFeeMarket feeMarket, final long value) {
public BaseFee(final BaseFeeMarket feeMarket, final Wei value) {
this.value = value;
this.delta = Math.floorDiv(value, feeMarket.getBasefeeMaxChangeDenominator());
this.minNextValue = value - delta;
this.maxNextValue = value + delta;
this.delta = value.divide(feeMarket.getBasefeeMaxChangeDenominator());
this.minNextValue = value.subtract(delta);
this.maxNextValue = value.add(delta);
}
public long getValue() {
public Wei getValue() {
return value;
}
public long getDelta() {
public Wei getDelta() {
return delta;
}
public long getMinNextValue() {
public Wei getMinNextValue() {
return minNextValue;
}
public long getMaxNextValue() {
public Wei getMaxNextValue() {
return maxNextValue;
}
}

@ -21,7 +21,7 @@ import java.util.Optional;
@FunctionalInterface
public interface CoinbaseFeePriceCalculator {
Wei price(Gas coinbaseFee, Wei transactionGasPrice, Optional<Long> baseFee);
Wei price(Gas coinbaseFee, Wei transactionGasPrice, Optional<Wei> baseFee);
static CoinbaseFeePriceCalculator frontier() {
return (coinbaseFee, transactionGasPrice, baseFee) -> coinbaseFee.priceFor(transactionGasPrice);
@ -29,7 +29,7 @@ public interface CoinbaseFeePriceCalculator {
static CoinbaseFeePriceCalculator eip1559() {
return (coinbaseFee, transactionGasPrice, baseFee) -> {
return coinbaseFee.priceFor(transactionGasPrice.subtract(Wei.of(baseFee.orElseThrow())));
return coinbaseFee.priceFor(transactionGasPrice.subtract(baseFee.orElseThrow()));
};
}
}

@ -21,7 +21,7 @@ import java.util.Optional;
@FunctionalInterface
public interface TransactionPriceCalculator {
Wei price(Transaction transaction, Optional<Long> baseFee);
Wei price(Transaction transaction, Optional<Wei> baseFee);
static TransactionPriceCalculator frontier() {
return (transaction, baseFee) -> transaction.getGasPrice().orElse(Wei.ZERO);
@ -29,7 +29,7 @@ public interface TransactionPriceCalculator {
static TransactionPriceCalculator eip1559() {
return (transaction, maybeBaseFee) -> {
final Wei baseFee = Wei.of(maybeBaseFee.orElseThrow());
final Wei baseFee = maybeBaseFee.orElseThrow();
if (!transaction.getType().supports1559FeeMarket()) {
return transaction.getGasPrice().orElse(Wei.ZERO);
}

@ -59,9 +59,9 @@ public class BaseFeeBlockBodyValidator extends MainnetBlockBodyValidator {
.getTransactionPriceCalculator();
for (final Transaction transaction : transactions) {
final Optional<Long> baseFee = block.getHeader().getBaseFee();
final Optional<Wei> baseFee = block.getHeader().getBaseFee();
final Wei price = transactionPriceCalculator.price(transaction, baseFee);
if (price.compareTo(Wei.of(baseFee.orElseThrow())) < 0) {
if (price.compareTo(baseFee.orElseThrow()) < 0) {
LOG.warn(
"Invalid block: transaction gas price {} must be greater than base fee {}",
price.toString(),

@ -188,7 +188,7 @@ public final class EthHash {
out.writeLongScalar(header.getTimestamp());
out.writeBytes(header.getExtraData());
if (header.getBaseFee().isPresent()) {
out.writeLongScalar(header.getBaseFee().get());
out.writeUInt256Scalar(header.getBaseFee().get());
}
out.endList();
return Bytes32.wrap(

@ -425,7 +425,7 @@ public class MainnetTransactionProcessor {
final var coinbase = worldState.getOrCreate(miningBeneficiary).getMutable();
final Gas coinbaseFee = Gas.of(transaction.getGasLimit()).minus(refunded);
if (blockHeader.getBaseFee().isPresent()) {
final Wei baseFee = Wei.of(blockHeader.getBaseFee().get());
final Wei baseFee = blockHeader.getBaseFee().get();
if (transactionGasPrice.compareTo(baseFee) < 0) {
return TransactionProcessingResult.failed(
gasUsedByTransaction.toLong(),

@ -105,7 +105,7 @@ public class MainnetTransactionValidator {
*/
public ValidationResult<TransactionInvalidReason> validate(
final Transaction transaction,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final TransactionValidationParams transactionValidationParams) {
final ValidationResult<TransactionInvalidReason> signatureResult =
validateTransactionSignature(transaction);
@ -131,7 +131,7 @@ public class MainnetTransactionValidator {
if (baseFee.isPresent()) {
final Wei price = feeMarket.getTransactionPriceCalculator().price(transaction, baseFee);
if (!transactionValidationParams.isAllowMaxFeeGasBelowBaseFee()
&& price.compareTo(Wei.of(baseFee.orElseThrow())) < 0) {
&& price.compareTo(baseFee.orElseThrow()) < 0) {
return ValidationResult.invalid(
TransactionInvalidReason.INVALID_TRANSACTION_FORMAT,
"gasPrice is less than the current BaseFee");

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.mainnet.feemarket;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
public interface BaseFeeMarket extends FeeMarket {
@ -25,7 +26,7 @@ public interface BaseFeeMarket extends FeeMarket {
long getBasefeeMaxChangeDenominator();
long getInitialBasefee();
Wei getInitialBasefee();
long getSlackCoefficient();
@ -40,9 +41,9 @@ public interface BaseFeeMarket extends FeeMarket {
return blockHeader.getGasLimit() / getSlackCoefficient();
}
long computeBaseFee(
Wei computeBaseFee(
final long blockNumber,
final long parentBaseFee,
final Wei parentBaseFee,
final long parentBlockGasUsed,
final long targetGasUsed);

@ -19,7 +19,6 @@ import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.feemarket.TransactionPriceCalculator;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.function.Supplier;
public interface FeeMarket {
@ -31,14 +30,14 @@ public interface FeeMarket {
TransactionPriceCalculator getTransactionPriceCalculator();
Wei minTransactionPriceInNextBlock(
Transaction transaction, Supplier<Optional<Long>> baseFeeSupplier);
Transaction transaction, Supplier<Optional<Wei>> baseFeeSupplier);
static BaseFeeMarket london(final long londonForkBlockNumber) {
return london(londonForkBlockNumber, OptionalLong.empty());
return london(londonForkBlockNumber, Optional.empty());
}
static BaseFeeMarket london(
final long londonForkBlockNumber, final OptionalLong baseFeePerGasOverride) {
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
return new LondonFeeMarket(londonForkBlockNumber, baseFeePerGasOverride);
}

@ -36,7 +36,7 @@ public class LegacyFeeMarket implements FeeMarket {
@Override
public Wei minTransactionPriceInNextBlock(
final Transaction transaction, final Supplier<Optional<Long>> baseFeeSupplier) {
final Transaction transaction, final Supplier<Optional<Wei>> baseFeeSupplier) {
return txPriceCalculator.price(transaction, Optional.empty());
}
}

@ -14,39 +14,36 @@
*/
package org.hyperledger.besu.ethereum.mainnet.feemarket;
import static java.lang.Math.max;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.feemarket.BaseFee;
import org.hyperledger.besu.ethereum.core.feemarket.TransactionPriceCalculator;
import java.math.BigInteger;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.units.bigints.UInt256s;
public class LondonFeeMarket implements BaseFeeMarket {
static final long DEFAULT_BASEFEE_INITIAL_VALUE =
static final Wei DEFAULT_BASEFEE_INITIAL_VALUE =
GenesisConfigFile.BASEFEE_AT_GENESIS_DEFAULT_VALUE;
static final long DEFAULT_BASEFEE_MAX_CHANGE_DENOMINATOR = 8L;
static final long DEFAULT_SLACK_COEFFICIENT = 2L;
private static final Logger LOG = LogManager.getLogger();
private final long baseFeeInitialValue;
private final Wei baseFeeInitialValue;
private final long londonForkBlockNumber;
private final TransactionPriceCalculator txPriceCalculator;
public LondonFeeMarket(final long londonForkBlockNumber) {
this(londonForkBlockNumber, OptionalLong.empty());
this(londonForkBlockNumber, Optional.empty());
}
public LondonFeeMarket(
final long londonForkBlockNumber, final OptionalLong baseFeePerGasOverride) {
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
this.txPriceCalculator = TransactionPriceCalculator.eip1559();
this.londonForkBlockNumber = londonForkBlockNumber;
this.baseFeeInitialValue = baseFeePerGasOverride.orElse(DEFAULT_BASEFEE_INITIAL_VALUE);
@ -58,7 +55,7 @@ public class LondonFeeMarket implements BaseFeeMarket {
}
@Override
public long getInitialBasefee() {
public Wei getInitialBasefee() {
return baseFeeInitialValue;
}
@ -74,43 +71,40 @@ public class LondonFeeMarket implements BaseFeeMarket {
@Override
public Wei minTransactionPriceInNextBlock(
final Transaction transaction, final Supplier<Optional<Long>> baseFeeSupplier) {
final Optional<Long> baseFee = baseFeeSupplier.get();
Optional<Long> minBaseFeeInNextBlock =
final Transaction transaction, final Supplier<Optional<Wei>> baseFeeSupplier) {
final Optional<Wei> baseFee = baseFeeSupplier.get();
Optional<Wei> minBaseFeeInNextBlock =
baseFee.map(bf -> new BaseFee(this, bf).getMinNextValue());
return this.getTransactionPriceCalculator().price(transaction, minBaseFeeInNextBlock);
}
@Override
public long computeBaseFee(
public Wei computeBaseFee(
final long blockNumber,
final long parentBaseFee,
final Wei parentBaseFee,
final long parentBlockGasUsed,
final long targetGasUsed) {
if (londonForkBlockNumber == blockNumber) {
return getInitialBasefee();
}
long gasDelta, feeDelta, baseFee;
long gasDelta;
Wei feeDelta, baseFee;
if (parentBlockGasUsed == targetGasUsed) {
return parentBaseFee;
} else if (parentBlockGasUsed > targetGasUsed) {
gasDelta = parentBlockGasUsed - targetGasUsed;
final BigInteger pBaseFee = BigInteger.valueOf(parentBaseFee);
final BigInteger gDelta = BigInteger.valueOf(gasDelta);
final BigInteger target = BigInteger.valueOf(targetGasUsed);
final BigInteger denominator = BigInteger.valueOf(getBasefeeMaxChangeDenominator());
feeDelta = max(pBaseFee.multiply(gDelta).divide(target).divide(denominator).longValue(), 1);
baseFee = parentBaseFee + feeDelta;
final long denominator = getBasefeeMaxChangeDenominator();
feeDelta =
UInt256s.max(
parentBaseFee.multiply(gasDelta).divide(targetGasUsed).divide(denominator), Wei.ONE);
baseFee = parentBaseFee.add(feeDelta);
} else {
gasDelta = targetGasUsed - parentBlockGasUsed;
final BigInteger pBaseFee = BigInteger.valueOf(parentBaseFee);
final BigInteger gDelta = BigInteger.valueOf(gasDelta);
final BigInteger target = BigInteger.valueOf(targetGasUsed);
final BigInteger denominator = BigInteger.valueOf(getBasefeeMaxChangeDenominator());
feeDelta = pBaseFee.multiply(gDelta).divide(target).divide(denominator).longValue();
baseFee = parentBaseFee - feeDelta;
final long denominator = getBasefeeMaxChangeDenominator();
feeDelta = parentBaseFee.multiply(gasDelta).divide(targetGasUsed).divide(denominator);
baseFee = parentBaseFee.subtract(feeDelta);
}
LOG.trace(
"block #{} parentBaseFee: {} parentGasUsed: {} parentGasTarget: {} baseFee: {}",

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet.headervalidationrules;
import static org.hyperledger.besu.ethereum.core.feemarket.FeeMarketException.MissingBaseFeeFromBlockHeader;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.feemarket.FeeMarketException;
import org.hyperledger.besu.ethereum.mainnet.DetachedBlockHeaderValidationRule;
@ -39,19 +40,20 @@ public class BaseFeeMarketBlockHeaderGasPriceValidationRule
// if this is the fork block, baseFee should be the initial baseFee
if (baseFeeMarket.isForkBlock(header.getNumber())) {
return baseFeeMarket.getInitialBasefee()
== header.getBaseFee().orElseThrow(() -> MissingBaseFeeFromBlockHeader());
return baseFeeMarket
.getInitialBasefee()
.equals(header.getBaseFee().orElseThrow(() -> MissingBaseFeeFromBlockHeader()));
}
final Long parentBaseFee =
final Wei parentBaseFee =
parent.getBaseFee().orElseThrow(() -> MissingBaseFeeFromBlockHeader());
final Long currentBaseFee =
final Wei currentBaseFee =
header.getBaseFee().orElseThrow(() -> MissingBaseFeeFromBlockHeader());
final long targetGasUsed = baseFeeMarket.targetGasUsed(parent);
final long expectedBaseFee =
final Wei expectedBaseFee =
baseFeeMarket.computeBaseFee(
header.getNumber(), parentBaseFee, parent.getGasUsed(), targetGasUsed);
if (expectedBaseFee != currentBaseFee) {
if (!expectedBaseFee.equals(currentBaseFee)) {
LOG.info(
"Invalid block header: basefee {} does not equal expected basefee {}",
header.getBaseFee().orElseThrow(),

@ -125,7 +125,7 @@ public final class ProofOfWorkValidationRule implements DetachedBlockHeaderValid
out.writeLongScalar(header.getTimestamp());
out.writeBytes(header.getExtraData());
if (imlementsBaseFeeMarket() && header.getBaseFee().isPresent()) {
out.writeLongScalar(header.getBaseFee().get());
out.writeUInt256Scalar(header.getBaseFee().get());
}
out.endList();

@ -164,7 +164,7 @@ public class TransactionSimulator {
if (header.getBaseFee().isPresent()) {
blockHeaderToProcess =
BlockHeaderBuilder.fromHeader(header)
.baseFee(0L)
.baseFee(Wei.ZERO)
.blockHeaderFunctions(protocolSpec.getBlockHeaderFunctions())
.buildBlockHeader();
}

@ -305,7 +305,7 @@ public class BlockDataGenerator {
.nonce(blockNonce)
.blockHeaderFunctions(
options.getBlockHeaderFunctions(new MainnetBlockHeaderFunctions()));
options.getBaseFee(Optional.of(uint256(2).toLong())).ifPresent(blockHeaderBuilder::baseFee);
options.getBaseFee(Optional.of(Wei.of(uint256(2)))).ifPresent(blockHeaderBuilder::baseFee);
return blockHeaderBuilder.buildBlockHeader();
}
@ -629,7 +629,7 @@ public class BlockDataGenerator {
private boolean hasTransactions = true;
private TransactionType[] transactionTypes = TransactionType.values();
private Optional<Address> coinbase = Optional.empty();
private Optional<Optional<Long>> maybeBaseFee = Optional.empty();
private Optional<Optional<Wei>> maybeBaseFee = Optional.empty();
public static BlockOptions create() {
return new BlockOptions();
@ -783,11 +783,11 @@ public class BlockDataGenerator {
return coinbase.orElse(defaultValue);
}
public Optional<Long> getBaseFee(final Optional<Long> defaultValue) {
public Optional<Wei> getBaseFee(final Optional<Wei> defaultValue) {
return maybeBaseFee.orElse(defaultValue);
}
public BlockOptions setBaseFee(final Optional<Long> baseFee) {
public BlockOptions setBaseFee(final Optional<Wei> baseFee) {
this.maybeBaseFee = Optional.of(baseFee);
return this;
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
@ -39,7 +40,7 @@ public class BlockHeaderTestFixture {
private long number = 0;
private long gasLimit = 0;
private Optional<Long> baseFee = Optional.empty();
private Optional<Wei> baseFee = Optional.empty();
private Optional<Bytes32> random = Optional.empty();
private long gasUsed = 0;
private long timestamp = 0;
@ -128,8 +129,8 @@ public class BlockHeaderTestFixture {
return this;
}
public BlockHeaderTestFixture baseFeePerGas(final long baseFee) {
this.baseFee = Optional.ofNullable(baseFee);
public BlockHeaderTestFixture baseFeePerGas(final Wei baseFee) {
this.baseFee = Optional.of(baseFee);
return this;
}

@ -79,7 +79,7 @@ public class LogRollingTests {
0,
0,
Bytes.EMPTY,
0L,
Wei.ZERO,
Hash.ZERO,
0,
new MainnetBlockHeaderFunctions());
@ -98,7 +98,7 @@ public class LogRollingTests {
0,
0,
Bytes.EMPTY,
0L,
Wei.ZERO,
Hash.ZERO,
0,
new MainnetBlockHeaderFunctions());

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.core.feemarket;
import static com.google.common.base.Preconditions.checkState;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
@ -65,16 +66,16 @@ public class BaseFeeMarketBaseFeeTest {
}
}
private final long parentBaseFee;
private final Wei parentBaseFee;
private final long parentGasUsed;
private final long parentTargetGasUsed;
private final long expectedBaseFee;
private final Wei expectedBaseFee;
public BaseFeeMarketBaseFeeTest(
final long parentBaseFee,
final Wei parentBaseFee,
final long parentGasUsed,
final long parentTargetGasUsed,
final long expectedBaseFee) {
final Wei expectedBaseFee) {
this.parentBaseFee = parentBaseFee;
this.parentGasUsed = parentGasUsed;
this.parentTargetGasUsed = parentTargetGasUsed;
@ -90,25 +91,25 @@ public class BaseFeeMarketBaseFeeTest {
private static class BaseFeeMarketBaseFeeTestCase {
private long parentBaseFee;
private Wei parentBaseFee;
private long parentGasUsed;
private long parentTargetGasUsed;
private long expectedBaseFee;
private Wei expectedBaseFee;
public BaseFeeMarketBaseFeeTestCase() {}
public BaseFeeMarketBaseFeeTestCase(
final long parentBaseFee,
final Wei parentBaseFee,
final long parentGasUsed,
final long parentTargetGasUsed,
final long expectedBaseFee) {
final Wei expectedBaseFee) {
this.parentBaseFee = parentBaseFee;
this.parentGasUsed = parentGasUsed;
this.parentTargetGasUsed = parentTargetGasUsed;
this.expectedBaseFee = expectedBaseFee;
}
public long getParentBaseFee() {
public Wei getParentBaseFee() {
return parentBaseFee;
}
@ -120,11 +121,11 @@ public class BaseFeeMarketBaseFeeTest {
return parentTargetGasUsed;
}
public long getExpectedBaseFee() {
public Wei getExpectedBaseFee() {
return expectedBaseFee;
}
public void setParentBaseFee(final long parentBaseFee) {
public void setParentBaseFee(final Wei parentBaseFee) {
this.parentBaseFee = parentBaseFee;
}
@ -136,7 +137,7 @@ public class BaseFeeMarketBaseFeeTest {
this.parentTargetGasUsed = parentTargetGasUsed;
}
public void setExpectedBaseFee(final long expectedBaseFee) {
public void setExpectedBaseFee(final Wei expectedBaseFee) {
this.expectedBaseFee = expectedBaseFee;
}
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.core.feemarket;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
@ -36,7 +37,7 @@ public class BaseFeeMarketTest {
TARGET_GAS_USED - 1000000L,
TARGET_GAS_USED))
.isLessThan(baseFeeMarket.getInitialBasefee())
.isEqualTo(987500000L);
.isEqualTo(Wei.of(987500000L));
}
@Test
@ -48,7 +49,7 @@ public class BaseFeeMarketTest {
TARGET_GAS_USED + 1000000L,
TARGET_GAS_USED))
.isGreaterThan(baseFeeMarket.getInitialBasefee())
.isEqualTo(1012500000L);
.isEqualTo(Wei.of(1012500000L));
}
@Test

@ -38,14 +38,14 @@ public class CoinbaseFeePriceCalculatorTest {
private final CoinbaseFeePriceCalculator coinbaseFeePriceCalculator;
private final Gas coinbaseFee;
private final Wei transactionGasPrice;
private final Optional<Long> baseFee;
private final Optional<Wei> baseFee;
private final Wei expectedPrice;
public CoinbaseFeePriceCalculatorTest(
final CoinbaseFeePriceCalculator coinbaseFeePriceCalculator,
final Gas coinbaseFee,
final Wei transactionGasPrice,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Wei expectedPrice) {
this.coinbaseFeePriceCalculator = coinbaseFeePriceCalculator;
this.coinbaseFee = coinbaseFee;
@ -61,7 +61,7 @@ public class CoinbaseFeePriceCalculatorTest {
// legacy transaction must return gas price * gas
{FRONTIER_CALCULATOR, Gas.of(100), Wei.of(10L), Optional.empty(), Wei.of(1000L)},
// EIP-1559 must return gas * (gas price - base fee)
{EIP_1559_CALCULATOR, Gas.of(100), Wei.of(10L), Optional.of(4L), Wei.of(600L)},
{EIP_1559_CALCULATOR, Gas.of(100), Wei.of(10L), Optional.of(Wei.of(4L)), Wei.of(600L)},
// Negative transaction gas price case
// {EIP_1559_CALCULATOR, Gas.of(100), Wei.of(95L), Optional.of(100L), Wei.of(-500L)}
});

@ -46,7 +46,7 @@ public class TransactionPriceCalculatorTest {
private final Wei gasPrice;
private final Wei maxPriorityFeePerGas;
private final Wei maxFeePerGas;
private final Optional<Long> baseFee;
private final Optional<Wei> baseFee;
private final Wei expectedPrice;
public TransactionPriceCalculatorTest(
@ -55,7 +55,7 @@ public class TransactionPriceCalculatorTest {
final Wei gasPrice,
final Wei maxPriorityFeePerGas,
final Wei maxFeePerGas,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final Wei expectedPrice) {
this.transactionPriceCalculator = transactionPriceCalculator;
this.transactionType = transactionType;
@ -84,7 +84,13 @@ public class TransactionPriceCalculatorTest {
},
// legacy transaction must return gas price
{
EIP_1559_CALCULATOR, FRONTIER, Wei.of(578L), null, null, Optional.of(150L), Wei.of(578L)
EIP_1559_CALCULATOR,
FRONTIER,
Wei.of(578L),
null,
null,
Optional.of(Wei.of(150L)),
Wei.of(578L)
},
// ACCESSLIST transaction must return gas price
{
@ -93,7 +99,7 @@ public class TransactionPriceCalculatorTest {
Wei.of(578L),
null,
null,
Optional.of(150L),
Optional.of(Wei.of(150L)),
Wei.of(578L)
},
// EIP-1559 must return maxPriorityFeePerGas + base fee
@ -103,7 +109,7 @@ public class TransactionPriceCalculatorTest {
null,
Wei.of(100L),
Wei.of(300L),
Optional.of(150L),
Optional.of(Wei.of(150L)),
Wei.of(250L)
},
// EIP-1559 must return fee cap
@ -113,7 +119,7 @@ public class TransactionPriceCalculatorTest {
null,
Wei.of(100L),
Wei.of(300L),
Optional.of(250L),
Optional.of(Wei.of(250L)),
Wei.of(300L)
}
});

@ -63,7 +63,7 @@ public class BaseFeeBlockBodyValidatorTest {
@Test
public void BlockBodyValidatorSucceed() {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(10L));
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.of(10L)));
when(block.getBody())
.thenReturn(
new BlockBody(
@ -83,7 +83,7 @@ public class BaseFeeBlockBodyValidatorTest {
@Test
public void BlockBodyValidatorFail_GasPrice() {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(10L));
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.of(10L)));
when(block.getBody())
.thenReturn(
new BlockBody(
@ -97,7 +97,7 @@ public class BaseFeeBlockBodyValidatorTest {
@Test
public void BlockBodyValidatorFail_MaxFeePerGas() {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(10L));
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.of(10L)));
when(block.getBody())
.thenReturn(
new BlockBody(

@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.SealableBlockHeader;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
@ -44,7 +45,7 @@ public class KeccakHasherTest {
final long gasUsed,
final long timestamp,
final Bytes extraData,
final Long baseFee,
final Wei baseFee,
final Bytes32 random) {
super(
parentHash,

@ -275,7 +275,7 @@ public class MainnetTransactionValidatorTest {
.signAndBuild(new SECP256K1().generateKeyPair());
final ValidationResult<TransactionInvalidReason> validationResult =
validator.validate(transaction, Optional.of(1L), transactionValidationParams);
validator.validate(transaction, Optional.of(Wei.ONE), transactionValidationParams);
assertThat(validationResult)
.isEqualTo(ValidationResult.invalid(MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS));
assertThat(validationResult.getErrorMessage())
@ -367,7 +367,9 @@ public class MainnetTransactionValidatorTest {
when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(0));
assertThat(eip1559Validator.validate(transaction, Optional.of(1L), transactionValidationParams))
assertThat(
eip1559Validator.validate(
transaction, Optional.of(Wei.ONE), transactionValidationParams))
.isEqualTo(ValidationResult.valid());
}
@ -388,7 +390,7 @@ public class MainnetTransactionValidatorTest {
.maxFeePerGas(Optional.of(Wei.of(1)))
.chainId(Optional.of(BigInteger.ONE))
.createTransaction(senderKeys);
final Optional<Long> basefee = Optional.of(150000L);
final Optional<Wei> basefee = Optional.of(Wei.of(150000L));
assertThat(validator.validate(transaction, basefee, transactionValidationParams))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.INVALID_TRANSACTION_FORMAT));
}
@ -410,7 +412,7 @@ public class MainnetTransactionValidatorTest {
.type(TransactionType.EIP1559)
.chainId(Optional.of(BigInteger.ONE))
.createTransaction(senderKeys);
final Optional<Long> basefee = Optional.of(150000L);
final Optional<Wei> basefee = Optional.of(Wei.of(150000L));
when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(50));
assertThat(validator.validate(transaction, basefee, transactionValidationParams))
@ -438,7 +440,7 @@ public class MainnetTransactionValidatorTest {
assertThat(
validator.validate(
transaction, Optional.of(1L), TransactionValidationParams.transactionPool()))
transaction, Optional.of(Wei.ONE), TransactionValidationParams.transactionPool()))
.isEqualTo(ValidationResult.valid());
}

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.mainnet.headervalidationrules;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.mainnet.headervalidationrules.EIP1559Helper.blockHeader;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
@ -42,7 +43,7 @@ public class BaseFeeMarketBlockHeaderGasPriceValidationRuleTest {
public void shouldTReturnFalseIfParentMissingBaseFeePostFork() {
assertThat(
validationRule.validate(
blockHeader(FORK_BLOCK - 1, 0, Optional.of(10_000L)),
blockHeader(FORK_BLOCK - 1, 0, Optional.of(Wei.of(10_000L))),
blockHeader(FORK_BLOCK - 2, 0, Optional.empty())))
.isFalse();
}
@ -52,7 +53,7 @@ public class BaseFeeMarketBlockHeaderGasPriceValidationRuleTest {
assertThat(
validationRule.validate(
blockHeader(FORK_BLOCK - 2, 0, Optional.empty()),
blockHeader(FORK_BLOCK - 1, 0, Optional.of(10_000L))))
blockHeader(FORK_BLOCK - 1, 0, Optional.of(Wei.of(10_000L)))))
.isFalse();
}
@ -68,7 +69,8 @@ public class BaseFeeMarketBlockHeaderGasPriceValidationRuleTest {
public void shouldReturnFalseIfNotInitialBaseFeeAtForkBlock() {
assertThat(
validationRule.validate(
blockHeader(FORK_BLOCK, 0, Optional.of(feeMarket.getInitialBasefee() - 1)), null))
blockHeader(FORK_BLOCK, 0, Optional.of(feeMarket.getInitialBasefee().subtract(1L))),
null))
.isFalse();
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet.headervalidationrules;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import java.util.Optional;
@ -25,12 +26,12 @@ import org.mockito.Mockito;
public class EIP1559Helper {
public static BlockHeader blockHeader(
final long number, final long gasUsed, final Optional<Long> baseFee) {
final long number, final long gasUsed, final Optional<Wei> baseFee) {
return blockHeader(number, gasUsed, baseFee, 0);
}
public static BlockHeader blockHeader(
final long number, final long gasUsed, final Optional<Long> baseFee, final long gasLimit) {
final long number, final long gasUsed, final Optional<Wei> baseFee, final long gasLimit) {
final BlockHeader mock = Mockito.mock(BlockHeader.class);
when(mock.getNumber()).thenReturn(number);
when(mock.getGasUsed()).thenReturn(gasUsed);

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet.headervalidationrules;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
@ -44,7 +45,7 @@ public class GasLimitRangeAndDeltaValidationRuleTest {
public boolean expectedResult;
@Parameter(4)
public Optional<Long> optionalBaseFee;
public Optional<Wei> optionalBaseFee;
@Parameters
public static Collection<Object[]> data() {
@ -68,7 +69,13 @@ public class GasLimitRangeAndDeltaValidationRuleTest {
4100, 4096, new GasLimitRangeAndDeltaValidationRule(4000, 4200), false, Optional.empty()
},
// In Range, == 1/1024 change = invalid,
{4099, 4096, new GasLimitRangeAndDeltaValidationRule(4000, 4200), false, Optional.of(10L)}
{
4099,
4096,
new GasLimitRangeAndDeltaValidationRule(4000, 4200),
false,
Optional.of(Wei.of(10L))
}
// In Range, <1/1024 change, has basefee = invalid,
});
}

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.mainnet.headervalidationrules;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
@ -177,7 +178,7 @@ public class ProofOfWorkValidationRuleTest {
final BlockHeaderBuilder headerBuilder =
BlockHeaderBuilder.fromHeader(blockHeader)
.difficulty(Difficulty.ONE)
.baseFee(10L)
.baseFee(Wei.of(10L))
.blockHeaderFunctions(mainnetBlockHashFunction())
.timestamp(1);
final BlockHeader preHeader = headerBuilder.buildBlockHeader();

@ -167,7 +167,7 @@ public class TransactionSimulatorTest {
public void shouldSetFeePerGasToZeroWhenExceedingBalanceAllowed() {
final CallParameter callParameter = eip1559TransactionCallParameter(Wei.ONE, Wei.ONE);
mockBlockchainForBlockHeader(Hash.ZERO, 1L, 1L);
mockBlockchainForBlockHeader(Hash.ZERO, 1L, Wei.ONE);
mockWorldStateForAccount(Hash.ZERO, callParameter.getFrom(), 1L);
final Transaction expectedTransaction =
@ -231,7 +231,7 @@ public class TransactionSimulatorTest {
public void shouldNotSetFeePerGasToZeroWhenExceedingBalanceIsNotAllowed() {
final CallParameter callParameter = eip1559TransactionCallParameter(Wei.ONE, Wei.ONE);
mockBlockchainForBlockHeader(Hash.ZERO, 1L, 1L);
mockBlockchainForBlockHeader(Hash.ZERO, 1L, Wei.ONE);
mockWorldStateForAccount(Hash.ZERO, callParameter.getFrom(), 1L);
final Transaction expectedTransaction =
@ -462,7 +462,7 @@ public class TransactionSimulatorTest {
public void shouldReturnSuccessfulResultWhenEip1559TransactionProcessingIsSuccessful() {
final CallParameter callParameter = eip1559TransactionCallParameter();
mockBlockchainForBlockHeader(Hash.ZERO, 1L, 1L);
mockBlockchainForBlockHeader(Hash.ZERO, 1L, Wei.ONE);
mockWorldStateForAccount(Hash.ZERO, callParameter.getFrom(), 1L);
final Transaction expectedTransaction =
@ -517,7 +517,7 @@ public class TransactionSimulatorTest {
}
private void mockBlockchainForBlockHeader(
final Hash stateRoot, final long blockNumber, final long baseFee) {
final Hash stateRoot, final long blockNumber, final Wei baseFee) {
final BlockHeader blockHeader = mock(BlockHeader.class, Answers.RETURNS_MOCKS);
when(blockHeader.getStateRoot()).thenReturn(stateRoot);
when(blockHeader.getNumber()).thenReturn(blockNumber);

@ -20,6 +20,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.evm.Gas;
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
@ -42,7 +43,7 @@ public class BaseFeeOperationTest {
@Test
public void shouldReturnGasCost() {
final MessageFrame frame = createMessageFrame(100, Optional.of(5L));
final MessageFrame frame = createMessageFrame(100, Optional.of(Wei.of(5L)));
final Operation operation = new BaseFeeOperation(gasCalculator);
final OperationResult result = operation.execute(frame, null);
assertThat(result.getGasCost()).contains(gasCalculator.getBaseTierGasCost());
@ -51,7 +52,7 @@ public class BaseFeeOperationTest {
@Test
public void shouldWriteBaseFeeToStack() {
final MessageFrame frame = createMessageFrame(100, Optional.of(5L));
final MessageFrame frame = createMessageFrame(100, Optional.of(Wei.of(5L)));
final Operation operation = new BaseFeeOperation(gasCalculator);
final OperationResult result = operation.execute(frame, null);
verify(frame).pushStackItem(eq(UInt256.fromBytes(Bytes32.leftPad(Bytes.ofUnsignedLong(5L)))));
@ -77,11 +78,11 @@ public class BaseFeeOperationTest {
assertThat(result.getHaltReason()).contains(reason);
}
private MessageFrame createMessageFrame(final long initialGas, final Optional<Long> baseFee) {
private MessageFrame createMessageFrame(final long initialGas, final Optional<Wei> baseFee) {
return createMessageFrame(Gas.of(initialGas), baseFee);
}
private MessageFrame createMessageFrame(final Gas initialGas, final Optional<Long> baseFee) {
private MessageFrame createMessageFrame(final Gas initialGas, final Optional<Wei> baseFee) {
final MessageFrame frame = mock(MessageFrame.class);
when(frame.getRemainingGas()).thenReturn(initialGas);
final BlockHeader blockHeader = mock(BlockHeader.class);

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.eth.transactions;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.AbstractPendingTransactionsSorter.TransactionInfo;
import java.util.Optional;
@ -24,7 +25,7 @@ public interface TransactionPoolReplacementRule {
boolean shouldReplace(
TransactionInfo existingTransactionInfo,
TransactionInfo newTransactionInfo,
Optional<Long> baseFee);
Optional<Wei> baseFee);
default boolean isNotGasPriced(final TransactionInfo tInfo) {
return tInfo.getTransaction().getType().supports1559FeeMarket();

@ -23,8 +23,6 @@ import org.hyperledger.besu.util.number.Percentage;
import java.util.Optional;
import org.apache.tuweni.units.bigints.UInt256;
public class TransactionReplacementByFeeMarketRule implements TransactionPoolReplacementRule {
private static final TransactionPriceCalculator FRONTIER_CALCULATOR =
@ -41,7 +39,7 @@ public class TransactionReplacementByFeeMarketRule implements TransactionPoolRep
public boolean shouldReplace(
final TransactionInfo existingTransactionInfo,
final TransactionInfo newTransactionInfo,
final Optional<Long> baseFee) {
final Optional<Wei> baseFee) {
// bail early if basefee is absent or neither transaction supports 1559 fee market
if (baseFee.isEmpty()
@ -50,32 +48,30 @@ public class TransactionReplacementByFeeMarketRule implements TransactionPoolRep
}
Wei newEffPrice = priceOf(newTransactionInfo.getTransaction(), baseFee);
Long newEffPriority =
newTransactionInfo.getTransaction().getEffectivePriorityFeePerGas(baseFee);
Wei newEffPriority = newTransactionInfo.getTransaction().getEffectivePriorityFeePerGas(baseFee);
// bail early if price is or priority is not strictly positive
if (!(newEffPrice.toLong() > 0L)) {
// bail early if price is not strictly positive
if (newEffPrice.equals(Wei.ZERO)) {
return false;
}
Wei curEffPrice = priceOf(existingTransactionInfo.getTransaction(), baseFee);
Long curEffPriority =
Wei curEffPriority =
existingTransactionInfo.getTransaction().getEffectivePriorityFeePerGas(baseFee);
if (isBumpedBy(curEffPrice.toUInt256(), newEffPrice.toUInt256(), priceBump)) {
if (isBumpedBy(curEffPrice, newEffPrice, priceBump)) {
// if effective price is bumped by percent:
// replace if new effective priority is >= current effective priority
return newEffPriority >= curEffPriority;
return newEffPriority.compareTo(curEffPriority) >= 0;
} else if (curEffPrice.equals(newEffPrice)) {
// elsif new effective price is equal to current effective price:
// replace if the new effective priority is bumped by priceBump relative to current priority
return isBumpedBy(
UInt256.valueOf(curEffPriority), UInt256.valueOf(newEffPriority), priceBump);
return isBumpedBy(curEffPriority, newEffPriority, priceBump);
}
return false;
}
private Wei priceOf(final Transaction transaction, final Optional<Long> baseFee) {
private Wei priceOf(final Transaction transaction, final Optional<Wei> baseFee) {
final TransactionPriceCalculator transactionPriceCalculator =
transaction.getType().equals(TransactionType.EIP1559)
? EIP1559_CALCULATOR
@ -83,7 +79,7 @@ public class TransactionReplacementByFeeMarketRule implements TransactionPoolRep
return transactionPriceCalculator.price(transaction, baseFee);
}
private boolean isBumpedBy(final UInt256 val, final UInt256 bumpVal, final Percentage percent) {
private boolean isBumpedBy(final Wei val, final Wei bumpVal, final Percentage percent) {
return val.multiply(percent.getValue() + 100L).compareTo(bumpVal.multiply(100L)) < 0;
}
}

@ -31,7 +31,7 @@ public class TransactionReplacementByGasPriceRule implements TransactionPoolRepl
public boolean shouldReplace(
final TransactionInfo existingTransactionInfo,
final TransactionInfo newTransactionInfo,
final Optional<Long> baseFee) {
final Optional<Wei> baseFee) {
assert existingTransactionInfo.getTransaction() != null
&& newTransactionInfo.getTransaction() != null;

@ -19,6 +19,7 @@ import static java.util.stream.Collectors.toUnmodifiableList;
import static org.hyperledger.besu.ethereum.eth.transactions.sorter.AbstractPendingTransactionsSorter.TransactionAddedStatus.ADDED;
import static org.hyperledger.besu.ethereum.eth.transactions.sorter.AbstractPendingTransactionsSorter.TransactionAddedStatus.ALREADY_KNOWN;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Transaction;
@ -48,7 +49,7 @@ public class BaseFeePendingTransactionsSorter extends AbstractPendingTransaction
private static final Logger LOG = LogManager.getLogger();
private Optional<Long> baseFee;
private Optional<Wei> baseFee;
public BaseFeePendingTransactionsSorter(
final int maxTransactionRetentionHours,
@ -157,18 +158,18 @@ public class BaseFeePendingTransactionsSorter extends AbstractPendingTransaction
} else {
// there are both static and dynamic txs remaining so we need to compare them by their
// effective priority fees
final long dynamicRangeEffectivePriorityFee =
final Wei dynamicRangeEffectivePriorityFee =
currentDynamicRangeTransaction
.get()
.getTransaction()
.getEffectivePriorityFeePerGas(baseFee);
final long staticRangeEffectivePriorityFee =
final Wei staticRangeEffectivePriorityFee =
currentStaticRangeTransaction
.get()
.getTransaction()
.getEffectivePriorityFeePerGas(baseFee);
final TransactionInfo best;
if (dynamicRangeEffectivePriorityFee > staticRangeEffectivePriorityFee) {
if (dynamicRangeEffectivePriorityFee.compareTo(staticRangeEffectivePriorityFee) > 0) {
best = currentDynamicRangeTransaction.get();
currentDynamicRangeTransaction = getNextOptional(dynamicRangeIterable);
} else {
@ -236,25 +237,25 @@ public class BaseFeePendingTransactionsSorter extends AbstractPendingTransaction
return ADDED;
}
private boolean isInStaticRange(final Transaction transaction, final Optional<Long> baseFee) {
private boolean isInStaticRange(final Transaction transaction, final Optional<Wei> baseFee) {
return transaction
.getMaxPriorityFeePerGas()
.map(
maxPriorityFeePerGas ->
transaction.getEffectivePriorityFeePerGas(baseFee)
>= maxPriorityFeePerGas.getValue().longValue())
transaction.getEffectivePriorityFeePerGas(baseFee).compareTo(maxPriorityFeePerGas)
>= 0)
.orElse(
// non-eip-1559 txs can't be in static range
false);
}
public void updateBaseFee(final Long newBaseFee) {
public void updateBaseFee(final Wei newBaseFee) {
LOG.trace("Updating base fee from {} to {}", this.baseFee, newBaseFee);
if (this.baseFee.orElse(0L).equals(newBaseFee)) {
if (this.baseFee.orElse(Wei.ZERO).equals(newBaseFee)) {
return;
}
synchronized (lock) {
final boolean baseFeeIncreased = newBaseFee > this.baseFee.orElse(0L);
final boolean baseFeeIncreased = newBaseFee.compareTo(this.baseFee.orElse(Wei.ZERO)) > 0;
this.baseFee = Optional.of(newBaseFee);
if (baseFeeIncreased) {
// base fee increases can only cause transactions to go from static to dynamic range

@ -62,7 +62,7 @@ public class PendingMultiTypesTransactionsTest {
MAX_TRANSACTION_HASHES,
TestClock.fixed(),
metricsSystem,
() -> mockBlockHeader(7),
() -> mockBlockHeader(Wei.of(7L)),
TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
@Test
@ -96,7 +96,7 @@ public class PendingMultiTypesTransactionsTest {
transactions.addLocalTransaction(localTransaction3);
transactions.addLocalTransaction(localTransaction4);
transactions.updateBaseFee(300L);
transactions.updateBaseFee(Wei.of(300L));
transactions.addLocalTransaction(localTransaction5);
assertThat(transactions.size()).isEqualTo(5);
@ -198,7 +198,7 @@ public class PendingMultiTypesTransactionsTest {
assertThat(iterationOrder)
.containsExactly(localTransaction1, localTransaction2, localTransaction0);
transactions.updateBaseFee(110L);
transactions.updateBaseFee(Wei.of(110L));
final List<Transaction> iterationOrderAfterBaseIncreased = new ArrayList<>();
transactions.selectTransactions(
@ -217,7 +217,7 @@ public class PendingMultiTypesTransactionsTest {
final Transaction localTransaction1 = create1559Transaction(1, 100, 20, KEYS2);
final Transaction localTransaction2 = create1559Transaction(2, 100, 19, KEYS2);
transactions.updateBaseFee(110L);
transactions.updateBaseFee(Wei.of(110L));
transactions.addLocalTransaction(localTransaction0);
transactions.addLocalTransaction(localTransaction1);
@ -233,7 +233,7 @@ public class PendingMultiTypesTransactionsTest {
assertThat(iterationOrder)
.containsExactly(localTransaction0, localTransaction1, localTransaction2);
transactions.updateBaseFee(50L);
transactions.updateBaseFee(Wei.of(50L));
final List<Transaction> iterationOrderAfterBaseIncreased = new ArrayList<>();
transactions.selectTransactions(
@ -369,7 +369,7 @@ public class PendingMultiTypesTransactionsTest {
.createTransaction(keyPair);
}
private BlockHeader mockBlockHeader(final long baseFee) {
private BlockHeader mockBlockHeader(final Wei baseFee) {
when(blockHeader.getBaseFee()).thenReturn(Optional.of(baseFee));
return blockHeader;
}

@ -51,31 +51,31 @@ public class TransactionReplacementRulesTest {
{frontierTx(100L), frontierTx(110L), empty(), 10, false},
{frontierTx(100L), frontierTx(111L), empty(), 10, true},
// basefee present
{frontierTx(5L), frontierTx(6L), Optional.of(3L), 0, true},
{frontierTx(5L), frontierTx(5L), Optional.of(3L), 0, false},
{frontierTx(5L), frontierTx(4L), Optional.of(3L), 0, false},
{frontierTx(100L), frontierTx(105L), Optional.of(3L), 10, false},
{frontierTx(100L), frontierTx(110L), Optional.of(3L), 10, false},
{frontierTx(100L), frontierTx(111L), Optional.of(3L), 10, true},
{frontierTx(5L), frontierTx(6L), Optional.of(Wei.of(3L)), 0, true},
{frontierTx(5L), frontierTx(5L), Optional.of(Wei.of(3L)), 0, false},
{frontierTx(5L), frontierTx(4L), Optional.of(Wei.of(3L)), 0, false},
{frontierTx(100L), frontierTx(105L), Optional.of(Wei.of(3L)), 10, false},
{frontierTx(100L), frontierTx(110L), Optional.of(Wei.of(3L)), 10, false},
{frontierTx(100L), frontierTx(111L), Optional.of(Wei.of(3L)), 10, true},
// TransactionReplacementByFeeMarketRule
// eip1559 replacing frontier
{frontierTx(5L), eip1559Tx(3L, 6L), Optional.of(1L), 0, false},
{frontierTx(5L), eip1559Tx(3L, 5L), Optional.of(3L), 0, false},
{frontierTx(5L), eip1559Tx(3L, 6L), Optional.of(3L), 0, true},
{frontierTx(5L), eip1559Tx(3L, 6L), Optional.of(Wei.of(1L)), 0, false},
{frontierTx(5L), eip1559Tx(3L, 5L), Optional.of(Wei.of(3L)), 0, false},
{frontierTx(5L), eip1559Tx(3L, 6L), Optional.of(Wei.of(3L)), 0, true},
// frontier replacing 1559
{eip1559Tx(3L, 8L), frontierTx(7L), Optional.of(4L), 0, false},
{eip1559Tx(3L, 8L), frontierTx(8L), Optional.of(4L), 0, true},
{eip1559Tx(3L, 8L), frontierTx(7L), Optional.of(Wei.of(4L)), 0, false},
{eip1559Tx(3L, 8L), frontierTx(8L), Optional.of(Wei.of(4L)), 0, true},
// eip1559 replacing eip1559
{eip1559Tx(3L, 6L), eip1559Tx(3L, 6L), Optional.of(3L), 0, false},
{eip1559Tx(3L, 6L), eip1559Tx(3L, 7L), Optional.of(3L), 0, false},
{eip1559Tx(3L, 6L), eip1559Tx(3L, 7L), Optional.of(4L), 0, true},
{eip1559Tx(10L, 200L), eip1559Tx(10L, 200L), Optional.of(90L), 10, false},
{eip1559Tx(10L, 200L), eip1559Tx(15L, 200L), Optional.of(90L), 10, false},
{eip1559Tx(10L, 200L), eip1559Tx(21L, 200L), Optional.of(90L), 10, true},
{eip1559Tx(3L, 6L), eip1559Tx(3L, 6L), Optional.of(Wei.of(3L)), 0, false},
{eip1559Tx(3L, 6L), eip1559Tx(3L, 7L), Optional.of(Wei.of(3L)), 0, false},
{eip1559Tx(3L, 6L), eip1559Tx(3L, 7L), Optional.of(Wei.of(4L)), 0, true},
{eip1559Tx(10L, 200L), eip1559Tx(10L, 200L), Optional.of(Wei.of(90L)), 10, false},
{eip1559Tx(10L, 200L), eip1559Tx(15L, 200L), Optional.of(Wei.of(90L)), 10, false},
{eip1559Tx(10L, 200L), eip1559Tx(21L, 200L), Optional.of(Wei.of(90L)), 10, true},
// pathological, priority fee > max fee
{eip1559Tx(8L, 6L), eip1559Tx(3L, 7L), Optional.of(3L), 0, false},
{eip1559Tx(8L, 6L), eip1559Tx(3L, 7L), Optional.of(4L), 0, true},
{eip1559Tx(8L, 6L), eip1559Tx(3L, 7L), Optional.of(Wei.of(3L)), 0, false},
{eip1559Tx(8L, 6L), eip1559Tx(3L, 7L), Optional.of(Wei.of(4L)), 0, true},
// pathological, eip1559 without basefee
{eip1559Tx(8L, 6L), eip1559Tx(3L, 7L), Optional.empty(), 0, false},
{eip1559Tx(8L, 6L), eip1559Tx(3L, 7L), Optional.empty(), 0, false},
@ -84,14 +84,14 @@ public class TransactionReplacementRulesTest {
private final TransactionInfo oldTx;
private final TransactionInfo newTx;
private final Optional<Long> baseFee;
private final Optional<Wei> baseFee;
private final int priceBump;
private final boolean expected;
public TransactionReplacementRulesTest(
final TransactionInfo oldTx,
final TransactionInfo newTx,
final Optional<Long> baseFee,
final Optional<Wei> baseFee,
final int priceBump,
final boolean expected) {
this.oldTx = oldTx;

@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -171,7 +172,7 @@ public class BlockchainReferenceTestCaseSpec {
Long.decode(gasUsed), // gasUsed
Long.decode(timestamp), // timestamp
Bytes.fromHexString(extraData), // extraData
baseFee != null ? Long.decode(baseFee) : null, // baseFee
baseFee != null ? Wei.fromHexString(baseFee) : null, // baseFee
Hash.fromHexString(mixHash), // mixHash
Bytes.fromHexString(nonce).getLong(0),
new BlockHeaderFunctions() {

@ -20,6 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
@ -31,7 +32,6 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
/** A memory holder for testing. */
@JsonIgnoreProperties(ignoreUnknown = true)
@ -69,7 +69,7 @@ public class ReferenceTestEnv extends BlockHeader {
0L,
Long.decode(timestamp),
Bytes.EMPTY,
Optional.ofNullable(baseFee).map(UInt256::fromHexString).map(UInt256::toLong).orElse(null),
Optional.ofNullable(baseFee).map(Wei::fromHexString).orElse(null),
Hash.ZERO,
0L,
new MainnetBlockHeaderFunctions());

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.retesteth.methods;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -104,7 +105,7 @@ public class TestSetChainParamsTest {
final BlockHeader blockHeader = context.getBlockHeader(0);
assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000"));
assertThat(blockHeader.getGasLimit()).isEqualTo(1234L);
assertThat(blockHeader.getBaseFee()).hasValue(12345L);
assertThat(blockHeader.getBaseFee()).hasValue(Wei.of(12345L));
assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x00");
assertThat(blockHeader.getTimestamp()).isEqualTo(0l);
assertThat(blockHeader.getNonce()).isEqualTo(0L);

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.rlp;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
import org.junit.Test;
public class BytesValueRLPOutputTest {
@ -176,6 +177,23 @@ public class BytesValueRLPOutputTest {
assertThat(out.encoded()).isEqualTo(expected);
}
@Test
public void uint256Scalar() {
// Scalar should be encoded as the minimal byte array representing the number. For 0, that means
// the empty byte array, which is a short element of zero-length, so 0x80.
assertUInt256Scalar(h("0x80"), UInt256.valueOf(0));
assertUInt256Scalar(h("0x01"), UInt256.valueOf(1));
assertUInt256Scalar(h("0x0F"), UInt256.valueOf(15));
assertUInt256Scalar(h("0x820400"), UInt256.valueOf(1024));
}
private void assertUInt256Scalar(final Bytes expected, final UInt256 toTest) {
final BytesValueRLPOutput out = new BytesValueRLPOutput();
out.writeUInt256Scalar(toTest);
assertThat(out.encoded()).isEqualTo(expected);
}
@Test
public void emptyList() {
final BytesValueRLPOutput out = new BytesValueRLPOutput();

@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.evm.frame;
import org.hyperledger.besu.datatypes.Wei;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
@ -38,7 +40,7 @@ public interface BlockValues {
*
* @return the raw bytes of the extra data field
*/
default Optional<Long> getBaseFee() {
default Optional<Wei> getBaseFee() {
return Optional.empty();
}

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.evm.operation;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
@ -21,10 +22,6 @@ import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
public class BaseFeeOperation extends AbstractFixedCostOperation {
public BaseFeeOperation(final GasCalculator gasCalculator) {
@ -34,17 +31,12 @@ public class BaseFeeOperation extends AbstractFixedCostOperation {
@Override
public Operation.OperationResult executeFixedCostOperation(
final MessageFrame frame, final EVM evm) {
Optional<Long> maybeBaseFee = frame.getBlockValues().getBaseFee();
Optional<Wei> maybeBaseFee = frame.getBlockValues().getBaseFee();
if (maybeBaseFee.isEmpty()) {
return new Operation.OperationResult(
Optional.of(gasCost), Optional.of(ExceptionalHaltReason.INVALID_OPERATION));
}
frame.pushStackItem(
maybeBaseFee
.map(Bytes::ofUnsignedLong)
.map(Bytes32::leftPad)
.map(UInt256::fromBytes)
.orElseThrow());
frame.pushStackItem(maybeBaseFee.orElseThrow());
return successResponse;
}
}

@ -15,6 +15,7 @@
*/
package org.hyperledger.besu.evm.toy;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.frame.BlockValues;
import java.util.Optional;
@ -30,7 +31,7 @@ public class ToyBlockValues implements BlockValues {
}
@Override
public Optional<Long> getBaseFee() {
public Optional<Wei> getBaseFee() {
return Optional.empty();
}

@ -64,7 +64,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = '/M23BAhwqtMpjhcoHDMJvbHyhJ4z39z2jJMWUGOBO14='
knownHash = 'QPxUj/HJM7DZkbUq538/S2f3MmwPOqaPX/BBTkKznQk='
}
check.dependsOn('checkAPIChanges')

@ -166,7 +166,7 @@ public interface BlockHeader {
* @return The BASEFEE of this header.
*/
@Unstable
default Optional<Long> getBaseFee() {
default Optional<? extends Quantity> getBaseFee() {
return Optional.empty();
}

Loading…
Cancel
Save