Merge pull request #11016 from filecoin-project/sbansal/invert-validation-switch-checks
refactor: Make all validation error actions explicit
This commit is contained in:
commit
807a5dbaa8
@ -63,6 +63,9 @@ var MaxNonceGap = uint64(4)
|
||||
|
||||
const MaxMessageSize = 64 << 10 // 64KiB
|
||||
|
||||
// NOTE: When adding a new error type, please make sure to add the new error type in
|
||||
// func (mv *MessageValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub.Message)
|
||||
// in /chain/sub/incoming.go
|
||||
var (
|
||||
ErrMessageTooBig = errors.New("message too big")
|
||||
|
||||
|
@ -350,6 +350,7 @@ func (mv *MessageValidator) Validate(ctx context.Context, pid peer.ID, msg *pubs
|
||||
)
|
||||
recordFailure(ctx, metrics.MessageValidationFailure, "add")
|
||||
switch {
|
||||
|
||||
case xerrors.Is(err, messagepool.ErrSoftValidationFailure):
|
||||
fallthrough
|
||||
case xerrors.Is(err, messagepool.ErrRBFTooLowPremium):
|
||||
@ -362,8 +363,17 @@ func (mv *MessageValidator) Validate(ctx context.Context, pid peer.ID, msg *pubs
|
||||
fallthrough
|
||||
case xerrors.Is(err, messagepool.ErrNonceTooLow):
|
||||
fallthrough
|
||||
case xerrors.Is(err, messagepool.ErrNotEnoughFunds):
|
||||
fallthrough
|
||||
case xerrors.Is(err, messagepool.ErrExistingNonce):
|
||||
return pubsub.ValidationIgnore
|
||||
|
||||
case xerrors.Is(err, messagepool.ErrMessageTooBig):
|
||||
fallthrough
|
||||
case xerrors.Is(err, messagepool.ErrMessageValueTooHigh):
|
||||
fallthrough
|
||||
case xerrors.Is(err, messagepool.ErrInvalidToAddr):
|
||||
fallthrough
|
||||
default:
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user