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