mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 00:27:38 +00:00
Beacon APIs: re enabling blob events (#13315)
* re enabling blob events * terence's comments * Update beacon-chain/rpc/eth/events/events_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
parent
bfaba378f6
commit
5e56b5fdd7
@ -10,6 +10,7 @@ go_library(
|
|||||||
visibility = ["//beacon-chain:__subpackages__"],
|
visibility = ["//beacon-chain:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"//async/event:go_default_library",
|
"//async/event:go_default_library",
|
||||||
|
"//consensus-types/blocks:go_default_library",
|
||||||
"//proto/prysm/v1alpha1:go_default_library",
|
"//proto/prysm/v1alpha1:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package operation
|
package operation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,5 +59,5 @@ type BLSToExecutionChangeReceivedData struct {
|
|||||||
|
|
||||||
// BlobSidecarReceivedData is the data sent with BlobSidecarReceived events.
|
// BlobSidecarReceivedData is the data sent with BlobSidecarReceived events.
|
||||||
type BlobSidecarReceivedData struct {
|
type BlobSidecarReceivedData struct {
|
||||||
Blob *ethpb.SignedBlobSidecar
|
Blob *blocks.VerifiedROBlob
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain"
|
||||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed"
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed"
|
||||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed/operation"
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed/operation"
|
||||||
statefeed "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed/state"
|
statefeed "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed/state"
|
||||||
@ -173,19 +174,18 @@ func handleBlockOperationEvents(w http.ResponseWriter, flusher http.Flusher, req
|
|||||||
if _, ok := requestedTopics[BlobSidecarTopic]; !ok {
|
if _, ok := requestedTopics[BlobSidecarTopic]; !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO: fix this when we fix p2p
|
blobData, ok := event.Data.(*operation.BlobSidecarReceivedData)
|
||||||
//blobData, ok := event.Data.(*operation.BlobSidecarReceivedData)
|
if !ok {
|
||||||
//if !ok {
|
write(w, flusher, topicDataMismatch, event.Data, BlobSidecarTopic)
|
||||||
// write(w, flusher, topicDataMismatch, event.Data, BlobSidecarTopic)
|
return
|
||||||
// return
|
}
|
||||||
//}
|
versionedHash := blockchain.ConvertKzgCommitmentToVersionedHash(blobData.Blob.KzgCommitment)
|
||||||
//versionedHash := blockchain.ConvertKzgCommitmentToVersionedHash(blobData.Blob.Message.KzgCommitment)
|
|
||||||
blobEvent := &BlobSidecarEvent{
|
blobEvent := &BlobSidecarEvent{
|
||||||
//BlockRoot: hexutil.Encode(blobData.Blob.Message.BlockRoot),
|
BlockRoot: hexutil.Encode(blobData.Blob.BlockRootSlice()),
|
||||||
//Index: fmt.Sprintf("%d", blobData.Blob.Message.Index),
|
Index: fmt.Sprintf("%d", blobData.Blob.Index),
|
||||||
//Slot: fmt.Sprintf("%d", blobData.Blob.Message.Slot),
|
Slot: fmt.Sprintf("%d", blobData.Blob.Slot()),
|
||||||
//VersionedHash: versionedHash.String(),
|
VersionedHash: versionedHash.String(),
|
||||||
//KzgCommitment: hexutil.Encode(blobData.Blob.Message.KzgCommitment),
|
KzgCommitment: hexutil.Encode(blobData.Blob.KzgCommitment),
|
||||||
}
|
}
|
||||||
send(w, flusher, BlobSidecarTopic, blobEvent)
|
send(w, flusher, BlobSidecarTopic, blobEvent)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func TestStreamEvents_OperationsEvents(t *testing.T) {
|
|||||||
OperationNotifier: &mockChain.MockOperationNotifier{},
|
OperationNotifier: &mockChain.MockOperationNotifier{},
|
||||||
}
|
}
|
||||||
|
|
||||||
topics := []string{AttestationTopic, VoluntaryExitTopic, SyncCommitteeContributionTopic, BLSToExecutionChangeTopic} // TODO: add blob sidecar back in later
|
topics := []string{AttestationTopic, VoluntaryExitTopic, SyncCommitteeContributionTopic, BLSToExecutionChangeTopic, BlobSidecarTopic}
|
||||||
for i, topic := range topics {
|
for i, topic := range topics {
|
||||||
topics[i] = "topics=" + topic
|
topics[i] = "topics=" + topic
|
||||||
}
|
}
|
||||||
@ -115,14 +115,15 @@ func TestStreamEvents_OperationsEvents(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// TODO: update when P2P is updated for blobs
|
ro, err := blocks.NewROBlob(util.HydrateBlobSidecar(ð.BlobSidecar{}))
|
||||||
//s.OperationNotifier.OperationFeed().Send(&feed.Event{
|
require.NoError(t, err)
|
||||||
// Type: operation.BlobSidecarReceived,
|
vblob := blocks.NewVerifiedROBlob(ro)
|
||||||
// Data: &operation.BlobSidecarReceivedData{
|
s.OperationNotifier.OperationFeed().Send(&feed.Event{
|
||||||
// Blob: util.HydrateSignedBlobSidecar(ð.SignedBlobSidecar{}),
|
Type: operation.BlobSidecarReceived,
|
||||||
// },
|
Data: &operation.BlobSidecarReceivedData{
|
||||||
//})
|
Blob: &vblob,
|
||||||
// wait for feed
|
},
|
||||||
|
})
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
request.Context().Done()
|
request.Context().Done()
|
||||||
|
|
||||||
@ -321,10 +322,10 @@ data: {"message":{"aggregator_index":"0","contribution":{"slot":"0","beacon_bloc
|
|||||||
event: bls_to_execution_change
|
event: bls_to_execution_change
|
||||||
data: {"message":{"validator_index":"0","from_bls_pubkey":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to_execution_address":"0x0000000000000000000000000000000000000000"},"signature":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}
|
data: {"message":{"validator_index":"0","from_bls_pubkey":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to_execution_address":"0x0000000000000000000000000000000000000000"},"signature":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}
|
||||||
|
|
||||||
`
|
event: blob_sidecar
|
||||||
|
data: {"block_root":"0xc78009fdf07fc56a11f122370658a353aaa542ed63e44c4bc15ff4cd105ab33c","index":"0","slot":"0","kzg_commitment":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","versioned_hash":"0x01b0761f87b081d5cf10757ccc89f12be355c70e2e29df288b65b30710dcbcd1"}
|
||||||
|
|
||||||
//event: blob_sidecar
|
`
|
||||||
//data: {"block_root":"0x0000000000000000000000000000000000000000000000000000000000000000","index":"0","slot":"0","kzg_commitment":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","versioned_hash":"0x01b0761f87b081d5cf10757ccc89f12be355c70e2e29df288b65b30710dcbcd1"}
|
|
||||||
|
|
||||||
const stateResult = `event: head
|
const stateResult = `event: head
|
||||||
data: {"slot":"0","block":"0x0000000000000000000000000000000000000000000000000000000000000000","state":"0x0000000000000000000000000000000000000000000000000000000000000000","epoch_transition":true,"execution_optimistic":false,"previous_duty_dependent_root":"0x0000000000000000000000000000000000000000000000000000000000000000","current_duty_dependent_root":"0x0000000000000000000000000000000000000000000000000000000000000000"}
|
data: {"slot":"0","block":"0x0000000000000000000000000000000000000000000000000000000000000000","state":"0x0000000000000000000000000000000000000000000000000000000000000000","epoch_transition":true,"execution_optimistic":false,"previous_duty_dependent_root":"0x0000000000000000000000000000000000000000000000000000000000000000","current_duty_dependent_root":"0x0000000000000000000000000000000000000000000000000000000000000000"}
|
||||||
|
@ -136,11 +136,7 @@ func generateTestSidecar(t *testing.T, root [32]byte, block interfaces.ReadOnlyS
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fakeEmptyProof(_ *testing.T, _ interfaces.ReadOnlySignedBeaconBlock, _ *ethpb.BlobSidecar) [][]byte {
|
func fakeEmptyProof(_ *testing.T, _ interfaces.ReadOnlySignedBeaconBlock, _ *ethpb.BlobSidecar) [][]byte {
|
||||||
r := make([][]byte, fieldparams.KzgCommitmentInclusionProofDepth)
|
return util.HydrateCommitmentInclusionProofs()
|
||||||
for i := range r {
|
|
||||||
r[i] = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type expectedBlobChunk struct {
|
type expectedBlobChunk struct {
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed"
|
||||||
|
opfeed "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/feed/operation"
|
||||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -20,14 +22,12 @@ func (s *Service) blobSubscriber(ctx context.Context, msg proto.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: convert operations feed to use ROBlob.
|
s.cfg.operationNotifier.OperationFeed().Send(&feed.Event{
|
||||||
/*
|
Type: opfeed.BlobSidecarReceived,
|
||||||
s.cfg.operationNotifier.OperationFeed().Send(&feed.Event{
|
Data: &opfeed.BlobSidecarReceivedData{
|
||||||
Type: opfeed.BlobSidecarReceived,
|
Blob: &b,
|
||||||
Data: &opfeed.BlobSidecarReceivedData{
|
},
|
||||||
Blob: b,
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -5,27 +5,13 @@ import (
|
|||||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HydrateSignedBlobSidecar hydrates a signed blob sidecar with correct field length sizes
|
|
||||||
// to comply with SSZ marshalling and unmarshalling rules.
|
|
||||||
func HydrateSignedBlobSidecar(b *ethpb.SignedBlobSidecar) *ethpb.SignedBlobSidecar {
|
|
||||||
if b.Signature == nil {
|
|
||||||
b.Signature = make([]byte, fieldparams.BLSSignatureLength)
|
|
||||||
}
|
|
||||||
if b.Message == nil {
|
|
||||||
b.Message = ðpb.DeprecatedBlobSidecar{}
|
|
||||||
}
|
|
||||||
b.Message = HydrateBlobSidecar(b.Message)
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// HydrateBlobSidecar hydrates a blob sidecar with correct field length sizes
|
// HydrateBlobSidecar hydrates a blob sidecar with correct field length sizes
|
||||||
// to comply with SSZ marshalling and unmarshalling rules.
|
// to comply with SSZ marshalling and unmarshalling rules.
|
||||||
func HydrateBlobSidecar(b *ethpb.DeprecatedBlobSidecar) *ethpb.DeprecatedBlobSidecar {
|
func HydrateBlobSidecar(b *ethpb.BlobSidecar) *ethpb.BlobSidecar {
|
||||||
if b.BlockRoot == nil {
|
if b.SignedBlockHeader == nil {
|
||||||
b.BlockRoot = make([]byte, fieldparams.RootLength)
|
b.SignedBlockHeader = HydrateSignedBeaconHeader(ðpb.SignedBeaconBlockHeader{
|
||||||
}
|
Header: ðpb.BeaconBlockHeader{},
|
||||||
if b.BlockParentRoot == nil {
|
})
|
||||||
b.BlockParentRoot = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
}
|
||||||
if b.Blob == nil {
|
if b.Blob == nil {
|
||||||
b.Blob = make([]byte, fieldparams.BlobLength)
|
b.Blob = make([]byte, fieldparams.BlobLength)
|
||||||
@ -36,39 +22,18 @@ func HydrateBlobSidecar(b *ethpb.DeprecatedBlobSidecar) *ethpb.DeprecatedBlobSid
|
|||||||
if b.KzgProof == nil {
|
if b.KzgProof == nil {
|
||||||
b.KzgProof = make([]byte, fieldparams.BLSPubkeyLength)
|
b.KzgProof = make([]byte, fieldparams.BLSPubkeyLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.CommitmentInclusionProof == nil {
|
||||||
|
b.CommitmentInclusionProof = HydrateCommitmentInclusionProofs()
|
||||||
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// HydrateSignedBlindedBlobSidecar hydrates a signed blinded blob sidecar with correct field length sizes
|
// HydrateCommitmentInclusionProofs returns 2d byte slice of Commitment Inclusion Proofs
|
||||||
// to comply with SSZ marshalling and unmarshalling rules.
|
func HydrateCommitmentInclusionProofs() [][]byte {
|
||||||
func HydrateSignedBlindedBlobSidecar(b *ethpb.SignedBlindedBlobSidecar) *ethpb.SignedBlindedBlobSidecar {
|
r := make([][]byte, fieldparams.KzgCommitmentInclusionProofDepth)
|
||||||
if b.Signature == nil {
|
for i := range r {
|
||||||
b.Signature = make([]byte, fieldparams.BLSSignatureLength)
|
r[i] = make([]byte, fieldparams.RootLength)
|
||||||
}
|
}
|
||||||
if b.Message == nil {
|
return r
|
||||||
b.Message = ðpb.BlindedBlobSidecar{}
|
|
||||||
}
|
|
||||||
b.Message = HydrateBlindedBlobSidecar(b.Message)
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// HydrateBlindedBlobSidecar hydrates a blinded blob sidecar with correct field length sizes
|
|
||||||
// to comply with SSZ marshalling and unmarshalling rules.
|
|
||||||
func HydrateBlindedBlobSidecar(b *ethpb.BlindedBlobSidecar) *ethpb.BlindedBlobSidecar {
|
|
||||||
if b.BlockRoot == nil {
|
|
||||||
b.BlockRoot = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
if b.BlockParentRoot == nil {
|
|
||||||
b.BlockParentRoot = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
if b.KzgCommitment == nil {
|
|
||||||
b.KzgCommitment = make([]byte, fieldparams.BLSPubkeyLength)
|
|
||||||
}
|
|
||||||
if b.KzgProof == nil {
|
|
||||||
b.KzgProof = make([]byte, fieldparams.BLSPubkeyLength)
|
|
||||||
}
|
|
||||||
if b.BlobRoot == nil {
|
|
||||||
b.BlobRoot = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
@ -77,19 +77,6 @@ func NewBeaconBlock() *ethpb.SignedBeaconBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlobsidecar() *ethpb.SignedBlobSidecar {
|
|
||||||
return ðpb.SignedBlobSidecar{
|
|
||||||
Message: ðpb.DeprecatedBlobSidecar{
|
|
||||||
BlockRoot: make([]byte, fieldparams.RootLength),
|
|
||||||
BlockParentRoot: make([]byte, fieldparams.RootLength),
|
|
||||||
Blob: make([]byte, fieldparams.BlobLength),
|
|
||||||
KzgCommitment: make([]byte, fieldparams.BLSPubkeyLength),
|
|
||||||
KzgProof: make([]byte, fieldparams.BLSPubkeyLength),
|
|
||||||
},
|
|
||||||
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateFullBlock generates a fully valid block with the requested parameters.
|
// GenerateFullBlock generates a fully valid block with the requested parameters.
|
||||||
// Use BlockGenConfig to declare the conditions you would like the block generated under.
|
// Use BlockGenConfig to declare the conditions you would like the block generated under.
|
||||||
func GenerateFullBlock(
|
func GenerateFullBlock(
|
||||||
|
Loading…
Reference in New Issue
Block a user