-
Notifications
You must be signed in to change notification settings - Fork 357
Implemented expectedGasLimit from spec #8909
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 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6f870b6
Implemented expectedGasLimit from spec
rolfyone 8e6a4cb
changelog
rolfyone 78060db
typo
rolfyone 71620bd
Merge branch 'master' into builder-gas-computation
rolfyone e8c4857
Merge branch 'master' into builder-gas-computation
rolfyone 7933623
Merge branch 'master' into builder-gas-computation
rolfyone 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
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| package tech.pegasys.teku.ethereum.executionlayer; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.doNothing; | ||
|
|
@@ -24,12 +25,16 @@ | |
| import static tech.pegasys.teku.spec.schemas.ApiSchemas.VALIDATOR_REGISTRATION_SCHEMA; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.stream.Stream; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
| import org.apache.tuweni.bytes.Bytes32; | ||
| import org.apache.tuweni.units.bigints.UInt256; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import tech.pegasys.teku.bls.BLS; | ||
| import tech.pegasys.teku.bls.BLSConstants; | ||
| import tech.pegasys.teku.bls.BLSKeyPair; | ||
|
|
@@ -148,10 +153,21 @@ void shouldBeInvalidIfLocalPayloadWithdrawalsRootDoesNotMatchTheRootOfTheBid() { | |
| .orElseThrow()); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "parent.{0}_target.{1}_result.{2}") | ||
| @MethodSource("expectedGasLimitPermutations") | ||
| void expectedGasLimitTestCases( | ||
| final long parentGasLimit, final long targetGasLimit, final long expectedGasLimit) { | ||
| final UInt64 computedGasLimit = | ||
| BuilderBidValidatorImpl.expectedGasLimit( | ||
| UInt64.valueOf(parentGasLimit), UInt64.valueOf(targetGasLimit)); | ||
|
|
||
| assertThat(computedGasLimit).isEqualTo(UInt64.valueOf(expectedGasLimit)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotLogEventIfGasLimitDecreases() throws BuilderBidValidationException { | ||
|
|
||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1022_000), UInt64.valueOf(1023_000)); | ||
| // 1023001 is as high as it can move in 1 shot | ||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1022_000), UInt64.valueOf(1023_001)); | ||
|
|
||
| builderBidValidatorWithMockSpec.validateBuilderBid( | ||
| signedBuilderBid, validatorRegistration, state, Optional.empty()); | ||
|
|
@@ -161,8 +177,8 @@ void shouldNotLogEventIfGasLimitDecreases() throws BuilderBidValidationException | |
|
|
||
| @Test | ||
| void shouldNotLogEventIfGasLimitIncreases() throws BuilderBidValidationException { | ||
|
|
||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1025_000), UInt64.valueOf(2048_000)); | ||
| // 1024999 is as high as it can move in 1 shot | ||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1025_000), UInt64.valueOf(1024_999)); | ||
|
|
||
| builderBidValidatorWithMockSpec.validateBuilderBid( | ||
| signedBuilderBid, validatorRegistration, state, Optional.empty()); | ||
|
|
@@ -184,27 +200,44 @@ void shouldNotLogEventIfGasLimitStaysTheSame() throws BuilderBidValidationExcept | |
| @Test | ||
| void shouldLogEventIfGasLimitDoesNotDecrease() throws BuilderBidValidationException { | ||
|
|
||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1024_000), UInt64.valueOf(1023_100)); | ||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1024_000), UInt64.valueOf(1020_000)); | ||
|
|
||
| builderBidValidatorWithMockSpec.validateBuilderBid( | ||
| signedBuilderBid, validatorRegistration, state, Optional.empty()); | ||
|
|
||
| verify(eventLogger) | ||
| .builderBidNotHonouringGasLimit( | ||
| UInt64.valueOf(1024_000), UInt64.valueOf(1024_000), UInt64.valueOf(1023_100)); | ||
| UInt64.valueOf(1024_000), UInt64.valueOf(1024_000), UInt64.valueOf(1020_000)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldLogEventIfGasLimitDoesNotIncrease() throws BuilderBidValidationException { | ||
|
|
||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1020_000), UInt64.valueOf(1024_100)); | ||
| prepareGasLimit(UInt64.valueOf(1024_000), UInt64.valueOf(1020_000), UInt64.valueOf(1028_000)); | ||
|
|
||
| builderBidValidatorWithMockSpec.validateBuilderBid( | ||
| signedBuilderBid, validatorRegistration, state, Optional.empty()); | ||
|
|
||
| verify(eventLogger) | ||
| .builderBidNotHonouringGasLimit( | ||
| UInt64.valueOf(1024_000), UInt64.valueOf(1020_000), UInt64.valueOf(1024_100)); | ||
| UInt64.valueOf(1024_000), UInt64.valueOf(1020_000), UInt64.valueOf(1028_000)); | ||
| } | ||
|
|
||
| static Stream<Arguments> expectedGasLimitPermutations() { | ||
| return Stream.of( | ||
| // same, expect no change | ||
| Arguments.of(36_000_000L, 36_000_000L, 36_000_000L), | ||
| Arguments.of(1024_000L, 1024_000L, 1024_000L), | ||
| // down inside bounds | ||
| Arguments.of(1024_000L, 1023_500L, 1023_500L), | ||
| // down outside bounds - results in a partial move | ||
| Arguments.of(36_000_000L, 35_000_000L, 35_964_845L), | ||
| Arguments.of(1024_000L, 1020_000L, 1023_001L), | ||
| // increase outside bounds - results in a partial move | ||
| Arguments.of(1024_000L, 1025_000L, 1024_999L), | ||
| Arguments.of(30_000_000L, 36_000_000L, 30_029_295L), | ||
| // increase inside bounds | ||
| Arguments.of(1024_000L, 1024_500L, 1024_500L)); | ||
|
Comment on lines
+229
to
+240
Contributor
Author
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. @jtraglia so the args are parent, target, expected output... |
||
| } | ||
|
|
||
| private void prepareValidSignedBuilderBid() { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.