Skip to content

Commit

Permalink
fix TestEquivocation
Browse files Browse the repository at this point in the history
  • Loading branch information
countvonzero committed Aug 20, 2023
1 parent 6c8acd7 commit 4bdad34
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func (cfg *Config) DataDir() string {
}

type TestConfig struct {
SmesherKey string `mapstructure:"testing-smesher-key"`
SmesherKey string `mapstructure:"testing-smesher-key"`
MinerGoodAtxPct int
}

// BaseConfig defines the default configuration options for spacemesh app.
Expand Down
2 changes: 2 additions & 0 deletions config/presets/fastnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func fastnet() config.Config {
types.SetNetworkHRP(conf.NetworkHRP) // set to generate coinbase
conf.BaseConfig.OptFilterThreshold = 90

conf.BaseConfig.TestConfig.MinerGoodAtxPct = 50

conf.HARE.N = 800
conf.HARE.ExpectedLeaders = 10
conf.HARE.LimitConcurrent = 5
Expand Down
3 changes: 2 additions & 1 deletion miner/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (o *Oracle) activeSet(targetEpoch types.EpochID) (uint64, uint64, types.ATX

if total := numOmitted + len(atxids); total == 0 {
return 0, 0, types.EmptyATXID, nil, errEmptyActiveSet

Check warning on line 182 in miner/oracle.go

View check run for this annotation

Codecov / codecov/patch

miner/oracle.go#L182

Added line #L182 was not covered by tests
} else if numOmitted*100/total > 100-o.cfg.syncedPct {
} else if numOmitted*100/total > 100-o.cfg.goodAtxPct {
// if the node is not synced during `targetEpoch-1`, it doesn't have the correct receipt timestamp
// for all the atx and malfeasance proof. this active set is not usable.
// TODO: change after timing info of ATXs and malfeasance proofs is sync'ed from peers as well
Expand All @@ -198,6 +198,7 @@ func (o *Oracle) activeSet(targetEpoch types.EpochID) (uint64, uint64, types.ATX
o.log.With().Info("active set selected for proposal",
log.Int("num atx", len(atxids)),
log.Int("num omitted", numOmitted),
log.Int("min atx good pct", o.cfg.goodAtxPct),
)
}
return ownWeight, totalWeight, ownAtx, atxids, nil
Expand Down
2 changes: 1 addition & 1 deletion miner/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestOracle_NewNode(t *testing.T) {
avgLayerSize := uint32(10)
lyrsPerEpoch := uint32(20)
o := createTestOracle(t, avgLayerSize, lyrsPerEpoch, 0)
o.cfg.syncedPct = 90
o.cfg.goodAtxPct = 90
lid := types.LayerID(lyrsPerEpoch * 3)
o.mClock.EXPECT().LayerToTime(gomock.Any()).Return(time.Now())
common := types.RandomActiveSet(100)
Expand Down
9 changes: 7 additions & 2 deletions miner/proposal_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type config struct {
networkDelay time.Duration

// used to determine whether a node has enough information on the active set this epoch
syncedPct int
goodAtxPct int
}

type defaultFetcher struct {
Expand Down Expand Up @@ -133,6 +133,12 @@ func WithNetworkDelay(delay time.Duration) Opt {
}
}

func WithMinGoodAtxPct(pct int) Opt {
return func(pb *ProposalBuilder) {
pb.cfg.goodAtxPct = pct
}
}

func withOracle(o proposalOracle) Opt {
return func(pb *ProposalBuilder) {
pb.proposalOracle = o
Expand Down Expand Up @@ -176,7 +182,6 @@ func NewProposalBuilder(
for _, opt := range opts {
opt(pb)
}
pb.cfg.syncedPct = 90
if pb.proposalOracle == nil {
pb.proposalOracle = newMinerOracle(pb.cfg, clock, cdb, vrfSigner, syncer, pb.logger)
}
Expand Down
6 changes: 6 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,11 @@ func (app *App) initServices(ctx context.Context) error {
app.addLogger(HareLogger, lg),
)

minerGoodAtxPct := 90
if app.Config.TestConfig.MinerGoodAtxPct > 0 {
// only set this for systest TestEquivocation.
minerGoodAtxPct = app.Config.TestConfig.MinerGoodAtxPct
}

Check warning on line 770 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L768-L770

Added lines #L768 - L770 were not covered by tests
proposalBuilder := miner.NewProposalBuilder(
ctx,
app.clock,
Expand All @@ -780,6 +785,7 @@ func (app *App) initServices(ctx context.Context) error {
miner.WithMinimalActiveSetWeight(app.Config.Tortoise.MinimalActiveSetWeight),
miner.WithHdist(app.Config.Tortoise.Hdist),
miner.WithNetworkDelay(app.Config.HARE.WakeupDelta),
miner.WithMinGoodAtxPct(minerGoodAtxPct),
miner.WithLogger(app.addLogger(ProposalBuilderLogger, lg)),
)

Expand Down

0 comments on commit 4bdad34

Please sign in to comment.