minor: Throw error if proposer/signer are not in the validator set (2.28)

This commit is contained in:
atvanguard 2020-04-22 12:42:03 +05:30
parent bfab1d932d
commit 18266b0d7a
2 changed files with 33 additions and 0 deletions

27
consensus/bor/errors.go Normal file
View file

@ -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())
}

View file

@ -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