Skip to content

Commit

Permalink
do not mark self malicious
Browse files Browse the repository at this point in the history
  • Loading branch information
countvonzero committed Sep 7, 2023
1 parent b694924 commit c89fa6d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion activation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions common/types/nodeid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions hare/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion hare3/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions malfeasance/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c89fa6d

Please sign in to comment.