prysm-pulse/proto/migration/v2_to_v1alpha1.go
james-prysm 83af9a5694
Beacon API: update Deneb endpoints after removing blob signing (#13235)
* making needed changes to beacon API based on removal of blobsidecar from block contents

* fixing tests and reverting some changes to be addressed later

* fixing generated code from protos

* gaz

* fixing get blob handler and adding blob storage to the blob service

* updating unit tests

* WIP

* wip tests

* got tests passing but needs cleanup

* removing gomod and gosum changes

* fixing more tests

* fixing more tests

* fixing more tests

* gaz

* moving some proto types around

* removing unneeded unit test

* fixing proposer paths

* adding more tests

* fixing more tests

* improving more unit tests

* updating one blob only unit test

* changing arguments of buildBlobSidecar

* reverting a change based on feedback

* terence's review items

* fixing test based on new develop changes

* radek's comments

* addressed more comments from radek

* adding in blobs to test data

* fixing casing in test

* removing extra line

* fixing issue from bad merge

* Update beacon-chain/rpc/eth/beacon/handlers_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/rpc/eth/beacon/handlers_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/rpc/eth/beacon/handlers_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/rpc/eth/blob/handlers.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* moving core getblob business logic to blocker based on radek's comment

* fixing mock blocker

* gaz

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-12-07 17:37:11 +00:00

114 lines
4.8 KiB
Go

package migration
import (
"github.com/pkg/errors"
ethpbv2 "github.com/prysmaticlabs/prysm/v4/proto/eth/v2"
ethpbalpha "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"google.golang.org/protobuf/proto"
)
// AltairToV1Alpha1SignedBlock converts a v2 SignedBeaconBlockAltair proto to a v1alpha1 proto.
func AltairToV1Alpha1SignedBlock(altairBlk *ethpbv2.SignedBeaconBlockAltair) (*ethpbalpha.SignedBeaconBlockAltair, error) {
marshaledBlk, err := proto.Marshal(altairBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBeaconBlockAltair{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}
// BellatrixToV1Alpha1SignedBlock converts a v2 SignedBeaconBlockBellatrix proto to a v1alpha1 proto.
func BellatrixToV1Alpha1SignedBlock(bellatrixBlk *ethpbv2.SignedBeaconBlockBellatrix) (*ethpbalpha.SignedBeaconBlockBellatrix, error) {
marshaledBlk, err := proto.Marshal(bellatrixBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBeaconBlockBellatrix{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}
// CapellaToV1Alpha1SignedBlock converts a v2 SignedBeaconBlockCapella proto to a v1alpha1 proto.
func CapellaToV1Alpha1SignedBlock(capellaBlk *ethpbv2.SignedBeaconBlockCapella) (*ethpbalpha.SignedBeaconBlockCapella, error) {
marshaledBlk, err := proto.Marshal(capellaBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBeaconBlockCapella{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}
// DenebToV1Alpha1SignedBlock converts a v2 SignedBeaconBlockDeneb proto to a v1alpha1 proto.
func DenebToV1Alpha1SignedBlock(denebBlk *ethpbv2.SignedBeaconBlockDeneb) (*ethpbalpha.SignedBeaconBlockDeneb, error) {
marshaledBlk, err := proto.Marshal(denebBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBeaconBlockDeneb{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}
// V2BeaconBlockDenebToV1Alpha1 converts a v2 Deneb beacon block to a v1alpha1
// Deneb block.
func V2BeaconBlockDenebToV1Alpha1(v2block *ethpbv2.BeaconBlockDeneb) (*ethpbalpha.BeaconBlockDeneb, error) {
marshaledBlk, err := proto.Marshal(v2block)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1block := &ethpbalpha.BeaconBlockDeneb{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1block, nil
}
// BlindedBellatrixToV1Alpha1SignedBlock converts a v2 SignedBlindedBeaconBlockBellatrix proto to a v1alpha1 proto.
func BlindedBellatrixToV1Alpha1SignedBlock(bellatrixBlk *ethpbv2.SignedBlindedBeaconBlockBellatrix) (*ethpbalpha.SignedBlindedBeaconBlockBellatrix, error) {
marshaledBlk, err := proto.Marshal(bellatrixBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBlindedBeaconBlockBellatrix{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}
// BlindedCapellaToV1Alpha1SignedBlock converts a v2 SignedBlindedBeaconBlockCapella proto to a v1alpha1 proto.
func BlindedCapellaToV1Alpha1SignedBlock(capellaBlk *ethpbv2.SignedBlindedBeaconBlockCapella) (*ethpbalpha.SignedBlindedBeaconBlockCapella, error) {
marshaledBlk, err := proto.Marshal(capellaBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBlindedBeaconBlockCapella{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}
// BlindedDenebToV1Alpha1SignedBlock converts a v2 SignedBlindedBeaconBlockDeneb proto to a v1alpha1 proto.
func BlindedDenebToV1Alpha1SignedBlock(denebBlk *ethpbv2.SignedBlindedBeaconBlockDeneb) (*ethpbalpha.SignedBlindedBeaconBlockDeneb, error) {
marshaledBlk, err := proto.Marshal(denebBlk)
if err != nil {
return nil, errors.Wrap(err, "could not marshal block")
}
v1alpha1Block := &ethpbalpha.SignedBlindedBeaconBlockDeneb{}
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
return nil, errors.Wrap(err, "could not unmarshal block")
}
return v1alpha1Block, nil
}