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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations