From 6fda3c877eae991d3347c387345056fcbb885d6f Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 29 Feb 2020 20:15:02 -0800 Subject: [PATCH] Re: #1302: Refine invalid message filtering - This commit slightly weakens the current invalid message check - The behaviour is that if you can't add a message to your pool, you *probably* won't broadcast it to your peers - The exceptions are that you will broadcast a message if you fail to validate it because nonce / balance lookup fails - This commit also lowers the invalid message log to debug (to lessen the annoyance of several invalid messages coming in, and hopefully to prevent confusion among node operators) --- chain/messagepool/messagepool.go | 6 ++++-- chain/sub/incoming.go | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 6d10ced49..390b2bad8 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -45,6 +45,8 @@ var ( ErrNotEnoughFunds = errors.New("not enough funds to execute transaction") ErrInvalidToAddr = errors.New("message had invalid to address") + + ErrBroadcastAnyway = errors.New("broadcasting message despite validation fail") ) const ( @@ -313,7 +315,7 @@ func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error snonce, err := mp.getStateNonce(m.Message.From, curTs) 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 { @@ -322,7 +324,7 @@ func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error balance, err := mp.getStateBalance(m.Message.From, curTs) 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()) { diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index 7c7039483..be1643425 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -2,6 +2,7 @@ package sub import ( "context" + "golang.org/x/xerrors" "time" 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 { - 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.Insert(metrics.FailureType, "add"), ) stats.Record(ctx, metrics.MessageValidationFailure.M(1)) - return false + return xerrors.Is(err, messagepool.ErrBroadcastAnyway) } stats.Record(ctx, metrics.MessageValidationSuccess.M(1)) return true