Skip to content

Commit

Permalink
rpc: avoid crashing on clique getSigner during sync (#23832)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman authored Nov 1, 2021
1 parent c113520 commit ff84491
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions consensus/clique/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff84491

Please sign in to comment.