Search in sources :

Example 11 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class WeakSubjectivityCalculator method computeWeakSubjectivityPeriod.

@VisibleForTesting
UInt64 computeWeakSubjectivityPeriod(final SpecVersion specVersion, final int activeValidatorCount, final UInt64 totalValidatorBalance) {
    final SpecConfig constants = specVersion.getConfig();
    final UInt64 N = UInt64.valueOf(activeValidatorCount);
    final UInt64 t = totalValidatorBalance.dividedBy(N).dividedBy(EthConstants.ETH_TO_GWEI);
    final UInt64 T = constants.getMaxEffectiveBalance().dividedBy(EthConstants.ETH_TO_GWEI);
    final UInt64 delta = specVersion.beaconStateAccessors().getValidatorChurnLimit(activeValidatorCount);
    final UInt64 Delta = UInt64.valueOf(constants.getMaxDeposits()).times(constants.getSlotsPerEpoch());
    final UInt64 D = safetyDecay;
    final UInt64 wsPeriod;
    final UInt64 maxBalanceMultiplier = D.times(3).plus(200);
    final UInt64 scaledMaxBalance = T.times(maxBalanceMultiplier);
    final UInt64 scaledAverageBalance = t.times(D.times(12).plus(200));
    if (scaledMaxBalance.isLessThan(scaledAverageBalance)) {
        final UInt64 churnDivisor = delta.times(600).times(t.times(2).plus(T));
        final UInt64 epochsForValidatorChurnSet = N.times(scaledAverageBalance.minus(scaledMaxBalance)).dividedBy(churnDivisor);
        final UInt64 epochsForBalanceTopUps = N.times(maxBalanceMultiplier).dividedBy(Delta.times(600));
        wsPeriod = epochsForValidatorChurnSet.max(epochsForBalanceTopUps);
    } else {
        final UInt64 divisor = Delta.times(200).times(T.minus(t));
        wsPeriod = N.times(D).times(t).times(3).dividedBy(divisor);
    }
    return wsPeriod.plus(constants.getMinValidatorWithdrawabilityDelay());
}
Also used : SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class TransitionTestExecutor method processAltairUpgrade.

private void processAltairUpgrade(final TestDefinition testDefinition, final MetaData metadata) throws Exception {
    final UInt64 forkEpoch = UInt64.valueOf(metadata.forkEpoch);
    final SpecConfig config = SpecConfigLoader.loadConfig(testDefinition.getConfigName(), c -> c.altairBuilder(a -> a.altairForkEpoch(forkEpoch)));
    final Spec spec = SpecFactory.create(config);
    final BeaconState preState = TestDataUtils.loadSsz(testDefinition, "pre.ssz_snappy", spec::deserializeBeaconState);
    final BeaconState postState = TestDataUtils.loadSsz(testDefinition, "post.ssz_snappy", spec::deserializeBeaconState);
    BeaconState result = preState;
    for (int i = 0; i < metadata.blocksCount; i++) {
        final SignedBeaconBlock block = TestDataUtils.loadSsz(testDefinition, "blocks_" + i + ".ssz_snappy", spec::deserializeSignedBeaconBlock);
        try {
            final BLSSignatureVerifier signatureVerifier = metadata.blsSetting == 2 ? BLSSignatureVerifier.NO_OP : BLSSignatureVerifier.SIMPLE;
            result = spec.processBlock(result, block, signatureVerifier, OptimisticExecutionPayloadExecutor.NOOP);
        } catch (final StateTransitionException e) {
            Assertions.fail("Failed to process block " + i + " at slot " + block.getSlot() + ": " + e.getMessage(), e);
        }
    }
    assertThatSszData(result).isEqualByGettersTo(postState);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ImmutableMap(com.google.common.collect.ImmutableMap) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) TestAbortedException(org.opentest4j.TestAbortedException) OptimisticExecutionPayloadExecutor(tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor) TestExecutor(tech.pegasys.teku.reference.TestExecutor) BLSSignatureVerifier(tech.pegasys.teku.bls.BLSSignatureVerifier) TestDataUtils(tech.pegasys.teku.reference.TestDataUtils) TestDefinition(tech.pegasys.teku.ethtests.finder.TestDefinition) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) SszDataAssert.assertThatSszData(tech.pegasys.teku.infrastructure.ssz.SszDataAssert.assertThatSszData) SpecFactory(tech.pegasys.teku.spec.SpecFactory) SpecConfigLoader(tech.pegasys.teku.spec.config.SpecConfigLoader) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) BLSSignatureVerifier(tech.pegasys.teku.bls.BLSSignatureVerifier) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)

