2021-05-20 11:10:14 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/api/client"
|
2024-02-01 19:44:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v1api"
|
2021-05-20 11:10:14 +00:00
|
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
2021-05-20 11:10:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MinerSealingService api.StorageMiner
|
|
|
|
type MinerStorageService api.StorageMiner
|
|
|
|
|
|
|
|
var _ sectorblocks.SectorBuilder = *new(MinerSealingService)
|
|
|
|
|
2024-02-01 19:44:29 +00:00
|
|
|
func connectMinerService(apiInfo string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fapi v1api.FullNode) (api.StorageMiner, error) {
|
|
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fapi v1api.FullNode) (api.StorageMiner, error) {
|
2021-05-20 11:10:14 +00:00
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
info := cliutil.ParseApiInfo(apiInfo)
|
|
|
|
addr, err := info.DialArgs("v0")
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("could not get DialArgs: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-05-26 10:47:21 +00:00
|
|
|
log.Infof("Checking (svc) api version of %s", addr)
|
2021-05-20 11:10:14 +00:00
|
|
|
|
|
|
|
mapi, closer, err := client.NewStorageMinerRPCV0(ctx, addr, info.AuthHeader())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStart: func(ctx context.Context) error {
|
|
|
|
v, err := mapi.Version(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("checking version: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !v.APIVersion.EqMajorMinor(api.MinerAPIVersion0) {
|
|
|
|
return xerrors.Errorf("remote service API version didn't match (expected %s, remote %s)", api.MinerAPIVersion0, v.APIVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
OnStop: func(context.Context) error {
|
|
|
|
closer()
|
|
|
|
return nil
|
|
|
|
}})
|
|
|
|
|
|
|
|
return mapi, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-01 19:44:29 +00:00
|
|
|
func ConnectSealingService(apiInfo string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fapi v1api.FullNode) (MinerSealingService, error) {
|
|
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fapi v1api.FullNode) (MinerSealingService, error) {
|
2021-05-26 10:47:21 +00:00
|
|
|
log.Info("Connecting sealing service to miner")
|
2024-02-01 19:44:29 +00:00
|
|
|
return connectMinerService(apiInfo)(mctx, lc, fapi)
|
2021-05-20 11:10:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-01 19:44:29 +00:00
|
|
|
func ConnectStorageService(apiInfo string) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fapi v1api.FullNode) (MinerStorageService, error) {
|
|
|
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, fapi v1api.FullNode) (MinerStorageService, error) {
|
2021-05-26 10:47:21 +00:00
|
|
|
log.Info("Connecting storage service to miner")
|
2024-02-01 19:44:29 +00:00
|
|
|
return connectMinerService(apiInfo)(mctx, lc, fapi)
|
2021-05-20 11:10:14 +00:00
|
|
|
}
|
|
|
|
}
|