Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deneb integration to Caplin #9093

Merged
merged 11 commits into from
Jan 12, 2024
1 change: 1 addition & 0 deletions cl/abstract/beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type BeaconStateExtension interface {
ValidatorIndexByPubkey(key [48]byte) (uint64, bool)
PreviousStateRoot() common.Hash
SetPreviousStateRoot(root common.Hash)
GetValidatorActivationChurnLimit() uint64
}

type BeaconStateBasic interface {
Expand Down
54 changes: 28 additions & 26 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,21 @@ type BeaconChainConfig struct {
JustificationBitsLength uint64 `yaml:"JUSTIFICATION_BITS_LENGTH"` // JustificationBitsLength defines number of epochs to track when implementing k-finality in Casper FFG.

// Misc constants.
PresetBase string `yaml:"PRESET_BASE" spec:"true"` // PresetBase represents the underlying spec preset this config is based on.
ConfigName string `yaml:"CONFIG_NAME" spec:"true"` // ConfigName for allowing an easy human-readable way of knowing what chain is being used.
TargetCommitteeSize uint64 `yaml:"TARGET_COMMITTEE_SIZE" spec:"true"` // TargetCommitteeSize is the number of validators in a committee when the chain is healthy.
MaxValidatorsPerCommittee uint64 `yaml:"MAX_VALIDATORS_PER_COMMITTEE" spec:"true"` // MaxValidatorsPerCommittee defines the upper bound of the size of a committee.
MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT" spec:"true"` // MaxCommitteesPerSlot defines the max amount of committee in a single slot.
MinPerEpochChurnLimit uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT" spec:"true"` // MinPerEpochChurnLimit is the minimum amount of churn allotted for validator rotations.
ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT" spec:"true"` // ChurnLimitQuotient is used to determine the limit of how many validators can rotate per epoch.
ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT" spec:"true"` // ShuffleRoundCount is used for retrieving the permuted index.
MinGenesisActiveValidatorCount uint64 `yaml:"MIN_GENESIS_ACTIVE_VALIDATOR_COUNT" spec:"true"` // MinGenesisActiveValidatorCount defines how many validator deposits needed to kick off beacon chain.
MinGenesisTime uint64 `yaml:"MIN_GENESIS_TIME" spec:"true"` // MinGenesisTime is the time that needed to pass before kicking off beacon chain.
TargetAggregatorsPerCommittee uint64 `yaml:"TARGET_AGGREGATORS_PER_COMMITTEE" spec:"true"` // TargetAggregatorsPerCommittee defines the number of aggregators inside one committee.
HysteresisQuotient uint64 `yaml:"HYSTERESIS_QUOTIENT" spec:"true"` // HysteresisQuotient defines the hysteresis quotient for effective balance calculations.
HysteresisDownwardMultiplier uint64 `yaml:"HYSTERESIS_DOWNWARD_MULTIPLIER" spec:"true"` // HysteresisDownwardMultiplier defines the hysteresis downward multiplier for effective balance calculations.
HysteresisUpwardMultiplier uint64 `yaml:"HYSTERESIS_UPWARD_MULTIPLIER" spec:"true"` // HysteresisUpwardMultiplier defines the hysteresis upward multiplier for effective balance calculations.
PresetBase string `yaml:"PRESET_BASE" spec:"true"` // PresetBase represents the underlying spec preset this config is based on.
ConfigName string `yaml:"CONFIG_NAME" spec:"true"` // ConfigName for allowing an easy human-readable way of knowing what chain is being used.
TargetCommitteeSize uint64 `yaml:"TARGET_COMMITTEE_SIZE" spec:"true"` // TargetCommitteeSize is the number of validators in a committee when the chain is healthy.
MaxValidatorsPerCommittee uint64 `yaml:"MAX_VALIDATORS_PER_COMMITTEE" spec:"true"` // MaxValidatorsPerCommittee defines the upper bound of the size of a committee.
MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT" spec:"true"` // MaxCommitteesPerSlot defines the max amount of committee in a single slot.
MinPerEpochChurnLimit uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT" spec:"true"` // MinPerEpochChurnLimit is the minimum amount of churn allotted for validator rotations.
ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT" spec:"true"` // ChurnLimitQuotient is used to determine the limit of how many validators can rotate per epoch.
MaxPerEpochActivationChurnLimit uint64 `yaml:"MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT" spec:"true"` // MaxPerEpochActivationChurnLimit defines the maximum amount of churn allowed in one epoch from deneb.
ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT" spec:"true"` // ShuffleRoundCount is used for retrieving the permuted index.
MinGenesisActiveValidatorCount uint64 `yaml:"MIN_GENESIS_ACTIVE_VALIDATOR_COUNT" spec:"true"` // MinGenesisActiveValidatorCount defines how many validator deposits needed to kick off beacon chain.
MinGenesisTime uint64 `yaml:"MIN_GENESIS_TIME" spec:"true"` // MinGenesisTime is the time that needed to pass before kicking off beacon chain.
TargetAggregatorsPerCommittee uint64 `yaml:"TARGET_AGGREGATORS_PER_COMMITTEE" spec:"true"` // TargetAggregatorsPerCommittee defines the number of aggregators inside one committee.
HysteresisQuotient uint64 `yaml:"HYSTERESIS_QUOTIENT" spec:"true"` // HysteresisQuotient defines the hysteresis quotient for effective balance calculations.
HysteresisDownwardMultiplier uint64 `yaml:"HYSTERESIS_DOWNWARD_MULTIPLIER" spec:"true"` // HysteresisDownwardMultiplier defines the hysteresis downward multiplier for effective balance calculations.
HysteresisUpwardMultiplier uint64 `yaml:"HYSTERESIS_UPWARD_MULTIPLIER" spec:"true"` // HysteresisUpwardMultiplier defines the hysteresis upward multiplier for effective balance calculations.

// Gwei value constants.
MinDepositAmount uint64 `yaml:"MIN_DEPOSIT_AMOUNT" spec:"true"` // MinDepositAmount is the minimum amount of Gwei a validator can send to the deposit contract at once (lower amounts will be reverted).
Expand Down Expand Up @@ -573,18 +574,19 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
GenesisDelay: 604800, // 1 week.

// Misc constant.
TargetCommitteeSize: 128,
MaxValidatorsPerCommittee: 2048,
MaxCommitteesPerSlot: 64,
MinPerEpochChurnLimit: 4,
ChurnLimitQuotient: 1 << 16,
ShuffleRoundCount: 90,
MinGenesisActiveValidatorCount: 16384,
MinGenesisTime: 1606824000, // Dec 1, 2020, 12pm UTC.
TargetAggregatorsPerCommittee: 16,
HysteresisQuotient: 4,
HysteresisDownwardMultiplier: 1,
HysteresisUpwardMultiplier: 5,
TargetCommitteeSize: 128,
MaxValidatorsPerCommittee: 2048,
MaxCommitteesPerSlot: 64,
MinPerEpochChurnLimit: 4,
ChurnLimitQuotient: 1 << 16,
MaxPerEpochActivationChurnLimit: 8,
ShuffleRoundCount: 90,
MinGenesisActiveValidatorCount: 16384,
MinGenesisTime: 1606824000, // Dec 1, 2020, 12pm UTC.
TargetAggregatorsPerCommittee: 16,
HysteresisQuotient: 4,
HysteresisDownwardMultiplier: 1,
HysteresisUpwardMultiplier: 5,

// Gwei value constants.
MinDepositAmount: 1 * 1e9,
Expand Down
2 changes: 1 addition & 1 deletion cl/cltypes/eth1_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e *Eth1Header) Capella() {
e.WithdrawalsRoot = libcommon.Hash{}
}

// Capella converts the header to capella version.
// Deneb converts the header to deneb version.
func (e *Eth1Header) Deneb() {
e.version = clparams.DenebVersion
e.BlobGasUsed = 0
Expand Down
13 changes: 12 additions & 1 deletion cl/phase1/core/state/cache_accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ func (b *CachingBeaconState) GetAttestationParticipationFlagIndicies(data solid.
if inclusionDelay <= utils.IntegerSquareRoot(b.BeaconConfig().SlotsPerEpoch) {
participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelySourceFlagIndex)
}
if matchingTarget && inclusionDelay <= b.BeaconConfig().SlotsPerEpoch {
if b.Version() < clparams.DenebVersion && matchingTarget && inclusionDelay <= b.BeaconConfig().SlotsPerEpoch {
participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelyTargetFlagIndex)
}
if b.Version() >= clparams.DenebVersion && matchingTarget {
participationFlagIndicies = append(participationFlagIndicies, b.BeaconConfig().TimelyTargetFlagIndex)
}
if matchingHead && inclusionDelay == b.BeaconConfig().MinAttestationInclusionDelay {
Expand Down Expand Up @@ -295,3 +298,11 @@ func (b *CachingBeaconState) GetValidatorChurnLimit() uint64 {
activeIndsCount := uint64(len(b.GetActiveValidatorsIndices(Epoch(b))))
return utils.Max64(activeIndsCount/b.BeaconConfig().ChurnLimitQuotient, b.BeaconConfig().MinPerEpochChurnLimit)
}

// https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/beacon-chain.md#new-get_validator_activation_churn_limit
func (b *CachingBeaconState) GetValidatorActivationChurnLimit() uint64 {
if b.Version() >= clparams.DenebVersion {
return utils.Min64(b.BeaconConfig().MaxPerEpochActivationChurnLimit, b.GetValidatorChurnLimit())
}
return b.GetValidatorChurnLimit()
}
11 changes: 10 additions & 1 deletion cl/phase1/forkchoice/on_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/Giulio2002/bls"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/fork"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
Expand Down Expand Up @@ -49,10 +50,18 @@ func (f *ForkChoiceStore) OnVoluntaryExit(signedVoluntaryExit *cltypes.SignedVol
pk := val.PublicKey()
f.mu.Unlock()

domain, err := s.GetDomain(s.BeaconConfig().DomainVoluntaryExit, voluntaryExit.Epoch)
domainType := f.beaconCfg.DomainVoluntaryExit
var domain []byte

if s.Version() < clparams.DenebVersion {
domain, err = s.GetDomain(domainType, voluntaryExit.Epoch)
} else if s.Version() >= clparams.DenebVersion {
domain, err = fork.ComputeDomain(domainType[:], utils.Uint32ToBytes4(s.BeaconConfig().CapellaForkVersion), s.GenesisValidatorsRoot())
}
if err != nil {
return err
}

signingRoot, err := fork.ComputeSigningRoot(voluntaryExit, domain)
if err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions cl/spectest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

tests:
GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/ethereum/consensus-spec-tests
cd consensus-spec-tests && git checkout 99549a414c10baa9e69abcb08eb256fc1a8d54f6 && git lfs pull --exclude=tests/general,tests/minimal && cd ..
cd consensus-spec-tests && git checkout 080c96fbbf3be58e75947debfeb9ba3b2b7c9748 && git lfs pull --exclude=tests/general,tests/minimal && cd ..
mv consensus-spec-tests/tests .
rm -rf consensus-spec-tests
rm -rf tests/minimal
# not needed for now
rm -rf tests/mainnet/eip6110
# will not implement until i see it on a testnet
rm -rf tests/mainnet/deneb

# FIXME: Add fork choice coverage for deneb
rm -rf tests/mainnet/deneb/fork_choice
clean:
rm -rf tests

Expand Down
12 changes: 10 additions & 2 deletions cl/transition/impl/eth2/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ func (I *impl) ProcessVoluntaryExit(s abstract.BeaconState, signedVoluntaryExit

// We can skip it in some instances if we want to optimistically sync up.
if I.FullValidation {
domain, err := s.GetDomain(s.BeaconConfig().DomainVoluntaryExit, voluntaryExit.Epoch)
var domain []byte
if s.Version() < clparams.DenebVersion {
domain, err = s.GetDomain(s.BeaconConfig().DomainVoluntaryExit, voluntaryExit.Epoch)
} else if s.Version() >= clparams.DenebVersion {
domain, err = fork.ComputeDomain(s.BeaconConfig().DomainVoluntaryExit[:], utils.Uint32ToBytes4(s.BeaconConfig().CapellaForkVersion), s.GenesisValidatorsRoot())
}
if err != nil {
return err
}
Expand Down Expand Up @@ -697,7 +702,10 @@ func (I *impl) processAttestation(s abstract.BeaconState, attestation *solid.Att
if (data.Target().Epoch() != currentEpoch && data.Target().Epoch() != previousEpoch) || data.Target().Epoch() != state.GetEpochAtSlot(s.BeaconConfig(), data.Slot()) {
return nil, errors.New("ProcessAttestation: attestation with invalid epoch")
}
if data.Slot()+beaconConfig.MinAttestationInclusionDelay > stateSlot || stateSlot > data.Slot()+beaconConfig.SlotsPerEpoch {
if s.Version() < clparams.DenebVersion && ((data.Slot()+beaconConfig.MinAttestationInclusionDelay > stateSlot) || (stateSlot > data.Slot()+beaconConfig.SlotsPerEpoch)) {
return nil, errors.New("ProcessAttestation: attestation slot not in range")
}
if s.Version() >= clparams.DenebVersion && data.Slot()+beaconConfig.MinAttestationInclusionDelay > stateSlot {
return nil, errors.New("ProcessAttestation: attestation slot not in range")
}
if data.ValidatorIndex() >= s.CommitteeCount(data.Target().Epoch()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func ProcessRegistryUpdates(s abstract.BeaconState) error {
}
return activationQueue[i].validatorIndex < activationQueue[j].validatorIndex
})
activationQueueLength := s.GetValidatorChurnLimit()
activationQueueLength := s.GetValidatorActivationChurnLimit()
if len(activationQueue) > int(activationQueueLength) {
activationQueue = activationQueue[:activationQueueLength]
}
Expand Down
Loading