Skip to content

Commit

Permalink
log received invalid malfeasance proofs on DEBUG (#6232)
Browse files Browse the repository at this point in the history
## Motivation

Users don't need to be informed that a peer sends invalid proofs and the peer should be dropped.
  • Loading branch information
poszu committed Aug 8, 2024
1 parent 714fa7b commit ef93b78
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion activation/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (mh *MalfeasanceHandler) Validate(ctx context.Context, data wire.ProofData)
msg1.InnerMsg.MsgHash != msg2.InnerMsg.MsgHash {
return msg1.SmesherID, nil
}
mh.logger.Warn("received invalid atx malfeasance proof",
mh.logger.Debug("received invalid atx malfeasance proof",
log.ZContext(ctx),
zap.Stringer("first_smesher", msg1.SmesherID),
zap.Object("first_proof", &msg1.InnerMsg),
Expand Down
2 changes: 1 addition & 1 deletion hare3/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (mh *MalfeasanceHandler) Validate(ctx context.Context, data wire.ProofData)
msg1.InnerMsg.MsgHash != msg2.InnerMsg.MsgHash {
return msg1.SmesherID, nil
}
mh.logger.Warn("received invalid hare malfeasance proof",
mh.logger.Debug("received invalid hare malfeasance proof",
log.ZContext(ctx),
zap.Stringer("first_smesher", hp.Messages[0].SmesherID),
zap.Object("first_proof", &hp.Messages[0].InnerMsg),
Expand Down
2 changes: 1 addition & 1 deletion hare4/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (mh *MalfeasanceHandler) Validate(ctx context.Context, data wire.ProofData)
msg1.InnerMsg.MsgHash != msg2.InnerMsg.MsgHash {
return msg1.SmesherID, nil
}
mh.logger.Warn("received invalid hare malfeasance proof",
mh.logger.Debug("received invalid hare malfeasance proof",
log.ZContext(ctx),
zap.Stringer("first_smesher", hp.Messages[0].SmesherID),
zap.Object("first_proof", &hp.Messages[0].InnerMsg),
Expand Down
9 changes: 5 additions & 4 deletions malfeasance/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (

errMalformedData = fmt.Errorf("%w: malformed data", pubsub.ErrValidationReject)
errWrongHash = fmt.Errorf("%w: incorrect hash", pubsub.ErrValidationReject)
errInvalidProof = fmt.Errorf("%w: invalid proof", pubsub.ErrValidationReject)
errUnknownProof = fmt.Errorf("%w: unknown proof type", pubsub.ErrValidationReject)
)

type MalfeasanceType byte
Expand Down Expand Up @@ -153,19 +153,20 @@ func (h *Handler) HandleMalfeasanceProof(ctx context.Context, peer p2p.Peer, dat

func (h *Handler) validateAndSave(ctx context.Context, p *wire.MalfeasanceGossip) (types.NodeID, error) {
if p.Eligibility != nil {
numMalformed.Inc()
return types.EmptyNodeID, fmt.Errorf(
"%w: eligibility field was deprecated with hare3",
pubsub.ErrValidationReject,
)
}
nodeID, err := h.Validate(ctx, p)
switch {
case errors.Is(err, errInvalidProof):
case errors.Is(err, errUnknownProof):
numMalformed.Inc()
return types.EmptyNodeID, err
case err != nil:
h.countInvalidProof(&p.MalfeasanceProof)
return types.EmptyNodeID, err
return types.EmptyNodeID, errors.Join(err, pubsub.ErrValidationReject)
}
if err := h.cdb.WithTx(ctx, func(dbtx *sql.Tx) error {
malicious, err := identities.IsMalicious(dbtx, nodeID)
Expand Down Expand Up @@ -208,7 +209,7 @@ func (h *Handler) validateAndSave(ctx context.Context, p *wire.MalfeasanceGossip
func (h *Handler) Validate(ctx context.Context, p *wire.MalfeasanceGossip) (types.NodeID, error) {
mh, ok := h.handlersV1[MalfeasanceType(p.Proof.Type)]
if !ok {
return types.EmptyNodeID, fmt.Errorf("%w: unknown malfeasance type", errInvalidProof)
return types.EmptyNodeID, fmt.Errorf("%w: unknown malfeasance type", errUnknownProof)
}

nodeID, err := mh.Validate(ctx, p.Proof.Data)
Expand Down
6 changes: 4 additions & 2 deletions malfeasance/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestHandler_HandleMalfeasanceProof(t *testing.T) {
}

err := h.HandleMalfeasanceProof(context.Background(), "peer", codec.MustEncode(gossip))
require.ErrorIs(t, err, errInvalidProof)
require.ErrorIs(t, err, errUnknownProof)
require.ErrorIs(t, err, pubsub.ErrValidationReject)
})

Expand Down Expand Up @@ -113,6 +113,7 @@ func TestHandler_HandleMalfeasanceProof(t *testing.T) {

err := h.HandleMalfeasanceProof(context.Background(), "peer", codec.MustEncode(gossip))
require.ErrorContains(t, err, "invalid proof")
require.ErrorIs(t, err, pubsub.ErrValidationReject)
})

t.Run("valid proof", func(t *testing.T) {
Expand Down Expand Up @@ -223,7 +224,7 @@ func TestHandler_HandleSyncedMalfeasanceProof(t *testing.T) {
"peer",
codec.MustEncode(proof),
)
require.ErrorIs(t, err, errInvalidProof)
require.ErrorIs(t, err, errUnknownProof)
require.ErrorIs(t, err, pubsub.ErrValidationReject)
})

Expand Down Expand Up @@ -291,6 +292,7 @@ func TestHandler_HandleSyncedMalfeasanceProof(t *testing.T) {
codec.MustEncode(proof),
)
require.ErrorContains(t, err, "invalid proof")
require.ErrorIs(t, err, pubsub.ErrValidationReject)
})

t.Run("valid proof", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion mesh/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (mh *MalfeasanceHandler) Validate(ctx context.Context, data wire.ProofData)
msg1.InnerMsg.MsgHash != msg2.InnerMsg.MsgHash {
return msg1.SmesherID, nil
}
mh.logger.Warn("received invalid ballot malfeasance proof",
mh.logger.Debug("received invalid ballot malfeasance proof",
log.ZContext(ctx),
zap.Stringer("first_smesher", bp.Messages[0].SmesherID),
zap.Object("first_proof", &bp.Messages[0].InnerMsg),
Expand Down

0 comments on commit ef93b78

Please sign in to comment.