Skip to content

Commit

Permalink
Add publisher for legacy malfeasance proofs (#6490)
Browse files Browse the repository at this point in the history
## Motivation

Part of #6143

This PR adds a dedicated service for publishing V1 malfeasance proofs.
  • Loading branch information
fasmat committed Nov 28, 2024
1 parent f8a9646 commit fd237fc
Show file tree
Hide file tree
Showing 29 changed files with 1,000 additions and 625 deletions.
3 changes: 2 additions & 1 deletion activation/builder_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql/atxs"
"github.com/spacemeshos/go-spacemesh/sql/localsql/nipost"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestBuilder_BuildsInitialAtxV2(t *testing.T) {

atxHandler := newTestHandler(t, tab.goldenATXID, WithAtxVersions(AtxVersions{1: types.AtxV2}))
atxHandler.expectInitialAtxV2(&atx)
require.NoError(t, atxHandler.HandleGossipAtx(context.Background(), "", got))
require.NoError(t, atxHandler.HandleGossipAtx(context.Background(), p2p.NoPeer, got))
return nil
})
require.Empty(t, atx.PreviousATXs)
Expand Down
18 changes: 9 additions & 9 deletions activation/e2e/atx_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/p2p/pubsub/mocks"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql/atxs"
"github.com/spacemeshos/go-spacemesh/sql/localsql"
Expand Down Expand Up @@ -275,9 +275,9 @@ func Test_MarryAndMerge(t *testing.T) {
)
require.NoError(t, err)

mpub := mocks.NewMockPublisher(ctrl)
mFetch := smocks.NewMockFetcher(ctrl)
mBeacon := activation.NewMockAtxReceiver(ctrl)
mLegacyPublish := activation.NewMocklegacyMalfeasancePublisher(ctrl)
mBeacon := activation.NewMockatxReceiver(ctrl)
mTortoise := smocks.NewMockTortoise(ctrl)

tickSize := uint64(3)
Expand All @@ -287,10 +287,10 @@ func Test_MarryAndMerge(t *testing.T) {
atxsdata.New(),
signing.NewEdVerifier(),
clock,
mpub,
mFetch,
goldenATX,
validator,
mLegacyPublish,
mBeacon,
mTortoise,
logger,
Expand Down Expand Up @@ -358,11 +358,11 @@ func Test_MarryAndMerge(t *testing.T) {
mFetch.EXPECT().GetPoetProof(gomock.Any(), gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
return atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(mergedIdAtx))
return atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(mergedIdAtx))
})
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(marriageATX))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(marriageATX))
require.NoError(t, err)

// Verify marriage
Expand Down Expand Up @@ -422,7 +422,7 @@ func Test_MarryAndMerge(t *testing.T) {
mFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any(), gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(mergedATX))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(mergedATX))
require.NoError(t, err)

// Step 3. verify the merged ATX
Expand Down Expand Up @@ -473,7 +473,7 @@ func Test_MarryAndMerge(t *testing.T) {
mFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any(), gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(mergedATX2))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(mergedATX2))
require.NoError(t, err)

atx, err = atxs.Get(db, mergedATX2.ID())
Expand Down Expand Up @@ -511,7 +511,7 @@ func Test_MarryAndMerge(t *testing.T) {
mFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any(), gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(atx))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(atx))
require.NoError(t, err)

