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

WIP: increase max effective balance #12418

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cl/abstract/beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type BeaconStateExtension interface {
PreviousStateRoot() common.Hash
SetPreviousStateRoot(root common.Hash)
GetValidatorActivationChurnLimit() uint64
GetPendingPartialWithdrawals() *solid.ListSSZ[*solid.PendingPartialWithdrawal]
}

type BeaconStateBasic interface {
Expand Down Expand Up @@ -123,6 +124,7 @@ type BeaconStateMutator interface {
SetCurrentEpochParticipationFlags(flags []cltypes.ParticipationFlags)
SetPreviousEpochParticipationFlags(flags []cltypes.ParticipationFlags)
SetPreviousEpochAttestations(attestations *solid.ListSSZ[*solid.PendingAttestation]) // temporarily skip this mock
SetPendingPartialWithdrawals(*solid.ListSSZ[*solid.PendingPartialWithdrawal])

AddEth1DataVote(vote *cltypes.Eth1Data)
AddValidator(validator solid.Validator, balance uint64)
Expand All @@ -136,6 +138,7 @@ type BeaconStateMutator interface {
AddPreviousEpochAttestation(attestation *solid.PendingAttestation)

AppendValidator(in solid.Validator)
AppendPendingDeposit(deposit *solid.PendingDeposit)

ResetEth1DataVotes()
ResetEpochParticipation()
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/block_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (a *ApiHandler) produceBeaconBody(
secsDiff := (targetSlot - baseBlock.Slot) * a.beaconChainCfg.SecondsPerSlot
feeRecipient, _ := a.validatorParams.GetFeeRecipient(proposerIndex)
var withdrawals []*types.Withdrawal
clWithdrawals := state.ExpectedWithdrawals(
clWithdrawals, _ := state.ExpectedWithdrawals(
baseState,
targetSlot/a.beaconChainCfg.SlotsPerEpoch,
)
Expand Down
3 changes: 2 additions & 1 deletion cl/beacon/handler/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func (a *ApiHandler) GetEth1V1BuilderStatesExpectedWithdrawals(w http.ResponseWr
return nil, beaconhttp.NewEndpointError(http.StatusServiceUnavailable, errors.New("beacon node is syncing"))
}
if root == headRoot {
return newBeaconResponse(state.ExpectedWithdrawals(a.syncedData.HeadState(), state.Epoch(a.syncedData.HeadState()))).WithFinalized(false), nil
ws, _ := state.ExpectedWithdrawals(a.syncedData.HeadState(), state.Epoch(a.syncedData.HeadState()))
return newBeaconResponse(ws).WithFinalized(false), nil
}
lookAhead := 1024
for currSlot := *slot + 1; currSlot < *slot+uint64(lookAhead); currSlot++ {
Expand Down
6 changes: 3 additions & 3 deletions cl/beacon/handler/duties_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/erigontech/erigon/cl/beacon/beaconhttp"
"github.com/erigontech/erigon/cl/persistence/base_encoding"
state_accessors "github.com/erigontech/erigon/cl/persistence/state"
shuffling2 "github.com/erigontech/erigon/cl/phase1/core/state/shuffling"
"github.com/erigontech/erigon/cl/phase1/core/state/shuffling"

libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/kv"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (a *ApiHandler) getDutiesProposer(w http.ResponseWriter, r *http.Request) (
a.beaconChainCfg.EpochsPerHistoricalVector
// Input for the seed hash.
mix := state.GetRandaoMix(int(mixPosition))
input := shuffling2.GetSeed(a.beaconChainCfg, mix, epoch, a.beaconChainCfg.DomainBeaconProposer)
input := shuffling.GetSeed(a.beaconChainCfg, mix, epoch, a.beaconChainCfg.DomainBeaconProposer)
slotByteArray := make([]byte, 8)
binary.LittleEndian.PutUint64(slotByteArray, slot)

Expand All @@ -124,7 +124,7 @@ func (a *ApiHandler) getDutiesProposer(w http.ResponseWriter, r *http.Request) (
// Do it in parallel
go func(i, slot uint64, indicies []uint64, seedArray [32]byte) {
defer wg.Done()
proposerIndex, err = shuffling2.ComputeProposerIndex(state.BeaconState, indices, seedArray)
proposerIndex, err = shuffling.ComputeProposerIndex(state.BeaconState, indices, seedArray)
if err != nil {
panic(err)
}
Expand Down
68 changes: 56 additions & 12 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,12 @@ type BeaconChainConfig struct {
MinEpochsForBlobsSidecarsRequest uint64 `yaml:"MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUEST" spec:"true" json:"MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUEST,string"` // MinEpochsForBlobsSidecarsRequest defines the minimum number of epochs to wait before requesting blobs sidecars.

// Gwei value constants.
MinDepositAmount uint64 `yaml:"MIN_DEPOSIT_AMOUNT" spec:"true" json:"MIN_DEPOSIT_AMOUNT,string"` // MinDepositAmount is the minimum amount of Gwei a validator can send to the deposit contract at once (lower amounts will be reverted).
MaxEffectiveBalance uint64 `yaml:"MAX_EFFECTIVE_BALANCE" spec:"true" json:"MAX_EFFECTIVE_BALANCE,string"` // MaxEffectiveBalance is the maximal amount of Gwei that is effective for staking.
EjectionBalance uint64 `yaml:"EJECTION_BALANCE" spec:"true" json:"EJECTION_BALANCE,string"` // EjectionBalance is the minimal GWei a validator needs to have before ejected.
EffectiveBalanceIncrement uint64 `yaml:"EFFECTIVE_BALANCE_INCREMENT" spec:"true" json:"EFFECTIVE_BALANCE_INCREMENT,string"` // EffectiveBalanceIncrement is used for converting the high balance into the low balance for validators.
MinDepositAmount uint64 `yaml:"MIN_DEPOSIT_AMOUNT" spec:"true" json:"MIN_DEPOSIT_AMOUNT,string"` // MinDepositAmount is the minimum amount of Gwei a validator can send to the deposit contract at once (lower amounts will be reverted).
MaxEffectiveBalance uint64 `yaml:"MAX_EFFECTIVE_BALANCE" spec:"true" json:"MAX_EFFECTIVE_BALANCE,string"` // MaxEffectiveBalance is the maximal amount of Gwei that is effective for staking.
MaxEffectiveBalanceElectra uint64 `yaml:"MAX_EFFECTIVE_BALANCE_ELECTRA" spec:"true" json:"MAX_EFFECTIVE_BALANCE_ELECTRA,string"` // MaxEffectiveBalanceElectra is the maximal amount of Gwei that is effective for staking in Electra.
MinActivationBalance uint64 `yaml:"MIN_ACTIVATION_BALANCE" spec:"true" json:"MIN_ACTIVATION_BALANCE,string"` // MinActivationBalance is the minimal GWei a validator needs to have before activated.
EjectionBalance uint64 `yaml:"EJECTION_BALANCE" spec:"true" json:"EJECTION_BALANCE,string"` // EjectionBalance is the minimal GWei a validator needs to have before ejected.
EffectiveBalanceIncrement uint64 `yaml:"EFFECTIVE_BALANCE_INCREMENT" spec:"true" json:"EFFECTIVE_BALANCE_INCREMENT,string"` // EffectiveBalanceIncrement is used for converting the high balance into the low balance for validators.

// Initial value constants.
BLSWithdrawalPrefixByte ConfigByte `yaml:"BLS_WITHDRAWAL_PREFIX" spec:"true" json:"BLS_WITHDRAWAL_PREFIX"` // BLSWithdrawalPrefixByte is used for BLS withdrawal and it's the first byte.
Expand Down Expand Up @@ -550,8 +552,14 @@ type BeaconChainConfig struct {
TargetNumberOfPeers uint64 `yaml:"TARGET_NUMBER_OF_PEERS" spec:"true" json:"TARGET_NUMBER_OF_PEERS,string"` // TargetNumberOfPeers defines the target number of peers.

// Electra
MinPerEpochChurnLimitElectra uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA" spec:"true" json:"MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA,string"` // MinPerEpochChurnLimitElectra defines the minimum per epoch churn limit for Electra.
MaxPerEpochActivationExitChurnLimit uint64 `yaml:"MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT" spec:"true" json:"MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT,string"` // MaxPerEpochActivationExitChurnLimit defines the maximum per epoch activation exit churn limit for Electra.
MinPerEpochChurnLimitElectra uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA" spec:"true" json:"MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA,string"` // MinPerEpochChurnLimitElectra defines the minimum per epoch churn limit for Electra.
MaxPerEpochActivationExitChurnLimit uint64 `yaml:"MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT" spec:"true" json:"MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT,string"` // MaxPerEpochActivationExitChurnLimit defines the maximum per epoch activation exit churn limit for Electra.
MaxDepositRequestsPerPayload uint64 `yaml:"MAX_DEPOSIT_REQUESTS_PER_PAYLOAD" spec:"true" json:"MAX_DEPOSIT_REQUESTS_PER_PAYLOAD,string"` // MaxDepositRequestsPerPayload defines the maximum number of deposit requests in a block.
MaxWithdrawalRequestsPerPayload uint64 `yaml:"MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD" spec:"true" json:"MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD,string"` // MaxWithdrawalRequestsPerPayload defines the maximum number of withdrawal requests in a block.
MaxConsolidationRequestsPerPayload uint64 `yaml:"MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD" spec:"true" json:"MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD,string"` // MaxConsolidationRequestsPerPayload defines the maximum number of consolidation requests in a block.
MinSlashingPenaltyQuotientElectra uint64 `yaml:"MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA" spec:"true" json:"MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA,string"` // MinSlashingPenaltyQuotientElectra for slashing penalties post Electra hard fork.
WhistleBlowerRewardQuotientElectra uint64 `yaml:"WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA" spec:"true" json:"WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA,string"` // WhistleBlowerRewardQuotientElectra is used to calculate whistle blower reward post Electra hard fork.
MaxPendingPartialsPerWithdrawalsSweep uint64 `yaml:"MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP" spec:"true" json:"MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,string"` // MaxPendingPartialsPerWithdrawalsSweep bounds the size of the sweep searching for pending partials per slot.
}

func (b *BeaconChainConfig) RoundSlotToEpoch(slot uint64) uint64 {
Expand Down Expand Up @@ -633,10 +641,12 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
MinEpochsForBlobsSidecarsRequest: 4096,

// Gwei value constants.
MinDepositAmount: 1 * 1e9,
MaxEffectiveBalance: 32 * 1e9,
EjectionBalance: 16 * 1e9,
EffectiveBalanceIncrement: 1 * 1e9,
MinDepositAmount: 1 * 1e9,
MaxEffectiveBalance: 32 * 1e9,
MinActivationBalance: 32 * 1e9,
MaxEffectiveBalanceElectra: 2048 * 1e9,
EjectionBalance: 16 * 1e9,
EffectiveBalanceIncrement: 1 * 1e9,

// Initial value constants.
BLSWithdrawalPrefixByte: ConfigByte(0),
Expand Down Expand Up @@ -798,8 +808,14 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
CustodyRequirement: 1,
TargetNumberOfPeers: 70,

MinPerEpochChurnLimitElectra: 128000000000,
MaxPerEpochActivationExitChurnLimit: 256000000000,
MinPerEpochChurnLimitElectra: 128000000000,
MaxPerEpochActivationExitChurnLimit: 256000000000,
MaxDepositRequestsPerPayload: 8192,
MaxWithdrawalRequestsPerPayload: 16,
MaxConsolidationRequestsPerPayload: 1,
MinSlashingPenaltyQuotientElectra: 4096,
WhistleBlowerRewardQuotientElectra: 4096,
MaxPendingPartialsPerWithdrawalsSweep: 8,
}

func mainnetConfig() BeaconChainConfig {
Expand Down Expand Up @@ -961,6 +977,21 @@ func (b *BeaconChainConfig) GetMinSlashingPenaltyQuotient(version StateVersion)
return b.MinSlashingPenaltyQuotientBellatrix
case DenebVersion:
return b.MinSlashingPenaltyQuotientBellatrix
case ElectraVersion:
return b.MinSlashingPenaltyQuotientElectra
default:
panic("not implemented")
}
}

func (b *BeaconChainConfig) GetProportionalSlashingMultiplier(version StateVersion) uint64 {
switch version {
case Phase0Version:
return b.ProportionalSlashingMultiplier
case AltairVersion:
return b.ProportionalSlashingMultiplierAltair
case BellatrixVersion, CapellaVersion, DenebVersion, ElectraVersion:
return b.ProportionalSlashingMultiplierBellatrix
default:
panic("not implemented")
}
Expand All @@ -978,6 +1009,8 @@ func (b *BeaconChainConfig) GetPenaltyQuotient(version StateVersion) uint64 {
return b.InactivityPenaltyQuotientBellatrix
case DenebVersion:
return b.InactivityPenaltyQuotientBellatrix
case ElectraVersion:
return b.InactivityPenaltyQuotientBellatrix
default:
panic("not implemented")
}
Expand Down Expand Up @@ -1012,6 +1045,17 @@ func (b *BeaconChainConfig) CurrentEpochAttestationsLength() uint64 {
return b.SlotsPerEpoch * b.MaxAttestations
}

func (b *BeaconChainConfig) MaxEffectiveBalanceForVersion(version StateVersion) uint64 {
switch version {
case Phase0Version, AltairVersion, BellatrixVersion, CapellaVersion, DenebVersion:
return b.MaxEffectiveBalance
case ElectraVersion:
return b.MaxEffectiveBalanceElectra
default:
panic("invalid version")
}
}

func (b *BeaconChainConfig) GetForkVersionByVersion(v StateVersion) uint32 {
switch v {
case Phase0Version:
Expand Down
45 changes: 45 additions & 0 deletions cl/cltypes/solid/consolidation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package solid

import (
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/types/clonable"
"github.com/erigontech/erigon-lib/types/ssz"
"github.com/erigontech/erigon/cl/merkle_tree"
ssz2 "github.com/erigontech/erigon/cl/ssz"
)

var (
_ ssz.EncodableSSZ = (*PendingConsolidation)(nil)
_ ssz.HashableSSZ = (*PendingConsolidation)(nil)
)

type PendingConsolidation struct {
SourceIndex uint64 // validator index
TargetIndex uint64 // validator index
}

func (p *PendingConsolidation) EncodingSizeSSZ() int {
return 16
}

func (p *PendingConsolidation) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, p.SourceIndex, p.TargetIndex)
}

func (p *PendingConsolidation) DecodeSSZ(buf []byte, version int) error {
return ssz2.UnmarshalSSZ(buf, version, &p.SourceIndex, &p.TargetIndex)
}

func (p PendingConsolidation) Clone() clonable.Clonable {
return &PendingConsolidation{}
}

func (p *PendingConsolidation) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(p.SourceIndex, p.TargetIndex)
}

type ConsolidationRequest struct {
SourceAddress common.Address
SourcePubKey common.Bytes48 // BLS public key
TargetPubKey common.Bytes48 // BLS public key
}
55 changes: 55 additions & 0 deletions cl/cltypes/solid/deposits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package solid

import (
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/length"
"github.com/erigontech/erigon-lib/types/clonable"
"github.com/erigontech/erigon-lib/types/ssz"
"github.com/erigontech/erigon/cl/merkle_tree"
ssz2 "github.com/erigontech/erigon/cl/ssz"
)

var (
_ ssz.EncodableSSZ = (*PendingDeposit)(nil)
_ ssz.HashableSSZ = (*PendingDeposit)(nil)
)

const (
SizePendingDeposit = length.Bytes48 + length.Hash + 8 + length.Bytes96 + 8
)

type PendingDeposit struct {
PubKey common.Bytes48 // BLS public key
WithdrawalCredentials common.Hash
Amount uint64 // Gwei
Signature common.Bytes96 // BLS signature
Slot uint64
}

func (p *PendingDeposit) EncodingSizeSSZ() int {
return SizePendingDeposit
}

func (p *PendingDeposit) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, p.PubKey, p.WithdrawalCredentials, p.Amount, p.Signature, p.Slot)
}

func (p *PendingDeposit) DecodeSSZ(buf []byte, version int) error {
return ssz2.UnmarshalSSZ(buf, version, p.PubKey[:], p.WithdrawalCredentials[:], &p.Amount, p.Signature[:], &p.Slot)
}

func (p PendingDeposit) Clone() clonable.Clonable {
return &PendingDeposit{}
}

func (p *PendingDeposit) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(p.PubKey, p.WithdrawalCredentials, p.Amount, p.Signature, p.Slot)
}

type DepositRequest struct {
PubKey common.Bytes48 // BLS public key
WithdrawalCredentials common.Hash
Amount uint64 // Gwei
Signature common.Bytes96 // BLS signature
Index uint64
}
21 changes: 21 additions & 0 deletions cl/cltypes/solid/list_ssz.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func (l *ListSSZ[T]) Truncate(length int) {
l.root = libcommon.Hash{}
}

func (l *ListSSZ[T]) Cut(length int) {
if length > len(l.list) {
l.list = make([]T, 0)
} else {
l.list = l.list[length:]
}
l.root = libcommon.Hash{}
}

func (l *ListSSZ[T]) ElementProof(i int) [][32]byte {
leaves := make([]interface{}, l.limit)
for i := range leaves {
Expand All @@ -191,3 +200,15 @@ func (l *ListSSZ[T]) ElementProof(i int) [][32]byte {
}
return append(branch, merkle_tree.Uint64Root(uint64(len(l.list))))
}

func (l *ListSSZ[T]) ShallowCopy() *ListSSZ[T] {
cpy := &ListSSZ[T]{
list: make([]T, len(l.list), cap(l.list)),
limit: l.limit,
static: l.static,
bytesPerElement: l.bytesPerElement,
root: libcommon.Hash(libcommon.CopyBytes(l.root[:])),
}
copy(cpy.list, l.list)
return cpy
}
50 changes: 50 additions & 0 deletions cl/cltypes/solid/withdrawal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package solid

import (
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/types/clonable"
"github.com/erigontech/erigon-lib/types/ssz"
"github.com/erigontech/erigon/cl/merkle_tree"
ssz2 "github.com/erigontech/erigon/cl/ssz"
)

var (
_ ssz.EncodableSSZ = (*PendingPartialWithdrawal)(nil)
_ ssz.HashableSSZ = (*PendingPartialWithdrawal)(nil)
)

const (
SizePendingPartialWithdrawal = 8 + 8 + 8
)

type PendingPartialWithdrawal struct {
Index uint64 // validator index
Amount uint64 // Gwei
WithdrawableEpoch uint64
}

func (p *PendingPartialWithdrawal) EncodingSizeSSZ() int {
return SizePendingPartialWithdrawal
}

func (p *PendingPartialWithdrawal) EncodeSSZ(buf []byte) ([]byte, error) {
return ssz2.MarshalSSZ(buf, p.Index, p.Amount, p.WithdrawableEpoch)
}

func (p *PendingPartialWithdrawal) DecodeSSZ(buf []byte, version int) error {
return ssz2.UnmarshalSSZ(buf, version, &p.Index, &p.Amount, &p.WithdrawableEpoch)
}

func (p PendingPartialWithdrawal) Clone() clonable.Clonable {
return &PendingPartialWithdrawal{}
}

func (p *PendingPartialWithdrawal) HashSSZ() ([32]byte, error) {
return merkle_tree.HashTreeRoot(p.Index, p.Amount, p.WithdrawableEpoch)
}

type WithdrawalRequest struct {
SourceAddress common.Address
ValidatorPubKey common.Bytes48 // BLS public key
Amount uint64 // Gwei
}
Loading
Loading