From e0ef563edf0bae94c253f9f363173269fac354b0 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Fri, 6 Jan 2023 22:05:44 +0530 Subject: [PATCH] consensus/bor: handle unauthorized signer in consensus.Prepare --- consensus/bor/bor.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index b6d643eeba..4f367430ec 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -676,6 +676,13 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e currentSigner := *c.authorizedSigner.Load() + // Bail out early if we're unauthorized to sign a block. This check also takes + // place before block is signed in `Seal`. + if !snap.ValidatorSet.HasAddress(currentSigner.signer) { + // Check the UnauthorizedSignerError.Error() msg to see why we pass number-1 + return &UnauthorizedSignerError{number - 1, currentSigner.signer.Bytes()} + } + // Set the correct difficulty header.Difficulty = new(big.Int).SetUint64(Difficulty(snap.ValidatorSet, currentSigner.signer))