mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-10 13:01:21 +00:00
30430d585a
this first major move separates the transient beacon state cache from the underlying tree. leaf updates are enforced in the setters, which should make programming easier. all exported methods of the raw.BeaconState should be safe to call (without disrupting internal state) changes many functions to consume *raw.BeaconState in perparation for interface beyond refactor it also: adds a pool for the leaves of the validator ssz hash adds a pool for the snappy writers removed the parallel hash experiment (high memory use)
68 lines
2.4 KiB
Go
68 lines
2.4 KiB
Go
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
|
|
}
|