Search in sources :

Example 1 with ChainUpdater

use of tech.pegasys.teku.storage.client.ChainUpdater in project teku by ConsenSys.

the class AbstractDataBackedRestAPIIntegrationTest method setupStorage.

private void setupStorage(final StateStorageMode storageMode, final boolean useMockForkChoice, final SpecMilestone specMilestone) {
    this.spec = TestSpecFactory.createMinimal(specMilestone);
    this.specConfig = spec.getGenesisSpecConfig();
    this.storageSystem = InMemoryStorageSystemBuilder.create().specProvider(spec).storageMode(storageMode).build();
    activeValidatorChannel = new ActiveValidatorCache(spec, 10);
    recentChainData = storageSystem.recentChainData();
    chainBuilder = ChainBuilder.create(spec, VALIDATOR_KEYS);
    chainUpdater = new ChainUpdater(recentChainData, chainBuilder, spec);
    forkChoice = useMockForkChoice ? mock(ForkChoice.class) : new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP));
}
Also used : ActiveValidatorCache(tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache) ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier)

Example 2 with ChainUpdater

use of tech.pegasys.teku.storage.client.ChainUpdater in project teku by ConsenSys.

the class DefaultPerformanceTrackerTest method shouldDisplayIncorrectTargetRoot.

@Test
void shouldDisplayIncorrectTargetRoot() {
    chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(1));
    ChainBuilder chainBuilderFork = chainBuilder.fork();
    ChainUpdater chainUpdaterFork = new ChainUpdater(storageSystem.recentChainData(), chainBuilderFork);
    chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(8));
    ChainBuilder.BlockOptions block1Options = ChainBuilder.BlockOptions.create();
    Attestation attestation1 = createAttestation(9, 8);
    block1Options.addAttestation(attestation1);
    SignedBlockAndState blockAndState1 = chainBuilder.generateBlockAtSlot(9, block1Options);
    chainUpdater.saveBlock(blockAndState1);
    chainUpdater.updateBestBlock(blockAndState1);
    chainUpdaterFork.advanceChain(6);
    chainUpdaterFork.advanceChainUntil(9);
    ChainBuilder.BlockOptions block2Options = ChainBuilder.BlockOptions.create();
    Attestation attestation2 = createAttestation(chainBuilderFork, 10, 9);
    block2Options.addAttestation(attestation2);
    SignedBlockAndState blockAndState2 = chainBuilder.generateBlockAtSlot(10, block2Options);
    chainUpdater.saveBlock(blockAndState2);
    chainUpdater.updateBestBlock(blockAndState2);
    performanceTracker.saveProducedAttestation(attestation1);
    performanceTracker.saveProducedAttestation(attestation2);
    when(validatorTracker.getNumberOfValidatorsForEpoch(any())).thenReturn(2);
    UInt64 slot = spec.computeStartSlotAtEpoch(ATTESTATION_INCLUSION_RANGE.plus(1));
    performanceTracker.onSlot(slot);
    when(validatorTracker.getNumberOfValidatorsForEpoch(any())).thenReturn(2);
    UInt64 attestationEpoch = spec.computeEpochAtSlot(slot).minus(ATTESTATION_INCLUSION_RANGE);
    AttestationPerformance expectedAttestationPerformance = new AttestationPerformance(attestationEpoch, 2, 2, 2, 1, 1, 1, 1, 1);
    verify(log).performance(expectedAttestationPerformance.toString());
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Test(org.junit.jupiter.api.Test)

Example 3 with ChainUpdater

use of tech.pegasys.teku.storage.client.ChainUpdater in project teku by ConsenSys.

the class DefaultPerformanceTrackerTest method shouldDisplayIncorrectHeadBlockRoot.

