From ff844918e806cf1337606b4aafdaefbf6d579a9a Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 1 Nov 2021 07:51:03 +0100 Subject: [PATCH] rpc: avoid crashing on clique getSigner during sync (#23832) --- consensus/clique/api.go | 3 +++ rpc/types.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/consensus/clique/api.go b/consensus/clique/api.go index 6129b5cc5..03f2daffa 100644 --- a/consensus/clique/api.go +++ b/consensus/clique/api.go @@ -214,6 +214,9 @@ func (api *API) GetSigner(rlpOrBlockNr *blockNumberOrHashOrRLP) (common.Address, } else if number, ok := blockNrOrHash.Number(); ok { header = api.chain.GetHeaderByNumber(uint64(number.Int64())) } + if header == nil { + return common.Address{}, fmt.Errorf("missing block %v", blockNrOrHash.String()) + } return api.clique.Author(header) } block := new(types.Block) diff --git a/rpc/types.go b/rpc/types.go index d9c2317a7..ca52d474d 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -186,6 +186,16 @@ func (bnh *BlockNumberOrHash) Number() (BlockNumber, bool) { return BlockNumber(0), false } +func (bnh *BlockNumberOrHash) String() string { + if bnh.BlockNumber != nil { + return strconv.Itoa(int(*bnh.BlockNumber)) + } + if bnh.BlockHash != nil { + return bnh.BlockHash.String() + } + return "nil" +} + func (bnh *BlockNumberOrHash) Hash() (common.Hash, bool) { if bnh.BlockHash != nil { return *bnh.BlockHash, true