mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
beacon-chain, config: get consensus values from beacon config (#11798)
* beacon-chain, config: get consensus values from beacon config * review feedback Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
parent
0a4b0a68d3
commit
c6338e3a31
@ -5,7 +5,7 @@ import (
|
||||
|
||||
nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
||||
)
|
||||
@ -54,7 +54,7 @@ func (b *BeaconState) AppendCurrentEpochAttestations(val *ethpb.PendingAttestati
|
||||
}
|
||||
|
||||
atts := b.currentEpochAttestations
|
||||
max := uint64(fieldparams.CurrentEpochAttestationsLength)
|
||||
max := uint64(params.BeaconConfig().CurrentEpochAttestationsLength())
|
||||
if uint64(len(atts)) >= max {
|
||||
return fmt.Errorf("current pending attestation exceeds max length %d", max)
|
||||
}
|
||||
@ -84,7 +84,7 @@ func (b *BeaconState) AppendPreviousEpochAttestations(val *ethpb.PendingAttestat
|
||||
}
|
||||
|
||||
atts := b.previousEpochAttestations
|
||||
max := uint64(fieldparams.PreviousEpochAttestationsLength)
|
||||
max := uint64(params.BeaconConfig().PreviousEpochAttestationsLength())
|
||||
if uint64(len(atts)) >= max {
|
||||
return fmt.Errorf("previous pending attestation exceeds max length %d", max)
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ func (b *BeaconState) rootSelector(ctx context.Context, field nativetypes.FieldI
|
||||
err := b.resetFieldTrie(
|
||||
field,
|
||||
b.eth1DataVotes,
|
||||
fieldparams.Eth1DataVotesLength,
|
||||
params.BeaconConfig().Eth1DataVotesLength(),
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
@ -788,7 +788,7 @@ func (b *BeaconState) rootSelector(ctx context.Context, field nativetypes.FieldI
|
||||
err := b.resetFieldTrie(
|
||||
field,
|
||||
b.previousEpochAttestations,
|
||||
fieldparams.PreviousEpochAttestationsLength,
|
||||
params.BeaconConfig().PreviousEpochAttestationsLength(),
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
@ -802,7 +802,7 @@ func (b *BeaconState) rootSelector(ctx context.Context, field nativetypes.FieldI
|
||||
err := b.resetFieldTrie(
|
||||
field,
|
||||
b.currentEpochAttestations,
|
||||
fieldparams.CurrentEpochAttestationsLength,
|
||||
params.BeaconConfig().CurrentEpochAttestationsLength(),
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
params "github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/ssz"
|
||||
@ -56,7 +56,7 @@ func Eth1DatasRoot(eth1Datas []*ethpb.Eth1Data) ([32]byte, error) {
|
||||
hasher,
|
||||
eth1VotesRoots,
|
||||
uint64(len(eth1VotesRoots)),
|
||||
fieldparams.Eth1DataVotesLength,
|
||||
params.BeaconConfig().Eth1DataVotesLength(),
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute eth1data votes merkleization")
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
params "github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/ssz"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@ -19,7 +19,7 @@ func RootsArrayHashTreeRoot(vals [][]byte, length uint64) ([32]byte, error) {
|
||||
}
|
||||
|
||||
func EpochAttestationsRoot(atts []*ethpb.PendingAttestation) ([32]byte, error) {
|
||||
max := uint64(fieldparams.CurrentEpochAttestationsLength)
|
||||
max := uint64(params.BeaconConfig().CurrentEpochAttestationsLength())
|
||||
if uint64(len(atts)) > max {
|
||||
return [32]byte{}, fmt.Errorf("epoch attestation exceeds max length %d", max)
|
||||
}
|
||||
@ -38,7 +38,7 @@ func EpochAttestationsRoot(atts []*ethpb.PendingAttestation) ([32]byte, error) {
|
||||
hasher,
|
||||
roots,
|
||||
uint64(len(roots)),
|
||||
fieldparams.CurrentEpochAttestationsLength,
|
||||
params.BeaconConfig().CurrentEpochAttestationsLength(),
|
||||
)
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute epoch attestations merkleization")
|
||||
|
@ -234,3 +234,23 @@ func configForkNames(b *BeaconChainConfig) map[[fieldparams.VersionLength]byte]s
|
||||
fvn[bytesutil.ToBytes4(b.CapellaForkVersion)] = "capella"
|
||||
return fvn
|
||||
}
|
||||
|
||||
// Eth1DataVotesLength returns the maximum length of the votes on the Eth1 data,
|
||||
// computed from the parameters in BeaconChainConfig.
|
||||
func (b *BeaconChainConfig) Eth1DataVotesLength() uint64 {
|
||||
return uint64(b.EpochsPerEth1VotingPeriod.Mul(uint64(b.SlotsPerEpoch)))
|
||||
}
|
||||
|
||||
// PreviousEpochAttestationsLength returns the maximum length of the pending
|
||||
// attestation list for the previous epoch, computed from the parameters in
|
||||
// BeaconChainConfig.
|
||||
func (b *BeaconChainConfig) PreviousEpochAttestationsLength() uint64 {
|
||||
return uint64(b.SlotsPerEpoch.Mul(b.MaxAttestations))
|
||||
}
|
||||
|
||||
// CurrentEpochAttestationsLength returns the maximum length of the pending
|
||||
// attestation list for the current epoch, computed from the parameters in
|
||||
// BeaconChainConfig.
|
||||
func (b *BeaconChainConfig) CurrentEpochAttestationsLength() uint64 {
|
||||
return uint64(b.SlotsPerEpoch.Mul(b.MaxAttestations))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user