2021-05-20 11:10:14 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-11-14 00:06:11 +00:00
|
|
|
|
2021-05-20 11:10:14 +00:00
|
|
|
"go.uber.org/fx"
|
|
|
|
"golang.org/x/xerrors"
|
2023-11-14 00:06:11 +00:00
|
|
|
|
2021-05-20 11:10:14 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2023-11-14 00:06:11 +00:00
|
|
|
|
2021-05-20 11:10:14 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2022-08-16 19:56:32 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v1api"
|
2021-08-26 13:59:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2021-05-20 11:10:14 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/gen"
|
|
|
|
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
|
2023-07-14 23:05:49 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
2021-05-20 11:10:14 +00:00
|
|
|
"github.com/filecoin-project/lotus/miner"
|
|
|
|
"github.com/filecoin-project/lotus/node/config"
|
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
|
|
|
"github.com/filecoin-project/lotus/storage"
|
2022-06-14 17:32:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/ctladdr"
|
2022-06-14 18:25:52 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/paths"
|
2022-06-14 17:41:59 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
2022-06-14 18:03:38 +00:00
|
|
|
sectorstorage "github.com/filecoin-project/lotus/storage/sealer"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2021-05-20 11:10:14 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
2022-06-14 17:27:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/wdpost"
|
2021-05-20 11:10:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var MinerNode = Options(
|
|
|
|
Override(new(sectorstorage.StorageAuth), modules.StorageAuth),
|
|
|
|
|
|
|
|
// Actor config
|
|
|
|
Override(new(dtypes.MinerAddress), modules.MinerAddress),
|
|
|
|
Override(new(dtypes.MinerID), modules.MinerID),
|
|
|
|
Override(new(abi.RegisteredSealProof), modules.SealProofType),
|
|
|
|
Override(new(dtypes.NetworkName), modules.StorageNetworkName),
|
|
|
|
|
|
|
|
// Mining / proving
|
2022-06-14 17:32:29 +00:00
|
|
|
Override(new(*ctladdr.AddressSelector), modules.AddressSelector(nil)),
|
2021-05-20 11:10:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ConfigStorageMiner(c interface{}) Option {
|
|
|
|
cfg, ok := c.(*config.StorageMiner)
|
|
|
|
if !ok {
|
|
|
|
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
|
|
|
|
}
|
|
|
|
|
|
|
|
return Options(
|
2022-04-06 19:04:39 +00:00
|
|
|
|
2022-08-17 14:47:05 +00:00
|
|
|
Override(new(v1api.FullNode), modules.MakeUuidWrapper),
|
2022-04-06 19:04:39 +00:00
|
|
|
// Needed to instantiate pubsub used by index provider via ConfigCommon
|
|
|
|
Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
|
|
|
|
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
|
|
|
|
Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap),
|
2024-06-05 14:14:50 +00:00
|
|
|
ConfigCommon(&cfg.Common, build.NodeUserVersion(), false),
|
2021-05-20 11:10:14 +00:00
|
|
|
|
2021-08-26 13:59:54 +00:00
|
|
|
Override(CheckFDLimit, modules.CheckFdLimit(build.MinerFDLimit)), // recommend at least 100k FD limit to miners
|
2021-08-17 12:39:36 +00:00
|
|
|
|
2021-07-28 22:46:21 +00:00
|
|
|
Override(new(api.MinerSubsystems), modules.ExtractEnabledMinerSubsystems(cfg.Subsystems)),
|
2022-06-14 18:25:52 +00:00
|
|
|
Override(new(paths.LocalStorage), From(new(repo.LockedRepo))),
|
|
|
|
Override(new(*paths.Local), modules.LocalStorage),
|
|
|
|
Override(new(*paths.Remote), modules.RemoteStorage),
|
|
|
|
Override(new(paths.Store), From(new(*paths.Remote))),
|
2021-05-20 11:10:14 +00:00
|
|
|
|
2022-09-29 12:08:05 +00:00
|
|
|
If(cfg.Subsystems.EnableMining || cfg.Subsystems.EnableSealing,
|
|
|
|
Override(GetParamsKey, modules.GetParams(!cfg.Proving.DisableBuiltinWindowPoSt || !cfg.Proving.DisableBuiltinWinningPoSt || cfg.Storage.AllowCommit || cfg.Storage.AllowProveReplicaUpdate2)),
|
|
|
|
),
|
|
|
|
|
2021-05-20 11:10:14 +00:00
|
|
|
If(!cfg.Subsystems.EnableMining,
|
|
|
|
If(cfg.Subsystems.EnableSealing, Error(xerrors.Errorf("sealing can only be enabled on a mining node"))),
|
|
|
|
If(cfg.Subsystems.EnableSectorStorage, Error(xerrors.Errorf("sealing can only be enabled on a mining node"))),
|
|
|
|
),
|
2023-08-29 16:28:44 +00:00
|
|
|
|
2021-05-20 11:10:14 +00:00
|
|
|
If(cfg.Subsystems.EnableMining,
|
|
|
|
If(!cfg.Subsystems.EnableSealing, Error(xerrors.Errorf("sealing can't be disabled on a mining node yet"))),
|
|
|
|
If(!cfg.Subsystems.EnableSectorStorage, Error(xerrors.Errorf("sealing can't be disabled on a mining node yet"))),
|
|
|
|
|
|
|
|
// Sector storage: Proofs
|
2022-06-17 11:52:19 +00:00
|
|
|
Override(new(storiface.Verifier), ffiwrapper.ProofVerifier),
|
|
|
|
Override(new(storiface.Prover), ffiwrapper.ProofProver),
|
|
|
|
Override(new(storiface.ProverPoSt), From(new(sectorstorage.SectorManager))),
|
2021-05-20 11:10:14 +00:00
|
|
|
|
|
|
|
Override(new(dtypes.SetSealingConfigFunc), modules.NewSetSealConfigFunc),
|
|
|
|
Override(new(dtypes.GetSealingConfigFunc), modules.NewGetSealConfigFunc),
|
|
|
|
|
|
|
|
// Mining / proving
|
|
|
|
Override(new(*slashfilter.SlashFilter), modules.NewSlashFilter),
|
2023-11-11 11:19:58 +00:00
|
|
|
|
|
|
|
If(!cfg.Subsystems.DisableWinningPoSt,
|
|
|
|
Override(new(*miner.Miner), modules.SetupBlockProducer),
|
|
|
|
Override(new(gen.WinningPoStProver), storage.NewWinningPoStProver),
|
|
|
|
),
|
|
|
|
|
2022-08-09 11:30:34 +00:00
|
|
|
Override(PreflightChecksKey, modules.PreflightChecks),
|
|
|
|
Override(new(*sealing.Sealing), modules.SealingPipeline(cfg.Fees)),
|
|
|
|
|
2023-11-09 17:11:10 +00:00
|
|
|
If(!cfg.Subsystems.DisableWindowPoSt, Override(new(*wdpost.WindowPoStScheduler), modules.WindowPostScheduler(cfg.Fees, cfg.Proving))),
|
2022-08-09 11:30:34 +00:00
|
|
|
Override(new(sectorblocks.SectorBuilder), From(new(*sealing.Sealing))),
|
2021-05-20 11:10:14 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
If(cfg.Subsystems.EnableSectorStorage,
|
|
|
|
// Sector storage
|
2023-11-15 13:59:35 +00:00
|
|
|
If(cfg.Subsystems.EnableSectorIndexDB,
|
|
|
|
Override(new(*paths.DBIndex), paths.NewDBIndex),
|
|
|
|
Override(new(paths.SectorIndex), From(new(*paths.DBIndex))),
|
2023-11-23 16:57:03 +00:00
|
|
|
|
|
|
|
// sector index db is the only thing on lotus-miner that will use harmonydb
|
|
|
|
Override(new(*harmonydb.DB), func(cfg config.HarmonyDB, id harmonydb.ITestID) (*harmonydb.DB, error) {
|
|
|
|
return harmonydb.NewFromConfigWithITestID(cfg)(id)
|
|
|
|
}),
|
2023-11-15 13:59:35 +00:00
|
|
|
),
|
|
|
|
If(!cfg.Subsystems.EnableSectorIndexDB,
|
|
|
|
Override(new(*paths.MemIndex), paths.NewMemIndex),
|
|
|
|
Override(new(paths.SectorIndex), From(new(*paths.MemIndex))),
|
|
|
|
),
|
|
|
|
|
2021-05-20 11:10:14 +00:00
|
|
|
Override(new(*sectorstorage.Manager), modules.SectorStorage),
|
|
|
|
Override(new(sectorstorage.Unsealer), From(new(*sectorstorage.Manager))),
|
|
|
|
Override(new(sectorstorage.SectorManager), From(new(*sectorstorage.Manager))),
|
|
|
|
Override(new(storiface.WorkerReturn), From(new(sectorstorage.SectorManager))),
|
|
|
|
),
|
|
|
|
|
|
|
|
If(!cfg.Subsystems.EnableSectorStorage,
|
2021-06-01 09:42:28 +00:00
|
|
|
Override(new(sectorstorage.StorageAuth), modules.StorageAuthWithURL(cfg.Subsystems.SectorIndexApiInfo)),
|
2021-05-20 11:10:14 +00:00
|
|
|
Override(new(modules.MinerStorageService), modules.ConnectStorageService(cfg.Subsystems.SectorIndexApiInfo)),
|
|
|
|
Override(new(sectorstorage.Unsealer), From(new(modules.MinerStorageService))),
|
|
|
|
Override(new(sectorblocks.SectorBuilder), From(new(modules.MinerStorageService))),
|
|
|
|
),
|
|
|
|
If(!cfg.Subsystems.EnableSealing,
|
|
|
|
Override(new(modules.MinerSealingService), modules.ConnectSealingService(cfg.Subsystems.SealerApiInfo)),
|
2022-06-14 18:25:52 +00:00
|
|
|
Override(new(paths.SectorIndex), From(new(modules.MinerSealingService))),
|
2021-05-20 11:10:14 +00:00
|
|
|
),
|
|
|
|
|
2022-10-31 17:15:09 +00:00
|
|
|
Override(new(config.SealerConfig), cfg.Storage),
|
|
|
|
Override(new(config.ProvingConfig), cfg.Proving),
|
2023-07-14 23:05:49 +00:00
|
|
|
Override(new(config.HarmonyDB), cfg.HarmonyDB),
|
|
|
|
Override(new(harmonydb.ITestID), harmonydb.ITestID("")),
|
2022-06-14 17:32:29 +00:00
|
|
|
Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&cfg.Addresses)),
|
2024-06-28 17:10:58 +00:00
|
|
|
If(build.F3Enabled, Override(F3Participation, modules.F3Participation)),
|
2021-05-20 11:10:14 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-05 14:14:50 +00:00
|
|
|
func StorageMiner(out *api.StorageMiner) Option {
|
2021-05-20 11:10:14 +00:00
|
|
|
return Options(
|
|
|
|
ApplyIf(func(s *Settings) bool { return s.Config },
|
|
|
|
Error(errors.New("the StorageMiner option must be set before Config option")),
|
|
|
|
),
|
|
|
|
|
|
|
|
func(s *Settings) error {
|
|
|
|
s.nodeType = repo.StorageMiner
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
|
|
|
|
func(s *Settings) error {
|
|
|
|
resAPI := &impl.StorageMinerAPI{}
|
|
|
|
s.invokes[ExtractApiKey] = fx.Populate(resAPI)
|
|
|
|
*out = resAPI
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|