mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
* Validator custody: Update to the latest specfication. * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence <terence@prysmaticlabs.com> * Fix James' comment. * Fix James' comment. * Fix James' comment. --------- Co-authored-by: terence <terence@prysmaticlabs.com> Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package peerdas
|
|
|
|
import (
|
|
beaconState "github.com/OffchainLabs/prysm/v6/beacon-chain/state"
|
|
"github.com/OffchainLabs/prysm/v6/config/params"
|
|
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// ValidatorsCustodyRequirement returns the number of custody groups regarding the validator indices attached to the beacon node.
|
|
// https://github.com/ethereum/consensus-specs/blob/master/specs/fulu/validator.md#validator-custody
|
|
func ValidatorsCustodyRequirement(state beaconState.ReadOnlyBeaconState, validatorsIndex map[primitives.ValidatorIndex]bool) (uint64, error) {
|
|
totalNodeBalance := uint64(0)
|
|
for index := range validatorsIndex {
|
|
validator, err := state.ValidatorAtIndexReadOnly(index)
|
|
if err != nil {
|
|
return 0, errors.Wrapf(err, "validator at index %v", index)
|
|
}
|
|
|
|
totalNodeBalance += validator.EffectiveBalance()
|
|
}
|
|
|
|
beaconConfig := params.BeaconConfig()
|
|
numberOfCustodyGroups := beaconConfig.NumberOfCustodyGroups
|
|
validatorCustodyRequirement := beaconConfig.ValidatorCustodyRequirement
|
|
balancePerAdditionalCustodyGroup := beaconConfig.BalancePerAdditionalCustodyGroup
|
|
|
|
count := totalNodeBalance / balancePerAdditionalCustodyGroup
|
|
return min(max(count, validatorCustodyRequirement), numberOfCustodyGroups), nil
|
|
}
|