mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
2f10b1c7b1
* Remove gogoproto compiler * Remove more gogoproto * Improvements * Fix gengo * More scripts * Gazelle, fix deps * Fix version and errors * Fix gocast for arrays * Fix ethapis * Fixes * Fix compile errors * fix go.mod * //proto/... builds * Update for protov2 * temp fix compilation to move on * Change everything to emptypb.empty * Add grpc to proto/slashings * Fix almost all build failures * Oher build problems * FIX THIS FUCKING THING * gaz literally every .bazel * Final touches * Final final touches * Fix proto * Begin moving proto.Marshal to native * Fix site_data * Fixes * Fix duplicate gateway * Fix gateway target * Fix ethapis * Fixes from review * Update * Fix * Fix status test * Fix fuzz * Add isprotoslice to fun * Change DeepEqual to DeepSSZEqual for proto arrays * Fix build * Fix gaz * Update go * Fixes * Fixes * Add case for nil validators after copy * Fix cast * Fix test * Fix imports * Go mod * Only use extension where needed * Fixes * Split gateway from gengo * gaz * go mod * Add back hydrated state * fix hydrate * Fix proto.clone * Fies * Revert "Split gateway from gengo" This reverts commit 7298bb2054d446e427d9af97e13b8fabe8695085. * Revert "gaz" This reverts commit ca952565701a88727e22302d6c8d60ac48d97255. * Merge all gateway into one target * go mod * Gaz * Add generate v1_gateway files * run pb again * goimports * gaz * Fix comments * Fix protos * Fix PR * Fix protos * Update grpc-gateway and ethapis * Update ethapis and gen-go-cast * Go tidy * Reorder * Fix ethapis * fix spec tests * Fix script * Remove unused import * Fix fuzz * Fix gomod * Update version * Error if the cloned result is nil * Handle optional slots * ADd more empty checks to clone * Undo fuzz changes * Fix build.bazel * Gaz * Redo fuzz changes * Undo some eth1data changes * Update go.mod Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Undo clone beacon state * Remove gogo proto more and unused v1_gateway * Add manual fix for nil vals * Fix gaz * tidy * Tidy again * Add detailed error * Revert "Add detailed error" This reverts commit 59bc053dcd59569a54c95b07739d5a379665ec5d. * Undo varint changes * Fix nil validators in deposit test * Commit * Undo Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
235 lines
8.2 KiB
Go
235 lines
8.2 KiB
Go
package migration
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1"
|
|
ethpb_alpha "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// V1Alpha1BlockToV1BlockHeader converts a v1alpha1 SignedBeaconBlock proto to a v1 SignedBeaconBlockHeader proto.
|
|
func V1Alpha1BlockToV1BlockHeader(block *ethpb_alpha.SignedBeaconBlock) (*ethpb.SignedBeaconBlockHeader, error) {
|
|
bodyRoot, err := block.Block.Body.HashTreeRoot()
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to get body root of block")
|
|
}
|
|
return ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: block.Block.Slot,
|
|
ProposerIndex: block.Block.ProposerIndex,
|
|
ParentRoot: block.Block.ParentRoot,
|
|
StateRoot: block.Block.StateRoot,
|
|
BodyRoot: bodyRoot[:],
|
|
},
|
|
Signature: block.Signature,
|
|
}, nil
|
|
}
|
|
|
|
// V1Alpha1ToV1Block converts a v1alpha1 SignedBeaconBlock proto to a v1 proto.
|
|
func V1Alpha1ToV1Block(alphaBlk *ethpb_alpha.SignedBeaconBlock) (*ethpb.SignedBeaconBlock, error) {
|
|
marshaledBlk, err := proto.Marshal(alphaBlk)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not marshal block")
|
|
}
|
|
v1Block := ðpb.SignedBeaconBlock{}
|
|
if err := proto.Unmarshal(marshaledBlk, v1Block); err != nil {
|
|
return nil, errors.Wrap(err, "could not unmarshal block")
|
|
}
|
|
return v1Block, nil
|
|
}
|
|
|
|
// V1ToV1Alpha1Block converts a v1 SignedBeaconBlock proto to a v1alpha1 proto.
|
|
func V1ToV1Alpha1Block(alphaBlk *ethpb.SignedBeaconBlock) (*ethpb_alpha.SignedBeaconBlock, error) {
|
|
marshaledBlk, err := proto.Marshal(alphaBlk)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not marshal block")
|
|
}
|
|
v1alpha1Block := ðpb_alpha.SignedBeaconBlock{}
|
|
if err := proto.Unmarshal(marshaledBlk, v1alpha1Block); err != nil {
|
|
return nil, errors.Wrap(err, "could not unmarshal block")
|
|
}
|
|
return v1alpha1Block, nil
|
|
}
|
|
|
|
// V1Alpha1IndexedAttToV1 converts a v1alpha1 indexed attestation to v1.
|
|
func V1Alpha1IndexedAttToV1(v1alpha1Att *ethpb_alpha.IndexedAttestation) *ethpb.IndexedAttestation {
|
|
if v1alpha1Att == nil {
|
|
return ðpb.IndexedAttestation{}
|
|
}
|
|
return ðpb.IndexedAttestation{
|
|
AttestingIndices: v1alpha1Att.AttestingIndices,
|
|
Data: V1Alpha1AttDataToV1(v1alpha1Att.Data),
|
|
Signature: v1alpha1Att.Signature,
|
|
}
|
|
}
|
|
|
|
// V1Alpha1AttDataToV1 converts a v1alpha1 attestation data to v1.
|
|
func V1Alpha1AttDataToV1(v1alpha1AttData *ethpb_alpha.AttestationData) *ethpb.AttestationData {
|
|
if v1alpha1AttData == nil || v1alpha1AttData.Source == nil || v1alpha1AttData.Target == nil {
|
|
return ðpb.AttestationData{}
|
|
}
|
|
return ðpb.AttestationData{
|
|
Slot: v1alpha1AttData.Slot,
|
|
CommitteeIndex: v1alpha1AttData.CommitteeIndex,
|
|
BeaconBlockRoot: v1alpha1AttData.BeaconBlockRoot,
|
|
Source: ðpb.Checkpoint{
|
|
Root: v1alpha1AttData.Source.Root,
|
|
Epoch: v1alpha1AttData.Source.Epoch,
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: v1alpha1AttData.Target.Root,
|
|
Epoch: v1alpha1AttData.Target.Epoch,
|
|
},
|
|
}
|
|
}
|
|
|
|
// V1Alpha1AttSlashingToV1 converts a v1alpha1 attester slashing to v1.
|
|
func V1Alpha1AttSlashingToV1(v1alpha1Slashing *ethpb_alpha.AttesterSlashing) *ethpb.AttesterSlashing {
|
|
if v1alpha1Slashing == nil {
|
|
return ðpb.AttesterSlashing{}
|
|
}
|
|
return ðpb.AttesterSlashing{
|
|
Attestation_1: V1Alpha1IndexedAttToV1(v1alpha1Slashing.Attestation_1),
|
|
Attestation_2: V1Alpha1IndexedAttToV1(v1alpha1Slashing.Attestation_2),
|
|
}
|
|
}
|
|
|
|
// V1Alpha1SignedHeaderToV1 converts a v1alpha1 signed beacon block header to v1.
|
|
func V1Alpha1SignedHeaderToV1(v1alpha1Hdr *ethpb_alpha.SignedBeaconBlockHeader) *ethpb.SignedBeaconBlockHeader {
|
|
if v1alpha1Hdr == nil || v1alpha1Hdr.Header == nil {
|
|
return ðpb.SignedBeaconBlockHeader{}
|
|
}
|
|
return ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: v1alpha1Hdr.Header.Slot,
|
|
ProposerIndex: v1alpha1Hdr.Header.ProposerIndex,
|
|
ParentRoot: v1alpha1Hdr.Header.ParentRoot,
|
|
StateRoot: v1alpha1Hdr.Header.StateRoot,
|
|
BodyRoot: v1alpha1Hdr.Header.BodyRoot,
|
|
},
|
|
Signature: v1alpha1Hdr.Signature,
|
|
}
|
|
}
|
|
|
|
// V1SignedHeaderToV1Alpha1 converts a v1 signed beacon block header to v1alpha1.
|
|
func V1SignedHeaderToV1Alpha1(v1Header *ethpb.SignedBeaconBlockHeader) *ethpb_alpha.SignedBeaconBlockHeader {
|
|
if v1Header == nil || v1Header.Header == nil {
|
|
return ðpb_alpha.SignedBeaconBlockHeader{}
|
|
}
|
|
return ðpb_alpha.SignedBeaconBlockHeader{
|
|
Header: ðpb_alpha.BeaconBlockHeader{
|
|
Slot: v1Header.Header.Slot,
|
|
ProposerIndex: v1Header.Header.ProposerIndex,
|
|
ParentRoot: v1Header.Header.ParentRoot,
|
|
StateRoot: v1Header.Header.StateRoot,
|
|
BodyRoot: v1Header.Header.BodyRoot,
|
|
},
|
|
Signature: v1Header.Signature,
|
|
}
|
|
}
|
|
|
|
// V1Alpha1ProposerSlashingToV1 converts a v1alpha1 proposer slashing to v1.
|
|
func V1Alpha1ProposerSlashingToV1(v1alpha1Slashing *ethpb_alpha.ProposerSlashing) *ethpb.ProposerSlashing {
|
|
if v1alpha1Slashing == nil {
|
|
return ðpb.ProposerSlashing{}
|
|
}
|
|
return ðpb.ProposerSlashing{
|
|
Header_1: V1Alpha1SignedHeaderToV1(v1alpha1Slashing.Header_1),
|
|
Header_2: V1Alpha1SignedHeaderToV1(v1alpha1Slashing.Header_2),
|
|
}
|
|
}
|
|
|
|
// V1Alpha1ExitToV1 converts a v1alpha1 SignedVoluntaryExit to v1.
|
|
func V1Alpha1ExitToV1(v1alpha1Exit *ethpb_alpha.SignedVoluntaryExit) *ethpb.SignedVoluntaryExit {
|
|
if v1alpha1Exit == nil || v1alpha1Exit.Exit == nil {
|
|
return ðpb.SignedVoluntaryExit{}
|
|
}
|
|
return ðpb.SignedVoluntaryExit{
|
|
Exit: ðpb.VoluntaryExit{
|
|
Epoch: v1alpha1Exit.Exit.Epoch,
|
|
ValidatorIndex: v1alpha1Exit.Exit.ValidatorIndex,
|
|
},
|
|
Signature: v1alpha1Exit.Signature,
|
|
}
|
|
}
|
|
|
|
// V1ExitToV1Alpha1 converts a v1 SignedVoluntaryExit to v1alpha1.
|
|
func V1ExitToV1Alpha1(v1Exit *ethpb.SignedVoluntaryExit) *ethpb_alpha.SignedVoluntaryExit {
|
|
if v1Exit == nil || v1Exit.Exit == nil {
|
|
return ðpb_alpha.SignedVoluntaryExit{}
|
|
}
|
|
return ðpb_alpha.SignedVoluntaryExit{
|
|
Exit: ðpb_alpha.VoluntaryExit{
|
|
Epoch: v1Exit.Exit.Epoch,
|
|
ValidatorIndex: v1Exit.Exit.ValidatorIndex,
|
|
},
|
|
Signature: v1Exit.Signature,
|
|
}
|
|
}
|
|
|
|
// V1AttToV1Alpha1 converts a v1 attestation to v1alpha1.
|
|
func V1AttToV1Alpha1(v1Att *ethpb.Attestation) *ethpb_alpha.Attestation {
|
|
if v1Att == nil {
|
|
return ðpb_alpha.Attestation{}
|
|
}
|
|
return ðpb_alpha.Attestation{
|
|
AggregationBits: v1Att.AggregationBits,
|
|
Data: V1AttDataToV1Alpha1(v1Att.Data),
|
|
Signature: v1Att.Signature,
|
|
}
|
|
}
|
|
|
|
// V1IndexedAttToV1Alpha1 converts a v1 indexed attestation to v1alpha1.
|
|
func V1IndexedAttToV1Alpha1(v1Att *ethpb.IndexedAttestation) *ethpb_alpha.IndexedAttestation {
|
|
if v1Att == nil {
|
|
return ðpb_alpha.IndexedAttestation{}
|
|
}
|
|
return ðpb_alpha.IndexedAttestation{
|
|
AttestingIndices: v1Att.AttestingIndices,
|
|
Data: V1AttDataToV1Alpha1(v1Att.Data),
|
|
Signature: v1Att.Signature,
|
|
}
|
|
}
|
|
|
|
// V1AttDataToV1Alpha1 converts a v1 attestation data to v1alpha1.
|
|
func V1AttDataToV1Alpha1(v1AttData *ethpb.AttestationData) *ethpb_alpha.AttestationData {
|
|
if v1AttData == nil || v1AttData.Source == nil || v1AttData.Target == nil {
|
|
return ðpb_alpha.AttestationData{}
|
|
}
|
|
return ðpb_alpha.AttestationData{
|
|
Slot: v1AttData.Slot,
|
|
CommitteeIndex: v1AttData.CommitteeIndex,
|
|
BeaconBlockRoot: v1AttData.BeaconBlockRoot,
|
|
Source: ðpb_alpha.Checkpoint{
|
|
Root: v1AttData.Source.Root,
|
|
Epoch: v1AttData.Source.Epoch,
|
|
},
|
|
Target: ðpb_alpha.Checkpoint{
|
|
Root: v1AttData.Target.Root,
|
|
Epoch: v1AttData.Target.Epoch,
|
|
},
|
|
}
|
|
}
|
|
|
|
// V1AttSlashingToV1Alpha1 converts a v1 attester slashing to v1alpha1.
|
|
func V1AttSlashingToV1Alpha1(v1Slashing *ethpb.AttesterSlashing) *ethpb_alpha.AttesterSlashing {
|
|
if v1Slashing == nil {
|
|
return ðpb_alpha.AttesterSlashing{}
|
|
}
|
|
return ðpb_alpha.AttesterSlashing{
|
|
Attestation_1: V1IndexedAttToV1Alpha1(v1Slashing.Attestation_1),
|
|
Attestation_2: V1IndexedAttToV1Alpha1(v1Slashing.Attestation_2),
|
|
}
|
|
}
|
|
|
|
// V1ProposerSlashingToV1Alpha1 converts a v1 proposer slashing to v1alpha1.
|
|
func V1ProposerSlashingToV1Alpha1(v1Slashing *ethpb.ProposerSlashing) *ethpb_alpha.ProposerSlashing {
|
|
if v1Slashing == nil {
|
|
return ðpb_alpha.ProposerSlashing{}
|
|
}
|
|
return ðpb_alpha.ProposerSlashing{
|
|
Header_1: V1SignedHeaderToV1Alpha1(v1Slashing.Header_1),
|
|
Header_2: V1SignedHeaderToV1Alpha1(v1Slashing.Header_2),
|
|
}
|
|
}
|