mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Fix Bad Merge in V4 (#12183)
This commit is contained in:
@@ -63,6 +63,7 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
fastssz "github.com/prysmaticlabs/fastssz"
|
||||
"github.com/prysmaticlabs/prysm/v4/cmd"
|
||||
"github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
@@ -189,3 +190,7 @@ func configureExecutionSetting(cliCtx *cli.Context) error {
|
||||
" Default fee recipient will be used as a fall back", checksumAddress.Hex())
|
||||
return params.SetActive(c)
|
||||
}
|
||||
|
||||
func configureFastSSZHashingAlgorithm() {
|
||||
fastssz.EnableVectorizedHTR = true
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ func New(cliCtx *cli.Context, opts ...Option) (*BeaconNode, error) {
|
||||
if err := configureExecutionSetting(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configureFastSSZHashingAlgorithm()
|
||||
|
||||
// Initializes any forks here.
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
|
||||
@@ -12,7 +12,6 @@ go_library(
|
||||
"//beacon-chain/state/state-native/custom-types:go_default_library",
|
||||
"//beacon-chain/state/state-native/types:go_default_library",
|
||||
"//beacon-chain/state/stateutil:go_default_library",
|
||||
"//crypto/hash:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//math:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
customtypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/custom-types"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
pmath "github.com/prysmaticlabs/prysm/v4/math"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
@@ -250,9 +249,8 @@ func handleEth1DataSlice(val []*ethpb.Eth1Data, indices []uint64, convertAll boo
|
||||
length = len(val)
|
||||
}
|
||||
roots := make([][32]byte, 0, length)
|
||||
hasher := hash.CustomSHA256Hasher()
|
||||
rootCreator := func(input *ethpb.Eth1Data) error {
|
||||
newRoot, err := stateutil.Eth1DataRootWithHasher(hasher, input)
|
||||
newRoot, err := stateutil.Eth1DataRootWithHasher(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stateutil"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
|
||||
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
||||
@@ -24,7 +23,6 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b
|
||||
if state == nil {
|
||||
return nil, errors.New("nil state")
|
||||
}
|
||||
hasher := hash.CustomSHA256Hasher()
|
||||
var fieldRoots [][]byte
|
||||
switch state.version {
|
||||
case version.Phase0:
|
||||
@@ -98,7 +96,7 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b
|
||||
fieldRoots[types.HistoricalRoots.RealPosition()] = historicalRootsRt[:]
|
||||
|
||||
// Eth1Data data structure root.
|
||||
eth1HashTreeRoot, err := stateutil.Eth1Root(hasher, state.eth1Data)
|
||||
eth1HashTreeRoot, err := stateutil.Eth1Root(state.eth1Data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not compute eth1data merkleization")
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v4/container/slice"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
@@ -694,7 +693,6 @@ func (b *BeaconState) rootSelector(ctx context.Context, field types.FieldIndex)
|
||||
defer span.End()
|
||||
span.AddAttributes(trace.StringAttribute("field", field.String(b.version)))
|
||||
|
||||
hasher := hash.CustomSHA256Hasher()
|
||||
switch field {
|
||||
case types.GenesisTime:
|
||||
return ssz.Uint64Root(b.genesisTime), nil
|
||||
@@ -735,7 +733,7 @@ func (b *BeaconState) rootSelector(ctx context.Context, field types.FieldIndex)
|
||||
}
|
||||
return ssz.ByteArrayRootWithLimit(hRoots, fieldparams.HistoricalRootsLength)
|
||||
case types.Eth1Data:
|
||||
return stateutil.Eth1Root(hasher, b.eth1Data)
|
||||
return stateutil.Eth1Root(b.eth1Data)
|
||||
case types.Eth1DataVotes:
|
||||
if b.rebuildTrie[field] {
|
||||
err := b.resetFieldTrie(
|
||||
|
||||
@@ -6,14 +6,13 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
params "github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
// Eth1DataRootWithHasher returns the hash tree root of input `eth1Data`.
|
||||
func Eth1DataRootWithHasher(hasher ssz.HashFn, eth1Data *ethpb.Eth1Data) ([32]byte, error) {
|
||||
func Eth1DataRootWithHasher(eth1Data *ethpb.Eth1Data) ([32]byte, error) {
|
||||
if eth1Data == nil {
|
||||
return [32]byte{}, errors.New("nil eth1 data")
|
||||
}
|
||||
@@ -42,21 +41,16 @@ func Eth1DataRootWithHasher(hasher ssz.HashFn, eth1Data *ethpb.Eth1Data) ([32]by
|
||||
|
||||
// Eth1DatasRoot returns the hash tree root of input `eth1Datas`.
|
||||
func Eth1DatasRoot(eth1Datas []*ethpb.Eth1Data) ([32]byte, error) {
|
||||
hasher := hash.CustomSHA256Hasher()
|
||||
eth1VotesRoots := make([][32]byte, 0, len(eth1Datas))
|
||||
for i := 0; i < len(eth1Datas); i++ {
|
||||
eth1, err := Eth1DataRootWithHasher(hasher, eth1Datas[i])
|
||||
eth1, err := Eth1DataRootWithHasher(eth1Datas[i])
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute eth1data merkleization")
|
||||
}
|
||||
eth1VotesRoots = append(eth1VotesRoots, eth1)
|
||||
}
|
||||
|
||||
eth1VotesRootsRoot, err := ssz.BitwiseMerkleize(
|
||||
eth1VotesRoots,
|
||||
uint64(len(eth1VotesRoots)),
|
||||
params.BeaconConfig().Eth1DataVotesLength(),
|
||||
)
|
||||
eth1VotesRootsRoot, err := ssz.BitwiseMerkleize(eth1VotesRoots, uint64(len(eth1VotesRoots)), params.BeaconConfig().Eth1DataVotesLength())
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute eth1data votes merkleization")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
params "github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
)
|
||||
@@ -24,21 +23,16 @@ func EpochAttestationsRoot(atts []*ethpb.PendingAttestation) ([32]byte, error) {
|
||||
return [32]byte{}, fmt.Errorf("epoch attestation exceeds max length %d", max)
|
||||
}
|
||||
|
||||
hasher := hash.CustomSHA256Hasher()
|
||||
roots := make([][32]byte, len(atts))
|
||||
for i := 0; i < len(atts); i++ {
|
||||
pendingRoot, err := pendingAttestationRoot(hasher, atts[i])
|
||||
pendingRoot, err := pendingAttestationRoot(atts[i])
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not attestation merkleization")
|
||||
}
|
||||
roots[i] = pendingRoot
|
||||
}
|
||||
|
||||
attsRootsRoot, err := ssz.BitwiseMerkleize(
|
||||
roots,
|
||||
uint64(len(roots)),
|
||||
params.BeaconConfig().CurrentEpochAttestationsLength(),
|
||||
)
|
||||
attsRootsRoot, err := ssz.BitwiseMerkleize(roots, uint64(len(roots)), params.BeaconConfig().CurrentEpochAttestationsLength())
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute epoch attestations merkleization")
|
||||
}
|
||||
@@ -53,7 +47,7 @@ func EpochAttestationsRoot(atts []*ethpb.PendingAttestation) ([32]byte, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func pendingAttestationRoot(hasher ssz.HashFn, att *ethpb.PendingAttestation) ([32]byte, error) {
|
||||
func pendingAttestationRoot(att *ethpb.PendingAttestation) ([32]byte, error) {
|
||||
if att == nil {
|
||||
return [32]byte{}, errors.New("nil pending attestation")
|
||||
}
|
||||
|
||||
@@ -2,18 +2,17 @@ package stateutil
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
// Eth1Root computes the HashTreeRoot Merkleization of
|
||||
// a BeaconBlockHeader struct according to the eth2
|
||||
// Simple Serialize specification.
|
||||
func Eth1Root(hasher ssz.HashFn, eth1Data *ethpb.Eth1Data) ([32]byte, error) {
|
||||
func Eth1Root(eth1Data *ethpb.Eth1Data) ([32]byte, error) {
|
||||
if eth1Data == nil {
|
||||
return [32]byte{}, errors.New("nil eth1 data")
|
||||
}
|
||||
return Eth1DataRootWithHasher(hasher, eth1Data)
|
||||
return Eth1DataRootWithHasher(eth1Data)
|
||||
}
|
||||
|
||||
// Eth1DataVotesRoot computes the HashTreeRoot Merkleization of
|
||||
|
||||
@@ -26,11 +26,7 @@ func HistoricalSummariesRoot(summaries []*ethpb.HistoricalSummary) ([32]byte, er
|
||||
roots[i] = r
|
||||
}
|
||||
|
||||
summariesRoot, err := ssz.BitwiseMerkleize(
|
||||
roots,
|
||||
uint64(len(roots)),
|
||||
fieldparams.HistoricalRootsLength,
|
||||
)
|
||||
summariesRoot, err := ssz.BitwiseMerkleize(roots, uint64(len(roots)), fieldparams.HistoricalRootsLength)
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute historical summaries merkleization")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user