address review feedback for PR 3960
## Motivation
<!-- Please mention the issue fixed by this PR or detailed motivation -->
review feedback for
MODIFY
activation/handler.go
activation/handler.go
@@ -297,7 +297,7 @@ func (h *Handler) StoreAtx(ctx context.Context, atx *types.VerifiedActivationTx)
malicious, err := h.cdb.IsMalicious(atx.NodeID())
if err != nil {
- return fmt.Errorf("store atx: %w", err)
+ return fmt.Errorf("checking if node is malicious: %w", err)
}
var proof *types.MalfeasanceProof
h.cdb.WithTx(ctx, func(dbtx *sql.Tx) error {
@@ -322,7 +322,7 @@ func (h *Handler) StoreAtx(ctx context.Context, atx *types.VerifiedActivationTx)
},
}
if err = h.cdb.AddMalfeasanceProof(atx.NodeID(), proof, dbtx); err != nil {
- return err
+ return fmt.Errorf("adding malfeasense proof: %w", err)
}
h.log.With().Warning("smesher produced more than one atx in the same epoch",
log.Stringer("smesher", atx.NodeID()),

MODIFY
api/grpcserver/mesh_service.go
api/grpcserver/mesh_service.go
@@ -21,9 +21,9 @@ type MeshService struct {
genTime api.GenesisTimeAPI
layersPerEpoch uint32
genesisID types.Hash20
- layerDurationSec int
- layerAvgSize int
- txsPerProposal int
+ layerDurationSec uint32
+ layerAvgSize uint32
+ txsPerProposal uint32
}
// RegisterService registers this service with a grpc server instance.
@@ -34,8 +34,8 @@ func (s MeshService) RegisterService(server *Server) {
// NewMeshService creates a new service using config data.
func NewMeshService(
msh api.MeshAPI, cstate api.ConservativeState, genTime api.GenesisTimeAPI,
- layersPerEpoch uint32, genesisID types.Hash20, layerDurationSec int,
- layerAvgSize int, txsPerProposal int,
+ layersPerEpoch uint32, genesisID types.Hash20, layerDurationSec uint32,
+ layerAvgSize uint32, txsPerProposal uint32,
) *MeshService {
return &MeshService{
mesh: msh,

MODIFY
cmd/node/node.go
cmd/node/node.go
@@ -363,10 +363,10 @@ func (app *App) Initialize() (err error) {
// hare's max time duration to run consensus for a layer
maxHareRoundsPerLayer := 1 + app.Config.HARE.LimitIterations*hare.RoundsPerIteration // pre-round + 4 rounds per iteration
maxHareLayerDurationSec := app.Config.HARE.WakeupDelta + maxHareRoundsPerLayer*app.Config.HARE.RoundDuration
- if app.Config.LayerDurationSec*int(app.Config.Tortoise.Zdist) <= maxHareLayerDurationSec {
+ if app.Config.LayerDurationSec*app.Config.Tortoise.Zdist <= uint32(maxHareLayerDurationSec) {
log.With().Error("incompatible params",
log.Uint32("tortoise_zdist", app.Config.Tortoise.Zdist),
- log.Int("layer_duration", app.Config.LayerDurationSec),
+ log.Uint32("layer_duration", app.Config.LayerDurationSec),
log.Int("hare_wakeup_delta", app.Config.HARE.WakeupDelta),
log.Int("hare_limit_iterations", app.Config.HARE.LimitIterations),
log.Int("hare_round_duration", app.Config.HARE.RoundDuration))
@@ -813,7 +813,7 @@ func (app *App) startAPIServices(ctx context.Context) {
registerService(grpcserver.NewGlobalStateService(app.mesh, app.conState))
}
if apiConf.StartMeshService {
- registerService(grpcserver.NewMeshService(app.mesh, app.conState, app.clock, app.Config.LayersPerEpoch, app.Config.Genesis.GenesisID(), layerDuration, app.Config.LayerAvgSize, app.Config.TxsPerProposal))
+ registerService(grpcserver.NewMeshService(app.mesh, app.conState, app.clock, app.Config.LayersPerEpoch, app.Config.Genesis.GenesisID(), layerDuration, app.Config.LayerAvgSize, uint32(app.Config.TxsPerProposal)))
}
if apiConf.StartNodeService {
nodeService := grpcserver.NewNodeService(app.host, app.mesh, app.clock, app.syncer, app.atxBuilder)

MODIFY
cmd/root.go
cmd/root.go
@@ -44,9 +44,9 @@ func AddCommands(cmd *cobra.Command) {
cfg.Genesis.GenesisTime, "Time of the genesis layer in 2019-13-02T17:02:00+00:00 format")
cmd.PersistentFlags().StringVar(&cfg.Genesis.ExtraData, "genesis-extra-data",
cfg.Genesis.ExtraData, "genesis extra-data will be committed to the genesis id")
- cmd.PersistentFlags().IntVar(&cfg.LayerDurationSec, "layer-duration-sec",
+ cmd.PersistentFlags().Uint32Var(&cfg.LayerDurationSec, "layer-duration-sec",
cfg.LayerDurationSec, "Duration between layers in seconds")
- cmd.PersistentFlags().IntVar(&cfg.LayerAvgSize, "layer-average-size",
+ cmd.PersistentFlags().Uint32Var(&cfg.LayerAvgSize, "layer-average-size",
cfg.LayerAvgSize, "Layer Avg size")
cmd.PersistentFlags().BoolVar(&cfg.PprofHTTPServer, "pprof-server",
cfg.PprofHTTPServer, "enable http pprof server")

MODIFY
config/config.go
config/config.go
@@ -83,8 +83,8 @@ type BaseConfig struct {
OracleServer string `mapstructure:"oracle_server"`
OracleServerWorldID int `mapstructure:"oracle_server_worldid"`
- LayerDurationSec int `mapstructure:"layer-duration-sec"`
- LayerAvgSize int `mapstructure:"layer-average-size"`
+ LayerDurationSec uint32 `mapstructure:"layer-duration-sec"`
+ LayerAvgSize uint32 `mapstructure:"layer-average-size"`
LayersPerEpoch uint32 `mapstructure:"layers-per-epoch"`
PoETServers []string `mapstructure:"poet-server"`

MODIFY
datastore/store.go
datastore/store.go
@@ -51,7 +51,7 @@ func (db *CachedDB) MalfeasanceCacheSize() int {
// IsMalicious returns true if the NodeID is malicious.
func (db *CachedDB) IsMalicious(id types.NodeID) (bool, error) {
if id == types.EmptyNodeID {
- return false, errors.New("cache db: get empty node id")
+ log.Fatal("invalid argument to IsMalicious")
}
db.mu.Lock()
@@ -77,7 +77,7 @@ func (db *CachedDB) IsMalicious(id types.NodeID) (bool, error) {
// GetMalfeasanceProof gets the malfeasance proof associated with the NodeID.
func (db *CachedDB) GetMalfeasanceProof(id types.NodeID) (*types.MalfeasanceProof, error) {
if id == types.EmptyNodeID {
- return nil, errors.New("cache db: get empty node id")
+ log.Fatal("invalid argument to GetMalfeasanceProof")
}
db.mu.Lock()
@@ -99,7 +99,7 @@ func (db *CachedDB) GetMalfeasanceProof(id types.NodeID) (*types.MalfeasanceProo
func (db *CachedDB) AddMalfeasanceProof(id types.NodeID, proof *types.MalfeasanceProof, dbtx *sql.Tx) error {
if id == types.EmptyNodeID {
- return errors.New("cache db: add empty node id")
+ log.Fatal("invalid argument to AddMalfeasanceProof")
}
encoded, err := codec.Encode(proof)

MODIFY
datastore/store_test.go
datastore/store_test.go
@@ -22,32 +22,6 @@ import (
"github.com/spacemeshos/go-spacemesh/sql/transactions"
)
-func TestMalfeasanceProof_EmptyNodeID(t *testing.T) {
- db := sql.InMemory()
- cdb := datastore.NewCachedDB(db, logtest.New(t))
- require.Equal(t, 0, cdb.MalfeasanceCacheSize())
-
- // empty node id
- got, err := cdb.GetMalfeasanceProof(types.NodeID{})
- require.Error(t, err)
- require.Nil(t, got)
-
- proof := &types.MalfeasanceProof{
- Layer: types.NewLayerID(11),
- Proof: types.Proof{
- Type: types.MultipleBallots,
- Data: &types.BallotProof{
- Messages: [2]types.BallotProofMsg{
- {},
- {},
- },
- },
- },
- }
- require.Error(t, cdb.AddMalfeasanceProof(types.NodeID{}, proof, nil))
- require.Equal(t, 0, cdb.MalfeasanceCacheSize())
-}
-
func TestMalfeasanceProof_Honest(t *testing.T) {
db := sql.InMemory()
cdb := datastore.NewCachedDB(db, logtest.New(t))
@@ -127,7 +101,6 @@ func TestMalfeasanceProof_Dishonest(t *testing.T) {
},
},
}
- require.Error(t, cdb.AddMalfeasanceProof(types.NodeID{}, proof, nil))
nodeID1 := types.NodeID{1}
require.NoError(t, cdb.AddMalfeasanceProof(nodeID1, proof, nil))

address review feedback for PR 3960 (#3968)

## Motivation
<!-- Please mention the issue fixed by this PR or detailed motivation -->
review feedback for https://github.com/spacemeshos/go-spacemesh/pull/3960