mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
beacon/light/api: change block server to use types.BeaconBlock
This commit is contained in:
parent
aec6b03f32
commit
b4e18c2b94
1 changed files with 12 additions and 11 deletions
|
|
@ -31,8 +31,6 @@ import (
|
||||||
"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"
|
"github.com/protolambda/zrnt/eth2/beacon/capella"
|
||||||
"github.com/protolambda/zrnt/eth2/configs"
|
|
||||||
"github.com/protolambda/ztyp/tree"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -359,27 +357,30 @@ func (api *BeaconLightApi) GetCheckpointData(checkpointHash common.Hash) (*types
|
||||||
return checkpoint, nil
|
return checkpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *BeaconLightApi) GetBeaconBlock(blockRoot common.Hash) (*capella.BeaconBlock, error) {
|
func (api *BeaconLightApi) GetBeaconBlock(blockRoot common.Hash) (*types.BeaconBlock, error) {
|
||||||
resp, err := api.httpGetf("/eth/v2/beacon/blocks/0x%x", blockRoot)
|
resp, err := api.httpGetf("/eth/v2/beacon/blocks/0x%x", blockRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var beaconBlockMessage struct {
|
var beaconBlockMessage struct {
|
||||||
|
Version string
|
||||||
Data struct {
|
Data struct {
|
||||||
Message capella.BeaconBlock `json:"message"`
|
Message json.RawMessage `json:"message"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(resp, &beaconBlockMessage); err != nil {
|
if err := json.Unmarshal(resp, &beaconBlockMessage); err != nil {
|
||||||
return nil, fmt.Errorf("invalid block json data: %v", err)
|
return nil, fmt.Errorf("invalid block json data: %v", err)
|
||||||
}
|
}
|
||||||
beaconBlock := new(capella.BeaconBlock)
|
block, err := types.BlockFromJSON(beaconBlockMessage.Version, beaconBlockMessage.Data.Message)
|
||||||
*beaconBlock = beaconBlockMessage.Data.Message
|
if err != nil {
|
||||||
root := common.Hash(beaconBlock.HashTreeRoot(configs.Mainnet, tree.GetHashFn()))
|
return nil, err
|
||||||
if root != blockRoot {
|
|
||||||
return nil, fmt.Errorf("Beacon block root hash mismatch (expected: %x, got: %x)", blockRoot, root)
|
|
||||||
}
|
}
|
||||||
return beaconBlock, nil
|
computedRoot := block.Hash()
|
||||||
|
if computedRoot != blockRoot {
|
||||||
|
return nil, fmt.Errorf("Beacon block root hash mismatch (expected: %x, got: %x)", blockRoot, computedRoot)
|
||||||
|
}
|
||||||
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeHeadEvent(enc []byte) (uint64, common.Hash, error) {
|
func decodeHeadEvent(enc []byte) (uint64, common.Hash, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue