Return correct root from GetBlockHeader (#12935)

* Return correct root from `GetBlockHeader`

* variable rename
This commit is contained in:
Radosław Kapka 2023-09-21 14:02:14 +02:00 committed by GitHub
parent b7cb5c81be
commit b40729f6c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -861,12 +861,12 @@ func (s *Server) GetBlockHeader(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
header, err := blk.Header()
blockHeader, err := blk.Header()
if err != nil {
http2.HandleError(w, "Could not get block header: %s"+err.Error(), http.StatusInternalServerError)
return
}
headerRoot, err := header.HashTreeRoot()
headerRoot, err := blockHeader.Header.HashTreeRoot()
if err != nil {
http2.HandleError(w, "Could not hash block header: %s"+err.Error(), http.StatusInternalServerError)
return
@ -892,8 +892,8 @@ func (s *Server) GetBlockHeader(w http.ResponseWriter, r *http.Request) {
Root: hexutil.Encode(headerRoot[:]),
Canonical: canonical,
Header: &shared.SignedBeaconBlockHeader{
Message: shared.BeaconBlockHeaderFromConsensus(header.Header),
Signature: hexutil.Encode(header.Signature),
Message: shared.BeaconBlockHeaderFromConsensus(blockHeader.Header),
Signature: hexutil.Encode(blockHeader.Signature),
},
},
ExecutionOptimistic: isOptimistic,

View File

@ -1376,7 +1376,7 @@ func TestServer_GetBlockHeader(t *testing.T) {
resp := &GetBlockHeaderResponse{}
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
assert.Equal(t, true, resp.Data.Canonical)
assert.Equal(t, "0x725b389a0e5a7623fa7600b9e5cb6248d5c293fc2f5877e42a665b44f40c85f6", resp.Data.Root)
assert.Equal(t, "0xd7d92f6206707f2c9c4e7e82320617d5abac2b6461a65ea5bb1a154b5b5ea2fa", resp.Data.Root)
assert.Equal(t, "0x736967000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", resp.Data.Header.Signature)
assert.Equal(t, "123", resp.Data.Header.Message.Slot)
assert.Equal(t, "0x706172656e74726f6f7400000000000000000000000000000000000000000000", resp.Data.Header.Message.ParentRoot)