package state import ( "sort" lru "github.com/hashicorp/golang-lru/v2" "github.com/ledgerwatch/erigon/cl/clparams" "github.com/ledgerwatch/erigon/cl/cltypes" "github.com/ledgerwatch/erigon/cl/utils" ) func copyLRU[K comparable, V any](dst *lru.Cache[K, V], src *lru.Cache[K, V]) *lru.Cache[K, V] { if dst == nil { dst = new(lru.Cache[K, V]) } for _, key := range src.Keys() { val, has := src.Get(key) if !has { continue } dst.Add(key, val) } return dst } func GetIndexedAttestation(attestation *cltypes.Attestation, attestingIndicies []uint64) *cltypes.IndexedAttestation { // Sort the the attestation indicies. sort.Slice(attestingIndicies, func(i, j int) bool { return attestingIndicies[i] < attestingIndicies[j] }) return &cltypes.IndexedAttestation{ AttestingIndices: attestingIndicies, Data: attestation.Data, Signature: attestation.Signature, } } func ValidatorFromDeposit(conf *clparams.BeaconChainConfig, deposit *cltypes.Deposit) *cltypes.Validator { amount := deposit.Data.Amount effectiveBalance := utils.Min64(amount-amount%conf.EffectiveBalanceIncrement, conf.MaxEffectiveBalance) return &cltypes.Validator{ PublicKey: deposit.Data.PubKey, WithdrawalCredentials: deposit.Data.WithdrawalCredentials, ActivationEligibilityEpoch: conf.FarFutureEpoch, ActivationEpoch: conf.FarFutureEpoch, ExitEpoch: conf.FarFutureEpoch, WithdrawableEpoch: conf.FarFutureEpoch, EffectiveBalance: effectiveBalance, } } // Check whether a validator is fully withdrawable at the given epoch. func isFullyWithdrawableValidator(conf *clparams.BeaconChainConfig, validator *cltypes.Validator, balance uint64, epoch uint64) bool { return validator.WithdrawalCredentials[0] == conf.ETH1AddressWithdrawalPrefixByte && validator.WithdrawableEpoch <= epoch && balance > 0 } // Check whether a validator is partially withdrawable. func isPartiallyWithdrawableValidator(conf *clparams.BeaconChainConfig, validator *cltypes.Validator, balance uint64) bool { return validator.WithdrawalCredentials[0] == conf.ETH1AddressWithdrawalPrefixByte && validator.EffectiveBalance == conf.MaxEffectiveBalance && balance > conf.MaxEffectiveBalance } func ComputeActivationExitEpoch(config *clparams.BeaconChainConfig, epoch uint64) uint64 { return epoch + 1 + config.MaxSeedLookahead }