From c89fa6d3aa64843ca75061e9a3a7e9b877ba8587 Mon Sep 17 00:00:00 2001 From: kimmy lin <30611210+countvonzero@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:52:36 -0700 Subject: [PATCH] do not mark self malicious --- activation/handler.go | 2 +- common/types/nodeid.go | 12 ++++++++++++ hare/hare.go | 3 +++ hare3/hare.go | 2 +- malfeasance/handler.go | 4 ++++ mesh/mesh.go | 2 +- node/node.go | 1 + 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/activation/handler.go b/activation/handler.go index 5c334b23a3..16f71e856e 100644 --- a/activation/handler.go +++ b/activation/handler.go @@ -364,7 +364,7 @@ func (h *Handler) storeAtx(ctx context.Context, atx *types.VerifiedActivationTx) } var proof *types.MalfeasanceProof if err := h.cdb.WithTx(ctx, func(dbtx *sql.Tx) error { - if !malicious { + if !malicious && atx.SmesherID != types.MinerNodeID() { prev, err := atxs.GetByEpochAndNodeID(dbtx, atx.PublishEpoch, atx.SmesherID) if err != nil && !errors.Is(err, sql.ErrNotFound) { return err diff --git a/common/types/nodeid.go b/common/types/nodeid.go index ff46b00f9c..8116b4cbe1 100644 --- a/common/types/nodeid.go +++ b/common/types/nodeid.go @@ -9,6 +9,18 @@ import ( "github.com/spacemeshos/go-spacemesh/log" ) +var ownNodeID NodeID + +func SetMinerNodeID(id NodeID) { + if ownNodeID == EmptyNodeID { + ownNodeID = id + } +} + +func MinerNodeID() NodeID { + return ownNodeID +} + // BytesToNodeID is a helper to copy buffer into NodeID struct. func BytesToNodeID(buf []byte) (id NodeID) { copy(id[:], buf) diff --git a/hare/hare.go b/hare/hare.go index a7d75b1b55..c6ff7d6445 100644 --- a/hare/hare.go +++ b/hare/hare.go @@ -714,6 +714,9 @@ func (h *Hare) malfeasanceLoop(ctx context.Context) { if err != nil { h.WithContext(ctx).With().Panic("failed to encode MalfeasanceProof", log.Err(err)) } + if gossip.Eligibility.NodeID == types.MinerNodeID() { + continue + } if err := identities.SetMalicious(h.msh.Cache(), gossip.Eligibility.NodeID, encoded, time.Now()); err != nil { h.With().Error("failed to save MalfeasanceProof", log.Context(ctx), diff --git a/hare3/hare.go b/hare3/hare.go index 643089aea3..574da56989 100644 --- a/hare3/hare.go +++ b/hare3/hare.go @@ -286,7 +286,7 @@ func (h *Hare) Handler(ctx context.Context, peer p2p.Peer, buf []byte) error { gossip, equivocation := session.OnInput(input) h.log.Debug("after on message", log.ZShortStringer("hash", input.msgHash), zap.Bool("gossip", gossip)) submitLatency.Observe(time.Since(start).Seconds()) - if equivocation != nil && !malicious { + if equivocation != nil && !malicious && msg.Sender != types.MinerNodeID() { h.log.Debug("registered equivocation", zap.Uint32("lid", msg.Layer.Uint32()), zap.Stringer("sender", equivocation.Messages[0].SmesherID)) diff --git a/malfeasance/handler.go b/malfeasance/handler.go index 07a38f7dbc..d7efdb5897 100644 --- a/malfeasance/handler.go +++ b/malfeasance/handler.go @@ -107,6 +107,10 @@ func (h *Handler) validateAndSave(ctx context.Context, p *types.MalfeasanceGossi if err != nil { return types.EmptyNodeID, err } + if nodeID == types.MinerNodeID() { + h.logger.WithContext(ctx).With().Warning("received gossip for own malfeasance proof", log.Inline(&p.MalfeasanceProof)) + return nodeID, nil + } if err := h.cdb.WithTx(ctx, func(dbtx *sql.Tx) error { malicious, err := identities.IsMalicious(dbtx, nodeID) if err != nil { diff --git a/mesh/mesh.go b/mesh/mesh.go index 92bc536b0d..ec4848d424 100644 --- a/mesh/mesh.go +++ b/mesh/mesh.go @@ -567,7 +567,7 @@ func (msh *Mesh) AddBallot(ctx context.Context, ballot *types.Ballot) (*types.Ma // ballots.LayerBallotByNodeID and ballots.Add should be atomic // otherwise concurrent ballots.Add from the same smesher may not be noticed if err = msh.cdb.WithTx(ctx, func(dbtx *sql.Tx) error { - if !malicious { + if !malicious && ballot.SmesherID != types.MinerNodeID() { prev, err := ballots.LayerBallotByNodeID(dbtx, ballot.Layer, ballot.SmesherID) if err != nil && !errors.Is(err, sql.ErrNotFound) { return err diff --git a/node/node.go b/node/node.go index b1e210c797..8bab521b5c 100644 --- a/node/node.go +++ b/node/node.go @@ -163,6 +163,7 @@ func GetCommand() *cobra.Command { if app.edSgn, err = app.LoadOrCreateEdSigner(); err != nil { return fmt.Errorf("could not retrieve identity: %w", err) } + types.SetMinerNodeID(app.edSgn.NodeID()) app.preserve, err = app.LoadCheckpoint(ctx) if err != nil {