diff --git a/activation/activation_multi_test.go b/activation/activation_multi_test.go index f6915c25e5..d74f22c704 100644 --- a/activation/activation_multi_test.go +++ b/activation/activation_multi_test.go @@ -13,6 +13,7 @@ import ( "golang.org/x/sync/errgroup" "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/pubsub" "github.com/spacemeshos/go-spacemesh/sql" @@ -409,7 +410,7 @@ func Test_Builder_Multi_HappyPath(t *testing.T) { atxChan := make(chan struct{}) atxStep := make(map[types.NodeID]chan struct{}) var atxMtx sync.Mutex - atxs := make(map[types.NodeID]types.ActivationTx) + atxs := make(map[types.NodeID]wire.ActivationTxV1) endChan := make(chan struct{}) for _, sig := range tab.signers { ch := make(chan struct{}) @@ -429,9 +430,9 @@ func Test_Builder_Multi_HappyPath(t *testing.T) { func(ctx context.Context, _ string, got []byte) error { atxMtx.Lock() defer atxMtx.Unlock() - atx, err := wire.ActivationTxFromBytes(got) - require.NoError(t, err) - atxs[atx.SmesherID] = *atx + var atx wire.ActivationTxV1 + codec.MustDecode(got, &atx) + atxs[atx.SmesherID] = atx return nil }, ) @@ -488,21 +489,21 @@ func Test_Builder_Multi_HappyPath(t *testing.T) { for _, sig := range tab.signers { atx := atxs[sig.NodeID()] - require.Equal(t, initialPost[sig.NodeID()].Nonce, atx.NIPostChallenge.InitialPost.Nonce) - require.Equal(t, initialPost[sig.NodeID()].Pow, atx.NIPostChallenge.InitialPost.Pow) - require.Equal(t, initialPost[sig.NodeID()].Indices, atx.NIPostChallenge.InitialPost.Indices) + require.Equal(t, initialPost[sig.NodeID()].Nonce, atx.InitialPost.Nonce) + require.Equal(t, initialPost[sig.NodeID()].Pow, atx.InitialPost.Pow) + require.Equal(t, initialPost[sig.NodeID()].Indices, atx.InitialPost.Indices) - require.Equal(t, initialPost[sig.NodeID()].CommitmentATX, *atx.NIPostChallenge.CommitmentATX) - require.Equal(t, postGenesisEpoch+1, atx.NIPostChallenge.PublishEpoch) - require.Equal(t, types.EmptyATXID, atx.NIPostChallenge.PrevATXID) - require.Equal(t, tab.goldenATXID, atx.NIPostChallenge.PositioningATX) - require.Equal(t, uint64(0), atx.NIPostChallenge.Sequence) + require.Equal(t, initialPost[sig.NodeID()].CommitmentATX, *atx.CommitmentATXID) + require.Equal(t, postGenesisEpoch+1, atx.PublishEpoch) + require.Equal(t, types.EmptyATXID, atx.PrevATXID) + require.Equal(t, tab.goldenATXID, atx.PositioningATXID) + require.Equal(t, uint64(0), atx.Sequence) require.Equal(t, types.Address{}, atx.Coinbase) require.Equal(t, nipostState[sig.NodeID()].NumUnits, atx.NumUnits) - require.Equal(t, nipostState[sig.NodeID()].NIPost, atx.NIPost) + require.Equal(t, nipostState[sig.NodeID()].NIPost, wire.NiPostFromWireV1(atx.NIPost)) require.Equal(t, sig.NodeID(), *atx.NodeID) - require.Equal(t, nipostState[sig.NodeID()].VRFNonce, *atx.VRFNonce) + require.Equal(t, uint64(nipostState[sig.NodeID()].VRFNonce), *atx.VRFNonce) } // stop smeshing diff --git a/activation/activation_test.go b/activation/activation_test.go index 571235e2ed..9cbdbed59b 100644 --- a/activation/activation_test.go +++ b/activation/activation_test.go @@ -21,6 +21,7 @@ import ( "golang.org/x/sync/errgroup" "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/events" "github.com/spacemeshos/go-spacemesh/p2p/pubsub" @@ -51,11 +52,10 @@ func TestMain(m *testing.M) { func newAtx( challenge types.NIPostChallenge, - nipost *types.NIPost, numUnits uint32, coinbase types.Address, ) *types.ActivationTx { - atx := types.NewActivationTx(challenge, coinbase, nipost, numUnits, nil) + atx := types.NewActivationTx(challenge, coinbase, numUnits, nil) atx.SetEffectiveNumUnits(numUnits) atx.SetReceived(time.Now()) atx.SetValidity(types.Valid) @@ -353,8 +353,7 @@ func TestBuilder_PublishActivationTx_HappyFlow(t *testing.T) { PositioningATX: tab.goldenATXID, CommitmentATX: &tab.goldenATXID, } - nipostData := newNIPostWithPoet(t, []byte("66666")) - prevAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) + prevAtx := newAtx(ch, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -396,8 +395,7 @@ func TestBuilder_Loop_WaitsOnStaleChallenge(t *testing.T) { PositioningATX: tab.goldenATXID, CommitmentATX: &tab.goldenATXID, } - nipostData := newNIPostWithPoet(t, []byte("66666")) - prevAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) + prevAtx := newAtx(ch, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -454,8 +452,7 @@ func TestBuilder_PublishActivationTx_FaultyNet(t *testing.T) { PositioningATX: tab.goldenATXID, CommitmentATX: &tab.goldenATXID, } - nipostData := newNIPostWithPoet(t, []byte("66666")) - prevAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) + prevAtx := newAtx(ch, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -543,8 +540,7 @@ func TestBuilder_PublishActivationTx_UsesExistingChallengeOnLatePublish(t *testi PositioningATX: types.ATXID{1, 2, 3}, CommitmentATX: nil, } - nipostData := newNIPostWithPoet(t, []byte("66666")) - prevAtx := newAtx(challenge, nipostData.NIPost, posEpoch.Uint32(), types.Address{}) + prevAtx := newAtx(challenge, posEpoch.Uint32(), types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -628,8 +624,7 @@ func TestBuilder_PublishActivationTx_RebuildNIPostWhenTargetEpochPassed(t *testi PositioningATX: types.ATXID{1, 2, 3}, CommitmentATX: nil, } - nipostData := newNIPostWithPoet(t, []byte("66666")) - prevAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) + prevAtx := newAtx(ch, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -700,7 +695,7 @@ func TestBuilder_PublishActivationTx_RebuildNIPostWhenTargetEpochPassed(t *testi PositioningATX: types.ATXID{1, 2, 3}, CommitmentATX: nil, } - posAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) + posAtx := newAtx(ch, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, posAtx)) vPosAtx, err := posAtx.Verify(0, 1) require.NoError(t, err) @@ -731,10 +726,9 @@ func TestBuilder_PublishActivationTx_NoPrevATX(t *testing.T) { PositioningATX: types.ATXID{1, 2, 3}, CommitmentATX: nil, } - nipostData := newNIPostWithPoet(t, []byte("66666")) otherSigner, err := signing.NewEdSigner() require.NoError(t, err) - posAtx := newAtx(challenge, nipostData.NIPost, 2, types.Address{}) + posAtx := newAtx(challenge, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(otherSigner, posAtx)) vPosAtx, err := posAtx.Verify(0, 1) require.NoError(t, err) @@ -786,10 +780,9 @@ func TestBuilder_PublishActivationTx_NoPrevATX_PublishFails_InitialPost_preserve PositioningATX: types.ATXID{1, 2, 3}, CommitmentATX: nil, } - nipostData := newNIPostWithPoet(t, []byte("66666")) otherSigner, err := signing.NewEdSigner() require.NoError(t, err) - posAtx := newAtx(challenge, nipostData.NIPost, 2, types.Address{}) + posAtx := newAtx(challenge, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(otherSigner, posAtx)) vPosAtx, err := posAtx.Verify(0, 1) require.NoError(t, err) @@ -894,8 +887,7 @@ func TestBuilder_PublishActivationTx_PrevATXWithoutPrevATX(t *testing.T) { CommitmentATX: &tab.goldenATXID, } poetBytes := []byte("66666") - nipostData := newNIPostWithPoet(t, poetBytes) - posAtx := newAtx(challenge, nipostData.NIPost, 2, types.Address{}) + posAtx := newAtx(challenge, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(otherSigner, posAtx)) vPosAtx, err := posAtx.Verify(0, 2) r.NoError(err) @@ -909,7 +901,7 @@ func TestBuilder_PublishActivationTx_PrevATXWithoutPrevATX(t *testing.T) { CommitmentATX: nil, } challenge.InitialPost = initialPost - prevAtx := newAtx(challenge, nipostData.NIPost, 2, types.Address{}) + prevAtx := newAtx(challenge, 2, types.Address{}) prevAtx.InitialPost = initialPost require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) @@ -956,31 +948,22 @@ func TestBuilder_PublishActivationTx_PrevATXWithoutPrevATX(t *testing.T) { tab.mpub.EXPECT(). Publish(gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn(func(ctx context.Context, _ string, msg []byte) error { - atx, err := wire.ActivationTxFromBytes(msg) - require.NoError(t, err) - atx.SetReceived(time.Now().Local()) - - atx.SetEffectiveNumUnits(atx.NumUnits) - vAtx, err := atx.Verify(0, 1) - r.NoError(err) - r.Equal(sig.NodeID(), vAtx.SmesherID) - - r.NoError(atxs.Add(tab.db, vAtx)) + var atx wire.ActivationTxV1 + codec.MustDecode(msg, &atx) + r.Equal(sig.NodeID(), atx.SmesherID) r.Equal(prevAtx.Sequence+1, atx.Sequence) r.Equal(prevAtx.ID(), atx.PrevATXID) r.Nil(atx.InitialPost) - r.Nil(atx.CommitmentATX) + r.Nil(atx.CommitmentATXID) r.Nil(atx.VRFNonce) - - r.Equal(posAtx.ID(), atx.PositioningATX) + r.Equal(posAtx.ID(), atx.PositioningATXID) r.Equal(postAtxPubEpoch+1, atx.PublishEpoch) - r.Equal(types.BytesToHash(poetBytes), atx.GetPoetProofRef()) - + r.Equal(poetBytes, atx.NIPost.PostMetadata.Challenge) return nil }) - tab.mnipost.EXPECT().ResetState(sig.NodeID()).Return(nil) + tab.mnipost.EXPECT().ResetState(sig.NodeID()) r.NoError(tab.PublishActivationTx(context.Background(), sig)) @@ -1009,8 +992,7 @@ func TestBuilder_PublishActivationTx_TargetsEpochBasedOnPosAtx(t *testing.T) { CommitmentATX: &types.ATXID{4, 5, 6}, } poetBytes := []byte("66666") - nipostData := newNIPostWithPoet(t, poetBytes) - posAtx := newAtx(challenge, nipostData.NIPost, 2, types.Address{}) + posAtx := newAtx(challenge, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(otherSigner, posAtx)) vPosAtx, err := posAtx.Verify(0, 1) r.NoError(err) @@ -1055,24 +1037,16 @@ func TestBuilder_PublishActivationTx_TargetsEpochBasedOnPosAtx(t *testing.T) { tab.mpub.EXPECT(). Publish(gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn(func(ctx context.Context, _ string, msg []byte) error { - atx, err := wire.ActivationTxFromBytes(msg) - require.NoError(t, err) - atx.SetReceived(time.Now().Local()) - - atx.SetEffectiveNumUnits(atx.NumUnits) - vAtx, err := atx.Verify(0, 1) - r.NoError(err) - r.Equal(sig.NodeID(), vAtx.SmesherID) - - r.NoError(atxs.Add(tab.db, vAtx)) + var atx wire.ActivationTxV1 + codec.MustDecode(msg, &atx) + r.Equal(sig.NodeID(), atx.SmesherID) r.Zero(atx.Sequence) r.Equal(types.EmptyATXID, atx.PrevATXID) r.NotNil(atx.InitialPost) - - r.Equal(posAtx.ID(), atx.PositioningATX) + r.Equal(posAtx.ID(), atx.PositioningATXID) r.Equal(posEpoch+1, atx.PublishEpoch) - r.Equal(types.BytesToHash(poetBytes), atx.GetPoetProofRef()) + r.Equal(poetBytes, atx.NIPost.PostMetadata.Challenge) return nil }) @@ -1120,8 +1094,7 @@ func TestBuilder_PublishActivationTx_FailsWhenNIPostBuilderFails(t *testing.T) { PositioningATX: types.ATXID{1, 2, 3}, CommitmentATX: nil, } - nipostData := newNIPostWithPoet(t, []byte("66666")) - posAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) + posAtx := newAtx(ch, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, posAtx)) vPosAtx, err := posAtx.Verify(0, 1) require.NoError(t, err) @@ -1157,8 +1130,7 @@ func TestBuilder_SignAtx(t *testing.T) { PositioningATX: prevAtx, CommitmentATX: nil, } - nipost := newNIPostWithPoet(t, []byte("66666")) - atx := newAtx(challenge, nipost.NIPost, 100, types.Address{}) + atx := newAtx(challenge, 100, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, atx)) msg := wire.ActivationTxToWireV1(atx).SignedBytes() @@ -1196,8 +1168,7 @@ func TestBuilder_RetryPublishActivationTx(t *testing.T) { CommitmentATX: nil, } poetBytes := []byte("66666") - nipostData := newNIPostWithPoet(t, poetBytes) - prevAtx := newAtx(challenge, nipostData.NIPost, 2, types.Address{}) + prevAtx := newAtx(challenge, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -1354,9 +1325,7 @@ func TestBuilder_InitialProofGeneratedOnce(t *testing.T) { PositioningATX: tab.goldenATXID, CommitmentATX: &tab.goldenATXID, } - poetByte := []byte("66666") - nipost := newNIPostWithPoet(t, poetByte) - prevAtx := newAtx(challenge, nipost.NIPost, 2, types.Address{}) + prevAtx := newAtx(challenge, 2, types.Address{}) require.NoError(t, SignAndFinalizeAtx(sig, prevAtx)) vPrevAtx, err := prevAtx.Verify(0, 1) require.NoError(t, err) @@ -1375,7 +1344,6 @@ func TestBuilder_InitialProofGeneratedOnce(t *testing.T) { require.Nil(t, atx.VRFNonce) require.Equal(t, vPrevAtx.ID(), atx.PositioningATX) require.Equal(t, vPrevAtx.PublishEpoch+1, atx.PublishEpoch) - require.Equal(t, types.BytesToHash(poetByte), atx.GetPoetProofRef()) // postClient.Proof() should not be called again require.NoError(t, tab.buildInitialPost(context.Background(), sig.NodeID())) @@ -1579,28 +1547,21 @@ func TestGetPositioningAtxPicksAtxWithValidChain(t *testing.T) { // Invalid chain with high height sigInvalid, err := signing.NewEdSigner() require.NoError(t, err) - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: tab.goldenATXID, - CommitmentATX: &tab.goldenATXID, - } - nipostData := newNIPostWithPoet(t, []byte("0")) - invalidAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(sigInvalid, invalidAtx)) - vInvalidAtx, err := invalidAtx.Verify(0, 100) + invalidAtx := newInitialATXv1(t, tab.goldenATXID) + invalidAtx.Sign(sigInvalid) + vInvalidAtx := toVerifiedAtx(t, invalidAtx) + vInvalidAtx, err = vInvalidAtx.Verify(0, 100) require.NoError(t, err) require.NoError(t, atxs.Add(tab.db, vInvalidAtx)) // Valid chain with lower height sigValid, err := signing.NewEdSigner() require.NoError(t, err) - nipostData = newNIPostWithPoet(t, []byte("1")) - validAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(sigValid, validAtx)) - vValidAtx, err := validAtx.Verify(0, 1) - require.NoError(t, err) + validAtx := newInitialATXv1(t, tab.goldenATXID) + validAtx.NumUnits += 10 + validAtx.Sign(sigValid) + vValidAtx := toVerifiedAtx(t, validAtx) + vValidAtx.Verify(0, 1) require.NoError(t, atxs.Add(tab.db, vValidAtx)) tab.mValidator.EXPECT(). diff --git a/activation/e2e/activation_test.go b/activation/e2e/activation_test.go index dc66a2211a..3fe74461ce 100644 --- a/activation/e2e/activation_test.go +++ b/activation/e2e/activation_test.go @@ -16,6 +16,7 @@ import ( "github.com/spacemeshos/go-spacemesh/activation" "github.com/spacemeshos/go-spacemesh/activation/wire" "github.com/spacemeshos/go-spacemesh/api/grpcserver" + "github.com/spacemeshos/go-spacemesh/codec" "github.com/spacemeshos/go-spacemesh/common/types" "github.com/spacemeshos/go-spacemesh/datastore" "github.com/spacemeshos/go-spacemesh/log" @@ -136,16 +137,17 @@ func Test_BuilderWithMultipleClients(t *testing.T) { } var atxMtx sync.Mutex - atxs := make(map[types.NodeID]types.ActivationTx) + atxs := make(map[types.NodeID]wire.ActivationTxV1) endChan := make(chan struct{}) mpub := mocks.NewMockPublisher(ctrl) mpub.EXPECT().Publish(gomock.Any(), pubsub.AtxProtocol, gomock.Any()).DoAndReturn( func(ctx context.Context, topic string, got []byte) error { atxMtx.Lock() defer atxMtx.Unlock() - gotAtx, err := wire.ActivationTxFromBytes(got) - require.NoError(t, err) - atxs[gotAtx.SmesherID] = *gotAtx + + var gotAtx wire.ActivationTxV1 + codec.MustDecode(got, &gotAtx) + atxs[gotAtx.SmesherID] = gotAtx if len(atxs) == numSigners { close(endChan) } @@ -194,9 +196,9 @@ func Test_BuilderWithMultipleClients(t *testing.T) { _, err = v.NIPost( context.Background(), sig.NodeID(), - *atx.CommitmentATX, - atx.NIPost, - wire.NIPostChallengeToWireV1(&atx.NIPostChallenge).Hash(), + *atx.CommitmentATXID, + wire.NiPostFromWireV1(atx.NIPost), + atx.NIPostChallengeV1.Hash(), atx.NumUnits, ) require.NoError(t, err) @@ -204,17 +206,17 @@ func Test_BuilderWithMultipleClients(t *testing.T) { require.NotNil(t, atx.VRFNonce) err := v.VRFNonce( sig.NodeID(), - *atx.CommitmentATX, + *atx.CommitmentATXID, uint64(*atx.VRFNonce), atx.NIPost.PostMetadata.LabelsPerUnit, atx.NumUnits, ) require.NoError(t, err) - require.Equal(t, postGenesisEpoch, atx.TargetEpoch()) - require.Equal(t, types.EmptyATXID, atx.NIPostChallenge.PrevATXID) - require.Equal(t, goldenATX, atx.NIPostChallenge.PositioningATX) - require.Equal(t, uint64(0), atx.NIPostChallenge.Sequence) + require.Equal(t, postGenesisEpoch, atx.PublishEpoch+1) + require.Equal(t, types.EmptyATXID, atx.PrevATXID) + require.Equal(t, goldenATX, atx.PositioningATXID) + require.Equal(t, uint64(0), atx.Sequence) require.Equal(t, types.Address{}, atx.Coinbase) require.Equal(t, sig.NodeID(), *atx.NodeID) diff --git a/activation/post_test.go b/activation/post_test.go index d1abc3d1e6..abc9323195 100644 --- a/activation/post_test.go +++ b/activation/post_test.go @@ -276,7 +276,7 @@ func TestPostSetupManager_findCommitmentAtx_UsesLatestAtx(t *testing.T) { challenge := types.NIPostChallenge{ PublishEpoch: 1, } - atx := types.NewActivationTx(challenge, types.Address{}, nil, 2, nil) + atx := types.NewActivationTx(challenge, types.Address{}, 2, nil) require.NoError(t, SignAndFinalizeAtx(signer, atx)) atx.SetEffectiveNumUnits(atx.NumUnits) atx.SetReceived(time.Now()) @@ -322,7 +322,7 @@ func TestPostSetupManager_getCommitmentAtx_getsCommitmentAtxFromInitialAtx(t *te // add an atx by the same node commitmentAtx := types.RandomATXID() - atx := types.NewActivationTx(types.NIPostChallenge{}, types.Address{}, nil, 1, nil) + atx := types.NewActivationTx(types.NIPostChallenge{}, types.Address{}, 1, nil) atx.CommitmentATX = &commitmentAtx require.NoError(t, SignAndFinalizeAtx(signer, atx)) atx.SetEffectiveNumUnits(atx.NumUnits) diff --git a/activation/validation.go b/activation/validation.go index 402910cb3f..7580489c6b 100644 --- a/activation/validation.go +++ b/activation/validation.go @@ -15,6 +15,7 @@ import ( "github.com/spacemeshos/go-spacemesh/activation/metrics" "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/sql" "github.com/spacemeshos/go-spacemesh/sql/atxs" @@ -364,6 +365,20 @@ func (v *Validator) VerifyChain(ctx context.Context, id, goldenATXID types.ATXID return v.verifyChainWithOpts(ctx, id, goldenATXID, options) } +func (v *Validator) getNipost(ctx context.Context, id types.ATXID) (*types.NIPost, error) { + var blob sql.Blob + if err := atxs.LoadBlob(ctx, v.db, id.Bytes(), &blob); err != nil { + return nil, fmt.Errorf("getting blob for %s: %w", id, err) + } + + // TODO: decide about version based on publish epoch + var atx wire.ActivationTxV1 + if err := codec.Decode(blob.Bytes, &atx); err != nil { + return nil, fmt.Errorf("decoding ATX blob: %w", err) + } + return wire.NiPostFromWireV1(atx.NIPost), nil +} + func (v *Validator) verifyChainWithOpts( ctx context.Context, id, goldenATXID types.ATXID, @@ -405,12 +420,16 @@ func (v *Validator) verifyChainWithOpts( commitmentAtxId = &atxId } } + nipost, err := v.getNipost(ctx, id) + if err != nil { + return fmt.Errorf("getting NIPost for ATX %s: %w", id, err) + } if err := v.Post( ctx, atx.SmesherID, *commitmentAtxId, - atx.NIPost.Post, - atx.NIPost.PostMetadata, + nipost.Post, + nipost.PostMetadata, atx.NumUnits, ); err != nil { if err := atxs.SetValidity(v.db, id, types.Invalid); err != nil { diff --git a/activation/validation_test.go b/activation/validation_test.go index 0cc2430576..168147dc2b 100644 --- a/activation/validation_test.go +++ b/activation/validation_test.go @@ -541,40 +541,21 @@ func TestVerifyChainDeps(t *testing.T) { signer, err := signing.NewEdSigner() require.NoError(t, err) - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: goldenATXID, - CommitmentATX: &goldenATXID, - } - nipostData := newNIPostWithPoet(t, []byte("00")) - invalidAtx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, invalidAtx)) - vInvalidAtx, err := invalidAtx.Verify(0, 1) - require.NoError(t, err) + invalidAtx := newInitialATXv1(t, goldenATXID) + invalidAtx.Sign(signer) + vInvalidAtx := toVerifiedAtx(t, invalidAtx) vInvalidAtx.SetValidity(types.Invalid) require.NoError(t, atxs.Add(db, vInvalidAtx)) t.Run("invalid prev ATX", func(t *testing.T) { - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: vInvalidAtx.ID(), - PublishEpoch: postGenesisEpoch, - PositioningATX: goldenATXID, - CommitmentATX: nil, - } - nipostData = newNIPostWithPoet(t, []byte("01")) - atx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, atx)) - vAtx, err := atx.Verify(0, 1) - require.NoError(t, err) - vAtx.SetValidity(types.Unknown) + atx := newChainedActivationTxV1(t, goldenATXID, invalidAtx, goldenATXID) + atx.Sign(signer) + vAtx := toVerifiedAtx(t, atx) require.NoError(t, atxs.Add(db, vAtx)) ctrl := gomock.NewController(t) v := NewMockPostVerifier(ctrl) - v.EXPECT().Verify(ctx, (*shared.Proof)(atx.NIPost.Post), gomock.Any(), gomock.Any()) + v.EXPECT().Verify(ctx, gomock.Any(), gomock.Any(), gomock.Any()) validator := NewValidator(db, nil, DefaultPostConfig(), config.ScryptParams{}, v) err = validator.VerifyChain(ctx, vAtx.ID(), goldenATXID) @@ -582,19 +563,9 @@ func TestVerifyChainDeps(t *testing.T) { }) t.Run("invalid pos ATX", func(t *testing.T) { - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: vInvalidAtx.ID(), - CommitmentATX: nil, - } - nipostData = newNIPostWithPoet(t, []byte("02")) - atx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, atx)) - vAtx, err := atx.Verify(0, 1) - require.NoError(t, err) - vAtx.SetValidity(types.Unknown) + atx := newInitialATXv1(t, invalidAtx.ID()) + atx.Sign(signer) + vAtx := toVerifiedAtx(t, atx) require.NoError(t, atxs.Add(db, vAtx)) ctrl := gomock.NewController(t) @@ -608,19 +579,10 @@ func TestVerifyChainDeps(t *testing.T) { t.Run("invalid commitment ATX", func(t *testing.T) { commitmentAtxID := vInvalidAtx.ID() - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: goldenATXID, - CommitmentATX: &commitmentAtxID, - } - nipostData = newNIPostWithPoet(t, []byte("03")) - atx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, atx)) - vAtx, err := atx.Verify(0, 1) - require.NoError(t, err) - vAtx.SetValidity(types.Unknown) + atx := newInitialATXv1(t, goldenATXID) + atx.Sign(signer) + atx.CommitmentATXID = &commitmentAtxID + vAtx := toVerifiedAtx(t, atx) require.NoError(t, atxs.Add(db, vAtx)) ctrl := gomock.NewController(t) @@ -632,19 +594,9 @@ func TestVerifyChainDeps(t *testing.T) { }) t.Run("with trusted node ID", func(t *testing.T) { - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: vInvalidAtx.ID(), - CommitmentATX: nil, - } - nipostData = newNIPostWithPoet(t, []byte("04")) - atx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, atx)) - vAtx, err := atx.Verify(0, 1) - require.NoError(t, err) - vAtx.SetValidity(types.Unknown) + atx := newInitialATXv1(t, invalidAtx.ID()) + atx.Sign(signer) + vAtx := toVerifiedAtx(t, atx) require.NoError(t, atxs.Add(db, vAtx)) ctrl := gomock.NewController(t) @@ -655,19 +607,9 @@ func TestVerifyChainDeps(t *testing.T) { }) t.Run("assume valid if older than X", func(t *testing.T) { - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: vInvalidAtx.ID(), - CommitmentATX: nil, - } - nipostData = newNIPostWithPoet(t, []byte("05")) - atx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, atx)) - vAtx, err := atx.Verify(0, 1) - require.NoError(t, err) - vAtx.SetValidity(types.Unknown) + atx := newInitialATXv1(t, invalidAtx.ID()) + atx.Sign(signer) + vAtx := toVerifiedAtx(t, atx) require.NoError(t, atxs.Add(db, vAtx)) ctrl := gomock.NewController(t) @@ -679,19 +621,9 @@ func TestVerifyChainDeps(t *testing.T) { }) t.Run("invalid top-level", func(t *testing.T) { - ch := types.NIPostChallenge{ - Sequence: 1, - PrevATXID: types.EmptyATXID, - PublishEpoch: postGenesisEpoch, - PositioningATX: vInvalidAtx.ID(), - CommitmentATX: nil, - } - nipostData = newNIPostWithPoet(t, []byte("06")) - atx := newAtx(ch, nipostData.NIPost, 2, types.Address{}) - require.NoError(t, SignAndFinalizeAtx(signer, atx)) - vAtx, err := atx.Verify(0, 1) - require.NoError(t, err) - vAtx.SetValidity(types.Unknown) + atx := newInitialATXv1(t, goldenATXID) + atx.Sign(signer) + vAtx := toVerifiedAtx(t, atx) require.NoError(t, atxs.Add(db, vAtx)) ctrl := gomock.NewController(t) diff --git a/activation/wire/wire_v1.go b/activation/wire/wire_v1.go index 907b2958b2..3d96f7fba5 100644 --- a/activation/wire/wire_v1.go +++ b/activation/wire/wire_v1.go @@ -155,8 +155,6 @@ func ActivationTxToWireV1(a *types.ActivationTx) *ActivationTxV1 { NIPostChallengeV1: *NIPostChallengeToWireV1(&a.NIPostChallenge), Coinbase: a.Coinbase, NumUnits: a.NumUnits, - NIPost: NiPostToWireV1(a.NIPost), - NodeID: a.NodeID, VRFNonce: (*uint64)(a.VRFNonce), }, SmesherID: a.SmesherID, @@ -189,8 +187,6 @@ func ActivationTxFromWireV1(atx *ActivationTxV1, blob ...byte) *types.Activation }, Coinbase: atx.Coinbase, NumUnits: atx.NumUnits, - NIPost: NiPostFromWireV1(atx.NIPost), - NodeID: atx.NodeID, VRFNonce: (*types.VRFPostIndex)(atx.VRFNonce), }, SmesherID: atx.SmesherID, diff --git a/api/grpcserver/admin_service_test.go b/api/grpcserver/admin_service_test.go index 94ea801c76..5685a45dc1 100644 --- a/api/grpcserver/admin_service_test.go +++ b/api/grpcserver/admin_service_test.go @@ -35,7 +35,6 @@ func newAtx(tb testing.TB, db *sql.Database) { vrfNonce := types.VRFPostIndex(11) atx.VRFNonce = &vrfNonce atx.SmesherID = types.BytesToNodeID(types.RandomBytes(20)) - atx.NodeID = &atx.SmesherID atx.SetEffectiveNumUnits(atx.NumUnits) atx.SetReceived(time.Now().Local()) vatx, err := atx.Verify(1111, 12) diff --git a/api/grpcserver/grpcserver_test.go b/api/grpcserver/grpcserver_test.go index f88057793d..0515f8c968 100644 --- a/api/grpcserver/grpcserver_test.go +++ b/api/grpcserver/grpcserver_test.go @@ -18,8 +18,6 @@ import ( "github.com/libp2p/go-libp2p/core/network" ma "github.com/multiformats/go-multiaddr" pb "github.com/spacemeshos/api/release/go/spacemesh/v1" - "github.com/spacemeshos/merkle-tree" - "github.com/spacemeshos/poet/shared" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -88,9 +86,6 @@ var ( addr2 types.Address rewardSmesherID = types.RandomNodeID() prevAtxID = types.ATXID(types.HexToHash32("44444")) - chlng = types.HexToHash32("55555") - poetRef = []byte("66666") - nipost = newNIPostWithChallenge(&chlng, poetRef) challenge = newChallenge(1, prevAtxID, prevAtxID, postGenesisEpoch) globalAtx *types.VerifiedActivationTx globalAtx2 *types.VerifiedActivationTx @@ -168,7 +163,7 @@ func TestMain(m *testing.M) { addr1 = wallet.Address(signer1.PublicKey().Bytes()) addr2 = wallet.Address(signer2.PublicKey().Bytes()) - atx := types.NewActivationTx(challenge, addr1, nipost, numUnits, nil) + atx := types.NewActivationTx(challenge, addr1, numUnits, nil) atx.SetEffectiveNumUnits(numUnits) atx.SetReceived(time.Now()) if err := activation.SignAndFinalizeAtx(signer, atx); err != nil { @@ -181,7 +176,7 @@ func TestMain(m *testing.M) { os.Exit(1) } - atx2 := types.NewActivationTx(challenge, addr2, nipost, numUnits, nil) + atx2 := types.NewActivationTx(challenge, addr2, numUnits, nil) atx2.SetEffectiveNumUnits(numUnits) atx2.SetReceived(time.Now()) if err := activation.SignAndFinalizeAtx(signer, atx2); err != nil { @@ -215,37 +210,6 @@ func TestMain(m *testing.M) { os.Exit(res) } -func newNIPostWithChallenge(challenge *types.Hash32, poetRef []byte) *types.NIPost { - tree, err := merkle.NewTreeBuilder(). - WithHashFunc(shared.HashMembershipTreeNode). - WithLeavesToProve(map[uint64]bool{0: true}). - Build() - if err != nil { - panic("failed to add leaf to tree") - } - if err := tree.AddLeaf(challenge[:]); err != nil { - panic("failed to add leaf to tree") - } - nodes := tree.Proof() - nodesH32 := make([]types.Hash32, 0, len(nodes)) - for _, n := range nodes { - nodesH32 = append(nodesH32, types.BytesToHash(n)) - } - return &types.NIPost{ - Membership: types.MerkleProof{ - Nodes: nodesH32, - }, - Post: &types.Post{ - Nonce: 0, - Indices: []byte(nil), - }, - PostMetadata: &types.PostMetadata{ - Challenge: poetRef, - LabelsPerUnit: labelsPerUnit, - }, - } -} - type MeshAPIMock struct{} // latest layer received. diff --git a/api/grpcserver/v2alpha1/activation_test.go b/api/grpcserver/v2alpha1/activation_test.go index 759e95674f..63ced36cd5 100644 --- a/api/grpcserver/v2alpha1/activation_test.go +++ b/api/grpcserver/v2alpha1/activation_test.go @@ -169,7 +169,7 @@ func TestActivationStreamService_Stream(t *testing.T) { { desc: "NodeID", request: &spacemeshv2alpha1.ActivationStreamRequest{ - NodeId: streamed[3].NodeID.Bytes(), + NodeId: streamed[3].SmesherID.Bytes(), StartEpoch: start, Watch: true, }, diff --git a/beacon/beacon_test.go b/beacon/beacon_test.go index 73ac367dab..484299e93e 100644 --- a/beacon/beacon_test.go +++ b/beacon/beacon_test.go @@ -118,16 +118,13 @@ func createATX( nonce := types.VRFPostIndex(1) atx := types.NewActivationTx( types.NIPostChallenge{PublishEpoch: lid.GetEpoch()}, - types.Address{}, - nil, + types.GenerateAddress(types.RandomBytes(types.AddressLength)), numUnits, &nonce, ) atx.SetEffectiveNumUnits(numUnits) atx.SetReceived(received) - nodeID := sig.NodeID() - atx.NodeID = &nodeID require.NoError(tb, activation.SignAndFinalizeAtx(sig, atx)) vAtx, err := atx.Verify(0, 1) require.NoError(tb, err) diff --git a/blocks/generator_test.go b/blocks/generator_test.go index 9c69ceb9b0..54c7421696 100644 --- a/blocks/generator_test.go +++ b/blocks/generator_test.go @@ -158,7 +158,6 @@ func createModifiedATXs( atx := types.NewActivationTx( types.NIPostChallenge{PublishEpoch: lid.GetEpoch()}, address, - nil, numUnit, nil, ) diff --git a/checkpoint/recovery_test.go b/checkpoint/recovery_test.go index 76631a1a22..f23bebe022 100644 --- a/checkpoint/recovery_test.go +++ b/checkpoint/recovery_test.go @@ -286,7 +286,7 @@ func validateAndPreserveData( mvalidator.EXPECT().PositioningAtx(vatx.PositioningATX, cdb, goldenAtx, vatx.PublishEpoch) mvalidator.EXPECT(). - NIPost(gomock.Any(), vatx.SmesherID, gomock.Any(), vatx.NIPost, gomock.Any(), vatx.NumUnits, gomock.Any()). + NIPost(gomock.Any(), vatx.SmesherID, gomock.Any(), gomock.Any(), gomock.Any(), vatx.NumUnits, gomock.Any()). Return(uint64(1111111), nil) mvalidator.EXPECT().IsVerifyingFullPost().AnyTimes().Return(true) mreceiver.EXPECT().OnAtx(gomock.Any()) diff --git a/checkpoint/runner_test.go b/checkpoint/runner_test.go index adc3dea595..465419ac1b 100644 --- a/checkpoint/runner_test.go +++ b/checkpoint/runner_test.go @@ -208,11 +208,6 @@ func newAtx( CommitmentATX: commitAtx, PrevATXID: prevID, }, - NIPost: &types.NIPost{ - PostMetadata: &types.PostMetadata{ - Challenge: types.RandomBytes(5), - }, - }, NumUnits: 2, Coinbase: types.Address{1, 2, 3}, }, diff --git a/common/fixture/atxs.go b/common/fixture/atxs.go index 727428d5f4..d5a16ff040 100644 --- a/common/fixture/atxs.go +++ b/common/fixture/atxs.go @@ -4,9 +4,6 @@ import ( "math/rand" "time" - "github.com/spacemeshos/merkle-tree" - "github.com/spacemeshos/poet/shared" - "github.com/spacemeshos/go-spacemesh/common/types" "github.com/spacemeshos/go-spacemesh/genvm/sdk/wallet" "github.com/spacemeshos/go-spacemesh/signing" @@ -43,39 +40,6 @@ func (g *AtxsGenerator) WithEpochs(start, n int) *AtxsGenerator { return g } -func (g *AtxsGenerator) newNIPost() *types.NIPost { - challenge := types.HexToHash32("55555") - poetRef := []byte("66666") - tree, err := merkle.NewTreeBuilder(). - WithHashFunc(shared.HashMembershipTreeNode). - WithLeavesToProve(map[uint64]bool{0: true}). - Build() - if err != nil { - panic("failed to add leaf to tree") - } - if err := tree.AddLeaf(challenge[:]); err != nil { - panic("failed to add leaf to tree") - } - nodes := tree.Proof() - nodesH32 := make([]types.Hash32, 0, len(nodes)) - for _, n := range nodes { - nodesH32 = append(nodesH32, types.BytesToHash(n)) - } - return &types.NIPost{ - Membership: types.MerkleProof{ - Nodes: nodesH32, - }, - Post: &types.Post{ - Nonce: 0, - Indices: []byte(nil), - }, - PostMetadata: &types.PostMetadata{ - Challenge: poetRef, - LabelsPerUnit: 2048, - }, - } -} - // Next generates VerifiedActivationTx. func (g *AtxsGenerator) Next() *types.VerifiedActivationTx { var atx types.VerifiedActivationTx @@ -103,8 +67,6 @@ func (g *AtxsGenerator) Next() *types.VerifiedActivationTx { }, Coinbase: wallet.Address(signer.PublicKey().Bytes()), NumUnits: g.rng.Uint32(), - NodeID: &nodeId, - NIPost: g.newNIPost(), }, SmesherID: nodeId, }, diff --git a/common/types/activation.go b/common/types/activation.go index 2d4e889a4e..06d7ff14a0 100644 --- a/common/types/activation.go +++ b/common/types/activation.go @@ -134,8 +134,6 @@ type InnerActivationTx struct { Coinbase Address NumUnits uint32 - NIPost *NIPost - NodeID *NodeID VRFNonce *VRFPostIndex // the following fields are kept private and from being serialized @@ -183,7 +181,6 @@ type ActivationTx struct { func NewActivationTx( challenge NIPostChallenge, coinbase Address, - nipost *NIPost, numUnits uint32, nonce *VRFPostIndex, ) *ActivationTx { @@ -192,9 +189,7 @@ func NewActivationTx( NIPostChallenge: challenge, Coinbase: coinbase, NumUnits: numUnits, - - NIPost: nipost, - VRFNonce: nonce, + VRFNonce: nonce, }, } return atx @@ -240,11 +235,6 @@ func (atx *ActivationTx) MarshalLogObject(encoder log.ObjectEncoder) error { return nil } -// GetPoetProofRef returns the reference to the PoET proof. -func (atx *ActivationTx) GetPoetProofRef() Hash32 { - return BytesToHash(atx.NIPost.PostMetadata.Challenge) -} - // ShortString returns the first 5 characters of the ID, for logging purposes. func (atx *ActivationTx) ShortString() string { return atx.ID().ShortString() diff --git a/fetch/mesh_data_test.go b/fetch/mesh_data_test.go index 0c05129bd4..c414ed5d44 100644 --- a/fetch/mesh_data_test.go +++ b/fetch/mesh_data_test.go @@ -450,7 +450,6 @@ func genATXs(tb testing.TB, num uint32) []*types.ActivationTx { atx := types.NewActivationTx( types.NIPostChallenge{}, types.Address{1, 2, 3}, - nil, i, nil, ) diff --git a/malfeasance/handler_test.go b/malfeasance/handler_test.go index 095f53f75a..e1d1b9a65b 100644 --- a/malfeasance/handler_test.go +++ b/malfeasance/handler_test.go @@ -37,7 +37,7 @@ func createIdentity(t *testing.T, db *sql.Database, sig *signing.EdSigner) { challenge := types.NIPostChallenge{ PublishEpoch: types.EpochID(1), } - atx := types.NewActivationTx(challenge, types.Address{}, nil, 1, nil) + atx := types.NewActivationTx(challenge, types.Address{}, 1, nil) require.NoError(t, activation.SignAndFinalizeAtx(sig, atx)) atx.SetEffectiveNumUnits(atx.NumUnits) atx.SetReceived(time.Now()) diff --git a/malfeasance/wire/malfeasance_test.go b/malfeasance/wire/malfeasance_test.go index 70cc942613..94cc0d752b 100644 --- a/malfeasance/wire/malfeasance_test.go +++ b/malfeasance/wire/malfeasance_test.go @@ -23,8 +23,8 @@ func TestMain(m *testing.M) { func TestCodec_MultipleATXs(t *testing.T) { epoch := types.EpochID(11) - a1 := types.NewActivationTx(types.NIPostChallenge{PublishEpoch: epoch}, types.Address{1, 2, 3}, nil, 10, nil) - a2 := types.NewActivationTx(types.NIPostChallenge{PublishEpoch: epoch}, types.Address{3, 2, 1}, nil, 11, nil) + a1 := types.NewActivationTx(types.NIPostChallenge{PublishEpoch: epoch}, types.Address{1, 2, 3}, 10, nil) + a2 := types.NewActivationTx(types.NIPostChallenge{PublishEpoch: epoch}, types.Address{3, 2, 1}, 11, nil) var atxProof wire.AtxProof for i, a := range []*types.ActivationTx{a1, a2} { diff --git a/mesh/executor_test.go b/mesh/executor_test.go index cac29c67de..9eafb742eb 100644 --- a/mesh/executor_test.go +++ b/mesh/executor_test.go @@ -74,7 +74,6 @@ func (t *testExecutor) createATX(epoch types.EpochID, cb types.Address) (types.A atx := types.NewActivationTx( types.NIPostChallenge{PublishEpoch: epoch}, cb, - nil, 11, &nonce, ) diff --git a/mesh/mesh_test.go b/mesh/mesh_test.go index c0a597207f..11a075d1d3 100644 --- a/mesh/mesh_test.go +++ b/mesh/mesh_test.go @@ -134,7 +134,7 @@ func createIdentity(t *testing.T, db sql.Executor, sig *signing.EdSigner) { challenge := types.NIPostChallenge{ PublishEpoch: types.EpochID(1), } - atx := types.NewActivationTx(challenge, types.Address{}, nil, 1, nil) + atx := types.NewActivationTx(challenge, types.Address{}, 1, nil) require.NoError(t, activation.SignAndFinalizeAtx(sig, atx)) atx.SetEffectiveNumUnits(atx.NumUnits) atx.SetReceived(time.Now()) diff --git a/sql/atxs/atxs_test.go b/sql/atxs/atxs_test.go index 2f6c191d5c..9cda7d754b 100644 --- a/sql/atxs/atxs_test.go +++ b/sql/atxs/atxs_test.go @@ -584,35 +584,35 @@ func TestLoadBlob(t *testing.T) { require.NoError(t, err) atx1, err := newAtx(sig, withPublishEpoch(1)) require.NoError(t, err) + atx1.AtxBlob.Blob = []byte("blob1") require.NoError(t, atxs.Add(db, atx1)) var blob1 sql.Blob require.NoError(t, atxs.LoadBlob(ctx, db, atx1.ID().Bytes(), &blob1)) - encoded := codec.MustEncode(wire.ActivationTxToWireV1(atx1.ActivationTx)) - require.Equal(t, encoded, blob1.Bytes) + + require.Equal(t, atx1.AtxBlob.Blob, blob1.Bytes) blobSizes, err := atxs.GetBlobSizes(db, [][]byte{atx1.ID().Bytes()}) require.NoError(t, err) require.Equal(t, []int{len(blob1.Bytes)}, blobSizes) var blob2 sql.Blob - atx2, err := newAtx(sig, func(atx *types.ActivationTx) { - nodeID := types.RandomNodeID() - atx.NodeID = &nodeID // ensure ATXs differ in size - }) - + atx2, err := newAtx(sig) require.NoError(t, err) + atx2.AtxBlob.Blob = []byte("blob2 of different size") + require.NoError(t, atxs.Add(db, atx2)) require.NoError(t, atxs.LoadBlob(ctx, db, atx2.ID().Bytes(), &blob2)) - encoded = codec.MustEncode(wire.ActivationTxToWireV1(atx2.ActivationTx)) - require.Equal(t, encoded, blob2.Bytes) + require.Equal(t, atx2.AtxBlob.Blob, blob2.Bytes) + blobSizes, err = atxs.GetBlobSizes(db, [][]byte{ atx1.ID().Bytes(), atx2.ID().Bytes(), }) require.NoError(t, err) require.Equal(t, []int{len(blob1.Bytes), len(blob2.Bytes)}, blobSizes) + require.NotEqual(t, len(blob1.Bytes), len(blob2.Bytes)) noSuchID := types.RandomATXID() require.ErrorIs(t, atxs.LoadBlob(ctx, db, noSuchID[:], &sql.Blob{}), sql.ErrNotFound) diff --git a/systest/tests/distributed_post_verification_test.go b/systest/tests/distributed_post_verification_test.go index abf1627583..a72003c062 100644 --- a/systest/tests/distributed_post_verification_test.go +++ b/systest/tests/distributed_post_verification_test.go @@ -168,7 +168,7 @@ func TestPostMalfeasanceProof(t *testing.T) { require.NoError(t, err) // 2.1. Create initial POST - var challenge *types.NIPostChallenge + var challenge *wire.NIPostChallengeV1 for { client, err := grpcPostService.Client(signer.NodeID()) if err != nil { @@ -180,17 +180,20 @@ func TestPostMalfeasanceProof(t *testing.T) { post, postInfo, err := client.Proof(ctx, shared.ZeroChallenge) require.NoError(t, err) - challenge = &types.NIPostChallenge{ - PrevATXID: types.EmptyATXID, - PublishEpoch: 2, - PositioningATX: goldenATXID, - CommitmentATX: &postInfo.CommitmentATX, - InitialPost: post, + challenge = &wire.NIPostChallengeV1{ + PrevATXID: types.EmptyATXID, + PublishEpoch: 2, + PositioningATXID: goldenATXID, + CommitmentATXID: &postInfo.CommitmentATX, + InitialPost: &wire.PostV1{ + Nonce: post.Nonce, + Indices: post.Indices, + Pow: post.Pow, + }, } break } - challengeHash := wire.NIPostChallengeToWireV1(challenge).Hash() - nipost, err := nipostBuilder.BuildNIPost(ctx, signer, challenge.PublishEpoch, challengeHash) + nipost, err := nipostBuilder.BuildNIPost(ctx, signer, challenge.PublishEpoch, challenge.Hash()) require.NoError(t, err) // 2.2 Create ATX with invalid POST @@ -204,7 +207,7 @@ func TestPostMalfeasanceProof(t *testing.T) { require.NoError(t, err) err = verifier.Verify(ctx, (*shared.Proof)(nipost.Post), &shared.ProofMetadata{ NodeId: signer.NodeID().Bytes(), - CommitmentAtxId: challenge.CommitmentATX.Bytes(), + CommitmentAtxId: challenge.CommitmentATXID.Bytes(), NumUnits: nipost.NumUnits, Challenge: nipost.PostMetadata.Challenge, LabelsPerUnit: nipost.PostMetadata.LabelsPerUnit, @@ -212,16 +215,17 @@ func TestPostMalfeasanceProof(t *testing.T) { var invalidIdxError *verifying.ErrInvalidIndex require.ErrorAs(t, err, &invalidIdxError) - atx := types.NewActivationTx( - *challenge, - types.Address{1, 2, 3, 4}, - nipost.NIPost, - nipost.NumUnits, - &nipost.VRFNonce, - ) nodeID := signer.NodeID() - atx.InnerActivationTx.NodeID = &nodeID - require.NoError(t, activation.SignAndFinalizeAtx(signer, atx)) + atx := wire.ActivationTxV1{ + InnerActivationTxV1: wire.InnerActivationTxV1{ + NIPostChallengeV1: *challenge, + Coinbase: types.Address{1, 2, 3, 4}, + NumUnits: nipost.NumUnits, + NodeID: &nodeID, + VRFNonce: (*uint64)(&nipost.VRFNonce), + }, + } + atx.Sign(signer) // 3. Wait for publish epoch epoch := atx.PublishEpoch @@ -240,8 +244,7 @@ func TestPostMalfeasanceProof(t *testing.T) { eg.Go(func() error { for { logger.Sugar().Infow("publishing ATX", "atx", atx) - buf, err := codec.Encode(wire.ActivationTxToWireV1(atx)) - require.NoError(t, err) + buf := codec.MustEncode(&atx) err = host.Publish(ctx, pubsub.AtxProtocol, buf) require.NoError(t, err) diff --git a/tortoise/model/core.go b/tortoise/model/core.go index 6f4411f72c..701ec43658 100644 --- a/tortoise/model/core.go +++ b/tortoise/model/core.go @@ -151,7 +151,7 @@ func (c *core) OnMessage(m Messenger, event Message) { PublishEpoch: ev.LayerID.GetEpoch(), } addr := types.GenerateAddress(c.signer.PublicKey().Bytes()) - atx := types.NewActivationTx(nipost, addr, nil, c.units, nil) + atx := types.NewActivationTx(nipost, addr, c.units, nil) if err := activation.SignAndFinalizeAtx(c.signer, atx); err != nil { c.logger.With().Fatal("failed to sign atx", log.Err(err)) } diff --git a/tortoise/sim/generator.go b/tortoise/sim/generator.go index 32c03593c2..78ea4e256c 100644 --- a/tortoise/sim/generator.go +++ b/tortoise/sim/generator.go @@ -234,7 +234,7 @@ func (g *Generator) generateAtxs() { nipost := types.NIPostChallenge{ PublishEpoch: g.nextLayer.Sub(1).GetEpoch(), } - atx := types.NewActivationTx(nipost, address, nil, units, nil) + atx := types.NewActivationTx(nipost, address, units, nil) var ticks uint64 if g.ticks != nil { ticks = g.ticks[i]