Skip to content

Commit

Permalink
Change param of to hexadecimal of Eth fee history to match spec (hype…
Browse files Browse the repository at this point in the history
…rledger#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>
  • Loading branch information
gfukushima authored Feb 6, 2023
1 parent a3a32dd commit 98ea871
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;
Expand Down Expand Up @@ -66,10 +66,7 @@ public String getName() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public void params() {
// 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});
}
Expand All @@ -87,7 +87,7 @@ public void allFieldsPresentForLatestBlock() {
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(
Expand All @@ -104,7 +104,9 @@ public void cantGetBlockHigherThanChainHead() {
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);
}

Expand All @@ -114,11 +116,11 @@ public void blockCountBounds() {
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);
}
Expand All @@ -130,7 +132,7 @@ public void doesntGoPastChainHeadWithHighBlockCount() {
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);
Expand All @@ -144,7 +146,7 @@ public void correctlyHandlesForkBlock() {
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());
}
Expand All @@ -162,7 +164,7 @@ public void allZeroPercentilesForZeroBlock() {
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")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": [
2,
"0x2",
"latest",
[
0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"jsonrpc": "2.0",
"method": "eth_feeHistory",
"params": [
2,
"0x2",
"latest"
]
},
Expand Down

0 comments on commit 98ea871

Please sign in to comment.