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());
}
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());
}
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));
}
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());
}
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);
}
Aggregations