Skip to content

Commit

Permalink
Merge pull request #6124 from filecoin-project/feat/invert-validation…
Browse files Browse the repository at this point in the history
…-switch-checks

Feat/invert validation switch checks
  • Loading branch information
simlecode authored Aug 28, 2023
2 parents c07ba57 + fab7182 commit a6372a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/submodule/mpool/mpool_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (mp *MessagePoolSubmodule) Validate(ctx context.Context, pid peer.ID, msg *

if err := mp.MPool.Add(ctx, m); err != nil {
log.Debugf("failed to add message from network to message pool (From: %s, To: %s, Nonce: %d, Value: %s): %s", m.Message.From, m.Message.To, m.Message.Nonce, types.FIL(m.Message.Value), err)

switch {
case errors.Is(err, messagepool.ErrSoftValidationFailure):
fallthrough
Expand All @@ -139,8 +140,21 @@ func (mp *MessagePoolSubmodule) Validate(ctx context.Context, pid peer.ID, msg *
fallthrough
case errors.Is(err, messagepool.ErrNonceGap):
fallthrough
case errors.Is(err, messagepool.ErrGasFeeCapTooLow):
fallthrough
case errors.Is(err, messagepool.ErrNonceTooLow):
fallthrough
case errors.Is(err, messagepool.ErrNotEnoughFunds):
fallthrough
case errors.Is(err, messagepool.ErrExistingNonce):
return pubsub.ValidationIgnore

case errors.Is(err, messagepool.ErrMessageTooBig):
fallthrough
case errors.Is(err, messagepool.ErrMessageValueTooHigh):
fallthrough
case errors.Is(err, messagepool.ErrInvalidToAddr):
fallthrough
default:
return pubsub.ValidationReject
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var (
ErrRBFTooLowPremium = errors.New("replace by fee has too low GasPremium")
ErrTooManyPendingMessages = errors.New("too many pending messages for actor")
ErrNonceGap = errors.New("unfulfilled nonce gap")
ErrExistingNonce = errors.New("message with nonce already exists")
)

const (
Expand Down Expand Up @@ -300,7 +301,7 @@ func (ms *msgSet) add(m *types.SignedMessage, mp *MessagePool, strict, untrusted
}
} else {
return false, fmt.Errorf("message from %s with nonce %d already in mpool: %w",
m.Message.From, m.Message.Nonce, ErrSoftValidationFailure)
m.Message.From, m.Message.Nonce, ErrExistingNonce)
}

ms.requiredFunds.Sub(ms.requiredFunds, exms.Message.RequiredFunds().Int)
Expand Down Expand Up @@ -912,7 +913,7 @@ func (mp *MessagePool) checkBalance(ctx context.Context, m *types.SignedMessage,

requiredFunds := m.Message.RequiredFunds()
if big.Cmp(balance, requiredFunds) < 0 {
return fmt.Errorf("not enough funds (required: %s, balance: %s): %v", types.FIL(requiredFunds), types.FIL(balance), ErrNotEnoughFunds)
return fmt.Errorf("not enough funds (required: %s, balance: %s): %w", types.FIL(requiredFunds), types.FIL(balance), ErrNotEnoughFunds)
}

// add Value for soft failure check
Expand Down Expand Up @@ -944,7 +945,7 @@ func (mp *MessagePool) addTS(ctx context.Context, m *types.SignedMessage, curTS
}

if snonce > m.Message.Nonce {
return false, fmt.Errorf("minimum expected nonce is %d: %v", snonce, ErrNonceTooLow)
return false, fmt.Errorf("minimum expected nonce is %d: %w", snonce, ErrNonceTooLow)
}

senderAct, err := mp.api.GetActorAfter(ctx, m.Message.From, curTS)
Expand Down

0 comments on commit a6372a9

Please sign in to comment.