Search in sources :

Example 1 with CombinedChainDataClient

use of tech.pegasys.teku.storage.client.CombinedChainDataClient in project teku by ConsenSys.

the class HistoricalBatchFetcherTest method setup.

@BeforeEach
public void setup() {
    storageSystem.chainUpdater().initializeGenesis();
    when(storageUpdateChannel.onFinalizedBlocks(any())).thenReturn(SafeFuture.COMPLETE);
    // Set up main chain and fork chain
    chainBuilder.generateGenesis();
    forkBuilder = chainBuilder.fork();
    chainBuilder.generateBlocksUpToSlot(20);
    // Fork skips one block then creates a chain of the same size
    forkBuilder.generateBlockAtSlot(2);
    forkBuilder.generateBlocksUpToSlot(20);
    blockBatch = chainBuilder.streamBlocksAndStates(10, 20).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
    lastBlockInBatch = chainBuilder.getLatestBlockAndState().getBlock();
    firstBlockInBatch = blockBatch.get(0);
    final StorageQueryChannel historicalChainData = mock(StorageQueryChannel.class);
    final RecentChainData recentChainData = storageSystem.recentChainData();
    chainDataClient = new CombinedChainDataClient(recentChainData, historicalChainData, spec);
    peer = RespondingEth2Peer.create(spec, chainBuilder);
    fetcher = new HistoricalBatchFetcher(storageUpdateChannel, signatureVerifier, chainDataClient, spec, peer, lastBlockInBatch.getSlot(), lastBlockInBatch.getRoot(), UInt64.valueOf(blockBatch.size()), maxRequests);
    final ForkInfo forkInfo = mock(ForkInfo.class);
    when(beaconState.getForkInfo()).thenReturn(forkInfo);
    when(forkInfo.getGenesisValidatorsRoot()).thenReturn(Bytes32.ZERO);
    when(signatureVerifier.verify(any(), any(), anyList())).thenReturn(SafeFuture.completedFuture(true));
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with CombinedChainDataClient

use of tech.pegasys.teku.storage.client.CombinedChainDataClient in project teku by ConsenSys.

the class WeakSubjectivityValidatorTest method mockChainDataClientPriorToCheckpoint.

private CombinedChainDataClient mockChainDataClientPriorToCheckpoint() {
    final CombinedChainDataClient client = mock(CombinedChainDataClient.class);
    when(client.isFinalizedEpoch(any())).thenReturn(false);
    return client;
}
Also used : CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient)

Example 3 with CombinedChainDataClient

use of tech.pegasys.teku.storage.client.CombinedChainDataClient in project teku by ConsenSys.

the class WeakSubjectivityValidatorTest method validateChainIsConsistentWithWSCheckpoint_checkpointFinalizedWithNonMatchingBlock.

@Test
public void validateChainIsConsistentWithWSCheckpoint_checkpointFinalizedWithNonMatchingBlock() {
    final UInt64 checkpointEpoch = UInt64.valueOf(100);
    final UInt64 checkpointSlot = spec.computeStartSlotAtEpoch(checkpointEpoch);
    final SignedBeaconBlock checkpointBlock = dataStructureUtil.randomSignedBeaconBlock(checkpointSlot);
    final SignedBeaconBlock otherBlock = dataStructureUtil.randomSignedBeaconBlock(checkpointSlot);
    final Checkpoint wsCheckpoint = new Checkpoint(checkpointEpoch, checkpointBlock.getRoot());
    final WeakSubjectivityConfig config = configBuilder().weakSubjectivityCheckpoint(wsCheckpoint).build();
    final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policy);
    final CombinedChainDataClient chainData = mockChainDataClientAfterCheckpoint(wsCheckpoint, otherBlock);
    SafeFuture<Void> result = validator.validateChainIsConsistentWithWSCheckpoint(chainData);
    assertThat(result).isCompleted();
    verify(chainData).isFinalizedEpoch(wsCheckpoint.getEpoch());
    verify(chainData).getFinalizedBlockInEffectAtSlot(wsCheckpoint.getEpochStartSlot(spec));
    verify(policy).onChainInconsistentWithWeakSubjectivityCheckpoint(wsCheckpoint, otherBlock.getRoot(), otherBlock.getSlot());
    verifyNoMoreInteractions(policy);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Test(org.junit.jupiter.api.Test)

Example 4 with CombinedChainDataClient

use of tech.pegasys.teku.storage.client.CombinedChainDataClient in project teku by ConsenSys.

the class WeakSubjectivityValidatorTest method validateChainIsConsistentWithWSCheckpoint_noCheckpointSet.

@Test
public void validateChainIsConsistentWithWSCheckpoint_noCheckpointSet() {
    final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policy);
    final CombinedChainDataClient chainData = mockChainDataClientPriorToCheckpoint();
    SafeFuture<Void> result = validator.validateChainIsConsistentWithWSCheckpoint(chainData);
    assertThat(result).isCompleted();
    verifyNoMoreInteractions(policy);
    verify(chainData, never()).isFinalizedEpoch(any());
}
Also used : CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) Test(org.junit.jupiter.api.Test)

Example 5 with CombinedChainDataClient

use of tech.pegasys.teku.storage.client.CombinedChainDataClient in project teku by ConsenSys.

the class WeakSubjectivityValidatorTest method validateChainIsConsistentWithWSCheckpoint_checkpointNotFinalized.

@Test
public void validateChainIsConsistentWithWSCheckpoint_checkpointNotFinalized() {
    final Checkpoint wsCheckpoint = new Checkpoint(UInt64.valueOf(100), Bytes32.fromHexStringLenient("0x01"));
    final WeakSubjectivityConfig config = configBuilder().weakSubjectivityCheckpoint(wsCheckpoint).build();
    final WeakSubjectivityValidator validator = new WeakSubjectivityValidator(config, calculator, policy);
    final CombinedChainDataClient chainData = mockChainDataClientPriorToCheckpoint();
    SafeFuture<Void> result = validator.validateChainIsConsistentWithWSCheckpoint(chainData);
    assertThat(result).isCompleted();
    verifyNoMoreInteractions(policy);
    verify(chainData).isFinalizedEpoch(wsCheckpoint.getEpoch());
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) Test(org.junit.jupiter.api.Test)

Aggregations

CombinedChainDataClient (tech.pegasys.teku.storage.client.CombinedChainDataClient)12 Test (org.junit.jupiter.api.Test)6 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)4 WeakSubjectivityConfig (tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)3 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)3 StorageQueryChannel (tech.pegasys.teku.storage.api.StorageQueryChannel)2 Optional (java.util.Optional)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)1 MetadataMessagesFactory (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessagesFactory)1 StatusMessageFactory (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.StatusMessageFactory)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)1 FinalizedCheckpointChannel (tech.pegasys.teku.storage.api.FinalizedCheckpointChannel)1 StubFinalizedCheckpointChannel (tech.pegasys.teku.storage.api.StubFinalizedCheckpointChannel)1 TrackingChainHeadChannel (tech.pegasys.teku.storage.api.TrackingChainHeadChannel)1 StorageBackedRecentChainData (tech.pegasys.teku.storage.client.StorageBackedRecentChainData)1 ChainStorage (tech.pegasys.teku.storage.server.ChainStorage)1