From 30cf227ef52a78a037282e406e85f799def8520c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 11 Nov 2023 12:44:36 +0100 Subject: [PATCH] lpwinning: select lowest epoch task id for mining task --- provider/lpwinning/winning_task.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/provider/lpwinning/winning_task.go b/provider/lpwinning/winning_task.go index e65823921..06bff5255 100644 --- a/provider/lpwinning/winning_task.go +++ b/provider/lpwinning/winning_task.go @@ -398,7 +398,23 @@ func (t *WinPostTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.Ta return nil, nil } - return &ids[0], nil + // select lowest epoch + var lowestEpoch abi.ChainEpoch + var lowestEpochID = ids[0] + for _, id := range ids { + var epoch uint64 + err := t.db.QueryRow(context.Background(), `SELECT epoch FROM mining_tasks WHERE task_id = $1`, id).Scan(&epoch) + if err != nil { + return nil, err + } + + if lowestEpoch == 0 || abi.ChainEpoch(epoch) < lowestEpoch { + lowestEpoch = abi.ChainEpoch(epoch) + lowestEpochID = id + } + } + + return &lowestEpochID, nil } func (t *WinPostTask) TypeDetails() harmonytask.TaskTypeDetails {