mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
Compare commits
1 Commits
feat/peer-
...
update-bpo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf664aa32a |
@@ -126,6 +126,9 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
|
||||
httputil.HandleError(w, "Could not compute fork digest: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if updateEpoch >= params.BeaconConfig().FuluForkEpoch {
|
||||
forkDigest = forks.ApplyBlobParamMask(updateEpoch, forkDigest)
|
||||
}
|
||||
updateSSZ, err := update.MarshalSSZ()
|
||||
if err != nil {
|
||||
httputil.HandleError(w, "Could not marshal update to SSZ: "+err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"github.com/OffchainLabs/prysm/v6/beacon-chain/core/signing"
|
||||
"github.com/OffchainLabs/prysm/v6/beacon-chain/p2p"
|
||||
"github.com/OffchainLabs/prysm/v6/config/params"
|
||||
"github.com/OffchainLabs/prysm/v6/network/forks"
|
||||
"github.com/OffchainLabs/prysm/v6/runtime/version"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
"github.com/libp2p/go-libp2p/core/protocol"
|
||||
"github.com/pkg/errors"
|
||||
@@ -92,7 +94,14 @@ func ContextByteVersionsForValRoot(valRoot [32]byte) (ContextByteVersions, error
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to compute fork digest for fork version %#x", fv)
|
||||
}
|
||||
m[digest] = v
|
||||
if v > version.Fulu {
|
||||
for _, b := range params.BeaconConfig().BlobSchedule {
|
||||
digest = forks.ApplyBlobParamMask(b.Epoch, digest)
|
||||
m[digest] = v
|
||||
}
|
||||
} else {
|
||||
m[digest] = v
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"github.com/OffchainLabs/prysm/v6/beacon-chain/startup"
|
||||
"github.com/OffchainLabs/prysm/v6/config/params"
|
||||
"github.com/OffchainLabs/prysm/v6/encoding/bytesutil"
|
||||
"github.com/OffchainLabs/prysm/v6/network/forks"
|
||||
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
"github.com/pkg/errors"
|
||||
@@ -99,29 +101,50 @@ func extractValidDataTypeFromTopic(topic string, digest []byte, clock *startup.C
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func extractDataTypeFromTypeMap[T any](typeMap map[[4]byte]func() (T, error), digest []byte, tor blockchain.TemporalOracle) (T, error) {
|
||||
func extractDataTypeFromTypeMap[T any](
|
||||
typeMap map[[4]byte]func() (T, error),
|
||||
digest []byte,
|
||||
tor blockchain.TemporalOracle,
|
||||
) (T, error) {
|
||||
var zero T
|
||||
|
||||
if len(digest) == 0 {
|
||||
f, ok := typeMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)]
|
||||
if !ok {
|
||||
return zero, fmt.Errorf("no %T type exists for the genesis fork version", zero)
|
||||
genesisDigest := bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)
|
||||
if f, ok := typeMap[genesisDigest]; ok {
|
||||
return f()
|
||||
}
|
||||
return f()
|
||||
return zero, fmt.Errorf("no %T type exists for the genesis fork version", zero)
|
||||
}
|
||||
|
||||
if len(digest) != forkDigestLength {
|
||||
return zero, errors.Errorf("invalid digest returned, wanted a length of %d but received %d", forkDigestLength, len(digest))
|
||||
return zero, errors.Errorf("invalid digest length: got %d, want %d", len(digest), forkDigestLength)
|
||||
}
|
||||
|
||||
targetDigest := bytesutil.ToBytes4(digest)
|
||||
vRoot := tor.GenesisValidatorsRoot()
|
||||
for k, f := range typeMap {
|
||||
rDigest, err := signing.ComputeForkDigest(k[:], vRoot[:])
|
||||
|
||||
fuluForkVersion := binary.BigEndian.Uint32(params.BeaconConfig().FuluForkVersion)
|
||||
|
||||
for version, factory := range typeMap {
|
||||
computedDigest, err := signing.ComputeForkDigest(version[:], vRoot[:])
|
||||
if err != nil {
|
||||
return zero, err
|
||||
}
|
||||
if rDigest == bytesutil.ToBytes4(digest) {
|
||||
return f()
|
||||
|
||||
versionNum := binary.BigEndian.Uint32(version[:])
|
||||
|
||||
if versionNum >= fuluForkVersion {
|
||||
for _, entry := range params.BeaconConfig().BlobSchedule {
|
||||
masked := forks.ApplyBlobParamMask(entry.Epoch, computedDigest)
|
||||
if masked == targetDigest {
|
||||
return factory()
|
||||
}
|
||||
}
|
||||
} else if computedDigest == targetDigest {
|
||||
return factory()
|
||||
}
|
||||
}
|
||||
|
||||
return zero, errors.Wrapf(
|
||||
ErrNoValidDigest,
|
||||
"could not extract %T data type, saw digest=%#x, genesis=%v, vr=%#x",
|
||||
|
||||
3
changelog/tt_potato.md
Normal file
3
changelog/tt_potato.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Changed
|
||||
|
||||
- Fork digest to consider blob parameter for fulu
|
||||
@@ -3,6 +3,7 @@ package forks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
@@ -49,7 +50,11 @@ func ForkDigestFromEpoch(currentEpoch primitives.Epoch, genesisValidatorsRoot []
|
||||
if err != nil {
|
||||
return [4]byte{}, err
|
||||
}
|
||||
return signing.ComputeForkDigest(forkData.CurrentVersion, genesisValidatorsRoot)
|
||||
d, err := signing.ComputeForkDigest(forkData.CurrentVersion, genesisValidatorsRoot)
|
||||
if err != nil {
|
||||
return [4]byte{}, errors.Wrap(err, "failed to compute fork digest")
|
||||
}
|
||||
return ApplyBlobParamMask(currentEpoch, d), nil
|
||||
}
|
||||
|
||||
// CreateForkDigest creates a fork digest from a genesis time and genesis
|
||||
@@ -77,7 +82,7 @@ func CreateForkDigest(
|
||||
if err != nil {
|
||||
return [4]byte{}, err
|
||||
}
|
||||
return digest, nil
|
||||
return ApplyBlobParamMask(currentEpoch, digest), nil
|
||||
}
|
||||
|
||||
// Fork given a target epoch,
|
||||
@@ -117,6 +122,9 @@ func RetrieveForkDataFromDigest(digest [4]byte, genesisValidatorsRoot []byte) ([
|
||||
if err != nil {
|
||||
return [4]byte{}, 0, err
|
||||
}
|
||||
if e >= params.BeaconConfig().FuluForkEpoch {
|
||||
rDigest = ApplyBlobParamMask(e, rDigest)
|
||||
}
|
||||
if rDigest == digest {
|
||||
return v, e, nil
|
||||
}
|
||||
@@ -200,3 +208,23 @@ func LastForkEpoch() primitives.Epoch {
|
||||
}
|
||||
return lastValidEpoch
|
||||
}
|
||||
|
||||
// ApplyBlobParamMask applies the blob parameter mask to the provided digest.
|
||||
func ApplyBlobParamMask(e primitives.Epoch, d [4]byte) [4]byte {
|
||||
if e < params.BeaconConfig().FuluForkEpoch {
|
||||
return d
|
||||
}
|
||||
maxBlobs := params.BeaconConfig().MaxBlobsPerBlockAtEpoch(e)
|
||||
if maxBlobs == 0 {
|
||||
return d
|
||||
}
|
||||
|
||||
var mask [4]byte
|
||||
binary.BigEndian.PutUint32(mask[:], uint32(maxBlobs))
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
d[i] = d[i] ^ mask[i]
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user