Search in sources :

Example 1 with BeaconStateUtil

use of tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil in project teku by ConsenSys.

the class EpochCachePrimer method primeEpochStateCaches.

private void primeEpochStateCaches(final BeaconState state) {
    UInt64.range(state.getSlot(), state.getSlot().plus(spec.getSlotsPerEpoch(state.getSlot()))).forEach(slot -> {
        final BeaconStateUtil beaconStateUtil = spec.getBeaconStateUtil(state.getSlot());
        // Calculate all proposers
        spec.getBeaconProposerIndex(state, slot);
        // Calculate attesters total effective balance
        beaconStateUtil.getAttestersTotalEffectiveBalance(state, slot);
    });
    // Calculate committees for furthest future epoch that can be calculated from this state
    // (assume earlier epochs were already requested)
    final UInt64 stateEpoch = spec.getCurrentEpoch(state);
    final UInt64 lookaheadEpoch = stateEpoch.plus(spec.getSpecConfig(stateEpoch).getMinSeedLookahead());
    final UInt64 lookAheadEpochStartSlot = spec.computeStartSlotAtEpoch(lookaheadEpoch);
    final UInt64 committeeCount = spec.getCommitteeCountPerSlot(state, lookaheadEpoch);
    UInt64.range(lookAheadEpochStartSlot, spec.computeStartSlotAtEpoch(lookaheadEpoch.plus(1))).forEach(slot -> UInt64.range(UInt64.ZERO, committeeCount).forEach(index -> spec.getBeaconCommittee(state, slot, index)));
}
Also used : Logger(org.apache.logging.log4j.Logger) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Spec(tech.pegasys.teku.spec.Spec) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil) LogManager(org.apache.logging.log4j.LogManager) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil)

Example 2 with BeaconStateUtil

use of tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil in project teku by ConsenSys.

the class SpecLogicPhase0 method create.

