mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -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
|
||||
|
||||
type LightClientHeader struct {
|
||||
Beacon *BeaconBlockHeader `json:"beacon"`
|
||||
}
|
||||
|
||||
type LightClientBootstrapResponse struct {
|
||||
Version string `json:"version"`
|
||||
Data *LightClientBootstrap `json:"data"`
|
||||
}
|
||||
|
||||
type LightClientBootstrap struct {
|
||||
Header *BeaconBlockHeader `json:"header"`
|
||||
Header *LightClientHeader `json:"header"`
|
||||
CurrentSyncCommittee *SyncCommittee `json:"current_sync_committee"`
|
||||
CurrentSyncCommitteeBranch []string `json:"current_sync_committee_branch"`
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestLightClientHandler_GetLightClientBootstrap(t *testing.T) {
|
||||
resp := &structs.LightClientBootstrapResponse{}
|
||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -67,17 +67,20 @@ func createLightClientBootstrap(ctx context.Context, state state.BeaconState) (*
|
||||
branch[i] = hexutil.Encode(proof)
|
||||
}
|
||||
|
||||
header := structs.BeaconBlockHeaderFromConsensus(latestBlockHeader)
|
||||
if header == nil {
|
||||
beacon := structs.BeaconBlockHeaderFromConsensus(latestBlockHeader)
|
||||
if beacon == nil {
|
||||
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
|
||||
stateRoot, err := state.HashTreeRoot(ctx)
|
||||
if err != nil {
|
||||
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
|
||||
result := &structs.LightClientBootstrap{
|
||||
@@ -237,7 +240,7 @@ func NewLightClientBootstrapFromJSON(bootstrapJSON *structs.LightClientBootstrap
|
||||
|
||||
var err error
|
||||
|
||||
v1Alpha1Header, err := bootstrapJSON.Header.ToConsensus()
|
||||
v1Alpha1Header, err := bootstrapJSON.Header.Beacon.ToConsensus()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user