mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
fix: replace BeaconBlockHeader in createLightClientBootstrap with LightClientHeader (#14374)
* fix: replace `BeaconBlockHeader` in `createLightClientBootstrap` with `LightClientHeader` * minor fix in `handlers_test.go` * check if `beacon` is `nil` instead of `header` --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
package structs
|
package structs
|
||||||
|
|
||||||
|
type LightClientHeader struct {
|
||||||
|
Beacon *BeaconBlockHeader `json:"beacon"`
|
||||||
|
}
|
||||||
|
|
||||||
type LightClientBootstrapResponse struct {
|
type LightClientBootstrapResponse struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Data *LightClientBootstrap `json:"data"`
|
Data *LightClientBootstrap `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LightClientBootstrap struct {
|
type LightClientBootstrap struct {
|
||||||
Header *BeaconBlockHeader `json:"header"`
|
Header *LightClientHeader `json:"header"`
|
||||||
CurrentSyncCommittee *SyncCommittee `json:"current_sync_committee"`
|
CurrentSyncCommittee *SyncCommittee `json:"current_sync_committee"`
|
||||||
CurrentSyncCommitteeBranch []string `json:"current_sync_committee_branch"`
|
CurrentSyncCommitteeBranch []string `json:"current_sync_committee_branch"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func TestLightClientHandler_GetLightClientBootstrap(t *testing.T) {
|
|||||||
resp := &structs.LightClientBootstrapResponse{}
|
resp := &structs.LightClientBootstrapResponse{}
|
||||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||||
require.Equal(t, "capella", resp.Version)
|
require.Equal(t, "capella", resp.Version)
|
||||||
require.Equal(t, hexutil.Encode(header.Header.BodyRoot), resp.Data.Header.BodyRoot)
|
require.Equal(t, hexutil.Encode(header.Header.BodyRoot), resp.Data.Header.Beacon.BodyRoot)
|
||||||
require.NotNil(t, resp.Data)
|
require.NotNil(t, resp.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,17 +67,20 @@ func createLightClientBootstrap(ctx context.Context, state state.BeaconState) (*
|
|||||||
branch[i] = hexutil.Encode(proof)
|
branch[i] = hexutil.Encode(proof)
|
||||||
}
|
}
|
||||||
|
|
||||||
header := structs.BeaconBlockHeaderFromConsensus(latestBlockHeader)
|
beacon := structs.BeaconBlockHeaderFromConsensus(latestBlockHeader)
|
||||||
if header == nil {
|
if beacon == nil {
|
||||||
return nil, fmt.Errorf("could not get beacon block header")
|
return nil, fmt.Errorf("could not get beacon block header")
|
||||||
}
|
}
|
||||||
|
header := &structs.LightClientHeader{
|
||||||
|
Beacon: beacon,
|
||||||
|
}
|
||||||
|
|
||||||
// Above shared util function won't calculate state root, so we need to do it manually
|
// Above shared util function won't calculate state root, so we need to do it manually
|
||||||
stateRoot, err := state.HashTreeRoot(ctx)
|
stateRoot, err := state.HashTreeRoot(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not get state root: %s", err.Error())
|
return nil, fmt.Errorf("could not get state root: %s", err.Error())
|
||||||
}
|
}
|
||||||
header.StateRoot = hexutil.Encode(stateRoot[:])
|
header.Beacon.StateRoot = hexutil.Encode(stateRoot[:])
|
||||||
|
|
||||||
// Return result
|
// Return result
|
||||||
result := &structs.LightClientBootstrap{
|
result := &structs.LightClientBootstrap{
|
||||||
@@ -237,7 +240,7 @@ func NewLightClientBootstrapFromJSON(bootstrapJSON *structs.LightClientBootstrap
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
v1Alpha1Header, err := bootstrapJSON.Header.ToConsensus()
|
v1Alpha1Header, err := bootstrapJSON.Header.Beacon.ToConsensus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user