Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into retry-registration-timeout-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ConvallariaMaj committed Aug 14, 2024
2 parents de5cd55 + dbcaf5c commit b7fcf55
Show file tree
Hide file tree
Showing 33 changed files with 614 additions and 656 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ such and the node will continue to scan new ATXs for their validity.
* [#6035](https://github.com/spacemeshos/go-spacemesh/issues/6035) Fixed an issue where the node retried registering for the PoET round
only for 15-20 minutes instead of continuing until the start of the round

## Release v1.6.6-hotfix1

### Improvements

* [#6248](https://github.com/spacemeshos/go-spacemesh/pull/6248) Fixed node not being able to handle more than 6.55M
ATXs per epoch.

## Release v1.6.6

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion activation/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestCheckpoint_PublishingSoloATXs(t *testing.T) {
// 3. Spawn new ATX handler and builder using the new DB
poetDb = activation.NewPoetDb(newDB, logger.Named("poetDb"))
cdb = datastore.NewCachedDB(newDB, logger)
atxdata, err = atxsdata.Warm(newDB, 1)
atxdata, err = atxsdata.Warm(newDB, 1, logger)
poetService = activation.NewPoetServiceWithClient(poetDb, client, poetCfg, logger)
validator = activation.NewValidator(newDB, poetDb, cfg, opts.Scrypt, verifier)
require.NoError(t, err)
Expand Down
56 changes: 2 additions & 54 deletions activation/handler_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,47 +284,6 @@ func (h *HandlerV1) validateNonInitialAtx(
return nil
}

// contextuallyValidateAtx ensures that the previous ATX referenced is the last known ATX for the referenced miner ID.
// If a previous ATX is not referenced, it validates that indeed there's no previous known ATX for that miner ID.
func (h *HandlerV1) contextuallyValidateAtx(atx *wire.ActivationTxV1) error {
lastAtx, err := atxs.GetLastIDByNodeID(h.cdb, atx.SmesherID)
if err == nil && atx.PrevATXID == lastAtx {
// last atx referenced equals last ATX seen from node
return nil
}

if err == nil && atx.PrevATXID == types.EmptyATXID {
// no previous atx declared, but already seen at least one atx from node
return fmt.Errorf(
"no prev atx reported, but other atx with same node id (%v) found: %v",
atx.SmesherID,
lastAtx.ShortString(),
)
}

if err == nil && atx.PrevATXID != lastAtx {
// last atx referenced does not equal last ATX seen from node
return errors.New("last atx is not the one referenced")
}

if errors.Is(err, sql.ErrNotFound) && atx.PrevATXID == types.EmptyATXID {
// no previous atx found and none referenced
return nil
}

if err != nil && atx.PrevATXID != types.EmptyATXID {
// no previous atx found but previous atx referenced
h.logger.Error("could not fetch node last atx",
zap.Stringer("atx_id", atx.ID()),
zap.Stringer("smesher", atx.SmesherID),
zap.Error(err),
)
return fmt.Errorf("could not fetch node last atx: %w", err)
}

return err
}

// cacheAtx caches the atx in the atxsdata cache.
// Returns true if the atx was cached, false otherwise.
func (h *HandlerV1) cacheAtx(ctx context.Context, atx *types.ActivationTx) *atxsdata.ATX {
Expand Down Expand Up @@ -397,7 +356,7 @@ func (h *HandlerV1) checkDoublePublish(
return nil, fmt.Errorf("add malfeasance proof: %w", err)
}

h.logger.Warn("smesher produced more than one atx in the same epoch",
h.logger.Debug("smesher produced more than one atx in the same epoch",
log.ZContext(ctx),
zap.Stringer("smesher", atx.SmesherID),
zap.Stringer("previous", prev),
Expand Down Expand Up @@ -478,7 +437,7 @@ func (h *HandlerV1) checkWrongPrevAtx(
return nil, fmt.Errorf("add malfeasance proof: %w", err)
}

h.logger.Warn("smesher referenced the wrong previous in published ATX",
h.logger.Debug("smesher referenced the wrong previous in published ATX",
log.ZContext(ctx),
zap.Stringer("smesher", atx.SmesherID),
log.ZShortStringer("actual", atx.PrevATXID),
Expand Down Expand Up @@ -593,17 +552,6 @@ func (h *HandlerV1) processATX(
return proof, nil
}

if err := h.contextuallyValidateAtx(watx); err != nil {
h.logger.Warn("atx is contextually invalid ",
log.ZContext(ctx),
zap.Stringer("atx_id", watx.ID()),
zap.Stringer("smesherID", watx.SmesherID),
zap.Error(err),
)
} else {
h.logger.Debug("atx is valid", zap.Stringer("atx_id", watx.ID()))
}

var baseTickHeight uint64
if watx.PositioningATXID != h.goldenATXID {
posAtx, err := h.cdb.GetAtx(watx.PositioningATXID)
Expand Down
79 changes: 0 additions & 79 deletions activation/handler_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,85 +453,6 @@ func TestHandlerV1_SyntacticallyValidateAtx(t *testing.T) {
})
}

func TestHandler_ContextuallyValidateAtx(t *testing.T) {
goldenATXID := types.ATXID{2, 3, 4}

sig, err := signing.NewEdSigner()
require.NoError(t, err)

t.Run("valid initial atx", func(t *testing.T) {
t.Parallel()

atx := newInitialATXv1(t, goldenATXID)
atx.Sign(sig)

atxHdlr := newV1TestHandler(t, goldenATXID)
require.NoError(t, atxHdlr.contextuallyValidateAtx(atx))
})

t.Run("missing prevAtx", func(t *testing.T) {
t.Parallel()

atxHdlr := newV1TestHandler(t, goldenATXID)

prevAtx := newInitialATXv1(t, goldenATXID)
atx := newChainedActivationTxV1(t, prevAtx, goldenATXID)

err = atxHdlr.contextuallyValidateAtx(atx)
require.ErrorIs(t, err, sql.ErrNotFound)
})

t.Run("wrong previous atx by same node", func(t *testing.T) {
t.Parallel()

atxHdlr := newV1TestHandler(t, goldenATXID)

atx0 := newInitialATXv1(t, goldenATXID)
atx0.Sign(sig)
atxHdlr.expectAtxV1(atx0, sig.NodeID())
_, err := atxHdlr.processATX(context.Background(), "", atx0, time.Now())
require.NoError(t, err)

atx1 := newChainedActivationTxV1(t, atx0, goldenATXID)
atx1.Sign(sig)
atxHdlr.expectAtxV1(atx1, sig.NodeID())
atxHdlr.mockFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any(), gomock.Any())
_, err = atxHdlr.processATX(context.Background(), "", atx1, time.Now())
require.NoError(t, err)

atxInvalidPrevious := newChainedActivationTxV1(t, atx0, goldenATXID)
atxInvalidPrevious.Sign(sig)
err = atxHdlr.contextuallyValidateAtx(atxInvalidPrevious)
require.EqualError(t, err, "last atx is not the one referenced")
})

t.Run("wrong previous atx from different node", func(t *testing.T) {
t.Parallel()

otherSig, err := signing.NewEdSigner()
require.NoError(t, err)

atxHdlr := newV1TestHandler(t, goldenATXID)

atx0 := newInitialATXv1(t, goldenATXID)
atx0.Sign(otherSig)
atxHdlr.expectAtxV1(atx0, otherSig.NodeID())
_, err = atxHdlr.processATX(context.Background(), "", atx0, time.Now())
require.NoError(t, err)

atx1 := newInitialATXv1(t, goldenATXID)
atx1.Sign(sig)
atxHdlr.expectAtxV1(atx1, sig.NodeID())
_, err = atxHdlr.processATX(context.Background(), "", atx1, time.Now())
require.NoError(t, err)

atxInvalidPrevious := newChainedActivationTxV1(t, atx0, goldenATXID)
atxInvalidPrevious.Sign(sig)
err = atxHdlr.contextuallyValidateAtx(atxInvalidPrevious)
require.EqualError(t, err, "last atx is not the one referenced")
})
}

func TestHandlerV1_StoreAtx(t *testing.T) {
goldenATXID := types.RandomATXID()

Expand Down
Loading

0 comments on commit b7fcf55

Please sign in to comment.