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__"],
|
||||
deps = [
|
||||
"//async/event:go_default_library",
|
||||
"//consensus-types/blocks:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -2,6 +2,7 @@
|
||||
package operation
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
@ -58,5 +59,5 @@ type BLSToExecutionChangeReceivedData struct {
|
||||
|
||||
// BlobSidecarReceivedData is the data sent with BlobSidecarReceived events.
|
||||
type BlobSidecarReceivedData struct {
|
||||
Blob *ethpb.SignedBlobSidecar
|
||||
Blob *blocks.VerifiedROBlob
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"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/operation"
|
||||
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 {
|
||||
return
|
||||
}
|
||||
// TODO: fix this when we fix p2p
|
||||
//blobData, ok := event.Data.(*operation.BlobSidecarReceivedData)
|
||||
//if !ok {
|
||||
// write(w, flusher, topicDataMismatch, event.Data, BlobSidecarTopic)
|
||||
// return
|
||||
//}
|
||||
//versionedHash := blockchain.ConvertKzgCommitmentToVersionedHash(blobData.Blob.Message.KzgCommitment)
|
||||
blobData, ok := event.Data.(*operation.BlobSidecarReceivedData)
|
||||
if !ok {
|
||||
write(w, flusher, topicDataMismatch, event.Data, BlobSidecarTopic)
|
||||
return
|
||||
}
|
||||
versionedHash := blockchain.ConvertKzgCommitmentToVersionedHash(blobData.Blob.KzgCommitment)
|
||||
blobEvent := &BlobSidecarEvent{
|
||||
//BlockRoot: hexutil.Encode(blobData.Blob.Message.BlockRoot),
|
||||
//Index: fmt.Sprintf("%d", blobData.Blob.Message.Index),
|
||||
//Slot: fmt.Sprintf("%d", blobData.Blob.Message.Slot),
|
||||
//VersionedHash: versionedHash.String(),
|
||||
//KzgCommitment: hexutil.Encode(blobData.Blob.Message.KzgCommitment),
|
||||
BlockRoot: hexutil.Encode(blobData.Blob.BlockRootSlice()),
|
||||
Index: fmt.Sprintf("%d", blobData.Blob.Index),
|
||||
Slot: fmt.Sprintf("%d", blobData.Blob.Slot()),
|
||||
VersionedHash: versionedHash.String(),
|
||||
KzgCommitment: hexutil.Encode(blobData.Blob.KzgCommitment),
|
||||
}
|
||||
send(w, flusher, BlobSidecarTopic, blobEvent)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func TestStreamEvents_OperationsEvents(t *testing.T) {
|
||||
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 {
|
||||
topics[i] = "topics=" + topic
|
||||
}
|
||||
@ -115,14 +115,15 @@ func TestStreamEvents_OperationsEvents(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
// TODO: update when P2P is updated for blobs
|
||||
//s.OperationNotifier.OperationFeed().Send(&feed.Event{
|
||||
// Type: operation.BlobSidecarReceived,
|
||||
// Data: &operation.BlobSidecarReceivedData{
|
||||
// Blob: util.HydrateSignedBlobSidecar(ð.SignedBlobSidecar{}),
|
||||
// },
|
||||
//})
|
||||
// wait for feed
|
||||
ro, err := blocks.NewROBlob(util.HydrateBlobSidecar(ð.BlobSidecar{}))
|
||||
require.NoError(t, err)
|
||||
vblob := blocks.NewVerifiedROBlob(ro)
|
||||
s.OperationNotifier.OperationFeed().Send(&feed.Event{
|
||||
Type: operation.BlobSidecarReceived,
|
||||
Data: &operation.BlobSidecarReceivedData{
|
||||
Blob: &vblob,
|
||||
},
|
||||
})
|
||||
time.Sleep(1 * time.Second)
|
||||
request.Context().Done()
|
||||
|
||||
@ -321,10 +322,10 @@ data: {"message":{"aggregator_index":"0","contribution":{"slot":"0","beacon_bloc
|
||||
event: bls_to_execution_change
|
||||
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
|
||||
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 {
|
||||
r := make([][]byte, fieldparams.KzgCommitmentInclusionProofDepth)
|
||||
for i := range r {
|
||||
r[i] = make([]byte, fieldparams.RootLength)
|
||||
}
|
||||
return r
|
||||
return util.HydrateCommitmentInclusionProofs()
|
||||
}
|
||||
|
||||
type expectedBlobChunk struct {
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"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"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -20,14 +22,12 @@ func (s *Service) blobSubscriber(ctx context.Context, msg proto.Message) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: convert operations feed to use ROBlob.
|
||||
/*
|
||||
s.cfg.operationNotifier.OperationFeed().Send(&feed.Event{
|
||||
Type: opfeed.BlobSidecarReceived,
|
||||
Data: &opfeed.BlobSidecarReceivedData{
|
||||
Blob: b,
|
||||
Blob: &b,
|
||||
},
|
||||
})
|
||||
*/
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -5,27 +5,13 @@ import (
|
||||
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
|
||||
// to comply with SSZ marshalling and unmarshalling rules.
|
||||
func HydrateBlobSidecar(b *ethpb.DeprecatedBlobSidecar) *ethpb.DeprecatedBlobSidecar {
|
||||
if b.BlockRoot == nil {
|
||||
b.BlockRoot = make([]byte, fieldparams.RootLength)
|
||||
}
|
||||
if b.BlockParentRoot == nil {
|
||||
b.BlockParentRoot = make([]byte, fieldparams.RootLength)
|
||||
func HydrateBlobSidecar(b *ethpb.BlobSidecar) *ethpb.BlobSidecar {
|
||||
if b.SignedBlockHeader == nil {
|
||||
b.SignedBlockHeader = HydrateSignedBeaconHeader(ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{},
|
||||
})
|
||||
}
|
||||
if b.Blob == nil {
|
||||
b.Blob = make([]byte, fieldparams.BlobLength)
|
||||
@ -36,39 +22,18 @@ func HydrateBlobSidecar(b *ethpb.DeprecatedBlobSidecar) *ethpb.DeprecatedBlobSid
|
||||
if b.KzgProof == nil {
|
||||
b.KzgProof = make([]byte, fieldparams.BLSPubkeyLength)
|
||||
}
|
||||
|
||||
if b.CommitmentInclusionProof == nil {
|
||||
b.CommitmentInclusionProof = HydrateCommitmentInclusionProofs()
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// HydrateSignedBlindedBlobSidecar hydrates a signed blinded blob sidecar with correct field length sizes
|
||||
// to comply with SSZ marshalling and unmarshalling rules.
|
||||
func HydrateSignedBlindedBlobSidecar(b *ethpb.SignedBlindedBlobSidecar) *ethpb.SignedBlindedBlobSidecar {
|
||||
if b.Signature == nil {
|
||||
b.Signature = make([]byte, fieldparams.BLSSignatureLength)
|
||||
// HydrateCommitmentInclusionProofs returns 2d byte slice of Commitment Inclusion Proofs
|
||||
func HydrateCommitmentInclusionProofs() [][]byte {
|
||||
r := make([][]byte, fieldparams.KzgCommitmentInclusionProofDepth)
|
||||
for i := range r {
|
||||
r[i] = make([]byte, fieldparams.RootLength)
|
||||
}
|
||||
if b.Message == nil {
|
||||
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
|
||||
return r
|
||||
}
|
||||
|
@ -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.
|
||||
// Use BlockGenConfig to declare the conditions you would like the block generated under.
|
||||
func GenerateFullBlock(
|
||||
|
Loading…
Reference in New Issue
Block a user