atxFromDb, err := atxs.Get(db, atx.ID())
Expand Down
5 changes: 3 additions & 2 deletions activation/e2e/builds_atx_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func TestBuilder_SwitchesToBuildV2(t *testing.T) {
edVerifier := signing.NewEdVerifier()
mpub := mocks.NewMockPublisher(ctrl)
mFetch := smocks.NewMockFetcher(ctrl)
mBeacon := activation.NewMockAtxReceiver(ctrl)
mLegacyPublish := activation.NewMocklegacyMalfeasancePublisher(ctrl)
mBeacon := activation.NewMockatxReceiver(ctrl)
mTortoise := smocks.NewMockTortoise(ctrl)

atxHdlr := activation.NewHandler(
Expand All @@ -127,10 +128,10 @@ func TestBuilder_SwitchesToBuildV2(t *testing.T) {
atxsdata,
edVerifier,
clock,
mpub,
mFetch,
goldenATX,
validator,
mLegacyPublish,
mBeacon,
mTortoise,
logger,
Expand Down
18 changes: 9 additions & 9 deletions activation/e2e/checkpoint_merged_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/p2p/pubsub/mocks"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql/accounts"
"github.com/spacemeshos/go-spacemesh/sql/atxs"
Expand Down Expand Up @@ -106,9 +106,9 @@ func Test_CheckpointAfterMerge(t *testing.T) {
)
require.NoError(t, err)

mpub := mocks.NewMockPublisher(ctrl)
mFetch := smocks.NewMockFetcher(ctrl)
mBeacon := activation.NewMockAtxReceiver(ctrl)
mLegacyPublish := activation.NewMocklegacyMalfeasancePublisher(ctrl)
mBeacon := activation.NewMockatxReceiver(ctrl)
mTortoise := smocks.NewMockTortoise(ctrl)

atxHdlr := activation.NewHandler(
Expand All @@ -117,10 +117,10 @@ func Test_CheckpointAfterMerge(t *testing.T) {
atxsdata.New(),
signing.NewEdVerifier(),
clock,
mpub,
mFetch,
goldenATX,
validator,
mLegacyPublish,
mBeacon,
mTortoise,
logger,
Expand Down Expand Up @@ -183,9 +183,9 @@ func Test_CheckpointAfterMerge(t *testing.T) {
mFetch.EXPECT().GetAtxs(gomock.Any(), []types.ATXID{mergedIdAtx.ID()}, gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any()).Times(2)
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any()).Times(2)
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(mergedIdAtx))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(mergedIdAtx))
require.NoError(t, err)
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(marriageATX))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(marriageATX))
require.NoError(t, err)

// Step 2. Publish merged ATX together
Expand Down Expand Up @@ -236,7 +236,7 @@ func Test_CheckpointAfterMerge(t *testing.T) {
mFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any(), gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(mergedATX))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(mergedATX))
require.NoError(t, err)

// Step 3. Checkpoint
Expand Down Expand Up @@ -296,10 +296,10 @@ func Test_CheckpointAfterMerge(t *testing.T) {
atxsdata.New(),
signing.NewEdVerifier(),
clock,
mpub,
mFetch,
goldenATX,
validator,
mLegacyPublish,
mBeacon,
mTortoise,
logger,
Expand Down Expand Up @@ -352,6 +352,6 @@ func Test_CheckpointAfterMerge(t *testing.T) {
mFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any(), gomock.Any())
mBeacon.EXPECT().OnAtx(gomock.Any())
mTortoise.EXPECT().OnAtx(gomock.Any(), gomock.Any(), gomock.Any())
err = atxHdlr.HandleGossipAtx(context.Background(), "", codec.MustEncode(mergedATX2))
err = atxHdlr.HandleGossipAtx(context.Background(), p2p.NoPeer, codec.MustEncode(mergedATX2))
require.NoError(t, err)
}
9 changes: 5 additions & 4 deletions activation/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func TestCheckpoint_PublishingSoloATXs(t *testing.T) {
atxdata := atxsdata.New()
atxVersions := activation.AtxVersions{0: types.AtxV2}
edVerifier := signing.NewEdVerifier()
mpub := mocks.NewMockPublisher(ctrl)
mFetch := smocks.NewMockFetcher(ctrl)
mBeacon := activation.NewMockAtxReceiver(ctrl)
mLegacyPublish := activation.NewMocklegacyMalfeasancePublisher(ctrl)
mBeacon := activation.NewMockatxReceiver(ctrl)
mTortoise := smocks.NewMockTortoise(ctrl)

atxHdlr := activation.NewHandler(
Expand All @@ -113,16 +113,17 @@ func TestCheckpoint_PublishingSoloATXs(t *testing.T) {
atxdata,
edVerifier,
clock,
mpub,
mFetch,
goldenATX,
validator,
mLegacyPublish,
mBeacon,
mTortoise,
logger,
activation.WithAtxVersions(atxVersions),
)

mpub := mocks.NewMockPublisher(ctrl)
tab := activation.NewBuilder(
activation.Config{GoldenATXID: goldenATX},
db,
Expand Down Expand Up @@ -202,10 +203,10 @@ func TestCheckpoint_PublishingSoloATXs(t *testing.T) {
atxdata,
edVerifier,
clock,
mpub,
mFetch,
goldenATX,
validator,
mLegacyPublish,
mBeacon,
mTortoise,
logger,
Expand Down
Loading

0 comments on commit fd237fc

Please sign in to comment.