Merge pull request #1313 from filecoin-project/asr/spam
Re: #1302: Refine invalid message filtering
This commit is contained in:
commit
163527a021
@ -45,6 +45,8 @@ var (
|
|||||||
ErrNotEnoughFunds = errors.New("not enough funds to execute transaction")
|
ErrNotEnoughFunds = errors.New("not enough funds to execute transaction")
|
||||||
|
|
||||||
ErrInvalidToAddr = errors.New("message had invalid to address")
|
ErrInvalidToAddr = errors.New("message had invalid to address")
|
||||||
|
|
||||||
|
ErrBroadcastAnyway = errors.New("broadcasting message despite validation fail")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -313,7 +315,7 @@ func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error
|
|||||||
|
|
||||||
snonce, err := mp.getStateNonce(m.Message.From, curTs)
|
snonce, err := mp.getStateNonce(m.Message.From, curTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to look up actor state nonce: %w", err)
|
return xerrors.Errorf("failed to look up actor state nonce: %s: %w", err, ErrBroadcastAnyway)
|
||||||
}
|
}
|
||||||
|
|
||||||
if snonce > m.Message.Nonce {
|
if snonce > m.Message.Nonce {
|
||||||
@ -322,7 +324,7 @@ func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error
|
|||||||
|
|
||||||
balance, err := mp.getStateBalance(m.Message.From, curTs)
|
balance, err := mp.getStateBalance(m.Message.From, curTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to check sender balance: %w", err)
|
return xerrors.Errorf("failed to check sender balance: %s: %w", err, ErrBroadcastAnyway)
|
||||||
}
|
}
|
||||||
|
|
||||||
if balance.LessThan(m.Message.RequiredFunds()) {
|
if balance.LessThan(m.Message.RequiredFunds()) {
|
||||||
|
@ -2,6 +2,7 @@ package sub
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
@ -181,13 +182,13 @@ func (mv *MessageValidator) Validate(ctx context.Context, pid peer.ID, msg *pubs
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := mv.mpool.Add(m); err != nil {
|
if err := mv.mpool.Add(m); err != nil {
|
||||||
log.Warnf("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)
|
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)
|
||||||
ctx, _ = tag.New(
|
ctx, _ = tag.New(
|
||||||
ctx,
|
ctx,
|
||||||
tag.Insert(metrics.FailureType, "add"),
|
tag.Insert(metrics.FailureType, "add"),
|
||||||
)
|
)
|
||||||
stats.Record(ctx, metrics.MessageValidationFailure.M(1))
|
stats.Record(ctx, metrics.MessageValidationFailure.M(1))
|
||||||
return false
|
return xerrors.Is(err, messagepool.ErrBroadcastAnyway)
|
||||||
}
|
}
|
||||||
stats.Record(ctx, metrics.MessageValidationSuccess.M(1))
|
stats.Record(ctx, metrics.MessageValidationSuccess.M(1))
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user