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
|
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 (
|
var (
|
||||||
ErrMessageTooBig = errors.New("message too big")
|
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")
|
recordFailure(ctx, metrics.MessageValidationFailure, "add")
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
case xerrors.Is(err, messagepool.ErrSoftValidationFailure):
|
case xerrors.Is(err, messagepool.ErrSoftValidationFailure):
|
||||||
fallthrough
|
fallthrough
|
||||||
case xerrors.Is(err, messagepool.ErrRBFTooLowPremium):
|
case xerrors.Is(err, messagepool.ErrRBFTooLowPremium):
|
||||||
@ -362,8 +363,17 @@ func (mv *MessageValidator) Validate(ctx context.Context, pid peer.ID, msg *pubs
|
|||||||
fallthrough
|
fallthrough
|
||||||
case xerrors.Is(err, messagepool.ErrNonceTooLow):
|
case xerrors.Is(err, messagepool.ErrNonceTooLow):
|
||||||
fallthrough
|
fallthrough
|
||||||
|
case xerrors.Is(err, messagepool.ErrNotEnoughFunds):
|
||||||
|
fallthrough
|
||||||
case xerrors.Is(err, messagepool.ErrExistingNonce):
|
case xerrors.Is(err, messagepool.ErrExistingNonce):
|
||||||
return pubsub.ValidationIgnore
|
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:
|
default:
|
||||||
return pubsub.ValidationReject
|
return pubsub.ValidationReject
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user