Search in sources :

Example 1 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder 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 2 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder 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 3 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.

the class AbstractBlockMetadataStoreTest method processHashesInChain_shouldWalkUpSpecifiedChain.

@Test
void processHashesInChain_shouldWalkUpSpecifiedChain() {
    // First chain has all blocks up to 10
    // Fork chain has 0-5, skips 6 and then has 7-10
    chainBuilder.generateBlocksUpToSlot(5);
    final ChainBuilder forkBuilder = chainBuilder.fork();
    chainBuilder.generateBlocksUpToSlot(10);
    forkBuilder.generateBlockAtSlot(7);
    forkBuilder.generateBlocksUpToSlot(10);
    final BlockMetadataStore store = createBlockMetadataStore(chainBuilder);
    store.applyUpdate(forkBuilder.streamBlocksAndStates().map(BlockAndCheckpointEpochs::fromBlockAndState).collect(toList()), Collections.emptySet(), genesisCheckpoint);
    verifyHashesInChain(store, forkBuilder, forkBuilder.getLatestBlockAndState().getRoot(), forkBuilder.streamBlocksAndStates());
    verifyHashesInChain(store, chainBuilder, chainBuilder.getLatestBlockAndState().getRoot(), chainBuilder.streamBlocksAndStates());
    // And check we can start from part way along the chain
    verifyHashesInChain(store, chainBuilder, chainBuilder.getBlockAtSlot(6).getRoot(), chainBuilder.streamBlocksAndStates(0, 6));
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) BlockAndCheckpointEpochs(tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs) Test(org.junit.jupiter.api.Test)

Example 4 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.

the class AbstractBlockMetadataStoreTest method findCommonAncestor_commonAncestorNotInProtoArray.

@Test
void findCommonAncestor_commonAncestorNotInProtoArray() {
    final ChainBuilder fork = chainBuilder.fork();
    final SignedBlockAndState chainHead = chainBuilder.generateBlockAtSlot(spec.getSlotsPerHistoricalRoot(fork.getLatestSlot()) + 2);
    // Fork skips slot 1 so the chains are different
    fork.generateBlockAtSlot(1);
    final SignedBlockAndState forkHead = fork.generateBlockAtSlot(spec.getSlotsPerHistoricalRoot(fork.getLatestSlot()) + 2);
    // We don't add the fork to protoarray, much like it was invalidated by the finalized checkpoint
    assertCommonAncestorFound(chainHead.getRoot(), forkHead.getRoot(), Optional.empty());
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 5 with ChainBuilder

use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.

the class ForkChoiceStrategyTest method createBlockMetadataStore.

@Override
protected BlockMetadataStore createBlockMetadataStore(final ChainBuilder chainBuilder, final ChainBuilder... additionalBuilders) {
    final BeaconState latestState = chainBuilder.getLatestBlockAndState().getState();
    final ProtoArray protoArray = ProtoArray.builder().finalizedCheckpoint(latestState.getFinalized_checkpoint()).justifiedCheckpoint(latestState.getCurrent_justified_checkpoint()).build();
    addBlocksFromBuilder(chainBuilder, protoArray);
    for (ChainBuilder builder : additionalBuilders) {
        addBlocksFromBuilder(builder, protoArray);
    }
    return ForkChoiceStrategy.initialize(spec, protoArray);
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

ChainBuilder (tech.pegasys.teku.core.ChainBuilder)33 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)30 Test (org.junit.jupiter.api.Test)27 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)18 BlockOptions (tech.pegasys.teku.core.ChainBuilder.BlockOptions)7 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)5 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)5 Eth1Data (tech.pegasys.teku.spec.datastructures.blocks.Eth1Data)4 StoreTransaction (tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction)4 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)3 ChainUpdater (tech.pegasys.teku.storage.client.ChainUpdater)3 HashSet (java.util.HashSet)2 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)2 BlockAndCheckpointEpochs (tech.pegasys.teku.spec.datastructures.blocks.BlockAndCheckpointEpochs)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 ReorgEvent (tech.pegasys.teku.storage.api.TrackingChainHeadChannel.ReorgEvent)2 StorageSystem (tech.pegasys.teku.storage.storageSystem.StorageSystem)2 ArrayList (java.util.ArrayList)1