-
Notifications
You must be signed in to change notification settings - Fork 1k
Add API to set and get the minGasPrice at runtime #6097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aebe260
Add API to set and get the minGasPrice at runtime
fab-10 6e902e8
Merge branch 'main' into miner_set_get_minGasPrice
fab-10 7c8e241
Restore javadoc and sources jar as trusted artifacts
fab-10 6196bbb
Merge branch 'verification-metadata-trust-javadoc-sources' into miner…
fab-10 59d0f5d
Add unit tests
fab-10 3161f1d
Merge branch 'main' into miner_set_get_minGasPrice
fab-10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPrice.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright Hyperledger Besu Contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner; | ||
|
|
||
| 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.methods.JsonRpcMethod; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; | ||
| import org.hyperledger.besu.ethereum.core.MiningParameters; | ||
|
|
||
| public class MinerGetMinGasPrice implements JsonRpcMethod { | ||
| private final MiningParameters miningParameters; | ||
|
|
||
| public MinerGetMinGasPrice(final MiningParameters miningParameters) { | ||
| this.miningParameters = miningParameters; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return RpcMethod.MINER_GET_MIN_GAS_PRICE.getMethodName(); | ||
| } | ||
|
|
||
| @Override | ||
| public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | ||
| return new JsonRpcSuccessResponse( | ||
| requestContext.getRequest().getId(), | ||
| Quantity.create(miningParameters.getMinTransactionGasPrice())); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPrice.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright Hyperledger Besu Contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner; | ||
|
|
||
| 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.methods.JsonRpcMethod; | ||
| 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; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; | ||
| import org.hyperledger.besu.ethereum.core.MiningParameters; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class MinerSetMinGasPrice implements JsonRpcMethod { | ||
| private static final Logger LOG = LoggerFactory.getLogger(MinerSetMinGasPrice.class); | ||
|
|
||
| private final MiningParameters miningParameters; | ||
|
|
||
| public MinerSetMinGasPrice(final MiningParameters miningParameters) { | ||
| this.miningParameters = miningParameters; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return RpcMethod.MINER_SET_MIN_GAS_PRICE.getMethodName(); | ||
| } | ||
|
|
||
| @Override | ||
| public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | ||
| try { | ||
| final Wei minGasPrice = | ||
| Wei.fromHexString(requestContext.getRequiredParameter(0, String.class)); | ||
| miningParameters.setMinTransactionGasPrice(minGasPrice); | ||
| LOG.debug("min gas price changed to {}", minGasPrice.toHumanReadableString()); | ||
| return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), true); | ||
| } catch (final IllegalArgumentException invalidJsonRpcParameters) { | ||
| return new JsonRpcErrorResponse( | ||
| requestContext.getRequest().getId(), | ||
| new JsonRpcError(RpcErrorType.INVALID_PARAMS, invalidJsonRpcParameters.getMessage())); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerGetMinGasPriceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright Hyperledger Besu Contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner; | ||
|
|
||
| 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.JsonRpcResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; | ||
| import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; | ||
| import org.hyperledger.besu.ethereum.core.MiningParameters; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class MinerGetMinGasPriceTest { | ||
|
|
||
| @Test | ||
| public void shouldReturnDefaultMinGasPrice() { | ||
| final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); | ||
| final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningParameters); | ||
| final JsonRpcRequestContext request = | ||
| new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); | ||
|
|
||
| final JsonRpcResponse expected = | ||
| new JsonRpcSuccessResponse( | ||
| request.getRequest().getId(), | ||
| Quantity.create(MiningParameters.MutableInitValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)); | ||
|
|
||
| final JsonRpcResponse actual = method.response(request); | ||
| assertThat(actual).usingRecursiveComparison().isEqualTo(expected); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnSetAtRuntimeMinGasPrice() { | ||
| final MiningParameters miningParameters = ImmutableMiningParameters.newDefault(); | ||
| final MinerGetMinGasPrice method = new MinerGetMinGasPrice(miningParameters); | ||
|
|
||
| final Wei minGasPriceAtRuntime = Wei.of(2000); | ||
|
|
||
| miningParameters.setMinTransactionGasPrice(minGasPriceAtRuntime); | ||
|
|
||
| final JsonRpcRequestContext request = | ||
| new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {})); | ||
|
|
||
| final JsonRpcResponse expected = | ||
| new JsonRpcSuccessResponse( | ||
| request.getRequest().getId(), Quantity.create(minGasPriceAtRuntime)); | ||
|
|
||
| final JsonRpcResponse actual = method.response(request); | ||
| assertThat(actual).usingRecursiveComparison().isEqualTo(expected); | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
...hyperledger/besu/ethereum/api/jsonrpc/internal/methods/miner/MinerSetMinGasPriceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright Hyperledger Besu Contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner; | ||
|
|
||
| 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.JsonRpcError; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; | ||
| import org.hyperledger.besu.ethereum.core.MiningParameters; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class MinerSetMinGasPriceTest { | ||
| MiningParameters miningParameters = MiningParameters.newDefault(); | ||
| private MinerSetMinGasPrice method; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| method = new MinerSetMinGasPrice(miningParameters); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnFalseWhenParameterIsInvalid() { | ||
| final String newMinGasPrice = "-1"; | ||
| final var request = request(newMinGasPrice); | ||
|
|
||
| method.response(request); | ||
| final JsonRpcResponse expected = | ||
| new JsonRpcErrorResponse( | ||
| request.getRequest().getId(), | ||
| new JsonRpcError( | ||
| RpcErrorType.INVALID_PARAMS, | ||
| "Illegal character '-' found at index 0 in hex binary representation")); | ||
|
|
||
| final JsonRpcResponse actual = method.response(request); | ||
| assertThat(actual).usingRecursiveComparison().isEqualTo(expected); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldChangeMinPriorityFee() { | ||
| final String newMinGasPrice = "0x10"; | ||
| final var request = request(newMinGasPrice); | ||
| method.response(request); | ||
| final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId(), true); | ||
|
|
||
| final JsonRpcResponse actual = method.response(request); | ||
| assertThat(actual).usingRecursiveComparison().isEqualTo(expected); | ||
| assertThat(miningParameters.getMinTransactionGasPrice()) | ||
| .isEqualTo(Wei.fromHexString(newMinGasPrice)); | ||
| } | ||
|
|
||
| private JsonRpcRequestContext request(final String newMinGasPrice) { | ||
| return new JsonRpcRequestContext( | ||
| new JsonRpcRequest("2.0", method.getName(), new Object[] {newMinGasPrice})); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double checking, did you mean to drop the first condition of this if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because now the
minGasPricecould change at runtime, so the check done in the txpool is no more enough, and we need to redo it here for every tx