public static SpecLogicPhase0 create(final SpecConfig config, final SchemaDefinitions schemaDefinitions) {
    // Helpers
    final Predicates predicates = new Predicates();
    final MiscHelpers miscHelpers = new MiscHelpers(config);
    final BeaconStateAccessors beaconStateAccessors = new BeaconStateAccessorsPhase0(config, predicates, miscHelpers);
    final BeaconStateMutators beaconStateMutators = new BeaconStateMutators(config, miscHelpers, beaconStateAccessors);
    // Operation validaton
    final OperationSignatureVerifier operationSignatureVerifier = new OperationSignatureVerifier(miscHelpers, beaconStateAccessors);
    // Util
    final ValidatorsUtil validatorsUtil = new ValidatorsUtil(config, miscHelpers, beaconStateAccessors);
    final BeaconStateUtil beaconStateUtil = new BeaconStateUtil(config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
    final AttestationUtil attestationUtil = new AttestationUtil(schemaDefinitions, beaconStateAccessors, miscHelpers);
    final OperationValidator operationValidator = OperationValidator.create(config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
    final ValidatorStatusFactoryPhase0 validatorStatusFactory = new ValidatorStatusFactoryPhase0(config, beaconStateUtil, attestationUtil, beaconStateAccessors, predicates);
    final EpochProcessorPhase0 epochProcessor = new EpochProcessorPhase0(config, miscHelpers, beaconStateAccessors, beaconStateMutators, validatorsUtil, beaconStateUtil, validatorStatusFactory, schemaDefinitions);
    final BlockProcessorPhase0 blockProcessor = new BlockProcessorPhase0(config, predicates, miscHelpers, beaconStateAccessors, beaconStateMutators, operationSignatureVerifier, beaconStateUtil, attestationUtil, validatorsUtil, operationValidator);
    final ForkChoiceUtil forkChoiceUtil = new ForkChoiceUtil(config, beaconStateAccessors, attestationUtil, miscHelpers);
    final BlockProposalUtil blockProposalUtil = new BlockProposalUtil(schemaDefinitions, blockProcessor);
    return new SpecLogicPhase0(predicates, miscHelpers, beaconStateAccessors, beaconStateMutators, operationSignatureVerifier, validatorsUtil, beaconStateUtil, attestationUtil, operationValidator, validatorStatusFactory, epochProcessor, blockProcessor, forkChoiceUtil, blockProposalUtil);
}
Also used : ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) AttestationUtil(tech.pegasys.teku.spec.logic.common.util.AttestationUtil) EpochProcessorPhase0(tech.pegasys.teku.spec.logic.versions.phase0.statetransition.epoch.EpochProcessorPhase0) MiscHelpers(tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers) OperationSignatureVerifier(tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier) ValidatorsUtil(tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil) ValidatorStatusFactoryPhase0(tech.pegasys.teku.spec.logic.versions.phase0.statetransition.epoch.ValidatorStatusFactoryPhase0) OperationValidator(tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil) BeaconStateMutators(tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators) BlockProposalUtil(tech.pegasys.teku.spec.logic.common.util.BlockProposalUtil) Predicates(tech.pegasys.teku.spec.logic.common.helpers.Predicates) BeaconStateAccessors(tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors) BlockProcessorPhase0(tech.pegasys.teku.spec.logic.versions.phase0.block.BlockProcessorPhase0) BeaconStateAccessorsPhase0(tech.pegasys.teku.spec.logic.versions.phase0.helpers.BeaconStateAccessorsPhase0)

Example 3 with BeaconStateUtil

use of tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil in project teku by ConsenSys.

the class GenesisValidityTestExecutor method runTest.

@Override
public void runTest(final TestDefinition testDefinition) throws Exception {
    final BeaconState state = loadStateFromSsz(testDefinition, "genesis.ssz_snappy");
    final Spec spec = testDefinition.getSpec();
    final BeaconStateUtil beaconStateUtil = spec.atEpoch(UInt64.ZERO).getBeaconStateUtil();
    final boolean expectedValidity = loadYaml(testDefinition, "is_valid.yaml", Boolean.class);
    final int activeValidatorCount = testDefinition.getSpec().countActiveValidators(state, SpecConfig.GENESIS_EPOCH);
    final boolean result = beaconStateUtil.isValidGenesisState(state.getGenesis_time(), activeValidatorCount);
    assertThat(result).isEqualTo(expectedValidity);
}
Also used : Spec(tech.pegasys.teku.spec.Spec) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with BeaconStateUtil

use of tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil in project teku by ConsenSys.

the class SpecLogicBellatrix method create.

public static SpecLogicBellatrix create(final SpecConfigBellatrix config, final SchemaDefinitionsBellatrix schemaDefinitions) {
    // Helpers
    final Predicates predicates = new Predicates();
    final MiscHelpersBellatrix miscHelpers = new MiscHelpersBellatrix(config);
    final BeaconStateAccessorsBellatrix beaconStateAccessors = new BeaconStateAccessorsBellatrix(config, predicates, miscHelpers);
    final BeaconStateMutatorsBellatrix beaconStateMutators = new BeaconStateMutatorsBellatrix(config, miscHelpers, beaconStateAccessors);
    // Operation validaton
    final OperationSignatureVerifier operationSignatureVerifier = new OperationSignatureVerifier(miscHelpers, beaconStateAccessors);
    // Util
    final ValidatorsUtil validatorsUtil = new ValidatorsUtil(config, miscHelpers, beaconStateAccessors);
    final BeaconStateUtil beaconStateUtil = new BeaconStateUtil(config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
    final AttestationUtil attestationUtil = new AttestationUtil(schemaDefinitions, beaconStateAccessors, miscHelpers);
    final OperationValidator operationValidator = OperationValidator.create(config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
    final ValidatorStatusFactoryAltair validatorStatusFactory = new ValidatorStatusFactoryAltair(config, beaconStateUtil, attestationUtil, predicates, miscHelpers, beaconStateAccessors);
    final EpochProcessorBellatrix epochProcessor = new EpochProcessorBellatrix(config, miscHelpers, beaconStateAccessors, beaconStateMutators, validatorsUtil, beaconStateUtil, validatorStatusFactory, schemaDefinitions);
    final SyncCommitteeUtil syncCommitteeUtil = new SyncCommitteeUtil(beaconStateAccessors, validatorsUtil, config, miscHelpers, schemaDefinitions);
    final BlockProcessorBellatrix blockProcessor = new BlockProcessorBellatrix(config, predicates, miscHelpers, syncCommitteeUtil, beaconStateAccessors, beaconStateMutators, operationSignatureVerifier, beaconStateUtil, attestationUtil, validatorsUtil, operationValidator, schemaDefinitions);
    final ForkChoiceUtil forkChoiceUtil = new ForkChoiceUtil(config, beaconStateAccessors, attestationUtil, miscHelpers);
    final BlockProposalUtil blockProposalUtil = new BlockProposalUtil(schemaDefinitions, blockProcessor);
    // State upgrade
    final BellatrixStateUpgrade stateUpgrade = new BellatrixStateUpgrade(config, schemaDefinitions, beaconStateAccessors);
    final BellatrixTransitionHelpers bellatrixTransitionHelpers = new BellatrixTransitionHelpers(config, miscHelpers);
    return new SpecLogicBellatrix(config, predicates, miscHelpers, beaconStateAccessors, beaconStateMutators, operationSignatureVerifier, validatorsUtil, beaconStateUtil, attestationUtil, operationValidator, validatorStatusFactory, epochProcessor, blockProcessor, forkChoiceUtil, blockProposalUtil, syncCommitteeUtil, stateUpgrade, bellatrixTransitionHelpers);
}
Also used : ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) AttestationUtil(tech.pegasys.teku.spec.logic.common.util.AttestationUtil) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) OperationSignatureVerifier(tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier) BlockProcessorBellatrix(tech.pegasys.teku.spec.logic.versions.bellatrix.block.BlockProcessorBellatrix) BeaconStateMutatorsBellatrix(tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BeaconStateMutatorsBellatrix) ValidatorsUtil(tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil) BellatrixTransitionHelpers(tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BellatrixTransitionHelpers) OperationValidator(tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator) BellatrixStateUpgrade(tech.pegasys.teku.spec.logic.versions.bellatrix.forktransition.BellatrixStateUpgrade) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil) BeaconStateAccessorsBellatrix(tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BeaconStateAccessorsBellatrix) BlockProposalUtil(tech.pegasys.teku.spec.logic.common.util.BlockProposalUtil) EpochProcessorBellatrix(tech.pegasys.teku.spec.logic.versions.bellatrix.statetransition.epoch.EpochProcessorBellatrix) MiscHelpersBellatrix(tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.MiscHelpersBellatrix) Predicates(tech.pegasys.teku.spec.logic.common.helpers.Predicates) ValidatorStatusFactoryAltair(tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.ValidatorStatusFactoryAltair)

