Search in sources :

Example 1 with Fork

use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.

the class HistoricalBatchFetcher method batchVerifyHistoricalBlockSignature.

private SafeFuture<Void> batchVerifyHistoricalBlockSignature(final Collection<SignedBeaconBlock> blocks, final BeaconState bestState) {
    List<BLSSignature> signatures = new ArrayList<>();
    List<Bytes> signingRoots = new ArrayList<>();
    List<List<BLSPublicKey>> proposerPublicKeys = new ArrayList<>();
    final Bytes32 genesisValidatorsRoot = bestState.getForkInfo().getGenesisValidatorsRoot();
    blocks.forEach(signedBlock -> {
        final BeaconBlock block = signedBlock.getMessage();
        if (block.getSlot().isGreaterThan(SpecConfig.GENESIS_SLOT)) {
            final UInt64 epoch = spec.computeEpochAtSlot(block.getSlot());
            final Fork fork = spec.fork(epoch);
            final Bytes32 domain = spec.getDomain(Domain.BEACON_PROPOSER, epoch, fork, genesisValidatorsRoot);
            signatures.add(signedBlock.getSignature());
            signingRoots.add(spec.computeSigningRoot(block, domain));
            BLSPublicKey proposerPublicKey = spec.getValidatorPubKey(bestState, block.getProposerIndex()).orElseThrow(() -> new IllegalStateException("Proposer has to be in the state since state is more recent than the block proposed"));
            proposerPublicKeys.add(List.of(proposerPublicKey));
        }
    });
    return signatureVerificationService.verify(proposerPublicKeys, signingRoots, signatures).thenAccept(signaturesValid -> {
        if (!signaturesValid) {
            throw new IllegalArgumentException("Batch signature verification failed");
        }
    });
}
Also used : Fork(tech.pegasys.teku.spec.datastructures.state.Fork) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ArrayList(java.util.ArrayList) Bytes32(org.apache.tuweni.bytes.Bytes32) Bytes(org.apache.tuweni.bytes.Bytes) ArrayList(java.util.ArrayList) List(java.util.List) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 2 with Fork

use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.

the class BellatrixStateUpgrade method upgrade.

@Override
public BeaconStateBellatrix upgrade(final BeaconState preState) {
    final UInt64 epoch = beaconStateAccessors.getCurrentEpoch(preState);
    BeaconStateAltair preStateAltair = BeaconStateAltair.required(preState);
    return schemaDefinitions.getBeaconStateSchema().createEmpty().updatedBellatrix(state -> {
        BeaconStateFields.copyCommonFieldsFromSource(state, preState);
        state.setCurrentEpochParticipation(preStateAltair.getCurrentEpochParticipation());
        state.setPreviousEpochParticipation(preStateAltair.getPreviousEpochParticipation());
        state.setCurrentSyncCommittee(preStateAltair.getCurrentSyncCommittee());
        state.setNextSyncCommittee(preStateAltair.getNextSyncCommittee());
        state.setInactivityScores(preStateAltair.getInactivityScores());
        state.setFork(new Fork(preState.getFork().getCurrent_version(), specConfig.getBellatrixForkVersion(), epoch));
        state.setLatestExecutionPayloadHeader(schemaDefinitions.getExecutionPayloadHeaderSchema().getDefault());
    });
}
Also used : Fork(tech.pegasys.teku.spec.datastructures.state.Fork) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconStateAltair(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair)

Example 3 with Fork

use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.

the class BlockProcessorTest method createBeaconState.

private BeaconState createBeaconState(boolean addToList, UInt64 amount, Validator knownValidator) {
    return spec.getGenesisSpec().getSchemaDefinitions().getBeaconStateSchema().createEmpty().updated(beaconState -> {
        beaconState.setSlot(dataStructureUtil.randomUInt64());
        beaconState.setFork(new Fork(specConfig.getGenesisForkVersion(), specConfig.getGenesisForkVersion(), SpecConfig.GENESIS_EPOCH));
        List<Validator> validatorList = new ArrayList<>(List.of(dataStructureUtil.randomValidator(), dataStructureUtil.randomValidator(), dataStructureUtil.randomValidator()));
        List<UInt64> balanceList = new ArrayList<>(List.of(dataStructureUtil.randomUInt64(), dataStructureUtil.randomUInt64(), dataStructureUtil.randomUInt64()));
        if (addToList) {
            validatorList.add(knownValidator);
            balanceList.add(amount);
        }
        beaconState.getValidators().appendAll(validatorList);
        beaconState.getBalances().appendAllElements(balanceList);
    });
}
Also used : Fork(tech.pegasys.teku.spec.datastructures.state.Fork) ArrayList(java.util.ArrayList) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Validator(tech.pegasys.teku.spec.datastructures.state.Validator)

Example 4 with Fork

use of tech.pegasys.teku.spec.datastructures.state.Fork 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 5 with Fork

use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.

the class ForkScheduleTest method getFork_withTransition.

@Test
public void getFork_withTransition() {
    final ForkSchedule forkSchedule = buildForkSchedule(TRANSITION_CONFIG);
    final Fork phase0Fork = getPhase0Fork(TRANSITION_CONFIG);
    for (UInt64 epoch = UInt64.ZERO; epoch.isLessThan(FORK_EPOCH_ALTAIR); epoch = epoch.increment()) {
        assertThat(forkSchedule.getFork(epoch)).isEqualTo(phase0Fork);
    }
    final Fork altairFork = getAltairFork(TRANSITION_CONFIG);
    for (UInt64 epoch = FORK_EPOCH_ALTAIR; epoch.isLessThan(FORK_EPOCH_ALTAIR.times(2)); epoch = epoch.increment()) {
        assertThat(forkSchedule.getFork(epoch)).isEqualTo(altairFork);
    }
}
Also used : Fork(tech.pegasys.teku.spec.datastructures.state.Fork) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

Fork (tech.pegasys.teku.spec.datastructures.state.Fork)18 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)12 Test (org.junit.jupiter.api.Test)7 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Bytes (org.apache.tuweni.bytes.Bytes)3 BLSSignature (tech.pegasys.teku.bls.BLSSignature)3 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)3 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)2 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 ForkAndSpecMilestone (tech.pegasys.teku.spec.datastructures.util.ForkAndSpecMilestone)2