diff --git a/consensus/bor/errors.go b/consensus/bor/errors.go new file mode 100644 index 0000000000000000000000000000000000000000..29b879ebe3b4c0cf16b91d2600371f80633cb9f2 --- /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 8f197f335b9315ba4660c4b08399342e1a14bd10..97ba2fa0a82ce6d5607b1117e0fa4ef3039c44d1 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