Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fasmat committed Oct 2, 2024
1 parent 6f990f1 commit 4dd9173
Show file tree
Hide file tree
Showing 44 changed files with 199 additions and 430 deletions.
2 changes: 1 addition & 1 deletion activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ func (b *Builder) broadcast(ctx context.Context, atx scale.Encodable) (int, erro
return len(buf), nil
}

// SearchPositioningAtx returns atx id with the highest tick height.
// searchPositioningAtx returns atx id with the highest tick height.
// Publish epoch is used for caching the positioning atx.
func (b *Builder) searchPositioningAtx(
ctx context.Context,
Expand Down
2 changes: 1 addition & 1 deletion activation/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func TestHandler_PostMalfeasanceProofs(t *testing.T) {
msg := codec.MustEncode(atx)

postVerifier := NewMockPostVerifier(gomock.NewController(t))
mh := NewInvalidPostIndexHandler(atxHdlr.cdb, atxHdlr.logger, atxHdlr.edVerifier, postVerifier)
mh := NewInvalidPostIndexHandler(atxHdlr.cdb, atxHdlr.edVerifier, postVerifier)
atxHdlr.mpub.EXPECT().Publish(gomock.Any(), pubsub.MalfeasanceProof, gomock.Any()).
DoAndReturn(func(_ context.Context, _ string, data []byte) error {
var got mwire.MalfeasanceGossip
Expand Down
2 changes: 1 addition & 1 deletion activation/handler_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func TestHandlerV1_StoreAtx(t *testing.T) {
require.NotNil(t, proof)
require.Equal(t, mwire.InvalidPrevATX, proof.Proof.Type)

mh := NewInvalidPrevATXHandler(atxHdlr.cdb, atxHdlr.logger, atxHdlr.edVerifier)
mh := NewInvalidPrevATXHandler(atxHdlr.cdb, atxHdlr.edVerifier)
nodeID, err := mh.Validate(context.Background(), proof.Proof.Data)
require.NoError(t, err)
require.Equal(t, sig.NodeID(), nodeID)
Expand Down
7 changes: 1 addition & 6 deletions activation/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ type InvalidPostIndexHandler struct {

func NewInvalidPostIndexHandler(
db sql.Executor,
_ *zap.Logger,
edVerifier *signing.EdVerifier,
postVerifier PostVerifier,
) *InvalidPostIndexHandler {
Expand Down Expand Up @@ -184,11 +183,7 @@ type InvalidPrevATXHandler struct {
edVerifier *signing.EdVerifier
}

func NewInvalidPrevATXHandler(
db sql.Executor,
_ *zap.Logger,
edVerifier *signing.EdVerifier,
) *InvalidPrevATXHandler {
func NewInvalidPrevATXHandler(db sql.Executor, edVerifier *signing.EdVerifier) *InvalidPrevATXHandler {
return &InvalidPrevATXHandler{
db: db,

Expand Down
16 changes: 2 additions & 14 deletions activation/malfeasance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,11 @@ type testInvalidPostIndexHandler struct {

func newTestInvalidPostIndexHandler(tb testing.TB) *testInvalidPostIndexHandler {
db := statesql.InMemory()
observer, _ := observer.New(zapcore.WarnLevel)
logger := zaptest.NewLogger(tb, zaptest.WrapOptions(zap.WrapCore(
func(core zapcore.Core) zapcore.Core {
return zapcore.NewTee(core, observer)
},
)))

ctrl := gomock.NewController(tb)
postVerifier := NewMockPostVerifier(ctrl)

h := NewInvalidPostIndexHandler(db, logger, signing.NewEdVerifier(), postVerifier)
h := NewInvalidPostIndexHandler(db, signing.NewEdVerifier(), postVerifier)
return &testInvalidPostIndexHandler{
InvalidPostIndexHandler: h,

Expand Down Expand Up @@ -427,14 +421,8 @@ type testInvalidPrevATXHandler struct {

func newTestInvalidPrevATXHandler(tb testing.TB) *testInvalidPrevATXHandler {
db := statesql.InMemory()
observer, _ := observer.New(zapcore.WarnLevel)
logger := zaptest.NewLogger(tb, zaptest.WrapOptions(zap.WrapCore(
func(core zapcore.Core) zapcore.Core {
return zapcore.NewTee(core, observer)
},
)))

h := NewInvalidPrevATXHandler(db, logger, signing.NewEdVerifier())
h := NewInvalidPrevATXHandler(db, signing.NewEdVerifier())
return &testInvalidPrevATXHandler{
InvalidPrevATXHandler: h,

Expand Down
2 changes: 1 addition & 1 deletion activation/post_supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (ps *PostSupervisor) Stop(deleteFiles bool) error {
}
}

// CaptureCmdOutput returns a function that reads from the given pipe and logs the output.
// captureCmdOutput returns a function that reads from the given pipe and logs the output.
// It returns when the pipe is closed.
func (ps *PostSupervisor) captureCmdOutput(pipe io.ReadCloser, smesherId types.NodeID) func() error {
return func() error {
Expand Down
3 changes: 1 addition & 2 deletions api/grpcserver/post_info_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -36,7 +35,7 @@ func (s *PostInfoService) String() string {
}

// NewPostInfoService creates a new instance of the post info grpc service.
func NewPostInfoService(_ *zap.Logger, states postState) *PostInfoService {
func NewPostInfoService(states postState) *PostInfoService {
return &PostInfoService{
states: states,
}
Expand Down
4 changes: 1 addition & 3 deletions api/grpcserver/post_info_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"go.uber.org/zap/zaptest"

"github.com/spacemeshos/go-spacemesh/common/types"
)
Expand All @@ -33,9 +32,8 @@ func (i idMock) Name() string {
}

func TestPostInfoService(t *testing.T) {
log := zaptest.NewLogger(t)
mpostStates := NewMockpostState(gomock.NewController(t))
svc := NewPostInfoService(log, mpostStates)
svc := NewPostInfoService(mpostStates)
cfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)

Expand Down
2 changes: 1 addition & 1 deletion beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func (pd *ProtocolDriver) initEpochStateIfNotPresent(logger *zap.Logger, target
)

checker := createProposalChecker(logger, pd.config, w1, w1+w2)
pd.states[target] = newState(logger, pd.config, active, epochWeight, miners, checker)
pd.states[target] = newState(logger, active, epochWeight, miners, checker)
return pd.states[target], nil
}

Expand Down
2 changes: 1 addition & 1 deletion beacon/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func createEpochState(
tb.Helper()
pd.mu.Lock()
defer pd.mu.Unlock()
pd.states[epoch] = newState(pd.logger, pd.config, nil, epochWeight, minerAtxs, checker)
pd.states[epoch] = newState(pd.logger, nil, epochWeight, minerAtxs, checker)
return pd.states[epoch]
}

Expand Down
3 changes: 1 addition & 2 deletions beacon/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type minerInfo struct {
malicious bool
}

// State does the data management for epoch specific data for the protocol.
// state does the data management for epoch specific data for the protocol.
// Not thread-safe. It relies on ProtocolDriver's thread-safety mechanism.
type state struct {
logger *zap.Logger
Expand All @@ -38,7 +38,6 @@ type state struct {

func newState(
logger *zap.Logger,
_ Config,
active map[types.NodeID]participant,
epochWeight uint64,
miners map[types.NodeID]*minerInfo,
Expand Down
2 changes: 1 addition & 1 deletion cmd/bootstrapper/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (s *Server) genWithRetry(ctx context.Context, epoch types.EpochID, maxRetri
}
}

// in systests, we want to be sure the nodes use the fallback data unconditionally.
// In systests, we want to be sure the nodes use the fallback data unconditionally.
// Use a fixed known value for beacon to be sure that fallback is used during testing.
func epochBeacon(epoch types.EpochID) types.Beacon {
b := make([]byte, types.BeaconSize)
Expand Down
2 changes: 1 addition & 1 deletion genvm/templates/multisig/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
)

// NewHandler instantiates multisig handler with a particular configuration.
func NewHandler(_ core.Address) core.Handler {
func NewHandler() core.Handler {
return &handler{}
}

Expand Down
4 changes: 2 additions & 2 deletions genvm/templates/vesting/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MethodDrainVault = 17
// Register vesting templates.
func Register(reg *registry.Registry) {
reg.Register(TemplateAddress, &handler{
multisig: multisig.NewHandler(TemplateAddress),
multisig: multisig.NewHandler(),
})
}

Expand All @@ -34,7 +34,7 @@ func (h *handler) Parse(method uint8, decoder *scale.Decoder) (output core.Parse
return h.multisig.Parse(method, decoder)
}

// New instatiates vesting state, note that the state is the same as multisig.
// New instantiates vesting state, note that the state is the same as multisig.
// The difference is that vesting supports one more transaction type.
func (h *handler) New(args any) (core.Template, error) {
template, err := h.multisig.New(args)
Expand Down
2 changes: 1 addition & 1 deletion hare3/hare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func withProposals(fraction float64) clusterOpt {
}
}

// WithSigners creates N signers in addition to regular active nodes.
// withSigners creates N signers in addition to regular active nodes.
// This signers will be partitioned in fair fashion across regular active nodes.
func withSigners(n int) clusterOpt {
return func(cluster *lockstepCluster) {
Expand Down
2 changes: 1 addition & 1 deletion hare4/hare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func withProposals(fraction float64) clusterOpt {
}
}

// WithSigners creates N signers in addition to regular active nodes.
// withSigners creates N signers in addition to regular active nodes.
// This signers will be partitioned in fair fashion across regular active nodes.
func withSigners(n int) clusterOpt {
return func(cluster *lockstepCluster) {
Expand Down
4 changes: 0 additions & 4 deletions mesh/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ type vmState interface {
[]types.CoinbaseReward,
) ([]types.Transaction, []types.TransactionWithResult, error)
}

type layerClock interface {
CurrentLayer() types.LayerID
}
3 changes: 1 addition & 2 deletions mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type Mesh struct {
func NewMesh(
db sql.StateDatabase,
atxsdata *atxsdata.Data,
_ layerClock,
trtl system.Tortoise,
exec *Executor,
state conservativeState,
Expand Down Expand Up @@ -304,7 +303,7 @@ func (msh *Mesh) ProcessLayer(ctx context.Context, lid types.LayerID) error {
msh.mu.Lock()
defer msh.mu.Unlock()

msh.trtl.TallyVotes(ctx, lid)
msh.trtl.TallyVotes(lid)

if err := msh.setProcessedLayer(lid); err != nil {
return err
Expand Down
10 changes: 3 additions & 7 deletions mesh/mesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type testMesh struct {
// it is used in malfeasence.Validate, which is called in the tests
cdb *datastore.CachedDB
atxsdata *atxsdata.Data
mockClock *mocks.MocklayerClock
mockVM *mocks.MockvmState
mockState *mocks.MockconservativeState
mockTortoise *smocks.MockTortoise
Expand All @@ -58,13 +57,12 @@ func createTestMesh(t *testing.T) *testMesh {
db: db,
cdb: datastore.NewCachedDB(db, lg),
atxsdata: atxsdata,
mockClock: mocks.NewMocklayerClock(ctrl),
mockVM: mocks.NewMockvmState(ctrl),
mockState: mocks.NewMockconservativeState(ctrl),
mockTortoise: smocks.NewMockTortoise(ctrl),
}
exec := NewExecutor(db, atxsdata, tm.mockVM, tm.mockState, lg)
msh, err := NewMesh(db, atxsdata, tm.mockClock, tm.mockTortoise, exec, tm.mockState, lg)
msh, err := NewMesh(db, atxsdata, tm.mockTortoise, exec, tm.mockState, lg)
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
Expand Down Expand Up @@ -210,7 +208,6 @@ func TestMesh_WakeUpWhileGenesis(t *testing.T) {
msh, err := NewMesh(
tm.db,
tm.atxsdata,
tm.mockClock,
tm.mockTortoise,
tm.executor,
tm.mockState,
Expand Down Expand Up @@ -248,7 +245,6 @@ func TestMesh_WakeUp(t *testing.T) {
msh, err := NewMesh(
tm.db,
tm.atxsdata,
tm.mockClock,
tm.mockTortoise,
tm.executor,
tm.mockState,
Expand Down Expand Up @@ -734,7 +730,7 @@ func TestProcessLayer(t *testing.T) {
t.Parallel()

tm := createTestMesh(t)
tm.mockTortoise.EXPECT().TallyVotes(gomock.Any(), gomock.Any()).AnyTimes()
tm.mockTortoise.EXPECT().TallyVotes(gomock.Any()).AnyTimes()
tm.mockVM.EXPECT().GetStateRoot().AnyTimes()
tm.mockVM.EXPECT().Revert(gomock.Any()).AnyTimes()
tm.mockState.EXPECT().RevertCache(gomock.Any()).AnyTimes()
Expand Down Expand Up @@ -945,7 +941,7 @@ func TestProcessLayerPerHareOutput(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
tm := createTestMesh(t)
tm.mockTortoise.EXPECT().TallyVotes(gomock.Any(), gomock.Any()).AnyTimes()
tm.mockTortoise.EXPECT().TallyVotes(gomock.Any()).AnyTimes()
tm.mockTortoise.EXPECT().
Updates().
Return(nil).
Expand Down
61 changes: 0 additions & 61 deletions mesh/mocks/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions miner/mocks/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4dd9173

Please sign in to comment.