lotus/cmd/curio/tasks/tasks.go

168 lines
5.3 KiB
Go
Raw Normal View History

// Package tasks contains tasks that can be run by the curio command.
package tasks
import (
"context"
logging "github.com/ipfs/go-log/v2"
2023-12-15 00:13:44 +00:00
"github.com/samber/lo"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/cmd/curio/deps"
curio "github.com/filecoin-project/lotus/curiosrc"
"github.com/filecoin-project/lotus/curiosrc/chainsched"
"github.com/filecoin-project/lotus/curiosrc/ffi"
"github.com/filecoin-project/lotus/curiosrc/message"
"github.com/filecoin-project/lotus/curiosrc/piece"
"github.com/filecoin-project/lotus/curiosrc/seal"
"github.com/filecoin-project/lotus/curiosrc/winning"
"github.com/filecoin-project/lotus/lib/harmony/harmonytask"
2024-02-28 20:50:12 +00:00
"github.com/filecoin-project/lotus/lib/lazy"
"github.com/filecoin-project/lotus/lib/must"
"github.com/filecoin-project/lotus/node/modules"
)
var log = logging.Logger("curio/deps")
func StartTasks(ctx context.Context, dependencies *deps.Deps) (*harmonytask.TaskEngine, error) {
cfg := dependencies.Cfg
db := dependencies.DB
full := dependencies.Full
verif := dependencies.Verif
lw := dependencies.LW
as := dependencies.As
maddrs := dependencies.Maddrs
stor := dependencies.Stor
2023-12-19 11:16:38 +00:00
lstor := dependencies.LocalStore
si := dependencies.Si
var activeTasks []harmonytask.TaskInterface
sender, sendTask := message.NewSender(full, full, db)
activeTasks = append(activeTasks, sendTask)
2024-01-05 15:10:34 +00:00
chainSched := chainsched.New(full)
var needProofParams bool
///////////////////////////////////////////////////////////////////////
///// Task Selection
///////////////////////////////////////////////////////////////////////
{
2023-12-19 11:16:38 +00:00
// PoSt
if cfg.Subsystems.EnableWindowPost {
wdPostTask, wdPoStSubmitTask, derlareRecoverTask, err := curio.WindowPostScheduler(
ctx, cfg.Fees, cfg.Proving, full, verif, lw, sender, chainSched,
as, maddrs, db, stor, si, cfg.Subsystems.WindowPostMaxTasks)
if err != nil {
return nil, err
}
activeTasks = append(activeTasks, wdPostTask, wdPoStSubmitTask, derlareRecoverTask)
needProofParams = true
}
if cfg.Subsystems.EnableWinningPost {
winPoStTask := winning.NewWinPostTask(cfg.Subsystems.WinningPostMaxTasks, db, lw, verif, full, maddrs)
activeTasks = append(activeTasks, winPoStTask)
needProofParams = true
}
}
2023-12-19 11:16:38 +00:00
slrLazy := lazy.MakeLazy(func() (*ffi.SealCalls, error) {
return ffi.NewSealCalls(stor, lstor, si), nil
2024-02-28 19:57:12 +00:00
})
{
// Piece handling
if cfg.Subsystems.EnableParkPiece {
parkPieceTask := piece.NewParkPieceTask(db, must.One(slrLazy.Val()), cfg.Subsystems.ParkPieceMaxTasks)
cleanupPieceTask := piece.NewCleanupPieceTask(db, must.One(slrLazy.Val()), 0)
2024-03-11 20:35:16 +00:00
activeTasks = append(activeTasks, parkPieceTask, cleanupPieceTask)
2024-02-28 19:57:12 +00:00
}
}
2024-02-14 13:26:55 +00:00
hasAnySealingTask := cfg.Subsystems.EnableSealSDR ||
cfg.Subsystems.EnableSealSDRTrees ||
cfg.Subsystems.EnableSendPrecommitMsg ||
cfg.Subsystems.EnablePoRepProof ||
cfg.Subsystems.EnableMoveStorage ||
cfg.Subsystems.EnableSendCommitMsg
2023-12-19 11:16:38 +00:00
{
// Sealing
var sp *seal.SealPoller
var slr *ffi.SealCalls
2023-12-19 11:16:38 +00:00
if hasAnySealingTask {
sp = seal.NewPoller(db, full)
2023-12-19 11:16:38 +00:00
go sp.RunPoller(ctx)
2024-02-28 19:57:12 +00:00
slr = must.One(slrLazy.Val())
2023-12-19 11:16:38 +00:00
}
2024-02-12 13:08:38 +00:00
// NOTE: Tasks with the LEAST priority are at the top
2023-12-19 11:16:38 +00:00
if cfg.Subsystems.EnableSealSDR {
sdrTask := seal.NewSDRTask(full, db, sp, slr, cfg.Subsystems.SealSDRMaxTasks)
2023-12-19 11:16:38 +00:00
activeTasks = append(activeTasks, sdrTask)
}
2023-12-20 13:45:19 +00:00
if cfg.Subsystems.EnableSealSDRTrees {
treesTask := seal.NewTreesTask(sp, db, slr, cfg.Subsystems.SealSDRTreesMaxTasks)
finalizeTask := seal.NewFinalizeTask(cfg.Subsystems.FinalizeMaxTasks, sp, slr, db)
2024-01-30 11:43:57 +00:00
activeTasks = append(activeTasks, treesTask, finalizeTask)
2023-12-20 13:45:19 +00:00
}
2024-01-05 15:10:34 +00:00
if cfg.Subsystems.EnableSendPrecommitMsg {
precommitTask := seal.NewSubmitPrecommitTask(sp, db, full, sender, as, cfg.Fees.MaxPreCommitGasFee)
2024-01-05 15:10:34 +00:00
activeTasks = append(activeTasks, precommitTask)
}
2024-01-11 15:47:07 +00:00
if cfg.Subsystems.EnablePoRepProof {
porepTask := seal.NewPoRepTask(db, full, sp, slr, cfg.Subsystems.PoRepProofMaxTasks)
2024-01-11 15:47:07 +00:00
activeTasks = append(activeTasks, porepTask)
needProofParams = true
2024-01-11 15:47:07 +00:00
}
2024-01-30 19:05:47 +00:00
if cfg.Subsystems.EnableMoveStorage {
moveStorageTask := seal.NewMoveStorageTask(sp, slr, db, cfg.Subsystems.MoveStorageMaxTasks)
2024-01-30 19:05:47 +00:00
activeTasks = append(activeTasks, moveStorageTask)
}
2024-01-11 18:24:28 +00:00
if cfg.Subsystems.EnableSendCommitMsg {
commitTask := seal.NewSubmitCommitTask(sp, db, full, sender, as, cfg.Fees.MaxCommitGasFee)
2024-01-11 18:24:28 +00:00
activeTasks = append(activeTasks, commitTask)
}
2023-12-19 11:16:38 +00:00
}
if needProofParams {
for spt := range dependencies.ProofTypes {
if err := modules.GetParams(true)(spt); err != nil {
return nil, xerrors.Errorf("getting params: %w", err)
}
}
}
log.Infow("This lotus_provider instance handles",
"miner_addresses", maddrs,
"tasks", lo.Map(activeTasks, func(t harmonytask.TaskInterface, _ int) string { return t.TypeDetails().Name }))
2024-02-12 13:08:38 +00:00
// harmony treats the first task as highest priority, so reverse the order
// (we could have just appended to this list in the reverse order, but defining
// tasks in pipeline order is more intuitive)
activeTasks = lo.Reverse(activeTasks)
2024-01-05 15:10:34 +00:00
ht, err := harmonytask.New(db, activeTasks, dependencies.ListenAddr)
if err != nil {
return nil, err
}
if hasAnySealingTask {
watcher, err := message.NewMessageWatcher(db, ht, chainSched, full)
2024-01-05 15:10:34 +00:00
if err != nil {
return nil, err
}
_ = watcher
}
if cfg.Subsystems.EnableWindowPost || hasAnySealingTask {
go chainSched.Run(ctx)
}
return ht, nil
}