Change param of to hexadecimal of Eth fee history to match spec (#5047)

* Convert blockCount from hex to match JSON-RPC Specification

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Fix tests

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Add changelog

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

---------

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
pull/5060/head
Gabriel Fukushima 2 years ago committed by GitHub
parent a3a32dda08
commit 98ea871c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java
  3. 22
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java
  4. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_feeHistory_fieldNamesWithReward.json
  5. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_feeHistory_fieldNamesWithoutReward.json

@ -4,11 +4,12 @@
### Breaking Changes
- Add a new CLI option to limit the number of requests in a single RPC batch request. Default=1 [#4965](https://github.com/hyperledger/besu/pull/4965)
- Changed JsonRpc http service to return the error -32602 (Invalid params) with a 200 http status code
- Change JsonRpc http service to return the error -32602 (Invalid params) with a 200 http status code
- Besu requires minimum Java 17 and up to build and run [#3320](https://github.com/hyperledger/besu/issues/3320)
- PKCS11 with nss module (PKCS11 based HSM can be used in DevP2P TLS and QBFT PKI) does not work with RSA keys
in Java 17. SoftHSM is tested manually and working. (Other PKCS11 HSM are not tested). The relevant unit and acceptance
tests are updated to use EC private keys instead of RSA keys.
- Change eth_feeHistory parameter `blockCount` to accept hexadecimal string (was accepting plain integer) [#5047](https://github.com/hyperledger/besu/pull/5047)
### Additions and Improvements
- Added option to evm CLI tool to allow code execution at specific forks [#4913](https://github.com/hyperledger/besu/pull/4913)

@ -20,7 +20,7 @@ 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;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedIntParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -66,10 +66,7 @@ public class EthFeeHistory implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final Object requestId = request.getRequest().getId();
final long blockCount =
Optional.of(request.getRequiredParameter(0, UnsignedLongParameter.class))
.map(UnsignedLongParameter::getValue)
.orElse(0L);
final int blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue();
if (blockCount < 1 || blockCount > 1024) {
return new JsonRpcErrorResponse(requestId, JsonRpcError.INVALID_PARAMS);

@ -69,14 +69,14 @@ public class EthFeeHistoryTest {
// should fail because no required params given
assertThatThrownBy(this::feeHistoryRequest).isInstanceOf(InvalidJsonRpcParameters.class);
// should fail because newestBlock not given
assertThatThrownBy(() -> feeHistoryRequest(1)).isInstanceOf(InvalidJsonRpcParameters.class);
assertThatThrownBy(() -> feeHistoryRequest("0x1")).isInstanceOf(InvalidJsonRpcParameters.class);
// should fail because blockCount not given
assertThatThrownBy(() -> feeHistoryRequest("latest"))
.isInstanceOf(InvalidJsonRpcParameters.class);
// should pass because both required params given
feeHistoryRequest(1, "latest");
feeHistoryRequest("0x1", "latest");
// should pass because both required params and optional param given
feeHistoryRequest(1, "latest", new double[] {1, 20.4});
feeHistoryRequest("0x1", "latest", new double[] {1, 20.4});
// should pass because both required params and optional param given
feeHistoryRequest("0x1", "latest", new double[] {1, 20.4});
}
@ -87,7 +87,7 @@ public class EthFeeHistoryTest {
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getByBlockNumber(eq(11L))).thenReturn(londonSpec);
assertThat(
((JsonRpcSuccessResponse) feeHistoryRequest(1, "latest", new double[] {100.0}))
((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest", new double[] {100.0}))
.getResult())
.isEqualTo(
FeeHistory.FeeHistoryResult.from(
@ -104,7 +104,9 @@ public class EthFeeHistoryTest {
final ProtocolSpec londonSpec = mock(ProtocolSpec.class);
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(londonSpec);
assertThat(((JsonRpcErrorResponse) feeHistoryRequest(2, "11", new double[] {100.0})).getError())
assertThat(
((JsonRpcErrorResponse) feeHistoryRequest("0x2", "11", new double[] {100.0}))
.getError())
.isEqualTo(JsonRpcError.INVALID_PARAMS);
}
@ -114,11 +116,11 @@ public class EthFeeHistoryTest {
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(londonSpec);
assertThat(
((JsonRpcErrorResponse) feeHistoryRequest(0, "latest", new double[] {100.0}))
((JsonRpcErrorResponse) feeHistoryRequest("0x0", "latest", new double[] {100.0}))
.getError())
.isEqualTo(JsonRpcError.INVALID_PARAMS);
assertThat(
((JsonRpcErrorResponse) feeHistoryRequest(1025, "latest", new double[] {100.0}))
((JsonRpcErrorResponse) feeHistoryRequest("0x401", "latest", new double[] {100.0}))
.getError())
.isEqualTo(JsonRpcError.INVALID_PARAMS);
}
@ -130,7 +132,7 @@ public class EthFeeHistoryTest {
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(londonSpec);
final FeeHistory.FeeHistoryResult result =
(ImmutableFeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest(20, "latest")).getResult();
((JsonRpcSuccessResponse) feeHistoryRequest("0x14", "latest")).getResult();
assertThat(Long.decode(result.getOldestBlock())).isEqualTo(0);
assertThat(result.getBaseFeePerGas()).hasSize(12);
assertThat(result.getGasUsedRatio()).hasSize(11);
@ -144,7 +146,7 @@ public class EthFeeHistoryTest {
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(londonSpec);
final FeeHistory.FeeHistoryResult result =
(FeeHistory.FeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest(1, "latest")).getResult();
((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest")).getResult();
assertThat(Wei.fromHexString(result.getBaseFeePerGas().get(1)))
.isEqualTo(FeeMarket.london(11).getInitialBasefee());
}
@ -162,7 +164,7 @@ public class EthFeeHistoryTest {
blockchain.appendBlock(emptyBlock, gen.receipts(emptyBlock));
final FeeHistory.FeeHistoryResult result =
(FeeHistory.FeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest(1, "latest", new double[] {100.0}))
((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest", new double[] {100.0}))
.getResult();
assertThat(result.getReward()).isEqualTo(List.of(List.of("0x0")));
}

@ -4,7 +4,7 @@
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": [
2,
"0x2",
"latest",
[
0.0,

@ -4,7 +4,7 @@
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": [
2,
"0x2",
"latest"
]
},

Loading…
Cancel
Save