From 18266b0d7a303276f771d40d35ccaf1aab9e44bc Mon Sep 17 00:00:00 2001
From: atvanguard <93arpit@gmail.com>
Date: Wed, 22 Apr 2020 12:42:03 +0530
Subject: [PATCH] minor: Throw error if proposer/signer are not in the
 validator set (2.28)

---
 consensus/bor/errors.go   | 27 +++++++++++++++++++++++++++
 consensus/bor/snapshot.go |  6 ++++++
 2 files changed, 33 insertions(+)
 create mode 100644 consensus/bor/errors.go

diff --git a/consensus/bor/errors.go b/consensus/bor/errors.go
new file mode 100644
index 000000000..29b879ebe
--- /dev/null
+++ b/consensus/bor/errors.go
@@ -0,0 +1,27 @@
+package bor
+
+import (
+	"fmt"
+
+	"github.com/maticnetwork/bor/common"
+)
+
+// Will include any new bor consensus errors here in an attempt to make error messages more descriptive
+
+// ProposerNotFoundError is returned if the given proposer address is not present in the validator set
+type ProposerNotFoundError struct {
+	Address common.Address
+}
+
+func (e *ProposerNotFoundError) Error() string {
+	return fmt.Sprintf("Proposer: %s not found", e.Address.Hex())
+}
+
+// SignerNotFoundError is returned when the signer address is not present in the validator set
+type SignerNotFoundError struct {
+	Address common.Address
+}
+
+func (e *SignerNotFoundError) Error() string {
+	return fmt.Sprintf("Signer: %s not found", e.Address.Hex())
+}
diff --git a/consensus/bor/snapshot.go b/consensus/bor/snapshot.go
index 8f197f335..97ba2fa0a 100644
--- a/consensus/bor/snapshot.go
+++ b/consensus/bor/snapshot.go
@@ -164,7 +164,13 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
 		// proposer will be the last signer if block is not epoch block
 		proposer := snap.ValidatorSet.GetProposer().Address
 		proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
+		if proposerIndex == -1 {
+			return nil, &ProposerNotFoundError{proposer}
+		}
 		signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
+		if signerIndex == -1 {
+			return nil, &SignerNotFoundError{signer}
+		}
 		limit := len(validators)/2 + 1
 
 		// temp index
-- 
GitLab