Previously we were returning success with a zero length hash, meaning we
understood the response but there were problems with the RLP. Instead
now we return one of two errors "Could not decode RLP for Block" or
"Could not import Block".
For #1130
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Produce error response if any of Address, Bytes or Bytes32 values
inside GraphQl requests are not prefixed with 0x as defined by the spec.
Fix old tests that used values that are not prefixed with 0x and add
additional tests to confirm Address, Bytes and Bytes32 values will be
rejected if not prefixed with 0x.
Signed-off-by: Mak Muftic <mak@nodefactory.io>
- Added `--rpc-tx-feecap` command line flag.
- Maximum transaction fees (in Wei) accepted for transaction submitted through RPC.
- Defaulted to 1 ether.
- Updated `TransactionPool.addLocalTransaction` method: performs an additional check to verify if transaction fees don't exceed user defined fee cap (if cap is set to 0 then it is ignored and means no cap).
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* rename more whitelist occurrences; change allowlisted to allowed and reword where we ended up with allowlisting
Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
* change Perm*Whitelist JSON-RPC methods to extend the Perm*Allowlist methods to remove dupe
* added unit test for Perm JSON RPC methods collection
Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
Internally we used to use an enum set to track halt reasons and we would
track multiple halt reasons. However, what the halt reason is does not
matter to reference tests and tracing, only that a halt occurred.
Repalace the EnumSet with an Optional and trace only one revert reason.
This saves us time in enumset management and also allows us to return
quicker once any halt is detected.
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Upgrade to ErrorProne 2.4.0
* public constructors on abstract classes are removed
* Javadoc must have meaningfull documentation
* lambdas should not be variables
* Added to the list of confusing inner class names (Entry and Type)
* no assert keyword in tests
* Obsolete JDK classes produce errors now
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
* Upgrade Library Versions
Upgrade library versions to most recent version
Exceptions:
* Errorprone - lots of new violations need fixing
There will be a follow on PR for this.
* picocli - non-trivial conformance changes
* EthSigner&Orion - similar non-trivial API changes, plus it's only for
integration testing
* Kubernetes - significant library revisions
* Web3j - Web3j changed some error semantics in 5.0 that broke
acceptance tests. Expect an update in a follow on PR.
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
* Detect zombies backend query and abort useless processing.
The timeout handler populate the request context with a boolean value indicating whether or not the query is alive, i.e the HTTP request has not expired. Backend queries are now conditioned by this value and can be stopped if needed.
This PR experiments this mechanism on a reduced scope. Hence, only `eth_getLogs` backend queries are affected.
- Created `BackendQuery` utility class to run a process only if the query is alive, i.e timeout not expired.
- Put `AtomicBoolean` value in the `JsonRpcRequestContext`
- `TimeoutHandler` sets the alive value to `false` if the timeout handler is triggered.
- Updated `BlockchainQueries` to run steps depending on the value of the `AtomicBoolean` retrieved from the request context.
- Added unit tests.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* replace whitelist/blacklist with allowlist/denylist and support both versions in CLI options
Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
- Implemented submitHashrate endpoint.
- Updated eth_hashrateEndpoint so that it returns the cumulative hashrate of all sealers if available. Otherwise it returns the local hashrate
- Added hashrate submission with Stratum1EthProxyProtocol and Stratum1Protocol
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
* Add onchain privacy group multi-tenancy support to priv_getPrivateTx and priv_getPrivRcpt
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
ProtocolContext uses a generic for the consensus state, which has a very
large footprint across the code to accomplish what it intends to
accomplish. For every call there are about 61 other lines per call that
need to be updated, over 1300 lines total.
Instead replace it with java.lang.Class#cast, which provides runtime
security, and use generics to provide the compile time sugar that
allows for chained methods of the appropriate type. Then remove its
(quite large) footprint from the rest of the code.
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
* Use seconds for timeout configuration
* Add units to variable names
* Change timeout to 5 minutes
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
* Add timeout handler in JsonRpcHttpService.
- Created `TimeoutOptions` class with fields:
- *timeout*: the timeout in milliseconds.
- *errorCode*: the http status code.
- Created `EthRpcTimeoutHandler`.
- Contains `handler` static method to create `Vertx Handler`. The process of the handler created is the following
- retrieve the body as string.
- parse it as a `JsonObject`.
- cache the resulting `JsonObject` in the `RoutingContext`.
- retrieve the RPC method name.
- set a timer based on the configuration if the method name matches one entry in the configuration map.
- call the next handler.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* Add checks on the replacement of a transaction in the pool:
- reject EIP-1559 for pre-fork blocks
- accept both frontier and EIP-1559 transactions during phase 1
- reject frontier transactions after phase 2 is finalized
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* The transaction gas price is computed when adding a transaction into the local pool using eth_sendRawTransaction JSON RPC endpoint. Transaction price must be computed properly depending on the type of the transaction.
For instance `shouldReplace` method of PendingTransactions must be updated to deal with EIP-1559 transactions.
- Updated `PendingTransactions` to add access to the chain header in order to retrieve the last base fee value.
- Updated `TransactionReplacementByPriceRule` to compute the transaction price depending on the type of the transaction (frontier or eip-1559).
- Added unit tests to cover all possible replacement scenarios.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
Retesteth requires even length quantities (in contravariance to the Eth
JSON-RPC standards). For storage range at provide even length
quantities.
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Fix cases where the gas estimate is too low and causes the transaction to fail
Implementation of a strategy that will estimate the number of gas needed by a transaction
1 - Estimate the number of gas used by a transaction
2 - Estimate the number of gas necessary to add for each sub call present in a transaction (65/64^depth)
3 - Add the minimum gas required for operations that need it (SSTORE)
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
* Update transaction pool error handling.
Transactions added locally into the pool via `eth_sendRawTransaction` can now generate 2 new JSON RPC errors:
- `ETH_SEND_TX_ALREADY_KNOWN`: occurs when adding a transaction already present in the pool.
- code: -32000
- message: `Known Transaction`
- `ETH_SEND_TX_REPLACEMENT_UNDERPRICED`: occurs when adding a transaction already present in the pool.
- code: -32000
- message: `Replacement transaction underpriced`
### Changes summary
- Created `TransactionAddedStatus` enum.
- `ALREADY_KNOWN`
- `REJECTED_UNDERPRICED_REPLACEMENT`
- `ADDED`
- Created 2 new errors in `JsonRpcError`.
- Updated JsonRpcErrorConverter to handle newly created errors.
- Updated `addLocalTransaction` method of `PendingTransactions` to return `TransactionAddedStatus` instead of boolean.
- Updated unit tests accordingly.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* When in retesteth return the coinbase in the eth_getBlockByHash, as
required by the retesteth tool.
* use genesis extraData when mining
* storage keys should be 0x00 instead of 0x when zero.
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
* Compute transaction gas budget allocation according to EIP-1559 rules.
- Added `TransactionGasBudgetCalculator` with `hasBudget` method.
- Updated `AbstractBlockProcessor` to compute the gas budget using `TransactionGasBudgetCalculator`.
- Added unit tests in `TransactionGasBudgetCalculatorTest`.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* Fixed unit test.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
Some of our loggers were not private, static, and final. In a few
cases these were non-static fields in classes that were repeatedly
instantiated in core transaction logic.
This is enforced via a new ErrorProne check, so the PR includes fixes
for all of the places this was a problem, not just the performance
impacting code.
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
* Handle legacy gas pool and EIP-1559 gas pool when mining blocks.
- Added `EIP1559` manager class in `ProtocolSpec` (defaulted to `Optional.empty()`).
- Updated `MainnetProtocolSpecs` EIP-1559 definition to set the `EIP1559` manager class.
- Updated `BlockTransactionSelector`
- Added `eip1559CumulativeGasUsed` field in `TransactionSelectionResults`.
- Updated `updateTransactionResultTracking` method to compute cumulative gas used according to `EIP-1559` rules.
- Updated `transactionTooLargeForBlock` method to compute gas remaining according to `EIP-1559` rules.
- Updated `blockOccupancyAboveThreshold` method to compute minimum block occupancy ratio according to `EIP-1559` rules.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
* Update BlockTransactionSelector transaction gas price computation.
BlockTransactionSelector should compare transaction gas price to the min transaction gas price parameter according to EIP-1559 rules.
- Added `TransactionPriceCalculator` to `ProtocolSpec` (defaulted to `TransactionPriceCalculator.frontier()`.
- Created `minTransactionPriceInNextBlock` method in `BaseFee`.
- Removed useless constructor in `BaseFee`.
- Updated EIP-1559 protocol spec definition to set the correct transaction price calculator.
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
@pinges correctly pointed out that, even though we have access to all the logs in the BlockAddedEvent, we still use BlockchainQueries to add the new logs from the event. Now we do the sane thing.
Unfortunately, it doesn't seem as easy with private logs so we still have to use privacyQueries as far as I can tell.
Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>