2023-12-18 11:02:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-12 10:03:37 +00:00
|
|
|
|
2024-05-07 11:03:51 +00:00
|
|
|
"github.com/ipfs/go-datastore"
|
2024-01-12 10:03:37 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2023-12-18 11:02:48 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2024-01-12 10:03:37 +00:00
|
|
|
|
2023-12-18 11:02:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2024-03-15 21:38:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/deps"
|
2024-05-07 11:03:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/guidedsetup"
|
2024-03-15 21:38:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/curiosrc/seal"
|
2023-12-18 11:02:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
2024-05-07 11:03:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2023-12-18 11:02:48 +00:00
|
|
|
)
|
|
|
|
|
2024-02-12 17:03:47 +00:00
|
|
|
var sealCmd = &cli.Command{
|
|
|
|
Name: "seal",
|
2023-12-18 11:02:48 +00:00
|
|
|
Usage: "Manage the sealing pipeline",
|
|
|
|
Subcommands: []*cli.Command{
|
2024-02-12 17:03:47 +00:00
|
|
|
sealStartCmd,
|
2024-05-07 11:03:51 +00:00
|
|
|
sealMigrateLMSectorsCmd,
|
2023-12-18 11:02:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-02-12 17:03:47 +00:00
|
|
|
var sealStartCmd = &cli.Command{
|
2023-12-18 11:02:48 +00:00
|
|
|
Name: "start",
|
|
|
|
Usage: "Start new sealing operations manually",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "actor",
|
|
|
|
Usage: "Specify actor address to start sealing sectors for",
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "now",
|
|
|
|
Usage: "Start sealing sectors for all actors now (not on schedule)",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "cc",
|
|
|
|
Usage: "Start sealing new CC sectors",
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "count",
|
|
|
|
Usage: "Number of sectors to start",
|
|
|
|
Value: 1,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "synthetic",
|
|
|
|
Usage: "Use synthetic PoRep",
|
2024-01-11 22:55:26 +00:00
|
|
|
Value: false, // todo implement synthetic
|
2023-12-18 11:02:48 +00:00
|
|
|
},
|
2024-03-06 09:41:37 +00:00
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "layers",
|
|
|
|
Usage: "list of layers to be interpreted (atop defaults). Default: base",
|
|
|
|
},
|
2023-12-18 11:02:48 +00:00
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
if !cctx.Bool("now") {
|
|
|
|
return xerrors.Errorf("schedule not implemented, use --now")
|
|
|
|
}
|
|
|
|
if !cctx.IsSet("actor") {
|
|
|
|
return cli.ShowCommandHelp(cctx, "start")
|
|
|
|
}
|
2023-12-18 22:48:49 +00:00
|
|
|
if !cctx.Bool("cc") {
|
|
|
|
return xerrors.Errorf("only CC sectors supported for now")
|
|
|
|
}
|
2023-12-18 11:02:48 +00:00
|
|
|
|
|
|
|
act, err := address.NewFromString(cctx.String("actor"))
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("parsing --actor: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
dep, err := deps.GetDepsCLI(ctx, cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
create table sectors_sdr_pipeline (
|
|
|
|
sp_id bigint not null,
|
|
|
|
sector_number bigint not null,
|
|
|
|
|
|
|
|
-- at request time
|
|
|
|
create_time timestamp not null,
|
|
|
|
reg_seal_proof int not null,
|
|
|
|
comm_d_cid text not null,
|
|
|
|
|
|
|
|
[... other not relevant fields]
|
|
|
|
*/
|
|
|
|
|
|
|
|
mid, err := address.IDFromAddress(act)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner id: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mi, err := dep.Full.StateMinerInfo(ctx, act, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
nv, err := dep.Full.StateNetworkVersion(ctx, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting network version: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
wpt := mi.WindowPoStProofType
|
|
|
|
spt, err := miner.PreferredSealProofTypeFromWindowPoStType(nv, wpt, cctx.Bool("synthetic"))
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting seal proof type: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-03-15 21:38:13 +00:00
|
|
|
num, err := seal.AllocateSectorNumbers(ctx, dep.Full, dep.DB, act, cctx.Int("count"), func(tx *harmonydb.Tx, numbers []abi.SectorNumber) (bool, error) {
|
2023-12-18 11:02:48 +00:00
|
|
|
for _, n := range numbers {
|
2023-12-18 22:48:49 +00:00
|
|
|
_, err := tx.Exec("insert into sectors_sdr_pipeline (sp_id, sector_number, reg_seal_proof) values ($1, $2, $3)", mid, n, spt)
|
2023-12-18 11:02:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("inserting into sectors_sdr_pipeline: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("allocating sector numbers: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, number := range num {
|
|
|
|
fmt.Println(number)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2024-05-07 11:03:51 +00:00
|
|
|
|
|
|
|
var sealMigrateLMSectorsCmd = &cli.Command{
|
|
|
|
Name: "migrate-lm-sectors",
|
|
|
|
Usage: "(debug tool) Copy LM sector metadata into Curio DB",
|
|
|
|
Hidden: true, // only needed in advanced cases where manual repair is needed
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "miner-repo",
|
|
|
|
Usage: "Path to miner repo",
|
|
|
|
Value: "~/.lotusminer",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "seal-ignore",
|
|
|
|
Usage: "Ignore sectors that cannot be migrated",
|
|
|
|
Value: false,
|
|
|
|
EnvVars: []string{"CURUO_MIGRATE_SEAL_IGNORE"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
db, err := deps.MakeDB(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := repo.NewFS(cctx.String("miner-repo"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ok, err := r.Exists()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("repo not initialized at: %s", cctx.String("miner-repo"))
|
|
|
|
}
|
|
|
|
|
|
|
|
lr, err := r.LockRO(repo.StorageMiner)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("locking repo: %w", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = lr.Close()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("error closing repo: ", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
mmeta, err := lr.Datastore(ctx, "/metadata")
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("opening miner metadata datastore: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
maddrBytes, err := mmeta.Get(ctx, datastore.NewKey("miner-address"))
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner address datastore entry: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromBytes(maddrBytes)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("parsing miner actor address: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
unmigSectorShouldFail := func() bool { return !cctx.Bool("seal-ignore") }
|
|
|
|
|
|
|
|
err = guidedsetup.MigrateSectors(ctx, addr, mmeta, db, func(n int) {
|
|
|
|
fmt.Printf("Migrating %d sectors\n", n)
|
|
|
|
}, unmigSectorShouldFail)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("migrating sectors: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|