From 4f601c2fbfaa64a2709a37e581850de11e347466 Mon Sep 17 00:00:00 2001 From: dmitry Date: Fri, 27 Aug 2021 11:31:25 +0300 Subject: [PATCH] Remove context.Context from StartSmeshing arguments --- activation/activation.go | 16 +- activation/mocks/activation_mocks.go | 673 --------------------------- api/grpcserver/grpcserver_test.go | 41 +- api/grpcserver/smesher_service.go | 2 +- cmd/node/node.go | 10 +- tortoise/state_test.go | 1 + 6 files changed, 21 insertions(+), 722 deletions(-) delete mode 100644 activation/mocks/activation_mocks.go diff --git a/activation/activation.go b/activation/activation.go index af214de47e..32f5da9866 100644 --- a/activation/activation.go +++ b/activation/activation.go @@ -92,12 +92,10 @@ type syncer interface { RegisterChForSynced(context.Context, chan struct{}) } -//go:generate mockgen -package=mocks -destination=./mocks/activation_mocks.go -source=./activation.go - // SmeshingProvider defines the functionality required for the node's Smesher API. type SmeshingProvider interface { Smeshing() bool - StartSmeshing(ctx context.Context, coinbase types.Address, opts PostSetupOpts) error + StartSmeshing(coinbase types.Address, opts PostSetupOpts) error StopSmeshing(deleteFiles bool) error SmesherID() types.NodeID Coinbase() types.Address @@ -179,11 +177,19 @@ func WithPoETClientInitializer(initializer PoETClientInitializer) BuilderOption } } +// WithContext modifies parent context for background job. +func WithContext(ctx context.Context) BuilderOption { + return func(b *Builder) { + b.runCtx = ctx + } +} + // NewBuilder returns an atx builder that will start a routine that will attempt to create an atx upon each new layer. func NewBuilder(conf Config, nodeID types.NodeID, signer signer, db atxDBProvider, net broadcaster, mesh meshProvider, layersPerEpoch uint32, nipostBuilder nipostBuilder, postSetupProvider PostSetupProvider, layerClock layerClock, syncer syncer, store bytesStore, log log.Log, opts ...BuilderOption) *Builder { b := &Builder{ + runCtx: context.Background(), signer: signer, nodeID: nodeID, coinbaseAccount: conf.CoinbaseAccount, @@ -204,6 +210,7 @@ func NewBuilder(conf Config, nodeID types.NodeID, signer signer, db atxDBProvide for _, opt := range opts { opt(b) } + b.runCtx, b.stop = context.WithCancel(b.runCtx) return b } @@ -220,14 +227,13 @@ func (b *Builder) Smeshing() bool { // If the post data is incomplete or missing, data creation // session will be preceded. Changing of the post potions (e.g., number of labels), // after initial setup, is supported. -func (b *Builder) StartSmeshing(ctx context.Context, coinbase types.Address, opts PostSetupOpts) error { +func (b *Builder) StartSmeshing(coinbase types.Address, opts PostSetupOpts) error { b.mtx.Lock() if b.status != smeshingStatusIdle { b.mtx.Unlock() return errors.New("already started") } b.status = smeshingStatusPendingPostSetup - b.runCtx, b.stop = context.WithCancel(ctx) b.mtx.Unlock() doneChan, err := b.postSetupProvider.StartSession(opts) diff --git a/activation/mocks/activation_mocks.go b/activation/mocks/activation_mocks.go deleted file mode 100644 index 540282e415..0000000000 --- a/activation/mocks/activation_mocks.go +++ /dev/null @@ -1,673 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: ./activation.go - -// Package mocks is a generated GoMock package. -package mocks - -import ( - context "context" - reflect "reflect" - time "time" - - gomock "github.com/golang/mock/gomock" - activation "github.com/spacemeshos/go-spacemesh/activation" - types "github.com/spacemeshos/go-spacemesh/common/types" - signing "github.com/spacemeshos/go-spacemesh/signing" -) - -// MockmeshProvider is a mock of meshProvider interface. -type MockmeshProvider struct { - ctrl *gomock.Controller - recorder *MockmeshProviderMockRecorder -} - -// MockmeshProviderMockRecorder is the mock recorder for MockmeshProvider. -type MockmeshProviderMockRecorder struct { - mock *MockmeshProvider -} - -// NewMockmeshProvider creates a new mock instance. -func NewMockmeshProvider(ctrl *gomock.Controller) *MockmeshProvider { - mock := &MockmeshProvider{ctrl: ctrl} - mock.recorder = &MockmeshProviderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockmeshProvider) EXPECT() *MockmeshProviderMockRecorder { - return m.recorder -} - -// GetOrphanBlocksBefore mocks base method. -func (m *MockmeshProvider) GetOrphanBlocksBefore(l types.LayerID) ([]types.BlockID, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetOrphanBlocksBefore", l) - ret0, _ := ret[0].([]types.BlockID) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetOrphanBlocksBefore indicates an expected call of GetOrphanBlocksBefore. -func (mr *MockmeshProviderMockRecorder) GetOrphanBlocksBefore(l interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrphanBlocksBefore", reflect.TypeOf((*MockmeshProvider)(nil).GetOrphanBlocksBefore), l) -} - -// LatestLayer mocks base method. -func (m *MockmeshProvider) LatestLayer() types.LayerID { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "LatestLayer") - ret0, _ := ret[0].(types.LayerID) - return ret0 -} - -// LatestLayer indicates an expected call of LatestLayer. -func (mr *MockmeshProviderMockRecorder) LatestLayer() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LatestLayer", reflect.TypeOf((*MockmeshProvider)(nil).LatestLayer)) -} - -// Mockbroadcaster is a mock of broadcaster interface. -type Mockbroadcaster struct { - ctrl *gomock.Controller - recorder *MockbroadcasterMockRecorder -} - -// MockbroadcasterMockRecorder is the mock recorder for Mockbroadcaster. -type MockbroadcasterMockRecorder struct { - mock *Mockbroadcaster -} - -// NewMockbroadcaster creates a new mock instance. -func NewMockbroadcaster(ctrl *gomock.Controller) *Mockbroadcaster { - mock := &Mockbroadcaster{ctrl: ctrl} - mock.recorder = &MockbroadcasterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *Mockbroadcaster) EXPECT() *MockbroadcasterMockRecorder { - return m.recorder -} - -// Broadcast mocks base method. -func (m *Mockbroadcaster) Broadcast(ctx context.Context, channel string, data []byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Broadcast", ctx, channel, data) - ret0, _ := ret[0].(error) - return ret0 -} - -// Broadcast indicates an expected call of Broadcast. -func (mr *MockbroadcasterMockRecorder) Broadcast(ctx, channel, data interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Broadcast", reflect.TypeOf((*Mockbroadcaster)(nil).Broadcast), ctx, channel, data) -} - -// MocknipostBuilder is a mock of nipostBuilder interface. -type MocknipostBuilder struct { - ctrl *gomock.Controller - recorder *MocknipostBuilderMockRecorder -} - -// MocknipostBuilderMockRecorder is the mock recorder for MocknipostBuilder. -type MocknipostBuilderMockRecorder struct { - mock *MocknipostBuilder -} - -// NewMocknipostBuilder creates a new mock instance. -func NewMocknipostBuilder(ctrl *gomock.Controller) *MocknipostBuilder { - mock := &MocknipostBuilder{ctrl: ctrl} - mock.recorder = &MocknipostBuilderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MocknipostBuilder) EXPECT() *MocknipostBuilderMockRecorder { - return m.recorder -} - -// BuildNIPost mocks base method. -func (m *MocknipostBuilder) BuildNIPost(ctx context.Context, challenge *types.Hash32, timeout chan struct{}) (*types.NIPost, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BuildNIPost", ctx, challenge, timeout) - ret0, _ := ret[0].(*types.NIPost) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BuildNIPost indicates an expected call of BuildNIPost. -func (mr *MocknipostBuilderMockRecorder) BuildNIPost(ctx, challenge, timeout interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BuildNIPost", reflect.TypeOf((*MocknipostBuilder)(nil).BuildNIPost), ctx, challenge, timeout) -} - -// updatePoETProver mocks base method. -func (m *MocknipostBuilder) updatePoETProver(arg0 activation.PoetProvingServiceClient) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "updatePoETProver", arg0) -} - -// updatePoETProver indicates an expected call of updatePoETProver. -func (mr *MocknipostBuilderMockRecorder) updatePoETProver(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "updatePoETProver", reflect.TypeOf((*MocknipostBuilder)(nil).updatePoETProver), arg0) -} - -// MockidStore is a mock of idStore interface. -type MockidStore struct { - ctrl *gomock.Controller - recorder *MockidStoreMockRecorder -} - -// MockidStoreMockRecorder is the mock recorder for MockidStore. -type MockidStoreMockRecorder struct { - mock *MockidStore -} - -// NewMockidStore creates a new mock instance. -func NewMockidStore(ctrl *gomock.Controller) *MockidStore { - mock := &MockidStore{ctrl: ctrl} - mock.recorder = &MockidStoreMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockidStore) EXPECT() *MockidStoreMockRecorder { - return m.recorder -} - -// GetIdentity mocks base method. -func (m *MockidStore) GetIdentity(id string) (types.NodeID, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetIdentity", id) - ret0, _ := ret[0].(types.NodeID) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetIdentity indicates an expected call of GetIdentity. -func (mr *MockidStoreMockRecorder) GetIdentity(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIdentity", reflect.TypeOf((*MockidStore)(nil).GetIdentity), id) -} - -// StoreNodeIdentity mocks base method. -func (m *MockidStore) StoreNodeIdentity(id types.NodeID) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StoreNodeIdentity", id) - ret0, _ := ret[0].(error) - return ret0 -} - -// StoreNodeIdentity indicates an expected call of StoreNodeIdentity. -func (mr *MockidStoreMockRecorder) StoreNodeIdentity(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreNodeIdentity", reflect.TypeOf((*MockidStore)(nil).StoreNodeIdentity), id) -} - -// MocknipostValidator is a mock of nipostValidator interface. -type MocknipostValidator struct { - ctrl *gomock.Controller - recorder *MocknipostValidatorMockRecorder -} - -// MocknipostValidatorMockRecorder is the mock recorder for MocknipostValidator. -type MocknipostValidatorMockRecorder struct { - mock *MocknipostValidator -} - -// NewMocknipostValidator creates a new mock instance. -func NewMocknipostValidator(ctrl *gomock.Controller) *MocknipostValidator { - mock := &MocknipostValidator{ctrl: ctrl} - mock.recorder = &MocknipostValidatorMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MocknipostValidator) EXPECT() *MocknipostValidatorMockRecorder { - return m.recorder -} - -// Validate mocks base method. -func (m *MocknipostValidator) Validate(id signing.PublicKey, NIPost *types.NIPost, expectedChallenge types.Hash32, numUnits uint) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Validate", id, NIPost, expectedChallenge, numUnits) - ret0, _ := ret[0].(error) - return ret0 -} - -// Validate indicates an expected call of Validate. -func (mr *MocknipostValidatorMockRecorder) Validate(id, NIPost, expectedChallenge, numUnits interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MocknipostValidator)(nil).Validate), id, NIPost, expectedChallenge, numUnits) -} - -// ValidatePost mocks base method. -func (m *MocknipostValidator) ValidatePost(id []byte, Post *types.Post, PostMetadata *types.PostMetadata, numUnits uint) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValidatePost", id, Post, PostMetadata, numUnits) - ret0, _ := ret[0].(error) - return ret0 -} - -// ValidatePost indicates an expected call of ValidatePost. -func (mr *MocknipostValidatorMockRecorder) ValidatePost(id, Post, PostMetadata, numUnits interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatePost", reflect.TypeOf((*MocknipostValidator)(nil).ValidatePost), id, Post, PostMetadata, numUnits) -} - -// MockatxDBProvider is a mock of atxDBProvider interface. -type MockatxDBProvider struct { - ctrl *gomock.Controller - recorder *MockatxDBProviderMockRecorder -} - -// MockatxDBProviderMockRecorder is the mock recorder for MockatxDBProvider. -type MockatxDBProviderMockRecorder struct { - mock *MockatxDBProvider -} - -// NewMockatxDBProvider creates a new mock instance. -func NewMockatxDBProvider(ctrl *gomock.Controller) *MockatxDBProvider { - mock := &MockatxDBProvider{ctrl: ctrl} - mock.recorder = &MockatxDBProviderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockatxDBProvider) EXPECT() *MockatxDBProviderMockRecorder { - return m.recorder -} - -// AwaitAtx mocks base method. -func (m *MockatxDBProvider) AwaitAtx(id types.ATXID) chan struct{} { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AwaitAtx", id) - ret0, _ := ret[0].(chan struct{}) - return ret0 -} - -// AwaitAtx indicates an expected call of AwaitAtx. -func (mr *MockatxDBProviderMockRecorder) AwaitAtx(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AwaitAtx", reflect.TypeOf((*MockatxDBProvider)(nil).AwaitAtx), id) -} - -// GetAtxHeader mocks base method. -func (m *MockatxDBProvider) GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAtxHeader", id) - ret0, _ := ret[0].(*types.ActivationTxHeader) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetAtxHeader indicates an expected call of GetAtxHeader. -func (mr *MockatxDBProviderMockRecorder) GetAtxHeader(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAtxHeader", reflect.TypeOf((*MockatxDBProvider)(nil).GetAtxHeader), id) -} - -// GetAtxTimestamp mocks base method. -func (m *MockatxDBProvider) GetAtxTimestamp(id types.ATXID) (time.Time, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAtxTimestamp", id) - ret0, _ := ret[0].(time.Time) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetAtxTimestamp indicates an expected call of GetAtxTimestamp. -func (mr *MockatxDBProviderMockRecorder) GetAtxTimestamp(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAtxTimestamp", reflect.TypeOf((*MockatxDBProvider)(nil).GetAtxTimestamp), id) -} - -// GetNodeLastAtxID mocks base method. -func (m *MockatxDBProvider) GetNodeLastAtxID(nodeID types.NodeID) (types.ATXID, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetNodeLastAtxID", nodeID) - ret0, _ := ret[0].(types.ATXID) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetNodeLastAtxID indicates an expected call of GetNodeLastAtxID. -func (mr *MockatxDBProviderMockRecorder) GetNodeLastAtxID(nodeID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNodeLastAtxID", reflect.TypeOf((*MockatxDBProvider)(nil).GetNodeLastAtxID), nodeID) -} - -// GetPosAtxID mocks base method. -func (m *MockatxDBProvider) GetPosAtxID() (types.ATXID, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetPosAtxID") - ret0, _ := ret[0].(types.ATXID) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetPosAtxID indicates an expected call of GetPosAtxID. -func (mr *MockatxDBProviderMockRecorder) GetPosAtxID() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPosAtxID", reflect.TypeOf((*MockatxDBProvider)(nil).GetPosAtxID)) -} - -// UnsubscribeAtx mocks base method. -func (m *MockatxDBProvider) UnsubscribeAtx(id types.ATXID) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "UnsubscribeAtx", id) -} - -// UnsubscribeAtx indicates an expected call of UnsubscribeAtx. -func (mr *MockatxDBProviderMockRecorder) UnsubscribeAtx(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnsubscribeAtx", reflect.TypeOf((*MockatxDBProvider)(nil).UnsubscribeAtx), id) -} - -// MockbytesStore is a mock of bytesStore interface. -type MockbytesStore struct { - ctrl *gomock.Controller - recorder *MockbytesStoreMockRecorder -} - -// MockbytesStoreMockRecorder is the mock recorder for MockbytesStore. -type MockbytesStoreMockRecorder struct { - mock *MockbytesStore -} - -// NewMockbytesStore creates a new mock instance. -func NewMockbytesStore(ctrl *gomock.Controller) *MockbytesStore { - mock := &MockbytesStore{ctrl: ctrl} - mock.recorder = &MockbytesStoreMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockbytesStore) EXPECT() *MockbytesStoreMockRecorder { - return m.recorder -} - -// Get mocks base method. -func (m *MockbytesStore) Get(key []byte) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", key) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Get indicates an expected call of Get. -func (mr *MockbytesStoreMockRecorder) Get(key interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockbytesStore)(nil).Get), key) -} - -// Put mocks base method. -func (m *MockbytesStore) Put(key, buf []byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Put", key, buf) - ret0, _ := ret[0].(error) - return ret0 -} - -// Put indicates an expected call of Put. -func (mr *MockbytesStoreMockRecorder) Put(key, buf interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockbytesStore)(nil).Put), key, buf) -} - -// Mocksigner is a mock of signer interface. -type Mocksigner struct { - ctrl *gomock.Controller - recorder *MocksignerMockRecorder -} - -// MocksignerMockRecorder is the mock recorder for Mocksigner. -type MocksignerMockRecorder struct { - mock *Mocksigner -} - -// NewMocksigner creates a new mock instance. -func NewMocksigner(ctrl *gomock.Controller) *Mocksigner { - mock := &Mocksigner{ctrl: ctrl} - mock.recorder = &MocksignerMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *Mocksigner) EXPECT() *MocksignerMockRecorder { - return m.recorder -} - -// Sign mocks base method. -func (m_2 *Mocksigner) Sign(m []byte) []byte { - m_2.ctrl.T.Helper() - ret := m_2.ctrl.Call(m_2, "Sign", m) - ret0, _ := ret[0].([]byte) - return ret0 -} - -// Sign indicates an expected call of Sign. -func (mr *MocksignerMockRecorder) Sign(m interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*Mocksigner)(nil).Sign), m) -} - -// MocklayerClock is a mock of layerClock interface. -type MocklayerClock struct { - ctrl *gomock.Controller - recorder *MocklayerClockMockRecorder -} - -// MocklayerClockMockRecorder is the mock recorder for MocklayerClock. -type MocklayerClockMockRecorder struct { - mock *MocklayerClock -} - -// NewMocklayerClock creates a new mock instance. -func NewMocklayerClock(ctrl *gomock.Controller) *MocklayerClock { - mock := &MocklayerClock{ctrl: ctrl} - mock.recorder = &MocklayerClockMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MocklayerClock) EXPECT() *MocklayerClockMockRecorder { - return m.recorder -} - -// AwaitLayer mocks base method. -func (m *MocklayerClock) AwaitLayer(layerID types.LayerID) chan struct{} { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AwaitLayer", layerID) - ret0, _ := ret[0].(chan struct{}) - return ret0 -} - -// AwaitLayer indicates an expected call of AwaitLayer. -func (mr *MocklayerClockMockRecorder) AwaitLayer(layerID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AwaitLayer", reflect.TypeOf((*MocklayerClock)(nil).AwaitLayer), layerID) -} - -// GetCurrentLayer mocks base method. -func (m *MocklayerClock) GetCurrentLayer() types.LayerID { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetCurrentLayer") - ret0, _ := ret[0].(types.LayerID) - return ret0 -} - -// GetCurrentLayer indicates an expected call of GetCurrentLayer. -func (mr *MocklayerClockMockRecorder) GetCurrentLayer() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentLayer", reflect.TypeOf((*MocklayerClock)(nil).GetCurrentLayer)) -} - -// Mocksyncer is a mock of syncer interface. -type Mocksyncer struct { - ctrl *gomock.Controller - recorder *MocksyncerMockRecorder -} - -// MocksyncerMockRecorder is the mock recorder for Mocksyncer. -type MocksyncerMockRecorder struct { - mock *Mocksyncer -} - -// NewMocksyncer creates a new mock instance. -func NewMocksyncer(ctrl *gomock.Controller) *Mocksyncer { - mock := &Mocksyncer{ctrl: ctrl} - mock.recorder = &MocksyncerMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *Mocksyncer) EXPECT() *MocksyncerMockRecorder { - return m.recorder -} - -// RegisterChForSynced mocks base method. -func (m *Mocksyncer) RegisterChForSynced(arg0 context.Context, arg1 chan struct{}) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "RegisterChForSynced", arg0, arg1) -} - -// RegisterChForSynced indicates an expected call of RegisterChForSynced. -func (mr *MocksyncerMockRecorder) RegisterChForSynced(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterChForSynced", reflect.TypeOf((*Mocksyncer)(nil).RegisterChForSynced), arg0, arg1) -} - -// MockSmeshingProvider is a mock of SmeshingProvider interface. -type MockSmeshingProvider struct { - ctrl *gomock.Controller - recorder *MockSmeshingProviderMockRecorder -} - -// MockSmeshingProviderMockRecorder is the mock recorder for MockSmeshingProvider. -type MockSmeshingProviderMockRecorder struct { - mock *MockSmeshingProvider -} - -// NewMockSmeshingProvider creates a new mock instance. -func NewMockSmeshingProvider(ctrl *gomock.Controller) *MockSmeshingProvider { - mock := &MockSmeshingProvider{ctrl: ctrl} - mock.recorder = &MockSmeshingProviderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockSmeshingProvider) EXPECT() *MockSmeshingProviderMockRecorder { - return m.recorder -} - -// Coinbase mocks base method. -func (m *MockSmeshingProvider) Coinbase() types.Address { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Coinbase") - ret0, _ := ret[0].(types.Address) - return ret0 -} - -// Coinbase indicates an expected call of Coinbase. -func (mr *MockSmeshingProviderMockRecorder) Coinbase() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Coinbase", reflect.TypeOf((*MockSmeshingProvider)(nil).Coinbase)) -} - -// MinGas mocks base method. -func (m *MockSmeshingProvider) MinGas() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MinGas") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// MinGas indicates an expected call of MinGas. -func (mr *MockSmeshingProviderMockRecorder) MinGas() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MinGas", reflect.TypeOf((*MockSmeshingProvider)(nil).MinGas)) -} - -// SetCoinbase mocks base method. -func (m *MockSmeshingProvider) SetCoinbase(coinbase types.Address) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetCoinbase", coinbase) -} - -// SetCoinbase indicates an expected call of SetCoinbase. -func (mr *MockSmeshingProviderMockRecorder) SetCoinbase(coinbase interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCoinbase", reflect.TypeOf((*MockSmeshingProvider)(nil).SetCoinbase), coinbase) -} - -// SetMinGas mocks base method. -func (m *MockSmeshingProvider) SetMinGas(value uint64) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetMinGas", value) -} - -// SetMinGas indicates an expected call of SetMinGas. -func (mr *MockSmeshingProviderMockRecorder) SetMinGas(value interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMinGas", reflect.TypeOf((*MockSmeshingProvider)(nil).SetMinGas), value) -} - -// SmesherID mocks base method. -func (m *MockSmeshingProvider) SmesherID() types.NodeID { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SmesherID") - ret0, _ := ret[0].(types.NodeID) - return ret0 -} - -// SmesherID indicates an expected call of SmesherID. -func (mr *MockSmeshingProviderMockRecorder) SmesherID() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SmesherID", reflect.TypeOf((*MockSmeshingProvider)(nil).SmesherID)) -} - -// Smeshing mocks base method. -func (m *MockSmeshingProvider) Smeshing() bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Smeshing") - ret0, _ := ret[0].(bool) - return ret0 -} - -// Smeshing indicates an expected call of Smeshing. -func (mr *MockSmeshingProviderMockRecorder) Smeshing() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Smeshing", reflect.TypeOf((*MockSmeshingProvider)(nil).Smeshing)) -} - -// StartSmeshing mocks base method. -func (m *MockSmeshingProvider) StartSmeshing(ctx context.Context, coinbase types.Address, opts activation.PostSetupOpts) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StartSmeshing", ctx, coinbase, opts) - ret0, _ := ret[0].(error) - return ret0 -} - -// StartSmeshing indicates an expected call of StartSmeshing. -func (mr *MockSmeshingProviderMockRecorder) StartSmeshing(ctx, coinbase, opts interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartSmeshing", reflect.TypeOf((*MockSmeshingProvider)(nil).StartSmeshing), ctx, coinbase, opts) -} - -// StopSmeshing mocks base method. -func (m *MockSmeshingProvider) StopSmeshing(deleteFiles bool) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StopSmeshing", deleteFiles) - ret0, _ := ret[0].(error) - return ret0 -} - -// StopSmeshing indicates an expected call of StopSmeshing. -func (mr *MockSmeshingProviderMockRecorder) StopSmeshing(deleteFiles interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopSmeshing", reflect.TypeOf((*MockSmeshingProvider)(nil).StopSmeshing), deleteFiles) -} diff --git a/api/grpcserver/grpcserver_test.go b/api/grpcserver/grpcserver_test.go index 5977daf084..0a4b4100c1 100644 --- a/api/grpcserver/grpcserver_test.go +++ b/api/grpcserver/grpcserver_test.go @@ -17,13 +17,11 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes/empty" "github.com/spacemeshos/ed25519" "github.com/spacemeshos/go-spacemesh/activation" - "github.com/spacemeshos/go-spacemesh/activation/mocks" "github.com/spacemeshos/go-spacemesh/api" "github.com/spacemeshos/go-spacemesh/cmd" "github.com/spacemeshos/go-spacemesh/common/util" @@ -444,7 +442,7 @@ func (*SmeshingAPIMock) Smeshing() bool { return false } -func (*SmeshingAPIMock) StartSmeshing(ctx context.Context, coinbase types.Address, opts activation.PostSetupOpts) error { +func (*SmeshingAPIMock) StartSmeshing(coinbase types.Address, opts activation.PostSetupOpts) error { return nil } @@ -1235,43 +1233,6 @@ func TestSmesherService(t *testing.T) { } } -func TestSmesherService_Context(t *testing.T) { - logtest.SetupGlobal(t) - ctrl := gomock.NewController(t) - smesher := mocks.NewMockSmeshingProvider(ctrl) - var received context.Context - smesher.EXPECT().StartSmeshing(gomock.Any(), gomock.Any(), gomock.Any()).Do(func(ctx context.Context, _ types.Address, _ activation.PostSetupOpts) { - received = ctx - }).Return(nil) - - svc := NewSmesherService(&PostAPIMock{}, smesher) - shutDown := launchServer(t, svc) - t.Cleanup(shutDown) - - conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", cfg.GrpcServerPort), grpc.WithInsecure(), grpc.WithBlock()) - require.NoError(t, err) - t.Cleanup(func() { conn.Close() }) - client := pb.NewSmesherServiceClient(conn) - - request := &pb.StartSmeshingRequest{ - Coinbase: &pb.AccountId{Address: []byte("123")}, - Opts: &pb.PostSetupOpts{ - DataDir: t.TempDir(), - NumUnits: 1, - NumFiles: 1, - }, - } - resp, err := client.StartSmeshing(context.Background(), request) - require.NoError(t, err) - require.EqualValues(t, code.Code_OK, resp.Status.Code) - require.NotNil(t, received) - select { - case <-received.Done(): - require.FailNow(t, "smesher context is closed") - default: - } -} - func TestMeshService(t *testing.T) { logtest.SetupGlobal(t) grpcService := NewMeshService(txAPI, mempoolMock, &genTime, layersPerEpoch, networkID, layerDurationSec, layerAvgSize, txsPerBlock) diff --git a/api/grpcserver/smesher_service.go b/api/grpcserver/smesher_service.go index f5041f04c1..394a0603b2 100644 --- a/api/grpcserver/smesher_service.go +++ b/api/grpcserver/smesher_service.go @@ -72,7 +72,7 @@ func (s SmesherService) StartSmeshing(ctx context.Context, in *pb.StartSmeshingR Throttle: in.Opts.Throttle, } - if err := s.smeshingProvider.StartSmeshing(context.Background(), coinbaseAddr, opts); err != nil { + if err := s.smeshingProvider.StartSmeshing(coinbaseAddr, opts); err != nil { err := fmt.Sprintf("failed to start smeshing: %v", err) log.Error(err) return nil, status.Error(codes.Internal, err) diff --git a/cmd/node/node.go b/cmd/node/node.go index 0234537b22..f3612e179c 100644 --- a/cmd/node/node.go +++ b/cmd/node/node.go @@ -751,7 +751,11 @@ func (app *App) initServices(ctx context.Context, LayersPerEpoch: layersPerEpoch, } - atxBuilder := activation.NewBuilder(builderConfig, nodeID, sgn, atxDB, swarm, msh, layersPerEpoch, nipostBuilder, postSetupMgr, clock, newSyncer, store, app.addLogger("atxBuilder", lg)) + atxBuilder := activation.NewBuilder(builderConfig, nodeID, sgn, + atxDB, swarm, msh, layersPerEpoch, nipostBuilder, + postSetupMgr, clock, newSyncer, store, app.addLogger("atxBuilder", lg), + activation.WithContext(ctx), + ) gossipListener.AddListener(ctx, state.IncomingTxProtocol, priorityq.Low, processor.HandleTxGossipData) gossipListener.AddListener(ctx, activation.AtxProtocol, priorityq.Low, atxDB.HandleGossipAtx) @@ -867,8 +871,8 @@ func (app *App) startServices(ctx context.Context) error { if app.Config.SMESHING.Start { coinbaseAddr := types.HexToAddress(app.Config.SMESHING.CoinbaseAccount) go func() { - if err := app.atxBuilder.StartSmeshing(ctx, coinbaseAddr, app.Config.SMESHING.Opts); err != nil { - log.With().Panic("failed to start smeshing", log.Err(err)) + if err := app.atxBuilder.StartSmeshing(coinbaseAddr, app.Config.SMESHING.Opts); err != nil { + log.Panic("failed to start smeshing: %v", err) } }() } else { diff --git a/tortoise/state_test.go b/tortoise/state_test.go index c429fcafeb..12e65233aa 100644 --- a/tortoise/state_test.go +++ b/tortoise/state_test.go @@ -182,6 +182,7 @@ func BenchmarkStatePersist(b *testing.B) { } func TestRecoverData(t *testing.T) { + t.Skip("for debugging purposes") mdb, err := mesh.NewPersistentMeshDB("/tmp/data55/203/mesh", 1, logtest.New(t)) require.NoError(t, err) db, err := database.NewLDBDatabase("/tmp/data55/203/turtle/", 0, 0, logtest.New(t))