diff --git a/cmd/lotus-provider/proving.go b/cmd/lotus-provider/proving.go index 129ca342f..584988469 100644 --- a/cmd/lotus-provider/proving.go +++ b/cmd/lotus-provider/proving.go @@ -13,6 +13,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lotus/lib/harmony/harmonydb" "github.com/filecoin-project/lotus/provider" ) @@ -30,6 +31,69 @@ var provingCompute = &cli.Command{ Usage: "Compute a proof-of-spacetime for a sector (requires the sector to be pre-sealed)", Subcommands: []*cli.Command{ provingComputeWindowPoStCmd, + scheduleWindowPostCmd, + }, +} + +var scheduleWindowPostCmd = &cli.Command{ + Name: "test-window-post", + Usage: "FOR TESTING: a way to test the windowpost scheduler. Use with 1 lotus-provider running only", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "i_have_set_LOTUS_PROVDER_NO_SEND_to_true", + }, + &cli.Uint64Flag{ + Name: "deadline", + Usage: "deadline to compute WindowPoSt for ", + Value: 0, + }, + &cli.StringSliceFlag{ + Name: "layers", + Usage: "list of layers to be interpreted (atop defaults). Default: base", + Value: cli.NewStringSlice("base"), + }, + }, + Action: func(cctx *cli.Context) error { + ctx := context.Background() + + if !cctx.Bool("i_have_set_LOTUS_PROVDER_NO_SEND_to_true") { + log.Info("This command is for testing only. It will not send any messages to the chain. If you want to run it, set LOTUS_PROVDER_NO_SEND=true on the lotus-provider environment.") + return nil + } + deps, err := getDeps(ctx, cctx) + if err != nil { + return err + } + + ts, err := deps.full.ChainHead(ctx) + if err != nil { + return xerrors.Errorf("cannot get chainhead %w", err) + } + + ht := ts.Height() + maddr, err := address.IDFromAddress(address.Address(deps.maddrs[0])) + if err != nil { + return xerrors.Errorf("cannot get miner id %w", err) + } + _ = ht + deps.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) { + _, err = tx.Exec(`INSERT INTO harmony_task (name) VALUES ('WdPost')`) + if err != nil { + return false, xerrors.Errorf("inserting harmony_task: %w", err) + } + var id int64 + if err = tx.QueryRow(`SELECT id FROM harmony_task ORDER BY update_time DESC LIMIT 1`).Scan(&id); err != nil { + return false, xerrors.Errorf("getting inserted id: %w", err) + } + _, err = tx.Exec(`INSERT INTO wdpost_partition_tasks + (task_id, sp_id, proving_period_start, deadline_index, partition_index) VALUES ($1, $2, $3, $4, $5)`, + id, maddr, ht, 1, cctx.Uint64("deadline"), 0) + if err != nil { + return false, xerrors.Errorf("inserting wdpost_partition_tasks: %w", err) + } + return true, nil + }) + return nil }, } diff --git a/provider/lpmessage/sender.go b/provider/lpmessage/sender.go index 1dff1d6f7..655b1238b 100644 --- a/provider/lpmessage/sender.go +++ b/provider/lpmessage/sender.go @@ -2,6 +2,7 @@ package lpmessage import ( "context" + "os" "github.com/google/uuid" "github.com/ipfs/go-cid" @@ -39,7 +40,8 @@ type Sender struct { api SenderAPI signer SignerAPI - db *harmonydb.DB + db *harmonydb.DB + noSend bool // For early testing with only 1 lotus-provider } // NewSender creates a new Sender. @@ -47,8 +49,8 @@ func NewSender(api SenderAPI, signer SignerAPI, db *harmonydb.DB) *Sender { return &Sender{ api: api, signer: signer, - - db: db, + db: db, + noSend: os.Getenv("LOTUS_PROVDER_NO_SEND") != "", } } @@ -137,6 +139,18 @@ func (s *Sender) Send(ctx context.Context, msg *types.Message, mss *api.MessageS return false, xerrors.Errorf("marshaling message: %w", err) } + if s.noSend { + log.Errorw("SKIPPED SENDING MESSAGE PER ENVIRONMENT VARIABLE - NOT PRODUCTION SAFE", + "from_key", fromA.String(), + "nonce", msg.Nonce, + "to_addr", msg.To.String(), + "signed_data", data, + "signed_json", string(jsonBytes), + "signed_cid", sigMsg.Cid(), + "send_reason", reason, + ) + return true, nil // nothing committed + } // write to db c, err := tx.Exec(`insert into message_sends (from_key, nonce, to_addr, signed_data, signed_json, signed_cid, send_reason) values ($1, $2, $3, $4, $5, $6, $7)`, fromA.String(), msg.Nonce, msg.To.String(), data, string(jsonBytes), sigMsg.Cid().String(), reason) @@ -153,6 +167,9 @@ func (s *Sender) Send(ctx context.Context, msg *types.Message, mss *api.MessageS if err != nil || !c { return cid.Undef, xerrors.Errorf("transaction failed or didn't commit: %w", err) } + if s.noSend { + return sigMsg.Cid(), nil + } // push to mpool _, err = s.api.MpoolPush(ctx, sigMsg)