Search in sources :

Example 1 with MinimalBeaconBlockSummary

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();
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Test(org.junit.jupiter.api.Test)

Example 2 with MinimalBeaconBlockSummary

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());
}
Also used : SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Test(org.junit.jupiter.api.Test)

Example 3 with MinimalBeaconBlockSummary

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());
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Test(org.junit.jupiter.api.Test)

Example 4 with MinimalBeaconBlockSummary

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());
}
Also used : SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Test(org.junit.jupiter.api.Test)

Example 5 with MinimalBeaconBlockSummary

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())));
}
Also used : HeadEvent(tech.pegasys.teku.storage.api.TrackingChainHeadChannel.HeadEvent) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Test(org.junit.jupiter.api.Test)

Aggregations

MinimalBeaconBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary)7 Test (org.junit.jupiter.api.Test)5 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)2 Throwables (com.google.common.base.Throwables)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 NavigableMap (java.util.NavigableMap)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 LogManager (org.apache.logging.log4j.LogManager)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 SafeFuture.completedFuture (tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture)1 ONE (tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE)1 ZERO (tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO)1 Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)1 BeaconChainMethodIds (tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethodIds)1 PeerRequiredLocalMessageHandler (tech.pegasys.teku.networking.eth2.rpc.core.PeerRequiredLocalMessageHandler)1 ResponseCallback (tech.pegasys.teku.networking.eth2.rpc.core.ResponseCallback)1