Search in sources :

Example 1 with ForkInfo

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));
}
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 ForkInfo

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);
}
Also used : ValidateableSyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ValidateableSyncCommitteeMessage) GossipManager(tech.pegasys.teku.networking.eth2.gossip.GossipManager) GossipForkSubscriptions(tech.pegasys.teku.networking.eth2.gossip.forks.GossipForkSubscriptions) OperationProcessor(tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor) DiscoveryNetwork(tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetwork) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) Fork(tech.pegasys.teku.spec.datastructures.state.Fork) AggregateGossipManager(tech.pegasys.teku.networking.eth2.gossip.AggregateGossipManager) ArrayList(java.util.ArrayList) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) AttesterSlashingGossipManager(tech.pegasys.teku.networking.eth2.gossip.AttesterSlashingGossipManager) BlockGossipManager(tech.pegasys.teku.networking.eth2.gossip.BlockGossipManager) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) AttestationSubnetSubscriptions(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationSubnetSubscriptions) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) GOSSIP_MAX_SIZE(tech.pegasys.teku.spec.config.Constants.GOSSIP_MAX_SIZE) AttestationGossipManager(tech.pegasys.teku.networking.eth2.gossip.AttestationGossipManager) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ProposerSlashingGossipManager(tech.pegasys.teku.networking.eth2.gossip.ProposerSlashingGossipManager) VoluntaryExitGossipManager(tech.pegasys.teku.networking.eth2.gossip.VoluntaryExitGossipManager) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) List(java.util.List) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) GossipManager(tech.pegasys.teku.networking.eth2.gossip.GossipManager) AggregateGossipManager(tech.pegasys.teku.networking.eth2.gossip.AggregateGossipManager) AttesterSlashingGossipManager(tech.pegasys.teku.networking.eth2.gossip.AttesterSlashingGossipManager) BlockGossipManager(tech.pegasys.teku.networking.eth2.gossip.BlockGossipManager) AttestationGossipManager(tech.pegasys.teku.networking.eth2.gossip.AttestationGossipManager) ProposerSlashingGossipManager(tech.pegasys.teku.networking.eth2.gossip.ProposerSlashingGossipManager) VoluntaryExitGossipManager(tech.pegasys.teku.networking.eth2.gossip.VoluntaryExitGossipManager) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo)

Example 3 with ForkInfo

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;
}
Also used : Logger(org.apache.logging.log4j.Logger) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) GossipTopicFilter(tech.pegasys.teku.networking.p2p.libp2p.gossip.GossipTopicFilter) Suppliers(com.google.common.base.Suppliers) Set(java.util.Set) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) GossipTopics.getAllTopics(tech.pegasys.teku.networking.eth2.gossip.topics.GossipTopics.getAllTopics) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) Spec(tech.pegasys.teku.spec.Spec) Supplier(java.util.function.Supplier) LogManager(org.apache.logging.log4j.LogManager) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4)

Example 4 with ForkInfo

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")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Signer(tech.pegasys.teku.core.signatures.Signer) ArgumentCaptor(org.mockito.ArgumentCaptor) ForkProvider(tech.pegasys.teku.validator.client.ForkProvider) Arrays.asList(java.util.Arrays.asList) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) DutyResult(tech.pegasys.teku.validator.client.duties.DutyResult) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) Validator(tech.pegasys.teku.validator.client.Validator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Validator(tech.pegasys.teku.validator.client.Validator) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 5 with ForkInfo

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

Aggregations

ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)22 Test (org.junit.jupiter.api.Test)11 BLSSignature (tech.pegasys.teku.bls.BLSSignature)11 Bytes32 (org.apache.tuweni.bytes.Bytes32)8 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)8 Spec (tech.pegasys.teku.spec.Spec)8 List (java.util.List)7 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)6 Validator (tech.pegasys.teku.validator.client.Validator)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)5 Bytes (org.apache.tuweni.bytes.Bytes)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 TestSpecFactory (tech.pegasys.teku.spec.TestSpecFactory)4 ContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof)4 SyncAggregatorSelectionData (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData)4 SyncCommitteeContribution (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution)4 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)4 ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)4 MalformedURLException (java.net.MalformedURLException)3