diff --git a/activation/activation.go b/activation/activation.go index cfa1efb3f5..6ac3396b40 100644 --- a/activation/activation.go +++ b/activation/activation.go @@ -342,7 +342,14 @@ func (b *Builder) verifyInitialPost(ctx context.Context, post *types.Post, metad if err != nil { b.log.With().Panic("failed to fetch commitment ATX ID.", log.Err(err)) } - err = b.validator.Post(ctx, b.nodeID, commitmentAtxId, post, metadata, b.postSetupProvider.LastOpts().NumUnits) + err = b.validator.Post( + ctx, + b.nodeID, + commitmentAtxId, + post, + metadata, + b.postSetupProvider.LastOpts().NumUnits, + ) switch { case errors.Is(err, context.Canceled): // If the context was canceled, we don't want to emit or log errors just propagate the cancellation signal. diff --git a/activation/activation_test.go b/activation/activation_test.go index 9f40809b58..9ad3d79d13 100644 --- a/activation/activation_test.go +++ b/activation/activation_test.go @@ -261,7 +261,7 @@ func TestBuilder_StartSmeshingCoinbase(t *testing.T) { tab.mpost.EXPECT().LastOpts().Return(&PostSetupOpts{}).AnyTimes() tab.mpost.EXPECT().CommitmentAtx().Return(tab.goldenATXID, nil).AnyTimes() tab.mpost.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(&types.Post{}, &types.PostMetadata{}, nil) - tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) tab.mclock.EXPECT().AwaitLayer(gomock.Any()).Return(make(chan struct{})).AnyTimes() require.NoError(t, tab.StartSmeshing(coinbase, postSetupOpts)) require.Equal(t, coinbase, tab.Coinbase()) @@ -285,7 +285,7 @@ func TestBuilder_RestartSmeshing(t *testing.T) { Challenge: shared.ZeroChallenge, }, nil) tab.mpost.EXPECT().Reset().AnyTimes() - tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) tab.mpost.EXPECT().Config().AnyTimes() ch := make(chan struct{}) close(ch) @@ -441,7 +441,7 @@ func TestBuilder_StopSmeshing_OnPoSTError(t *testing.T) { tab.mpost.EXPECT().CommitmentAtx().Return(types.EmptyATXID, nil).AnyTimes() tab.mpost.EXPECT().LastOpts().Return(&PostSetupOpts{}).AnyTimes() tab.mpost.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()).Return(&types.Post{}, &types.PostMetadata{}, nil).AnyTimes() - tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) ch := make(chan struct{}) close(ch) now := time.Now() @@ -1146,7 +1146,7 @@ func TestBuilder_InitialProofGeneratedOnce(t *testing.T) { tab.mpost.EXPECT().GenerateProof(gomock.Any(), shared.ZeroChallenge, gomock.Any()).Return(&types.Post{}, &types.PostMetadata{}, nil) tab.mpost.EXPECT().LastOpts().Return(&PostSetupOpts{}) tab.mpost.EXPECT().CommitmentAtx().Return(tab.goldenATXID, nil) - tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) require.NoError(t, tab.generateInitialPost(context.Background())) posEpoch := postGenesisEpoch + 1 @@ -1173,12 +1173,12 @@ func TestBuilder_InitialProofGeneratedOnce(t *testing.T) { func TestBuilder_InitialPostIsPersisted(t *testing.T) { tab := newTestBuilder(t, WithPoetConfig(PoetConfig{PhaseShift: layerDuration * 4})) tab.mpost.EXPECT().Config().AnyTimes().Return(PostConfig{}) - tab.mpost.EXPECT().LastOpts().Return(&PostSetupOpts{}).Times(3) + tab.mpost.EXPECT().LastOpts().Return(&PostSetupOpts{}).AnyTimes() tab.mpost.EXPECT().CommitmentAtx().Return(tab.goldenATXID, nil).Times(3) tab.mpost.EXPECT().GenerateProof(gomock.Any(), shared.ZeroChallenge, gomock.Any()).Return(&types.Post{}, &types.PostMetadata{ Challenge: shared.ZeroChallenge, }, nil) - tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + tab.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) require.NoError(t, tab.generateInitialPost(context.Background())) // GenerateProof() should not be called again diff --git a/activation/handler_test.go b/activation/handler_test.go index 8c86a7beae..5f573b16b9 100644 --- a/activation/handler_test.go +++ b/activation/handler_test.go @@ -218,7 +218,7 @@ func TestHandler_SyntacticallyValidateAtx(t *testing.T) { atxHdlr.mclock.EXPECT().CurrentLayer().Return(currentLayer) require.NoError(t, atxHdlr.SyntacticallyValidate(context.Background(), atx)) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) atxHdlr.mValidator.EXPECT().NIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) _, err := atxHdlr.SyntacticallyValidateDeps(context.Background(), atx) @@ -241,7 +241,7 @@ func TestHandler_SyntacticallyValidateAtx(t *testing.T) { atxHdlr.mclock.EXPECT().CurrentLayer().Return(currentLayer) require.NoError(t, atxHdlr.SyntacticallyValidate(context.Background(), atx)) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) atxHdlr.mValidator.EXPECT().NIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().VRFNonce(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) @@ -262,7 +262,7 @@ func TestHandler_SyntacticallyValidateAtx(t *testing.T) { atxHdlr.mclock.EXPECT().CurrentLayer().Return(currentLayer) require.NoError(t, atxHdlr.SyntacticallyValidate(context.Background(), atx)) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) atxHdlr.mValidator.EXPECT().NIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) vAtx, err := atxHdlr.SyntacticallyValidateDeps(context.Background(), atx) @@ -284,7 +284,7 @@ func TestHandler_SyntacticallyValidateAtx(t *testing.T) { atxHdlr.mclock.EXPECT().CurrentLayer().Return(currentLayer) require.NoError(t, atxHdlr.SyntacticallyValidate(context.Background(), atx)) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) atxHdlr.mValidator.EXPECT().NIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().VRFNonce(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) @@ -334,11 +334,11 @@ func TestHandler_SyntacticallyValidateAtx(t *testing.T) { require.NoError(t, SignAndFinalizeAtx(sig, atx)) atxHdlr.mclock.EXPECT().CurrentLayer().Return(currentLayer) - atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) + atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().VRFNonce(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) require.NoError(t, atxHdlr.SyntacticallyValidate(context.Background(), atx)) atxHdlr.mValidator.EXPECT().InitialNIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(1), nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) _, err := atxHdlr.SyntacticallyValidateDeps(context.Background(), atx) require.NoError(t, err) @@ -516,7 +516,7 @@ func TestHandler_SyntacticallyValidateAtx(t *testing.T) { atxHdlr.mclock.EXPECT().CurrentLayer().Return(currentLayer) atxHdlr.mValidator.EXPECT().VRFNonce(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) - atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("failed post validation")) + atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("failed post validation")) err := atxHdlr.SyntacticallyValidate(context.Background(), atx) require.ErrorContains(t, err, "failed post validation") }) @@ -1245,8 +1245,8 @@ func TestHandler_AtxWeight(t *testing.T) { atxHdlr.mockFetch.EXPECT().RegisterPeerHashes(peer, []types.Hash32{proofRef}) atxHdlr.mockFetch.EXPECT().GetPoetProof(gomock.Any(), proofRef) atxHdlr.mValidator.EXPECT().VRFNonce(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) - atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(leaves, nil) + atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(leaves, nil) atxHdlr.mValidator.EXPECT().InitialNIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mbeacon.EXPECT().OnAtx(gomock.Any()) @@ -1289,7 +1289,7 @@ func TestHandler_AtxWeight(t *testing.T) { }) atxHdlr.mockFetch.EXPECT().GetPoetProof(gomock.Any(), proofRef) atxHdlr.mockFetch.EXPECT().GetAtxs(gomock.Any(), gomock.Any()) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(leaves, nil) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(leaves, nil) atxHdlr.mValidator.EXPECT().NIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mbeacon.EXPECT().OnAtx(gomock.Any()) @@ -1343,8 +1343,8 @@ func TestHandler_WrongHash(t *testing.T) { atxHdlr.mockFetch.EXPECT().RegisterPeerHashes(peer, []types.Hash32{proofRef}) atxHdlr.mockFetch.EXPECT().GetPoetProof(gomock.Any(), proofRef) atxHdlr.mValidator.EXPECT().VRFNonce(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) - atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) - atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(111), nil) + atxHdlr.mValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) + atxHdlr.mValidator.EXPECT().NIPost(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(111), nil) atxHdlr.mValidator.EXPECT().InitialNIPostChallenge(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) atxHdlr.mValidator.EXPECT().PositioningAtx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) err = atxHdlr.HandleSyncedAtx(context.Background(), types.RandomHash(), peer, buf) diff --git a/activation/interface.go b/activation/interface.go index 3295c14c4d..d413546f21 100644 --- a/activation/interface.go +++ b/activation/interface.go @@ -25,10 +25,10 @@ type PostVerifier interface { type nipostValidator interface { InitialNIPostChallenge(challenge *types.NIPostChallenge, atxs atxProvider, goldenATXID types.ATXID) error NIPostChallenge(challenge *types.NIPostChallenge, atxs atxProvider, nodeID types.NodeID) error - NIPost(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, NIPost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32, opts ...verifying.OptionFunc) (uint64, error) + NIPost(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, NIPost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32) (uint64, error) NumUnits(cfg *PostConfig, numUnits uint32) error - Post(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, Post *types.Post, PostMetadata *types.PostMetadata, numUnits uint32, opts ...verifying.OptionFunc) error + Post(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, Post *types.Post, PostMetadata *types.PostMetadata, numUnits uint32) error PostMetadata(cfg *PostConfig, metadata *types.PostMetadata) error VRFNonce(nodeId types.NodeID, commitmentAtxId types.ATXID, vrfNonce *types.VRFPostIndex, PostMetadata *types.PostMetadata, numUnits uint32) error diff --git a/activation/mocks.go b/activation/mocks.go index 14176cbc12..2c907b1b4c 100644 --- a/activation/mocks.go +++ b/activation/mocks.go @@ -241,23 +241,18 @@ func (c *nipostValidatorInitialNIPostChallengeCall) DoAndReturn(f func(*types.NI } // NIPost mocks base method. -func (m *MocknipostValidator) NIPost(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, NIPost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32, opts ...verifying.OptionFunc) (uint64, error) { +func (m *MocknipostValidator) NIPost(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, NIPost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32) (uint64, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx, nodeId, atxId, NIPost, expectedChallenge, numUnits} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "NIPost", varargs...) + ret := m.ctrl.Call(m, "NIPost", ctx, nodeId, atxId, NIPost, expectedChallenge, numUnits) ret0, _ := ret[0].(uint64) ret1, _ := ret[1].(error) return ret0, ret1 } // NIPost indicates an expected call of NIPost. -func (mr *MocknipostValidatorMockRecorder) NIPost(ctx, nodeId, atxId, NIPost, expectedChallenge, numUnits interface{}, opts ...interface{}) *nipostValidatorNIPostCall { +func (mr *MocknipostValidatorMockRecorder) NIPost(ctx, nodeId, atxId, NIPost, expectedChallenge, numUnits interface{}) *nipostValidatorNIPostCall { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, nodeId, atxId, NIPost, expectedChallenge, numUnits}, opts...) - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NIPost", reflect.TypeOf((*MocknipostValidator)(nil).NIPost), varargs...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NIPost", reflect.TypeOf((*MocknipostValidator)(nil).NIPost), ctx, nodeId, atxId, NIPost, expectedChallenge, numUnits) return &nipostValidatorNIPostCall{Call: call} } @@ -273,13 +268,13 @@ func (c *nipostValidatorNIPostCall) Return(arg0 uint64, arg1 error) *nipostValid } // Do rewrite *gomock.Call.Do -func (c *nipostValidatorNIPostCall) Do(f func(context.Context, types.NodeID, types.ATXID, *types.NIPost, types.Hash32, uint32, ...verifying.OptionFunc) (uint64, error)) *nipostValidatorNIPostCall { +func (c *nipostValidatorNIPostCall) Do(f func(context.Context, types.NodeID, types.ATXID, *types.NIPost, types.Hash32, uint32) (uint64, error)) *nipostValidatorNIPostCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *nipostValidatorNIPostCall) DoAndReturn(f func(context.Context, types.NodeID, types.ATXID, *types.NIPost, types.Hash32, uint32, ...verifying.OptionFunc) (uint64, error)) *nipostValidatorNIPostCall { +func (c *nipostValidatorNIPostCall) DoAndReturn(f func(context.Context, types.NodeID, types.ATXID, *types.NIPost, types.Hash32, uint32) (uint64, error)) *nipostValidatorNIPostCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -399,22 +394,17 @@ func (c *nipostValidatorPositioningAtxCall) DoAndReturn(f func(types.ATXID, atxP } // Post mocks base method. -func (m *MocknipostValidator) Post(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, Post *types.Post, PostMetadata *types.PostMetadata, numUnits uint32, opts ...verifying.OptionFunc) error { +func (m *MocknipostValidator) Post(ctx context.Context, nodeId types.NodeID, atxId types.ATXID, Post *types.Post, PostMetadata *types.PostMetadata, numUnits uint32) error { m.ctrl.T.Helper() - varargs := []interface{}{ctx, nodeId, atxId, Post, PostMetadata, numUnits} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Post", varargs...) + ret := m.ctrl.Call(m, "Post", ctx, nodeId, atxId, Post, PostMetadata, numUnits) ret0, _ := ret[0].(error) return ret0 } // Post indicates an expected call of Post. -func (mr *MocknipostValidatorMockRecorder) Post(ctx, nodeId, atxId, Post, PostMetadata, numUnits interface{}, opts ...interface{}) *nipostValidatorPostCall { +func (mr *MocknipostValidatorMockRecorder) Post(ctx, nodeId, atxId, Post, PostMetadata, numUnits interface{}) *nipostValidatorPostCall { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, nodeId, atxId, Post, PostMetadata, numUnits}, opts...) - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Post", reflect.TypeOf((*MocknipostValidator)(nil).Post), varargs...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Post", reflect.TypeOf((*MocknipostValidator)(nil).Post), ctx, nodeId, atxId, Post, PostMetadata, numUnits) return &nipostValidatorPostCall{Call: call} } @@ -430,13 +420,13 @@ func (c *nipostValidatorPostCall) Return(arg0 error) *nipostValidatorPostCall { } // Do rewrite *gomock.Call.Do -func (c *nipostValidatorPostCall) Do(f func(context.Context, types.NodeID, types.ATXID, *types.Post, *types.PostMetadata, uint32, ...verifying.OptionFunc) error) *nipostValidatorPostCall { +func (c *nipostValidatorPostCall) Do(f func(context.Context, types.NodeID, types.ATXID, *types.Post, *types.PostMetadata, uint32) error) *nipostValidatorPostCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *nipostValidatorPostCall) DoAndReturn(f func(context.Context, types.NodeID, types.ATXID, *types.Post, *types.PostMetadata, uint32, ...verifying.OptionFunc) error) *nipostValidatorPostCall { +func (c *nipostValidatorPostCall) DoAndReturn(f func(context.Context, types.NodeID, types.ATXID, *types.Post, *types.PostMetadata, uint32) error) *nipostValidatorPostCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/activation/nipost.go b/activation/nipost.go index c40899dd53..9aad94de02 100644 --- a/activation/nipost.go +++ b/activation/nipost.go @@ -12,7 +12,6 @@ import ( "github.com/spacemeshos/merkle-tree" "github.com/spacemeshos/poet/shared" "github.com/spacemeshos/post/proving" - "github.com/spacemeshos/post/verifying" "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" @@ -301,7 +300,6 @@ func (nb *NIPostBuilder) BuildNIPost(ctx context.Context, challenge *types.NIPos proof, proofMetadata, nb.postSetupProvider.LastOpts().NumUnits, - verifying.WithLabelScryptParams(nb.postSetupProvider.LastOpts().Scrypt), ); err != nil { events.EmitInvalidPostProof() return nil, fmt.Errorf("failed to verify Post: %w", err) diff --git a/activation/nipost_test.go b/activation/nipost_test.go index 93bb3a51b7..23fa12f5c0 100644 --- a/activation/nipost_test.go +++ b/activation/nipost_test.go @@ -10,7 +10,6 @@ import ( "github.com/spacemeshos/go-scale/tester" "github.com/spacemeshos/poet/logging" "github.com/spacemeshos/post/proving" - "github.com/spacemeshos/post/verifying" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -61,7 +60,7 @@ func TestNIPostBuilderWithMocks(t *testing.T) { postProvider.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()) nipostValidator := NewMocknipostValidator(ctrl) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) poetProvider := defaultPoetServiceMock(t, []byte("poet"), "http://localhost:9999") poetProvider.EXPECT().Proof(gomock.Any(), "").Return(&types.PoetProofMessage{ @@ -113,7 +112,7 @@ func TestPostSetup(t *testing.T) { mclock := defaultLayerClockMock(t) nipostValidator := NewMocknipostValidator(gomock.NewController(t)) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) nb, err := NewNIPostBuilder( postProvider.id, @@ -154,7 +153,7 @@ func TestNIPostBuilderWithClients(t *testing.T) { require.NoError(t, err) defer verifier.Close() - v := NewValidator(poetDb, postProvider.Config(), logger, verifier) + v := NewValidator(poetDb, postProvider.Config(), postProvider.opts.Scrypt, logger, verifier) nipost := buildNIPost(t, postProvider, challenge, poetDb, v) _, err = v.NIPost( context.Background(), @@ -163,7 +162,6 @@ func TestNIPostBuilderWithClients(t *testing.T) { nipost, challenge.Hash(), postProvider.opts.NumUnits, - verifying.WithLabelScryptParams(postProvider.opts.Scrypt), ) require.NoError(t, err) } @@ -260,7 +258,7 @@ func TestNewNIPostBuilderNotInitialized(t *testing.T) { mclock := defaultLayerClockMock(t) nipostValidator := NewMocknipostValidator(ctrl) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) nb, err := NewNIPostBuilder( postProvider.id, @@ -291,7 +289,7 @@ func TestNewNIPostBuilderNotInitialized(t *testing.T) { verifier, err := NewPostVerifier(postProvider.cfg, logger) r.NoError(err) defer verifier.Close() - v := NewValidator(poetDb, postProvider.cfg, logger, verifier) + v := NewValidator(poetDb, postProvider.cfg, postProvider.opts.Scrypt, logger, verifier) _, err = v.NIPost( context.Background(), postProvider.id, @@ -299,7 +297,6 @@ func TestNewNIPostBuilderNotInitialized(t *testing.T) { nipost, challenge.Hash(), postProvider.opts.NumUnits, - verifying.WithLabelScryptParams(postProvider.opts.Scrypt), ) r.NoError(err) } @@ -362,7 +359,7 @@ func TestNIPostBuilder_BuildNIPost(t *testing.T) { req.NoError(err) postProvider.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) nipost, err := nb.BuildNIPost(context.Background(), &challenge) req.NoError(err) req.NotNil(nipost) @@ -412,7 +409,7 @@ func TestNIPostBuilder_BuildNIPost(t *testing.T) { ) req.NoError(err) postProvider.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()).Times(1) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) // check that proof ref is not called again nipost, err = nb.BuildNIPost(context.Background(), &challenge2) req.NoError(err) @@ -421,7 +418,7 @@ func TestNIPostBuilder_BuildNIPost(t *testing.T) { // test state not loading if other challenge provided poetDb.EXPECT().ValidateAndStore(gomock.Any(), gomock.Any()).Return(nil) postProvider.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()) nipost, err = nb.BuildNIPost(context.Background(), &challenge3) req.NoError(err) req.NotNil(nipost) @@ -483,7 +480,7 @@ func TestNIPostBuilder_ManyPoETs_SubmittingChallenge_DeadlineReached(t *testing. }, nil }, ) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) nb, err := NewNIPostBuilder( types.NodeID{1}, postProvider, @@ -559,7 +556,7 @@ func TestNIPostBuilder_ManyPoETs_AllFinished(t *testing.T) { }, nil }, ) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) nb, err := NewNIPostBuilder( types.NodeID{1}, postProvider, @@ -963,7 +960,7 @@ func TestNIPoSTBuilder_Continues_After_Interrupted(t *testing.T) { }, ) nipostValidator := NewMocknipostValidator(ctrl) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(nil) nb, err := NewNIPostBuilder( types.NodeID{1}, postProvider, @@ -1056,7 +1053,7 @@ func TestNIPostBuilder_Mainnet_PoetRound3_Workaround(t *testing.T) { postProvider.EXPECT().GenerateProof(gomock.Any(), gomock.Any(), gomock.Any()) nipostValidator := NewMocknipostValidator(ctrl) - nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) + nipostValidator.EXPECT().Post(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(nil) poets := make([]PoetProvingServiceClient, 0, 2) { diff --git a/activation/post_verifier_test.go b/activation/post_verifier_test.go index e1932cabd6..6c12d3d893 100644 --- a/activation/post_verifier_test.go +++ b/activation/post_verifier_test.go @@ -13,6 +13,7 @@ import ( "github.com/spacemeshos/go-spacemesh/activation" "github.com/spacemeshos/go-spacemesh/log" + "github.com/spacemeshos/go-spacemesh/log/logtest" ) func TestOffloadingPostVerifier(t *testing.T) { @@ -40,7 +41,7 @@ func TestOffloadingPostVerifier(t *testing.T) { } func TestPostVerifierDetectsInvalidProof(t *testing.T) { - verifier, err := activation.NewPostVerifier(activation.PostConfig{}, log.NewDefault(t.Name())) + verifier, err := activation.NewPostVerifier(activation.PostConfig{}, logtest.New(t)) require.NoError(t, err) defer verifier.Close() require.Error(t, verifier.Verify(context.Background(), &shared.Proof{}, &shared.ProofMetadata{})) diff --git a/activation/validation.go b/activation/validation.go index 7e11748012..4b8b82852d 100644 --- a/activation/validation.go +++ b/activation/validation.go @@ -8,6 +8,7 @@ import ( "github.com/spacemeshos/merkle-tree" poetShared "github.com/spacemeshos/poet/shared" + "github.com/spacemeshos/post/config" "github.com/spacemeshos/post/shared" "github.com/spacemeshos/post/verifying" @@ -40,13 +41,14 @@ func (e *ErrAtxNotFound) Is(target error) bool { type Validator struct { poetDb poetDbAPI cfg PostConfig + scrypt config.ScryptParams log log.Log postVerifier PostVerifier } // NewValidator returns a new NIPost validator. -func NewValidator(poetDb poetDbAPI, cfg PostConfig, log log.Log, postVerifier PostVerifier) *Validator { - return &Validator{poetDb, cfg, log, postVerifier} +func NewValidator(poetDb poetDbAPI, cfg PostConfig, scrypt config.ScryptParams, log log.Log, postVerifier PostVerifier) *Validator { + return &Validator{poetDb, cfg, scrypt, log, postVerifier} } // NIPost validates a NIPost, given a node id and expected challenge. It returns an error if the NIPost is invalid. @@ -54,7 +56,7 @@ func NewValidator(poetDb poetDbAPI, cfg PostConfig, log log.Log, postVerifier Po // Some of the Post metadata fields validation values is ought to eventually be derived from // consensus instead of local configuration. If so, their validation should be removed to contextual validation, // while still syntactically-validate them here according to locally configured min/max values. -func (v *Validator) NIPost(ctx context.Context, nodeId types.NodeID, commitmentAtxId types.ATXID, nipost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32, opts ...verifying.OptionFunc) (uint64, error) { +func (v *Validator) NIPost(ctx context.Context, nodeId types.NodeID, commitmentAtxId types.ATXID, nipost *types.NIPost, expectedChallenge types.Hash32, numUnits uint32) (uint64, error) { if err := v.NumUnits(&v.cfg, numUnits); err != nil { return 0, err } @@ -63,7 +65,7 @@ func (v *Validator) NIPost(ctx context.Context, nodeId types.NodeID, commitmentA return 0, err } - if err := v.Post(ctx, nodeId, commitmentAtxId, nipost.Post, nipost.PostMetadata, numUnits, opts...); err != nil { + if err := v.Post(ctx, nodeId, commitmentAtxId, nipost.Post, nipost.PostMetadata, numUnits); err != nil { return 0, fmt.Errorf("invalid Post: %w", err) } @@ -113,7 +115,7 @@ func validateMerkleProof(leaf []byte, proof *types.MerkleProof, expectedRoot []b // Post validates a Proof of Space-Time (PoST). It returns nil if validation passed or an error indicating why // validation failed. -func (v *Validator) Post(ctx context.Context, nodeId types.NodeID, commitmentAtxId types.ATXID, PoST *types.Post, PostMetadata *types.PostMetadata, numUnits uint32, opts ...verifying.OptionFunc) error { +func (v *Validator) Post(ctx context.Context, nodeId types.NodeID, commitmentAtxId types.ATXID, PoST *types.Post, PostMetadata *types.PostMetadata, numUnits uint32) error { p := (*shared.Proof)(PoST) m := &shared.ProofMetadata{ @@ -124,10 +126,8 @@ func (v *Validator) Post(ctx context.Context, nodeId types.NodeID, commitmentAtx LabelsPerUnit: PostMetadata.LabelsPerUnit, } - opts = append(opts, verifying.WithPowCreator(nodeId.Bytes())) - start := time.Now() - if err := v.postVerifier.Verify(ctx, p, m, opts...); err != nil { + if err := v.postVerifier.Verify(ctx, p, m, verifying.WithPowCreator(nodeId.Bytes()), verifying.WithLabelScryptParams(v.scrypt)); err != nil { return fmt.Errorf("verify PoST: %w", err) } metrics.PostVerificationLatency.Observe(time.Since(start).Seconds()) @@ -152,7 +152,7 @@ func (*Validator) PostMetadata(cfg *PostConfig, metadata *types.PostMetadata) er return nil } -func (*Validator) VRFNonce(nodeId types.NodeID, commitmentAtxId types.ATXID, vrfNonce *types.VRFPostIndex, PostMetadata *types.PostMetadata, numUnits uint32) error { +func (v *Validator) VRFNonce(nodeId types.NodeID, commitmentAtxId types.ATXID, vrfNonce *types.VRFPostIndex, PostMetadata *types.PostMetadata, numUnits uint32) error { if vrfNonce == nil { return errors.New("VRFNonce is nil") } @@ -164,7 +164,7 @@ func (*Validator) VRFNonce(nodeId types.NodeID, commitmentAtxId types.ATXID, vrf LabelsPerUnit: PostMetadata.LabelsPerUnit, } - if err := verifying.VerifyVRFNonce((*uint64)(vrfNonce), meta); err != nil { + if err := verifying.VerifyVRFNonce((*uint64)(vrfNonce), meta, verifying.WithPowCreator(nodeId.Bytes()), verifying.WithLabelScryptParams(v.scrypt)); err != nil { return fmt.Errorf("verify VRF nonce: %w", err) } return nil diff --git a/activation/validation_test.go b/activation/validation_test.go index 45b49b59e6..3997cf9c19 100644 --- a/activation/validation_test.go +++ b/activation/validation_test.go @@ -6,9 +6,9 @@ import ( "fmt" "testing" + "github.com/spacemeshos/post/config" "github.com/spacemeshos/post/initialization" "github.com/spacemeshos/post/shared" - "github.com/spacemeshos/post/verifying" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -48,7 +48,7 @@ func Test_Validation_VRFNonce(t *testing.T) { nonce := (*types.VRFPostIndex)(init.Nonce()) - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), nil) + v := NewValidator(poetDbAPI, postCfg, initOpts.Scrypt, logtest.New(t).WithName("validator"), nil) // Act & Assert t.Run("valid vrf nonce", func(t *testing.T) { @@ -89,7 +89,7 @@ func Test_Validation_InitialNIPostChallenge(t *testing.T) { postCfg := DefaultPostConfig() goldenATXID := types.ATXID{2, 3, 4} - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), nil) + v := NewValidator(poetDbAPI, postCfg, config.ScryptParams{}, logtest.New(t).WithName("validator"), nil) // Act & Assert t.Run("valid initial nipost challenge passes", func(t *testing.T) { @@ -157,7 +157,7 @@ func Test_Validation_NIPostChallenge(t *testing.T) { poetDbAPI := NewMockpoetDbAPI(ctrl) postCfg := DefaultPostConfig() - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), nil) + v := NewValidator(poetDbAPI, postCfg, config.ScryptParams{}, logtest.New(t).WithName("validator"), nil) // Act & Assert t.Run("valid nipost challenge passes", func(t *testing.T) { @@ -283,7 +283,7 @@ func Test_Validation_Post(t *testing.T) { postCfg := DefaultPostConfig() postVerifier := NewMockPostVerifier(ctrl) - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), postVerifier) + v := NewValidator(poetDbAPI, postCfg, config.ScryptParams{}, logtest.New(t).WithName("validator"), postVerifier) post := types.Post{} meta := types.PostMetadata{} @@ -305,7 +305,7 @@ func Test_Validation_PositioningAtx(t *testing.T) { poetDbAPI := NewMockpoetDbAPI(ctrl) postCfg := DefaultPostConfig() - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), nil) + v := NewValidator(poetDbAPI, postCfg, config.ScryptParams{}, logtest.New(t).WithName("validator"), nil) // Act & Assert t.Run("valid nipost challenge passes", func(t *testing.T) { @@ -409,7 +409,7 @@ func Test_Validate_NumUnits(t *testing.T) { poetDbAPI := NewMockpoetDbAPI(ctrl) postCfg := DefaultPostConfig() - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), nil) + v := NewValidator(poetDbAPI, postCfg, config.ScryptParams{}, logtest.New(t).WithName("validator"), nil) // Act & Assert t.Run("valid number of num units passes", func(t *testing.T) { @@ -443,7 +443,7 @@ func Test_Validate_PostMetadata(t *testing.T) { poetDbAPI := NewMockpoetDbAPI(ctrl) postCfg := DefaultPostConfig() - v := NewValidator(poetDbAPI, postCfg, logtest.New(t).WithName("validator"), nil) + v := NewValidator(poetDbAPI, postCfg, config.ScryptParams{}, logtest.New(t).WithName("validator"), nil) // Act & Assert t.Run("valid post metadata", func(t *testing.T) { @@ -485,39 +485,37 @@ func TestValidator_Validate(t *testing.T) { r.NoError(err) defer verifier.Close() - v := NewValidator(poetDb, postProvider.cfg, logger, verifier) + v := NewValidator(poetDb, postProvider.cfg, postProvider.opts.Scrypt, logger, verifier) nipost := buildNIPost(t, postProvider, challenge, poetDb, v) - opts := []verifying.OptionFunc{verifying.WithLabelScryptParams(postProvider.opts.Scrypt)} - - _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits, opts...) + _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits) r.NoError(err) - _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, types.BytesToHash([]byte("lerner")), postProvider.opts.NumUnits, opts...) + _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, types.BytesToHash([]byte("lerner")), postProvider.opts.NumUnits) r.Contains(err.Error(), "invalid membership proof") newNIPost := *nipost newNIPost.Post = &types.Post{} - _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, &newNIPost, challengeHash, postProvider.opts.NumUnits, opts...) + _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, &newNIPost, challengeHash, postProvider.opts.NumUnits) r.Contains(err.Error(), "invalid Post") newPostCfg := postProvider.cfg newPostCfg.MinNumUnits = postProvider.opts.NumUnits + 1 - v = NewValidator(poetDb, newPostCfg, logtest.New(t).WithName("validator"), nil) - _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits, opts...) + v = NewValidator(poetDb, newPostCfg, postProvider.opts.Scrypt, logtest.New(t).WithName("validator"), nil) + _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits) r.EqualError(err, fmt.Sprintf("invalid `numUnits`; expected: >=%d, given: %d", newPostCfg.MinNumUnits, postProvider.opts.NumUnits)) newPostCfg = postProvider.cfg newPostCfg.MaxNumUnits = postProvider.opts.NumUnits - 1 - v = NewValidator(poetDb, newPostCfg, logtest.New(t).WithName("validator"), nil) - _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits, opts...) + v = NewValidator(poetDb, newPostCfg, postProvider.opts.Scrypt, logtest.New(t).WithName("validator"), nil) + _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits) r.EqualError(err, fmt.Sprintf("invalid `numUnits`; expected: <=%d, given: %d", newPostCfg.MaxNumUnits, postProvider.opts.NumUnits)) newPostCfg = postProvider.cfg newPostCfg.LabelsPerUnit = nipost.PostMetadata.LabelsPerUnit + 1 - v = NewValidator(poetDb, newPostCfg, logtest.New(t).WithName("validator"), nil) - _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits, opts...) + v = NewValidator(poetDb, newPostCfg, postProvider.opts.Scrypt, logtest.New(t).WithName("validator"), nil) + _, err = v.NIPost(context.Background(), postProvider.id, postProvider.commitmentAtxId, nipost, challengeHash, postProvider.opts.NumUnits) r.EqualError(err, fmt.Sprintf("invalid `LabelsPerUnit`; expected: >=%d, given: %d", newPostCfg.LabelsPerUnit, nipost.PostMetadata.LabelsPerUnit)) } diff --git a/config/presets/fastnet.go b/config/presets/fastnet.go index 8c08e30832..924633e211 100644 --- a/config/presets/fastnet.go +++ b/config/presets/fastnet.go @@ -72,7 +72,8 @@ func fastnet() config.Config { conf.SMESHING.Start = false conf.SMESHING.Opts.ProviderID.SetInt64(int64(initialization.CPUProviderID())) conf.SMESHING.Opts.NumUnits = 2 - conf.SMESHING.Opts.Throttle = true + conf.SMESHING.Opts.ComputeBatchSize = 128 + conf.SMESHING.Opts.Scrypt.N = 2 // faster scrypt // Override proof of work flags to use light mode (less memory intensive) conf.SMESHING.ProvingOpts.Flags = postCfg.RecommendedPowFlags() diff --git a/node/node.go b/node/node.go index 5396ed3016..3b13a33cbf 100644 --- a/node/node.go +++ b/node/node.go @@ -564,7 +564,7 @@ func (app *App) initServices(ctx context.Context) error { } app.postVerifier = activation.NewOffloadingPostVerifier(postVerifiers, nipostValidatorLogger) - validator := activation.NewValidator(poetDb, app.Config.POST, nipostValidatorLogger, app.postVerifier) + validator := activation.NewValidator(poetDb, app.Config.POST, app.Config.SMESHING.Opts.Scrypt, nipostValidatorLogger, app.postVerifier) app.validator = validator cfg := vm.DefaultConfig()