Skip to content

Commit 5e92d0c

Browse files
holimanzzyalbert
authored andcommitted
rpc: avoid crashing on clique getSigner during sync (ethereum#23832)
1 parent 2607824 commit 5e92d0c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

consensus/clique/api.go

+3
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ func (api *API) GetSigner(rlpOrBlockNr *blockNumberOrHashOrRLP) (common.Address,
214214
} else if number, ok := blockNrOrHash.Number(); ok {
215215
header = api.chain.GetHeaderByNumber(uint64(number.Int64()))
216216
}
217+
if header == nil {
218+
return common.Address{}, fmt.Errorf("missing block %v", blockNrOrHash.String())
219+
}
217220
return api.clique.Author(header)
218221
}
219222
block := new(types.Block)

rpc/types.go

+10
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ func (bnh *BlockNumberOrHash) Number() (BlockNumber, bool) {
186186
return BlockNumber(0), false
187187
}
188188

189+
func (bnh *BlockNumberOrHash) String() string {
190+
if bnh.BlockNumber != nil {
191+
return strconv.Itoa(int(*bnh.BlockNumber))
192+
}
193+
if bnh.BlockHash != nil {
194+
return bnh.BlockHash.String()
195+
}
196+
return "nil"
197+
}
198+
189199
func (bnh *BlockNumberOrHash) Hash() (common.Hash, bool) {
190200
if bnh.BlockHash != nil {
191201
return *bnh.BlockHash, true

0 commit comments

Comments
 (0)