Example 5 with BeaconStateUtil

use of tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil in project teku by ConsenSys.

the class SpecLogicAltair method create.

public static SpecLogicAltair create(final SpecConfigAltair config, final SchemaDefinitionsAltair schemaDefinitions) {
    // Helpers
    final Predicates predicates = new Predicates();
    final MiscHelpersAltair miscHelpers = new MiscHelpersAltair(config);
    final BeaconStateAccessorsAltair beaconStateAccessors = new BeaconStateAccessorsAltair(config, predicates, miscHelpers);
    final BeaconStateMutatorsAltair beaconStateMutators = new BeaconStateMutatorsAltair(config, miscHelpers, beaconStateAccessors);
    // Operation validaton
    final OperationSignatureVerifier operationSignatureVerifier = new OperationSignatureVerifier(miscHelpers, beaconStateAccessors);
    // Util
    final ValidatorsUtil validatorsUtil = new ValidatorsUtil(config, miscHelpers, beaconStateAccessors);
    final BeaconStateUtil beaconStateUtil = new BeaconStateUtil(config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors);
    final AttestationUtil attestationUtil = new AttestationUtil(schemaDefinitions, beaconStateAccessors, miscHelpers);
    final OperationValidator operationValidator = OperationValidator.create(config, predicates, miscHelpers, beaconStateAccessors, attestationUtil);
    final ValidatorStatusFactoryAltair validatorStatusFactory = new ValidatorStatusFactoryAltair(config, beaconStateUtil, attestationUtil, predicates, miscHelpers, beaconStateAccessors);
    final EpochProcessorAltair epochProcessor = new EpochProcessorAltair(config, miscHelpers, beaconStateAccessors, beaconStateMutators, validatorsUtil, beaconStateUtil, validatorStatusFactory, schemaDefinitions);
    final SyncCommitteeUtil syncCommitteeUtil = new SyncCommitteeUtil(beaconStateAccessors, validatorsUtil, config, miscHelpers, schemaDefinitions);
    final BlockProcessorAltair blockProcessor = new BlockProcessorAltair(config, predicates, miscHelpers, syncCommitteeUtil, beaconStateAccessors, beaconStateMutators, operationSignatureVerifier, beaconStateUtil, attestationUtil, validatorsUtil, operationValidator);
    final ForkChoiceUtil forkChoiceUtil = new ForkChoiceUtil(config, beaconStateAccessors, attestationUtil, miscHelpers);
    final BlockProposalUtil blockProposalUtil = new BlockProposalUtil(schemaDefinitions, blockProcessor);
    // State upgrade
    final AltairStateUpgrade stateUpgrade = new AltairStateUpgrade(config, schemaDefinitions, beaconStateAccessors, attestationUtil, miscHelpers);
    return new SpecLogicAltair(config, predicates, miscHelpers, beaconStateAccessors, beaconStateMutators, operationSignatureVerifier, validatorsUtil, beaconStateUtil, attestationUtil, operationValidator, validatorStatusFactory, epochProcessor, blockProcessor, forkChoiceUtil, blockProposalUtil, syncCommitteeUtil, stateUpgrade);
}
Also used : ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) AttestationUtil(tech.pegasys.teku.spec.logic.common.util.AttestationUtil) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) OperationSignatureVerifier(tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier) ValidatorsUtil(tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil) BlockProcessorAltair(tech.pegasys.teku.spec.logic.versions.altair.block.BlockProcessorAltair) MiscHelpersAltair(tech.pegasys.teku.spec.logic.versions.altair.helpers.MiscHelpersAltair) OperationValidator(tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator) EpochProcessorAltair(tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.EpochProcessorAltair) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil) BeaconStateAccessorsAltair(tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateAccessorsAltair) BlockProposalUtil(tech.pegasys.teku.spec.logic.common.util.BlockProposalUtil) AltairStateUpgrade(tech.pegasys.teku.spec.logic.versions.altair.forktransition.AltairStateUpgrade) BeaconStateMutatorsAltair(tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateMutatorsAltair) Predicates(tech.pegasys.teku.spec.logic.common.helpers.Predicates) ValidatorStatusFactoryAltair(tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.ValidatorStatusFactoryAltair)

Aggregations

BeaconStateUtil (tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil)6 Spec (tech.pegasys.teku.spec.Spec)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 Predicates (tech.pegasys.teku.spec.logic.common.helpers.Predicates)3 OperationSignatureVerifier (tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier)3 OperationValidator (tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator)3 AttestationUtil (tech.pegasys.teku.spec.logic.common.util.AttestationUtil)3 BlockProposalUtil (tech.pegasys.teku.spec.logic.common.util.BlockProposalUtil)3 ForkChoiceUtil (tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil)3 ValidatorsUtil (tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil)3 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 MinimalBeaconBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary)2 SlotAndBlockRoot (tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot)2 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)2 ValidatorStatusFactoryAltair (tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.ValidatorStatusFactoryAltair)2 Collections (java.util.Collections)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1