mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/light/api: use types.ExecutionHeader
This commit is contained in:
parent
27088a9c29
commit
63471ba7cc
1 changed files with 18 additions and 7 deletions
|
|
@ -30,7 +30,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/beacon/types"
|
"github.com/ethereum/go-ethereum/beacon/types"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/protolambda/zrnt/eth2/beacon/capella"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -67,7 +66,7 @@ type jsonBeaconHeader struct {
|
||||||
|
|
||||||
type jsonHeaderWithExecProof struct {
|
type jsonHeaderWithExecProof struct {
|
||||||
Beacon types.Header `json:"beacon"`
|
Beacon types.Header `json:"beacon"`
|
||||||
Execution *capella.ExecutionPayloadHeader `json:"execution"`
|
Execution json.RawMessage `json:"execution"`
|
||||||
ExecutionBranch merkle.Values `json:"execution_branch"`
|
ExecutionBranch merkle.Values `json:"execution_branch"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,6 +242,7 @@ func (api *BeaconLightApi) GetFinalityUpdate() (types.FinalityUpdate, error) {
|
||||||
func decodeFinalityUpdate(enc []byte) (types.FinalityUpdate, error) {
|
func decodeFinalityUpdate(enc []byte) (types.FinalityUpdate, error) {
|
||||||
var data struct {
|
var data struct {
|
||||||
Data struct {
|
Data struct {
|
||||||
|
Version string `json:"version"`
|
||||||
Attested jsonHeaderWithExecProof `json:"attested_header"`
|
Attested jsonHeaderWithExecProof `json:"attested_header"`
|
||||||
Finalized jsonHeaderWithExecProof `json:"finalized_header"`
|
Finalized jsonHeaderWithExecProof `json:"finalized_header"`
|
||||||
FinalityBranch merkle.Values `json:"finality_branch"`
|
FinalityBranch merkle.Values `json:"finality_branch"`
|
||||||
|
|
@ -253,22 +253,33 @@ func decodeFinalityUpdate(enc []byte) (types.FinalityUpdate, error) {
|
||||||
if err := json.Unmarshal(enc, &data); err != nil {
|
if err := json.Unmarshal(enc, &data); err != nil {
|
||||||
return types.FinalityUpdate{}, err
|
return types.FinalityUpdate{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data.Data.Aggregate.Signers) != params.SyncCommitteeBitmaskSize {
|
if len(data.Data.Aggregate.Signers) != params.SyncCommitteeBitmaskSize {
|
||||||
return types.FinalityUpdate{}, errors.New("invalid sync_committee_bits length")
|
return types.FinalityUpdate{}, errors.New("invalid sync_committee_bits length")
|
||||||
}
|
}
|
||||||
if len(data.Data.Aggregate.Signature) != params.BLSSignatureSize {
|
if len(data.Data.Aggregate.Signature) != params.BLSSignatureSize {
|
||||||
return types.FinalityUpdate{}, errors.New("invalid sync_committee_signature length")
|
return types.FinalityUpdate{}, errors.New("invalid sync_committee_signature length")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode the execution payload headers.
|
||||||
|
fork := data.Data.Version
|
||||||
|
attestedExecHeader, err := types.ExecutionHeaderFromJSON(fork, data.Data.Attested.Execution)
|
||||||
|
if err != nil {
|
||||||
|
return types.FinalityUpdate{}, fmt.Errorf("invalid attested header: %v", err)
|
||||||
|
}
|
||||||
|
finalizedExecHeader, err := types.ExecutionHeaderFromJSON(fork, data.Data.Finalized.Execution)
|
||||||
|
if err != nil {
|
||||||
|
return types.FinalityUpdate{}, fmt.Errorf("invalid finalized header: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return types.FinalityUpdate{
|
return types.FinalityUpdate{
|
||||||
Attested: types.HeaderWithExecProof{
|
Attested: types.HeaderWithExecProof{
|
||||||
Header: data.Data.Attested.Beacon,
|
Header: data.Data.Attested.Beacon,
|
||||||
PayloadHeader: data.Data.Attested.Execution,
|
PayloadHeader: attestedExecHeader,
|
||||||
PayloadBranch: data.Data.Attested.ExecutionBranch,
|
PayloadBranch: data.Data.Attested.ExecutionBranch,
|
||||||
},
|
},
|
||||||
Finalized: types.HeaderWithExecProof{
|
Finalized: types.HeaderWithExecProof{
|
||||||
Header: data.Data.Finalized.Beacon,
|
Header: data.Data.Finalized.Beacon,
|
||||||
PayloadHeader: data.Data.Finalized.Execution,
|
PayloadHeader: finalizedExecHeader,
|
||||||
PayloadBranch: data.Data.Finalized.ExecutionBranch,
|
PayloadBranch: data.Data.Finalized.ExecutionBranch,
|
||||||
},
|
},
|
||||||
FinalityBranch: data.Data.FinalityBranch,
|
FinalityBranch: data.Data.FinalityBranch,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue