From 9d93bccde7ef7acf2bbef491471cfec270054588 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 11 Apr 2022 20:19:13 +0200 Subject: [PATCH] core/types: make "miner" optional in Header JSON (#24666) "miner" is not set for pending block responses in some cases. Fixes #24632 --- core/types/block.go | 2 +- core/types/gen_header_json.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index e7bd434dcf80..d7fa0fe1bd77 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -71,7 +71,7 @@ func (n *BlockNonce) UnmarshalText(input []byte) error { type Header struct { ParentHash common.Hash `json:"parentHash" gencodec:"required"` UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase common.Address `json:"miner" gencodec:"required"` + Coinbase common.Address `json:"miner"` Root common.Hash `json:"stateRoot" gencodec:"required"` TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 4c2dd3552b38..ac1c56053306 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -18,7 +18,7 @@ func (h Header) MarshalJSON() ([]byte, error) { type Header struct { ParentHash common.Hash `json:"parentHash" gencodec:"required"` UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase common.Address `json:"miner" gencodec:"required"` + Coinbase common.Address `json:"miner"` Root common.Hash `json:"stateRoot" gencodec:"required"` TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` @@ -68,7 +68,7 @@ func (h *Header) UnmarshalJSON(input []byte) error { type Header struct { ParentHash *common.Hash `json:"parentHash" gencodec:"required"` UncleHash *common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase *common.Address `json:"miner" gencodec:"required"` + Coinbase *common.Address `json:"miner"` Root *common.Hash `json:"stateRoot" gencodec:"required"` TxHash *common.Hash `json:"transactionsRoot" gencodec:"required"` ReceiptHash *common.Hash `json:"receiptsRoot" gencodec:"required"` @@ -99,10 +99,9 @@ func (h *Header) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'sha3Uncles' for Header") } h.UncleHash = *dec.UncleHash - if dec.Coinbase == nil { - return errors.New("missing required field 'miner' for Header") + if dec.Coinbase != nil { + h.Coinbase = *dec.Coinbase } - h.Coinbase = *dec.Coinbase if dec.Root == nil { return errors.New("missing required field 'stateRoot' for Header") }