Skip to content

Commit

Permalink
Add max epoch activation churn limit for Deneb (Consensys#7522)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov authored Sep 21, 2023
1 parent 9f169a8 commit 78a929f
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ For information on changes in released versions of Teku, see the [releases page]
### Additions and Improvements
- The latest version of [blst](https://github.com/supranational/blst) will automatically use optimized code paths if they are supported. As a result, `JAVA_OPTS="-Dteku.portableBlst=true"` is no longer necessary for some older systems.
- The voluntary exit subcommand now accepts `--network=<NETWORK>` command line option, using it to load the network specification rather than loading configuration from the rest api, if specified.
- Add `/teku/v1/beacon/blob_sidecars/{slot}` Teku API which returns all blob sidecars (canonical and non-canonical) at a specific slot
- Add `/teku/v1/beacon/blob_sidecars/{slot}` Teku API which returns all blob sidecars (canonical and non-canonical) at a specific slot. This endpoint will become available once Deneb fork is scheduled.
- Updated LevelDb native library which is using LevelDb 1.23 using latest Snappy to 1.1.10 for compression (this change doesn't apply to Windows)
- Updated holesky configuration with new genesis time of 28th September 12:00 UTC, and fork changes.
- Apply proposer boost to first block in case of equivocation ([spec PR](https://github.com/ethereum/consensus-specs/pull/3352))

### Bug Fixes
- When the rest-api's fail to start up they can now potentially 'fail fast' rather than silently ignoring the issue.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ allprojects {
}
}

def refTestVersion = 'v1.4.0-beta.1' // Arbitrary change to refresh cache number: 1
def refTestVersion = 'v1.4.0-beta.2-hotfix' // Arbitrary change to refresh cache number: 1
def blsRefTestVersion = 'v0.1.2'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
def blsRefTestBaseUrl = 'https://github.com/ethereum/bls12-381-tests/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ private TestExecutor getExecutorFor(final TestDefinition testDefinition) {
testExecutor = COMMON_TEST_TYPES.get(testDefinition.getTestType());
}

// TODO: https://github.com/Consensys/teku/issues/7539
if (testDefinition.getFork().equals(TestFork.DENEB)
&& testExecutor instanceof ForkChoiceTestExecutor) {
testExecutor = TestExecutor.IGNORE_TESTS;
}

if (testExecutor == null) {
return Assertions.fail("Unsupported test type " + testDefinition.getTestType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Eth2NetworkConfiguration {
private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 30;

public static final boolean DEFAULT_FORK_CHOICE_UPDATE_HEAD_ON_BLOCK_IMPORT_ENABLED = false;
public static final boolean DEFAULT_FORK_CHOICE_PROPOSER_BOOST_UNIQUENESS_ENABLED = false;
public static final boolean DEFAULT_FORK_CHOICE_PROPOSER_BOOST_UNIQUENESS_ENABLED = true;

public static final String INITIAL_STATE_URL_PATH = "eth/v2/debug/beacon/states/finalized";
// 26 thousand years should be enough
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static SpecConfigDeneb required(final SpecConfig specConfig) {

UInt64 getDenebForkEpoch();

int getMaxPerEpochActivationChurnLimit();

int getFieldElementsPerBlob();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SpecConfigDenebImpl extends DelegatingSpecConfigCapella implements
private final Bytes4 denebForkVersion;
private final UInt64 denebForkEpoch;

private final int maxPerEpochActivationChurnLimit;
private final int fieldElementsPerBlob;
private final int maxBlobCommitmentsPerBlock;
private final int maxBlobsPerBlock;
Expand All @@ -38,6 +39,7 @@ public SpecConfigDenebImpl(
final SpecConfigCapella specConfig,
final Bytes4 denebForkVersion,
final UInt64 denebForkEpoch,
final int maxPerEpochActivationChurnLimit,
final int fieldElementsPerBlob,
final int maxBlobCommitmentsPerBlock,
final int maxBlobsPerBlock,
Expand All @@ -51,6 +53,7 @@ public SpecConfigDenebImpl(
super(specConfig);
this.denebForkVersion = denebForkVersion;
this.denebForkEpoch = denebForkEpoch;
this.maxPerEpochActivationChurnLimit = maxPerEpochActivationChurnLimit;
this.fieldElementsPerBlob = fieldElementsPerBlob;
this.maxBlobCommitmentsPerBlock = maxBlobCommitmentsPerBlock;
this.maxBlobsPerBlock = maxBlobsPerBlock;
Expand All @@ -73,6 +76,11 @@ public UInt64 getDenebForkEpoch() {
return denebForkEpoch;
}

@Override
public int getMaxPerEpochActivationChurnLimit() {
return maxPerEpochActivationChurnLimit;
}

@Override
public int getFieldElementsPerBlob() {
return fieldElementsPerBlob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class DenebBuilder implements ForkConfigBuilder<SpecConfigCapella, SpecCo
private Bytes4 denebForkVersion;
private UInt64 denebForkEpoch;

private Integer maxPerEpochActivationChurnLimit;
private Integer fieldElementsPerBlob;
private Integer maxBlobCommitmentsPerBlock;
private Integer maxBlobsPerBlock;
Expand All @@ -51,6 +52,7 @@ public SpecConfigDeneb build(final SpecConfigCapella specConfig) {
specConfig,
denebForkVersion,
denebForkEpoch,
maxPerEpochActivationChurnLimit,
fieldElementsPerBlob,
maxBlobCommitmentsPerBlock,
maxBlobsPerBlock,
Expand All @@ -75,6 +77,13 @@ public DenebBuilder denebForkVersion(final Bytes4 denebForkVersion) {
return this;
}

public DenebBuilder maxPerEpochActivationChurnLimit(
final Integer maxPerEpochActivationChurnLimit) {
checkNotNull(maxPerEpochActivationChurnLimit);
this.maxPerEpochActivationChurnLimit = maxPerEpochActivationChurnLimit;
return this;
}

public DenebBuilder fieldElementsPerBlob(final Integer fieldElementsPerBlob) {
this.fieldElementsPerBlob = fieldElementsPerBlob;
return this;
Expand Down Expand Up @@ -140,6 +149,8 @@ public void validate() {

SpecBuilderUtil.validateConstant("denebForkEpoch", denebForkEpoch);
SpecBuilderUtil.validateConstant("denebForkVersion", denebForkVersion);
SpecBuilderUtil.validateConstant(
"maxPerEpochActivationChurnLimit", maxPerEpochActivationChurnLimit);
SpecBuilderUtil.validateConstant("fieldElementsPerBlob", fieldElementsPerBlob);
SpecBuilderUtil.validateConstant("maxBlobCommitmentsPerBlock", maxBlobCommitmentsPerBlock);
SpecBuilderUtil.validateConstant("maxBlobsPerBlock", maxBlobsPerBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public UInt64 getPreviousEpoch(BeaconState state) {
return currentEpoch.equals(GENESIS_EPOCH) ? GENESIS_EPOCH : currentEpoch.minus(UInt64.ONE);
}

public UInt64 getValidatorChurnLimit(BeaconState state) {
public UInt64 getValidatorChurnLimit(final BeaconState state) {
final int activeValidatorCount =
getActiveValidatorIndices(state, getCurrentEpoch(state)).size();
return getValidatorChurnLimit(activeValidatorCount);
Expand All @@ -69,6 +69,10 @@ public UInt64 getValidatorChurnLimit(final int activeValidatorCount) {
.max(UInt64.valueOf(activeValidatorCount / config.getChurnLimitQuotient()));
}

public UInt64 getValidatorActivationChurnLimit(final BeaconState state) {
return getValidatorChurnLimit(state);
}

public Optional<BLSPublicKey> getValidatorPubKey(BeaconState state, UInt64 validatorIndex) {
if (state.getValidators().size() <= validatorIndex.longValue()
|| validatorIndex.longValue() < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void processRegistryUpdates(
.toList();

// Dequeued validators for activation up to churn limit (without resetting activation epoch)
int churnLimit = beaconStateAccessors.getValidatorChurnLimit(state).intValue();
int churnLimit = beaconStateAccessors.getValidatorActivationChurnLimit(state).intValue();
int sublistSize = Math.min(churnLimit, activationQueue.size());
for (Integer index : activationQueue.subList(0, sublistSize)) {
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,29 @@

import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.constants.Domain;
import tech.pegasys.teku.spec.datastructures.state.Fork;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateAccessorsAltair;

public class BeaconStateAccessorsDeneb extends BeaconStateAccessorsAltair {

private final SpecConfigDeneb denebConfig;

public BeaconStateAccessorsDeneb(
final SpecConfigDeneb config,
final Predicates predicates,
final MiscHelpersDeneb miscHelpers) {
super(config, predicates, miscHelpers);
this.denebConfig = config;
}

/** <a href="https://eips.ethereum.org/EIPS/eip-7514">EIP-7514: Add Max Epoch Churn Limit</a> */
@Override
public UInt64 getValidatorActivationChurnLimit(final BeaconState state) {
return getValidatorChurnLimit(state).min(denebConfig.getMaxPerEpochActivationChurnLimit());
}

/**
Expand All @@ -39,9 +48,7 @@ public BeaconStateAccessorsDeneb(
public Bytes32 getVoluntaryExitDomain(
final UInt64 epoch, final Fork fork, final Bytes32 genesisValidatorsRoot) {
return miscHelpers.computeDomain(
Domain.VOLUNTARY_EXIT,
SpecConfigCapella.required(config).getCapellaForkVersion(),
genesisValidatorsRoot);
Domain.VOLUNTARY_EXIT, denebConfig.getCapellaForkVersion(), genesisValidatorsRoot);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ EJECTION_BALANCE: 28000000000
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536
# [New in Deneb:EIP7514] 2**3 (= 8)
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8

# Fork choice
# ---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ EJECTION_BALANCE: 16000000000
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536
# [New in Deneb:EIP7514] 2**3 (= 8)
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8


# Fork choice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ INACTIVITY_SCORE_BIAS: 4
INACTIVITY_SCORE_RECOVERY_RATE: 16
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE: 16000000000
# 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT: 4
# [customized] more easily demonstrate the difference between this value and the activation churn limit
MIN_PER_EPOCH_CHURN_LIMIT: 2
# [customized] scale queue churn at much lower validator counts for testing
CHURN_LIMIT_QUOTIENT: 32
# [New in Deneb:EIP7514] [customized]
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 4


# Fork choice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ EJECTION_BALANCE: 16000000000
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 32
# [New in Deneb:EIP7514] 2**3 (= 8)
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8


# Fork choice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private SpecConfigDeneb createRandomDenebConfig(
dataStructureUtil.randomPositiveInt(),
dataStructureUtil.randomPositiveInt(),
dataStructureUtil.randomPositiveInt(),
dataStructureUtil.randomPositiveInt(),
Optional.empty(),
true,
dataStructureUtil.randomPositiveInt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ private void setupWithSpec(final Spec spec) {
new TickProcessor(spec, recentChainData),
transitionBlockValidator,
DEFAULT_FORK_CHOICE_UPDATE_HEAD_ON_BLOCK_IMPORT_ENABLED,
// will use DEFAULT_FORK_CHOICE_PROPOSER_BOOST_UNIQUENESS_ENABLED in an upcoming PR
// which will update to the new ref tests and set the const to true
true,
DEFAULT_FORK_CHOICE_PROPOSER_BOOST_UNIQUENESS_ENABLED,
metricsSystem);

// Starting and mocks
Expand Down
Binary file not shown.

0 comments on commit 78a929f

Please sign in to comment.