mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 10:20:44 +00:00
internal/ethapi: avoid full block load in debug_getRawHeader
This commit is contained in:
parent
745b0a8c09
commit
4c8566639c
1 changed files with 8 additions and 9 deletions
|
|
@ -1966,19 +1966,18 @@ func NewDebugAPI(b Backend) *DebugAPI {
|
||||||
|
|
||||||
// GetRawHeader retrieves the RLP encoding for a single header.
|
// GetRawHeader retrieves the RLP encoding for a single header.
|
||||||
func (api *DebugAPI) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
|
func (api *DebugAPI) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
|
||||||
var hash common.Hash
|
var header *types.Header
|
||||||
if h, ok := blockNrOrHash.Hash(); ok {
|
if h, ok := blockNrOrHash.Hash(); ok {
|
||||||
hash = h
|
header, _ = api.b.HeaderByHash(ctx, h)
|
||||||
|
if header == nil {
|
||||||
|
return nil, fmt.Errorf("header #%d not found", h)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
block, err := api.b.BlockByNumberOrHash(ctx, blockNrOrHash)
|
var err error
|
||||||
if block == nil || err != nil {
|
header, err = api.b.HeaderByNumberOrHash(ctx, blockNrOrHash)
|
||||||
|
if header == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
hash = block.Hash()
|
|
||||||
}
|
|
||||||
header, _ := api.b.HeaderByHash(ctx, hash)
|
|
||||||
if header == nil {
|
|
||||||
return nil, fmt.Errorf("header #%d not found", hash)
|
|
||||||
}
|
}
|
||||||
return rlp.EncodeToBytes(header)
|
return rlp.EncodeToBytes(header)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue