-
Notifications
You must be signed in to change notification settings - Fork 871
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
[PAN-3023] Add command line option for target gas limit #24
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2d529b8
[PAN-3023] Add command line option for target gas limit
cfelde d6b2cdf
Merge remote-tracking branch 'remotes/upstream/master' into PAN-3023
cfelde fd74238
[PAN-3023] Add command line option for target gas limit
cfelde c7bb027
Merge remote-tracking branch 'remotes/upstream/master' into PAN-3023
cfelde e0012e7
[PAN-3023] Add command line option for target gas limit
cfelde c04fbcb
Merge remote-tracking branch 'remotes/upstream/master' into PAN-3023
cfelde 0765ec5
Merge remote-tracking branch 'remotes/upstream/master' into PAN-3023
cfelde a18c3ee
[PAN-3023] Add command line option for target gas limit
cfelde 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 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 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 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 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
46 changes: 46 additions & 0 deletions
46
besu/src/main/java/org/hyperledger/besu/controller/GasLimitCalculator.java
This file contains 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,46 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* 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. | ||
*/ | ||
package org.hyperledger.besu.controller; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class GasLimitCalculator implements Function<Long, Long> { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
public static final long ADJUSTMENT_FACTOR = 1024L; | ||
public static final Long DEFAULT = null; | ||
private final long targetGasLimit; | ||
|
||
public GasLimitCalculator(final Long targetGasLimit) { | ||
shemnon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.targetGasLimit = targetGasLimit == null ? 0L : targetGasLimit; | ||
} | ||
|
||
@Override | ||
public Long apply(final Long gasLimit) { | ||
long newGasLimit; | ||
|
||
if (targetGasLimit > gasLimit) { | ||
cfelde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
newGasLimit = Math.min(targetGasLimit, gasLimit + ADJUSTMENT_FACTOR); | ||
} else if (targetGasLimit < gasLimit) { | ||
newGasLimit = Math.max(targetGasLimit, gasLimit - ADJUSTMENT_FACTOR); | ||
} else { | ||
return gasLimit; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returns should occur at the same level of logic, unless this is a guard block. If targetGasLimit were an optional this return could be come a guard block at the top of the method. edit disregard, Github was showing me old code on my second review. |
||
} | ||
|
||
LOG.debug("Adjusting block gas limit from {} to {}", gasLimit, newGasLimit); | ||
|
||
return newGasLimit; | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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
44 changes: 44 additions & 0 deletions
44
besu/src/test/java/org/hyperledger/besu/controller/GasLimitCalculatorTest.java
This file contains 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,44 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* 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. | ||
*/ | ||
package org.hyperledger.besu.controller; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.junit.Test; | ||
|
||
public class GasLimitCalculatorTest { | ||
cfelde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Test | ||
public void verifyGasLimitIsIncreasedWithinLimits() { | ||
Function<Long, Long> gasLimitCalculator = new GasLimitCalculator(10_000_000L); | ||
assertThat(gasLimitCalculator.apply(8_000_000L)) | ||
.isEqualTo(8_000_000L + GasLimitCalculator.ADJUSTMENT_FACTOR); | ||
} | ||
|
||
@Test | ||
public void verifyGasLimitIsDecreasedWithinLimits() { | ||
Function<Long, Long> gasLimitCalculator = new GasLimitCalculator(10_000_000L); | ||
assertThat(gasLimitCalculator.apply(12_000_000L)) | ||
.isEqualTo(12_000_000L - GasLimitCalculator.ADJUSTMENT_FACTOR); | ||
} | ||
|
||
@Test | ||
public void verifyGasLimitReachesTarget() { | ||
final long target = 10_000_000L; | ||
final long offset = GasLimitCalculator.ADJUSTMENT_FACTOR / 2; | ||
Function<Long, Long> gasLimitCalculator = new GasLimitCalculator(target); | ||
assertThat(gasLimitCalculator.apply(target - offset)).isEqualTo(target); | ||
assertThat(gasLimitCalculator.apply(target + offset)).isEqualTo(target); | ||
} | ||
} |
This file contains 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 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.
I think this should be OptionalLong, so we don't have to deal with empty.
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.
Per our coding conventions we should be using modern Java featurs such as optional instead of giving null contextual meaning.
edit Disregard, this was off of old code github was showing me.