use of tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary in project teku by ConsenSys.
the class ForkChoiceTest method onBlock_shouldNotTriggerReorgWhenSelectingChildOfChainHeadWhenForkChoiceSlotHasAdvanced.
@Test
void onBlock_shouldNotTriggerReorgWhenSelectingChildOfChainHeadWhenForkChoiceSlotHasAdvanced() {
// Advance the current head
final UInt64 nodeSlot = UInt64.valueOf(5);
processHead(nodeSlot);
final SignedBlockAndState blockAndState = chainBuilder.generateBlockAtSlot(ONE);
final SafeFuture<BlockImportResult> importResult = forkChoice.onBlock(blockAndState.getBlock(), executionEngine);
assertBlockImportedSuccessfully(importResult, false);
assertThat(recentChainData.getHeadBlock().map(MinimalBeaconBlockSummary::getRoot)).contains(blockAndState.getRoot());
assertThat(recentChainData.getHeadSlot()).isEqualTo(blockAndState.getSlot());
assertThat(storageSystem.chainHeadChannel().getReorgEvents()).isEmpty();
}
use of tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary in project teku by ConsenSys.
the class RecentChainDataTest method updateHead_blockAndStateAreMissing.
@Test
public void updateHead_blockAndStateAreMissing() {
initPostGenesis();
final SignedBlockAndState bestBlock = chainBuilder.generateNextBlock();
recentChainData.updateHead(bestBlock.getRoot(), bestBlock.getSlot());
assertThat(recentChainData.getChainHead().map(MinimalBeaconBlockSummary::getRoot)).contains(genesis.getRoot());
}
use of tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary in project teku by ConsenSys.
the class SlotProcessorTest method shouldPrecomputeEpochTransitionJustBeforeFirstSlotOfNextEpoch.
@Test
void shouldPrecomputeEpochTransitionJustBeforeFirstSlotOfNextEpoch() {
final RecentChainData recentChainData = mock(RecentChainData.class);
when(recentChainData.getGenesisTime()).thenReturn(genesisTime);
final Optional<MinimalBeaconBlockSummary> headBlock = storageSystem.recentChainData().getHeadBlock();
when(recentChainData.getHeadBlock()).thenReturn(headBlock);
when(recentChainData.retrieveStateAtSlot(any())).thenReturn(new SafeFuture<>());
when(syncStateProvider.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
final SlotProcessor slotProcessor = new SlotProcessor(spec, recentChainData, syncStateProvider, forkChoiceTrigger, forkChoiceNotifier, p2pNetwork, slotEventsChannel, epochCachePrimer, eventLogger);
slotProcessor.setCurrentSlot(UInt64.valueOf(6));
final UInt64 slot6StartTime = spec.getSlotStartTime(UInt64.valueOf(6), genesisTime);
final UInt64 slot7StartTime = spec.getSlotStartTime(UInt64.valueOf(7), genesisTime);
// Progress through to end of initial epoch
slotProcessor.onTick(slot6StartTime);
slotProcessor.onTick(slot6StartTime.plus(secondsPerSlot / 3));
slotProcessor.onTick(slot6StartTime.plus(secondsPerSlot / 3 * 2));
slotProcessor.onTick(slot7StartTime);
slotProcessor.onTick(slot7StartTime.plus(secondsPerSlot / 3));
// Shouldn't have precomputed epoch transition yet.
verify(recentChainData, never()).retrieveStateAtSlot(any());
// But just before the last slot of the epoch ends, we should precompute the next epoch
slotProcessor.onTick(slot7StartTime.plus(secondsPerSlot / 3 * 2));
verify(epochCachePrimer).primeCacheForEpoch(ONE);
// Should not repeat computation
slotProcessor.onTick(slot7StartTime.plus(secondsPerSlot / 3 * 2 + 1));
slotProcessor.onTick(slot7StartTime.plus(secondsPerSlot / 3 * 2 + 2));
verify(recentChainData, atMostOnce()).retrieveStateAtSlot(any());
}
use of tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary in project teku by ConsenSys.
the class ForkChoiceTest method onBlock_shouldImmediatelyMakeChildOfCurrentHeadTheNewHead.
@Test
void onBlock_shouldImmediatelyMakeChildOfCurrentHeadTheNewHead() {
final SignedBlockAndState blockAndState = chainBuilder.generateBlockAtSlot(ONE);
final SafeFuture<BlockImportResult> importResult = forkChoice.onBlock(blockAndState.getBlock(), executionEngine);
assertBlockImportedSuccessfully(importResult, false);
assertThat(recentChainData.getHeadBlock().map(MinimalBeaconBlockSummary::getRoot)).contains(blockAndState.getRoot());
assertThat(recentChainData.getHeadSlot()).isEqualTo(blockAndState.getSlot());
}
use of tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary in project teku by ConsenSys.
the class RecentChainDataTest method updateHead_validUpdate.
@Test
public void updateHead_validUpdate() {
initPostGenesis();
// Ensure the current and previous target root blocks are different
chainBuilder.generateBlockAtSlot(genesisSpecConfig.getSlotsPerEpoch() - 1);
chainBuilder.generateBlockAtSlot(genesisSpecConfig.getSlotsPerEpoch() * 2L - 1);
final SignedBlockAndState bestBlock = chainBuilder.generateNextBlock();
chainBuilder.streamBlocksAndStates().forEach(blockAndState -> saveBlock(recentChainData, blockAndState));
recentChainData.updateHead(bestBlock.getRoot(), bestBlock.getSlot());
assertThat(recentChainData.getChainHead().map(MinimalBeaconBlockSummary::getRoot)).contains(bestBlock.getRoot());
assertThat(this.storageSystem.chainHeadChannel().getHeadEvents()).contains(new HeadEvent(bestBlock.getSlot(), bestBlock.getStateRoot(), bestBlock.getRoot(), true, true, spec.getBeaconStateUtil(bestBlock.getSlot()).getPreviousDutyDependentRoot(bestBlock.getState()), spec.getBeaconStateUtil(bestBlock.getSlot()).getCurrentDutyDependentRoot(bestBlock.getState())));
}
Aggregations