-
Notifications
You must be signed in to change notification settings - Fork 289
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
Starting from transitioned initial anchor with tests #8221
Draft
zilm13
wants to merge
14
commits into
Consensys:master
Choose a base branch
from
zilm13:finalized-anchor-spike
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bd487b5
Make checkpoint sync work when finalized state is transitioned with e…
StefanBratanov 0526205
fix
StefanBratanov f157063
Add actual verification
StefanBratanov e076e5d
change comment a bit
StefanBratanov 9e78600
changes
StefanBratanov b201ce3
Add to changelog
StefanBratanov 872953b
Add test
StefanBratanov c05a1f2
change test name
StefanBratanov 6199a4a
add additional checks
StefanBratanov e05a5d7
change comment
StefanBratanov 11db693
Merge branch 'master' into finalized-anchor-spike
zilm13 c846f69
Merge branch 'master' into finalized-anchor-spike
zilm13 6158de3
Merge branch 'master' into finalized-anchor-spike
zilm13 1684b68
Transitioned anchor startup with acceptance test
zilm13 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
143 changes: 143 additions & 0 deletions
143
...eptance-test/java/tech/pegasys/teku/test/acceptance/TransitionedAnchorAcceptanceTest.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,143 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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 tech.pegasys.teku.test.acceptance; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.google.common.io.Resources; | ||
import java.net.URL; | ||
import java.security.SecureRandom; | ||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import org.junit.jupiter.api.Test; | ||
import tech.pegasys.teku.api.schema.bellatrix.SignedBeaconBlockBellatrix; | ||
import tech.pegasys.teku.bls.BLSKeyPair; | ||
import tech.pegasys.teku.infrastructure.bytes.Bytes20; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase; | ||
import tech.pegasys.teku.test.acceptance.dsl.GenesisGenerator.InitialStateData; | ||
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode; | ||
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder; | ||
import tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeys; | ||
import tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeystores; | ||
|
||
public class TransitionedAnchorAcceptanceTest extends AcceptanceTestBase { | ||
private static final URL JWT_FILE = Resources.getResource("auth/ee-jwt-secret.hex"); | ||
// SEED is chosen to have empty slots in the end of 3rd epoch. | ||
// TODO: Good to find one with earlier end epoch empty slots | ||
private static final byte[] SEED = new byte[] {0x11, 0x03, 0x04}; | ||
|
||
@Test | ||
@SuppressWarnings("DoNotCreateSecureRandomDirectly") | ||
void shouldMaintainValidatorsInMutableClient() throws Exception { | ||
final SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG"); | ||
rnd.setSeed(SEED); | ||
final String networkName = "swift"; | ||
|
||
final List<BLSKeyPair> node1Validators = | ||
IntStream.range(0, 16).mapToObj(__ -> BLSKeyPair.random(rnd)).toList(); | ||
final List<BLSKeyPair> node2Validators = | ||
IntStream.range(0, 3).mapToObj(__ -> BLSKeyPair.random(rnd)).toList(); | ||
|
||
final ValidatorKeystores node1ValidatorKeystores = | ||
new ValidatorKeystores( | ||
node1Validators.stream() | ||
.map(keyPair -> new ValidatorKeys(keyPair, Bytes32.random(rnd), false)) | ||
.toList()); | ||
// will be non-active in the beginning | ||
final ValidatorKeystores node2ValidatorKeystores = | ||
new ValidatorKeystores( | ||
node2Validators.stream() | ||
.map(keyPair -> new ValidatorKeys(keyPair, Bytes32.random(rnd), false)) | ||
.toList()); | ||
|
||
final InitialStateData genesis = | ||
createGenesisGenerator() | ||
.network(networkName) | ||
.withAltairEpoch(UInt64.ZERO) | ||
.withBellatrixEpoch(UInt64.ZERO) | ||
.validatorKeys(node1ValidatorKeystores, node2ValidatorKeystores) | ||
.generate(); | ||
|
||
final String node1FeeRecipient = "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73"; | ||
final TekuBeaconNode beaconNode1 = | ||
createTekuBeaconNode( | ||
TekuNodeConfigBuilder.createBeaconNode() | ||
.withStubExecutionEngine() | ||
.withJwtSecretFile(JWT_FILE) | ||
.withNetwork(networkName) | ||
.withRealNetwork() | ||
.withInitialState(genesis) | ||
.withAltairEpoch(UInt64.ZERO) | ||
.withBellatrixEpoch(UInt64.ZERO) | ||
.withValidatorProposerDefaultFeeRecipient(node1FeeRecipient) | ||
.withReadOnlyKeystorePath(node1ValidatorKeystores) | ||
.build()); | ||
|
||
beaconNode1.start(); | ||
beaconNode1.waitForFinalizationAfter(UInt64.valueOf(3)); | ||
|
||
final BeaconState finalizedState = beaconNode1.fetchFinalizedState(); | ||
final UInt64 finalizedSlot = finalizedState.getSlot(); | ||
final UInt64 finalizedEpoch = beaconNode1.getSpec().computeEpochAtSlot(finalizedSlot); | ||
final UInt64 finalizedEpochFirstSlot = | ||
beaconNode1.getSpec().computeStartSlotAtEpoch(finalizedEpoch); | ||
assertNotEquals(finalizedSlot, finalizedEpochFirstSlot); | ||
final UInt64 maxFinalizedSlot = | ||
beaconNode1.getSpec().computeStartSlotAtEpoch(finalizedEpoch.plus(1)); | ||
System.out.println( | ||
"State slot: " | ||
+ finalizedState.getSlot() | ||
+ ", maxSlot: " | ||
+ maxFinalizedSlot | ||
+ ", finalized Epoch: " | ||
+ finalizedEpoch); | ||
assertTrue(finalizedState.getSlot().isLessThan(maxFinalizedSlot)); | ||
final BeaconState transitionedFinalizedState = | ||
beaconNode1.getSpec().processSlots(finalizedState, maxFinalizedSlot); | ||
|
||
final String node2FeeRecipient = "0xfe3b557E8Fb62B89F4916B721be55ceB828DBd55"; | ||
final TekuBeaconNode beaconNode2 = | ||
createTekuBeaconNode( | ||
TekuNodeConfigBuilder.createBeaconNode() | ||
.withStubExecutionEngine() | ||
.withJwtSecretFile(JWT_FILE) | ||
.withNetwork(networkName) | ||
.withRealNetwork() | ||
.withInitialState(new InitialStateData(transitionedFinalizedState)) | ||
.withAltairEpoch(UInt64.ZERO) | ||
.withBellatrixEpoch(UInt64.ZERO) | ||
.withValidatorProposerDefaultFeeRecipient(node2FeeRecipient) | ||
.withReadOnlyKeystorePath(node2ValidatorKeystores) | ||
.withPeers(beaconNode1) | ||
.build()); | ||
|
||
beaconNode2.start(); | ||
beaconNode2.waitUntilInSyncWith(beaconNode1); | ||
beaconNode2.waitForBlockSatisfying( | ||
block -> { | ||
assertThat(block).isInstanceOf(SignedBeaconBlockBellatrix.class); | ||
final SignedBeaconBlockBellatrix bellatrixBlock = (SignedBeaconBlockBellatrix) block; | ||
assertEquals( | ||
Bytes20.fromHexString(node2FeeRecipient), | ||
bellatrixBlock.getMessage().getBody().executionPayload.feeRecipient); | ||
}); | ||
beaconNode2.waitForNewFinalization(); | ||
} | ||
} |
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
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.
my understand is that this is ok since this endpoint should mimic the same behaviour as the
/eth/v2/debug/beacon/states/{state_id}
but allowing to search for block. We're using the same blockroot for the transitioned state so it looks logical to me that we returned the transitioned state