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