[2/5] light client http api (#12984)

Co-authored-by: Lizhang <lizhang@polymerlabs.org>
This commit is contained in:
Nicolás Pernas Maradei
2023-11-21 13:26:39 +01:00
committed by GitHub
parent d035be29cd
commit 10ccf1840f
18 changed files with 1958 additions and 21 deletions

View File

@@ -33,15 +33,15 @@ option php_namespace = "Ethereum\\Eth\\v2";
message LightClientBootstrap {
v1.BeaconBlockHeader header = 1;
SyncCommittee current_sync_committee = 2;
repeated bytes current_sync_committee_branch = 3 [(ethereum.eth.ext.ssz_size) = "current_sync_committee_branch.depth,32"];
repeated bytes current_sync_committee_branch = 3;
}
message LightClientUpdate {
v1.BeaconBlockHeader attested_header = 1;
SyncCommittee next_sync_committee = 2;
repeated bytes next_sync_committee_branch = 3 [(ethereum.eth.ext.ssz_size) = "next_sync_committee_branch.depth,32"];
repeated bytes next_sync_committee_branch = 3;
v1.BeaconBlockHeader finalized_header = 4;
repeated bytes finality_branch = 5 [(ethereum.eth.ext.ssz_size) = "finality_branch.depth,32"];
repeated bytes finality_branch = 5;
v1.SyncAggregate sync_aggregate = 6;
uint64 signature_slot = 7 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];
}
@@ -54,7 +54,7 @@ message LightClientFinalityUpdateWithVersion {
message LightClientFinalityUpdate {
v1.BeaconBlockHeader attested_header = 1;
v1.BeaconBlockHeader finalized_header = 2;
repeated bytes finality_branch = 3 [(ethereum.eth.ext.ssz_size) = "finality_branch.depth,32"];
repeated bytes finality_branch = 3;
v1.SyncAggregate sync_aggregate = 4;
uint64 signature_slot = 5 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];
}

View File

@@ -2,12 +2,13 @@ package migration
import (
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
ethpbv1 "github.com/prysmaticlabs/prysm/v4/proto/eth/v1"
ethpbalpha "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"google.golang.org/protobuf/proto"
)
// BlockIfaceToV1BlockHeader converts a signed beacon block interface into a signed beacon block header.
@@ -170,17 +171,26 @@ func V1Alpha1SignedHeaderToV1(v1alpha1Hdr *ethpbalpha.SignedBeaconBlockHeader) *
return &ethpbv1.SignedBeaconBlockHeader{}
}
return &ethpbv1.SignedBeaconBlockHeader{
Message: &ethpbv1.BeaconBlockHeader{
Slot: v1alpha1Hdr.Header.Slot,
ProposerIndex: v1alpha1Hdr.Header.ProposerIndex,
ParentRoot: v1alpha1Hdr.Header.ParentRoot,
StateRoot: v1alpha1Hdr.Header.StateRoot,
BodyRoot: v1alpha1Hdr.Header.BodyRoot,
},
Message: V1Alpha1HeaderToV1(v1alpha1Hdr.Header),
Signature: v1alpha1Hdr.Signature,
}
}
// V1Alpha1HeaderToV1 converts a v1alpha1 beacon block header to v1.
func V1Alpha1HeaderToV1(v1alpha1Hdr *ethpbalpha.BeaconBlockHeader) *ethpbv1.BeaconBlockHeader {
if v1alpha1Hdr == nil {
return &ethpbv1.BeaconBlockHeader{}
}
return &ethpbv1.BeaconBlockHeader{
Slot: v1alpha1Hdr.Slot,
ProposerIndex: v1alpha1Hdr.ProposerIndex,
ParentRoot: v1alpha1Hdr.ParentRoot,
StateRoot: v1alpha1Hdr.StateRoot,
BodyRoot: v1alpha1Hdr.BodyRoot,
}
}
// V1SignedHeaderToV1Alpha1 converts a v1 signed beacon block header to v1alpha1.
func V1SignedHeaderToV1Alpha1(v1Header *ethpbv1.SignedBeaconBlockHeader) *ethpbalpha.SignedBeaconBlockHeader {
if v1Header == nil || v1Header.Message == nil {
@@ -198,6 +208,20 @@ func V1SignedHeaderToV1Alpha1(v1Header *ethpbv1.SignedBeaconBlockHeader) *ethpba
}
}
// V1HeaderToV1Alpha1 converts a v1 beacon block header to v1alpha1.
func V1HeaderToV1Alpha1(v1Header *ethpbv1.BeaconBlockHeader) *ethpbalpha.BeaconBlockHeader {
if v1Header == nil {
return &ethpbalpha.BeaconBlockHeader{}
}
return &ethpbalpha.BeaconBlockHeader{
Slot: v1Header.Slot,
ProposerIndex: v1Header.ProposerIndex,
ParentRoot: v1Header.ParentRoot,
StateRoot: v1Header.StateRoot,
BodyRoot: v1Header.BodyRoot,
}
}
// V1Alpha1ProposerSlashingToV1 converts a v1alpha1 proposer slashing to v1.
func V1Alpha1ProposerSlashingToV1(v1alpha1Slashing *ethpbalpha.ProposerSlashing) *ethpbv1.ProposerSlashing {
if v1alpha1Slashing == nil {

View File

@@ -2,6 +2,8 @@ package migration
import (
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
@@ -10,7 +12,6 @@ import (
ethpbv1 "github.com/prysmaticlabs/prysm/v4/proto/eth/v1"
ethpbv2 "github.com/prysmaticlabs/prysm/v4/proto/eth/v2"
ethpbalpha "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"google.golang.org/protobuf/proto"
)
// V1Alpha1BeaconBlockAltairToV2 converts a v1alpha1 Altair beacon block to a v2 Altair block.
@@ -1290,3 +1291,28 @@ func V1Alpha1SignedBLSToExecChangeToV2(alphaChange *ethpbalpha.SignedBLSToExecut
}
return result
}
// V1Alpha1SyncCommitteeToV2 converts a v1alpha1 SyncCommittee object to its v2 equivalent.
func V1Alpha1SyncCommitteeToV2(alphaCommittee *ethpbalpha.SyncCommittee) *ethpbv2.SyncCommittee {
if alphaCommittee == nil {
return nil
}
result := &ethpbv2.SyncCommittee{
Pubkeys: bytesutil.SafeCopy2dBytes(alphaCommittee.Pubkeys),
AggregatePubkey: bytesutil.SafeCopyBytes(alphaCommittee.AggregatePubkey),
}
return result
}
func V2SyncCommitteeToV1Alpha1(committee *ethpbv2.SyncCommittee) *ethpbalpha.SyncCommittee {
if committee == nil {
return nil
}
result := &ethpbalpha.SyncCommittee{
Pubkeys: bytesutil.SafeCopy2dBytes(committee.Pubkeys),
AggregatePubkey: bytesutil.SafeCopyBytes(committee.AggregatePubkey),
}
return result
}