Example 13 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class SpecFactoryTest method shouldSupportAltairWhenForkEpochSetInConfig.

@Test
void shouldSupportAltairWhenForkEpochSetInConfig() {
    final SpecConfig config = SpecConfigLoader.loadConfig("mainnet", phase0Builder -> phase0Builder.altairBuilder(altairBuilder -> altairBuilder.altairForkEpoch(UInt64.valueOf(10))));
    final Spec spec = SpecFactory.create(config);
    assertThat(spec.getForkSchedule().getSupportedMilestones()).containsExactly(PHASE0, ALTAIR);
    assertThat(spec.getForkSchedule().getSpecMilestoneAtEpoch(UInt64.valueOf(10))).isEqualTo(ALTAIR);
}
Also used : Eth2Network(tech.pegasys.teku.spec.networks.Eth2Network) Arrays(java.util.Arrays) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Arguments(org.junit.jupiter.params.provider.Arguments) ALTAIR(tech.pegasys.teku.spec.SpecMilestone.ALTAIR) Test(org.junit.jupiter.api.Test) PHASE0(tech.pegasys.teku.spec.SpecMilestone.PHASE0) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) SpecConfigLoader(tech.pegasys.teku.spec.config.SpecConfigLoader) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BELLATRIX(tech.pegasys.teku.spec.SpecMilestone.BELLATRIX) AttestationWorthinessCheckerAltair(tech.pegasys.teku.spec.logic.versions.altair.statetransition.attestation.AttestationWorthinessCheckerAltair) MethodSource(org.junit.jupiter.params.provider.MethodSource) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class BeaconBlockBodySchemaPhase0Test method create_minimal.

@Test
public void create_minimal() {
    final Spec spec = TestSpecFactory.createMinimalPhase0();
    final SpecConfig specConfig = spec.getGenesisSpecConfig();
    final BeaconBlockBodySchemaPhase0 specA = BeaconBlockBodySchemaPhase0.create(specConfig, new AttesterSlashingSchema(new IndexedAttestationSchema(specConfig)));
    final BeaconBlockBodySchemaPhase0 specB = BeaconBlockBodySchemaPhase0.create(specConfig, new AttesterSlashingSchema(new IndexedAttestationSchema(specConfig)));
    assertThat(specA).isEqualTo(specB);
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) AttesterSlashingSchema(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test)

Example 15 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class BeaconStateSchemaAltairTest method changeSpecConfigTest_checkAltairFields.

@Test
public void changeSpecConfigTest_checkAltairFields() {
    final Spec standardSpec = TestSpecFactory.createMinimalPhase0();
    final SpecConfig modifiedConstants = SpecConfigLoader.loadConfig("minimal", b -> b.validatorRegistryLimit(123L));
    BeaconStateAltair s1 = getSchema(modifiedConstants).createEmpty();
    BeaconStateAltair s2 = getSchema(standardSpec.getGenesisSpecConfig()).createEmpty();
    assertThat(s1.getPreviousEpochParticipation().getSchema()).isNotEqualTo(s2.getPreviousEpochParticipation().getSchema());
    assertThat(s1.getCurrentEpochParticipation().getSchema()).isNotEqualTo(s2.getCurrentEpochParticipation().getSchema());
}
Also used : SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test) AbstractBeaconStateSchemaTest(tech.pegasys.teku.spec.datastructures.state.beaconstate.common.AbstractBeaconStateSchemaTest)

Aggregations

SpecConfig (tech.pegasys.teku.spec.config.SpecConfig)19 Test (org.junit.jupiter.api.Test)12 Spec (tech.pegasys.teku.spec.Spec)7 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 GetSpecResponse (tech.pegasys.teku.api.response.v1.config.GetSpecResponse)2 SpecConfigLoader (tech.pegasys.teku.spec.config.SpecConfigLoader)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1