Skip to content

Commit

Permalink
stop atx grading at layer N
Browse files Browse the repository at this point in the history
use legacy layer
  • Loading branch information
countvonzero authored and dshulyak committed Aug 11, 2023
1 parent 57041b1 commit b4f342f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
1 change: 1 addition & 0 deletions hare/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Config struct {
ExpectedLeaders int `mapstructure:"hare-exp-leaders"` // the expected number of leaders
LimitIterations int `mapstructure:"hare-limit-iterations"` // limit on number of iterations
LimitConcurrent int `mapstructure:"hare-limit-concurrent"` // limit number of concurrent CPs
StopAtxGrading uint32 `mapstructure:"stop-atx-grading"`

Hdist uint32
}
Expand Down
38 changes: 20 additions & 18 deletions hare/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (h *Hare) onTick(ctx context.Context, lid types.LayerID) (bool, error) {
report: h.outputChan,
wc: h.wcChan,
}
props := goodProposals(ctx, h.Log, h.msh, h.nodeID, lid, beacon, h.layerClock.LayerToTime(lid.GetEpoch().FirstLayer()), h.config.WakeupDelta)
props := goodProposals(ctx, h.Log, h.msh, h.nodeID, lid, types.LayerID(h.config.StopAtxGrading), beacon, h.layerClock.LayerToTime(lid.GetEpoch().FirstLayer()), h.config.WakeupDelta)
preNumProposals.Add(float64(len(props)))
set := NewSet(props)
cp := h.factory(ctx, h.config, lid, set, h.rolacle, et, h.sign, h.publisher, comm, clock)
Expand Down Expand Up @@ -452,7 +452,7 @@ func goodProposals(
logger log.Log,
msh mesh,
nodeID types.NodeID,
lid types.LayerID,
lid, stopGrading types.LayerID,
epochBeacon types.Beacon,
epochStart time.Time,
networkDelay time.Duration,
Expand Down Expand Up @@ -560,22 +560,24 @@ func goodProposals(
)
return []types.ProposalID{}
}
if evil, err := gradeActiveSet(cache, activeSet, msh, epochStart, networkDelay); err != nil {
logger.With().Error("failed to grade active set",
log.Context(ctx),
lid,
p.ID(),
log.Err(err),
)
return []types.ProposalID{}
} else if evil != types.EmptyATXID {
logger.With().Warning("proposal has grade 0 active set",
log.Context(ctx),
lid,
p.ID(),
log.Stringer("evil atx", evil),
)
continue
if lid < stopGrading {
if evil, err := gradeActiveSet(cache, activeSet, msh, epochStart, networkDelay); err != nil {
logger.With().Error("failed to grade active set",
log.Context(ctx),
lid,
p.ID(),
log.Err(err),
)
return []types.ProposalID{}
} else if evil != types.EmptyATXID {
logger.With().Warning("proposal has grade 0 active set",
log.Context(ctx),
lid,
p.ID(),
log.Stringer("evil atx", evil),
)
continue
}
}

if beacon == epochBeacon {
Expand Down
16 changes: 2 additions & 14 deletions hare/hare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,6 @@ func TestHare_onTick(t *testing.T) {
}
for _, p := range pList {
mockMesh.EXPECT().GetAtxHeader(p.AtxID).Return(&types.ActivationTxHeader{BaseTickHeight: 11, TickCount: 1, NodeID: p.SmesherID}, nil)
for _, id := range p.ActiveSet {
nodeID := types.RandomNodeID()
mockMesh.EXPECT().GetAtxHeader(id).Return(&types.ActivationTxHeader{BaseTickHeight: 11, TickCount: 1, NodeID: nodeID}, nil)
mockMesh.EXPECT().GetMalfeasanceProof(nodeID)
}
}
mockMesh.EXPECT().GetEpochAtx(lyrID.GetEpoch()-1, h.nodeID).Return(&types.ActivationTxHeader{BaseTickHeight: 11, TickCount: 1}, nil)
mockMesh.EXPECT().Proposals(lyrID).Return(pList, nil)
Expand Down Expand Up @@ -418,13 +413,6 @@ func TestHare_onTick_notMining(t *testing.T) {
randomProposal(lyrID, beacon),
randomProposal(lyrID, beacon),
}
for _, p := range pList {
for _, id := range p.ActiveSet {
nodeID := types.RandomNodeID()
mockMesh.EXPECT().GetAtxHeader(id).Return(&types.ActivationTxHeader{BaseTickHeight: 11, TickCount: 1, NodeID: nodeID}, nil)
mockMesh.EXPECT().GetMalfeasanceProof(nodeID)
}
}
mockMesh.EXPECT().GetEpochAtx(lyrID.GetEpoch()-1, h.nodeID).Return(nil, sql.ErrNotFound)
mockMesh.EXPECT().Proposals(lyrID).Return(pList, nil)
h.mockCoin.EXPECT().Set(lyrID, gomock.Any()).DoAndReturn(
Expand Down Expand Up @@ -609,7 +597,7 @@ func TestHare_goodProposals(t *testing.T) {
for _, i := range tc.expected {
expected = append(expected, pList[i].ID())
}
got := goodProposals(context.Background(), logtest.New(t), mockMesh, nodeID, lyrID, nodeBeacon, time.Now(), time.Second)
got := goodProposals(context.Background(), logtest.New(t), mockMesh, nodeID, lyrID, types.LayerID(0), nodeBeacon, time.Now(), time.Second)
require.ElementsMatch(t, expected, got)
})
}
Expand Down Expand Up @@ -689,7 +677,7 @@ func TestHare_goodProposals_gradedAtxs(t *testing.T) {
nodeID := types.NodeID{1, 2, 3}
mockMesh.EXPECT().GetEpochAtx(lyrID.GetEpoch()-1, nodeID).Return(&types.ActivationTxHeader{BaseTickHeight: tickHeight, TickCount: 1}, nil)
mockMesh.EXPECT().Proposals(lyrID).Return(pList, nil)
got := goodProposals(context.Background(), logtest.New(t), mockMesh, nodeID, lyrID, beacon, epochStart, delay)
got := goodProposals(context.Background(), logtest.New(t), mockMesh, nodeID, lyrID, lyrID+1, beacon, epochStart, delay)
require.ElementsMatch(t, types.ToProposalIDs(pList[:5]), got)
}

Expand Down
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ func (app *App) initServices(ctx context.Context) error {

hareCfg := app.Config.HARE
hareCfg.Hdist = app.Config.Tortoise.Hdist
hareCfg.StopAtxGrading = types.GetLegacyLayer()
app.hare = hare.New(
app.cachedDB,
hareCfg,
Expand Down

0 comments on commit b4f342f

Please sign in to comment.