use of tech.pegasys.teku.spec.datastructures.state.ForkInfo 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.spec.datastructures.state.ForkInfo in project teku by ConsenSys.
the class GossipForkSubscriptionsPhase0 method startGossip.
@Override
public final void startGossip(final Bytes32 genesisValidatorsRoot, final boolean isOptimisticHead) {
if (gossipManagers.isEmpty()) {
final ForkInfo forkInfo = new ForkInfo(fork, genesisValidatorsRoot);
addGossipManagers(forkInfo);
}
gossipManagers.stream().filter(manager -> manager.isEnabledDuringOptimisticSync() || !isOptimisticHead).forEach(GossipManager::subscribe);
}
use of tech.pegasys.teku.spec.datastructures.state.ForkInfo in project teku by ConsenSys.
the class Eth2GossipTopicFilter method computeRelevantTopics.
private Set<String> computeRelevantTopics(final RecentChainData recentChainData, final GossipEncoding gossipEncoding) {
final ForkInfo forkInfo = recentChainData.getCurrentForkInfo().orElseThrow();
final Bytes4 forkDigest = forkInfo.getForkDigest(spec);
final Set<String> topics = getAllTopics(gossipEncoding, forkDigest);
spec.getForkSchedule().getForks().stream().filter(fork -> fork.getEpoch().isGreaterThanOrEqualTo(forkInfo.getFork().getEpoch())).map(futureFork -> spec.atEpoch(futureFork.getEpoch()).miscHelpers().computeForkDigest(futureFork.getCurrent_version(), forkInfo.getGenesisValidatorsRoot())).forEach(futureForkDigest -> topics.addAll(getAllTopics(gossipEncoding, futureForkDigest)));
return topics;
}
use of tech.pegasys.teku.spec.datastructures.state.ForkInfo in project teku by ConsenSys.
the class SyncCommitteeProductionDutyTest method shouldReportPartialFailureWhenBeaconNodeRejectsSomeMessages.
@Test
void shouldReportPartialFailureWhenBeaconNodeRejectsSomeMessages() {
final UInt64 slot = UInt64.valueOf(48);
final int validatorIndex1 = 11;
final int validatorIndex2 = 22;
final Validator validator2 = createValidator();
final BLSSignature signature1 = dataStructureUtil.randomSignature();
final BLSSignature signature2 = dataStructureUtil.randomSignature();
final SyncCommitteeProductionDuty duties = createDuty(committeeAssignment(validator, validatorIndex1, 1, 2, 3), committeeAssignment(validator2, validatorIndex2, 1, 5));
when(validator.getSigner().signSyncCommitteeMessage(slot, blockRoot, forkInfo)).thenReturn(SafeFuture.completedFuture(signature1));
when(validator2.getSigner().signSyncCommitteeMessage(slot, blockRoot, forkInfo)).thenReturn(SafeFuture.completedFuture(signature2));
when(validatorApiChannel.sendSyncCommitteeMessages(any())).thenReturn(SafeFuture.completedFuture(List.of(new SubmitDataError(UInt64.ZERO, "API Rejected"))));
produceMessagesAndReport(duties, slot);
assertSentMessages(createMessage(slot, blockRoot, validatorIndex1, signature1), createMessage(slot, blockRoot, validatorIndex2, signature2));
verify(validatorLogger).dutyCompleted(MESSAGE_TYPE, slot, 1, Set.of(blockRoot));
verify(validatorLogger).dutyFailed(eq(MESSAGE_TYPE), eq(slot), eq(Set.of(validator.getPublicKey().toAbbreviatedString())), argThat(error -> error.getMessage().equals("API Rejected")));
}
use of tech.pegasys.teku.spec.datastructures.state.ForkInfo in project teku by ConsenSys.
the class ActiveEth2P2PNetworkTest method onEpoch_shouldUpdateDiscoveryNetworkForkInfo.
@Test
public void onEpoch_shouldUpdateDiscoveryNetworkForkInfo() {
setupForkInfo();
// Start network
verify(discoveryNetwork, never()).setForkInfo(any(), any());
assertThat(network.start()).isCompleted();
// Verify updates at startup
verify(discoveryNetwork).start();
ForkInfo expectedFork = new ForkInfo(phase0Fork, genesisValidatorsRoot);
verify(discoveryNetwork).setForkInfo(expectedFork, Optional.of(altairFork));
// Process epoch 1 - we shouldn't update fork info here
network.onEpoch(UInt64.ONE);
asyncRunner.executeDueActions();
verify(discoveryNetwork).updateGossipTopicScoring(any());
verifyNoMoreInteractions(discoveryNetwork);
// At the altair upgrade epoch, we should update fork info
network.onEpoch(altairForkEpoch);
expectedFork = new ForkInfo(altairFork, genesisValidatorsRoot);
verify(discoveryNetwork).setForkInfo(expectedFork, Optional.empty());
// Processing altair again shouldn't cause any updates
network.onEpoch(altairForkEpoch);
verifyNoMoreInteractions(discoveryNetwork);
// Next epoch should not update fork info
network.onEpoch(altairForkEpoch.plus(1));
verifyNoMoreInteractions(discoveryNetwork);
// Reprocessing prior epoch should not update fork info
network.onEpoch(UInt64.ONE);
verifyNoMoreInteractions(discoveryNetwork);
}
Aggregations