@Test
void shouldDisplayIncorrectHeadBlockRoot() {
    chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(1));
    ChainBuilder chainBuilderFork = chainBuilder.fork();
    ChainUpdater chainUpdaterFork = new ChainUpdater(storageSystem.recentChainData(), chainBuilderFork);
    chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(9));
    ChainBuilder.BlockOptions block1Options = ChainBuilder.BlockOptions.create();
    Attestation attestation1 = createAttestation(10, 9);
    block1Options.addAttestation(attestation1);
    SignedBlockAndState blockAndState1 = chainBuilder.generateBlockAtSlot(10, block1Options);
    chainUpdater.saveBlock(blockAndState1);
    chainUpdater.updateBestBlock(blockAndState1);
    SignedBlockAndState blockAndState = chainUpdaterFork.advanceChainUntil(8);
    ChainBuilder.BlockOptions block2Options = ChainBuilder.BlockOptions.create();
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, chainBuilder.getValidatorKeys());
    Attestation attestation2 = attestationGenerator.validAttestation(blockAndState.toUnsigned(), UInt64.valueOf(9));
    block2Options.addAttestation(attestation2);
    SignedBlockAndState blockAndState2 = chainBuilder.generateBlockAtSlot(11, block2Options);
    chainUpdater.saveBlock(blockAndState2);
    chainUpdater.updateBestBlock(blockAndState2);
    performanceTracker.saveProducedAttestation(attestation1);
    performanceTracker.saveProducedAttestation(attestation2);
    when(validatorTracker.getNumberOfValidatorsForEpoch(any())).thenReturn(2);
    UInt64 slot = spec.computeStartSlotAtEpoch(ATTESTATION_INCLUSION_RANGE.plus(1));
    performanceTracker.onSlot(slot);
    UInt64 attestationEpoch = spec.computeEpochAtSlot(slot).minus(ATTESTATION_INCLUSION_RANGE);
    AttestationPerformance expectedAttestationPerformance = new AttestationPerformance(attestationEpoch, 2, 2, 2, 2, 1, 1.5, 2, 1);
    verify(log).performance(expectedAttestationPerformance.toString());
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Test(org.junit.jupiter.api.Test)

Example 4 with ChainUpdater

use of tech.pegasys.teku.storage.client.ChainUpdater in project teku by ConsenSys.

the class ForkChoiceTest method onBlock_shouldHandleNonCanonicalBlockThatUpdatesJustifiedCheckpoint.

@Test
void onBlock_shouldHandleNonCanonicalBlockThatUpdatesJustifiedCheckpoint() {
    // If the new block is not the child of the current head block we use `ProtoArray.findHead`
    // to check if it should become the new head.  If importing that block caused the justified
    // checkpoint to be updated, then the justified epoch in ProtoArray won't match the justified
    // epoch of the new head so it considers the head invalid.  Normally that update is done when
    // applying pending votes.
    final ChainUpdater chainUpdater = storageSystem.chainUpdater();
    final UInt64 epoch4StartSlot = spec.computeStartSlotAtEpoch(UInt64.valueOf(4));
    // Set the time to be the start of epoch 3 so all the blocks we need are valid
    chainUpdater.setTime(spec.getSlotStartTime(epoch4StartSlot, genesis.getState().getGenesis_time()));
    justifyEpoch(chainUpdater, 2);
    // Update ProtoArray to avoid the special case of considering the anchor
    // epoch as allowing all nodes to be a valid head.
    processHead(epoch4StartSlot);
    prepEpochForJustification(chainUpdater, epoch4StartSlot);
    // Switch head to a different fork so the next block has to use findHead
    chainUpdater.updateBestBlock(chainBuilder.fork().generateNextBlock());
    final SignedBlockAndState epoch4Block = chainBuilder.generateBlockAtSlot(epoch4StartSlot);
    importBlock(epoch4Block);
    // Should now have justified epoch 3
    assertThat(recentChainData.getJustifiedCheckpoint()).map(Checkpoint::getEpoch).contains(UInt64.valueOf(3));
    // The only block with the newly justified checkpoint is epoch4Block so it should become head
    assertThat(recentChainData.getBestBlockRoot()).contains(epoch4Block.getRoot());
}
Also used : ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 5 with ChainUpdater

use of tech.pegasys.teku.storage.client.ChainUpdater in project teku by ConsenSys.

the class ForkChoiceTest method prepFinalizeEpoch.

private UInt64 prepFinalizeEpoch(long epoch) {
    final ChainUpdater chainUpdater = storageSystem.chainUpdater();
    final UInt64 epochPlus2StartSlot = spec.computeStartSlotAtEpoch(UInt64.valueOf(epoch).plus(2));
    chainUpdater.setTime(spec.getSlotStartTime(epochPlus2StartSlot, genesis.getState().getGenesis_time()));
    justifyEpoch(chainUpdater, epoch);
    prepEpochForJustification(chainUpdater, epochPlus2StartSlot);
    return epochPlus2StartSlot;
}
Also used : ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Aggregations

ChainUpdater (tech.pegasys.teku.storage.client.ChainUpdater)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)4 Test (org.junit.jupiter.api.Test)3 ChainBuilder (tech.pegasys.teku.core.ChainBuilder)3 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 TestTemplate (org.junit.jupiter.api.TestTemplate)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)1 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)1 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)1 ForkChoice (tech.pegasys.teku.statetransition.forkchoice.ForkChoice)1 MergeTransitionBlockValidator (tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator)1 StubForkChoiceNotifier (tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier)1 ActiveValidatorCache (tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache)1 StorageSystem (tech.pegasys.teku.storage.storageSystem.StorageSystem)1