test-window-post
This commit is contained in:
parent
25f9eb4c07
commit
1dc28104a3
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/dline"
|
"github.com/filecoin-project/go-state-types/dline"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
||||||
"github.com/filecoin-project/lotus/provider"
|
"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)",
|
Usage: "Compute a proof-of-spacetime for a sector (requires the sector to be pre-sealed)",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
provingComputeWindowPoStCmd,
|
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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package lpmessage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -40,6 +41,7 @@ type Sender struct {
|
|||||||
signer SignerAPI
|
signer SignerAPI
|
||||||
|
|
||||||
db *harmonydb.DB
|
db *harmonydb.DB
|
||||||
|
noSend bool // For early testing with only 1 lotus-provider
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSender creates a new Sender.
|
// NewSender creates a new Sender.
|
||||||
@ -47,8 +49,8 @@ func NewSender(api SenderAPI, signer SignerAPI, db *harmonydb.DB) *Sender {
|
|||||||
return &Sender{
|
return &Sender{
|
||||||
api: api,
|
api: api,
|
||||||
signer: signer,
|
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)
|
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
|
// 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)`,
|
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)
|
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 {
|
if err != nil || !c {
|
||||||
return cid.Undef, xerrors.Errorf("transaction failed or didn't commit: %w", err)
|
return cid.Undef, xerrors.Errorf("transaction failed or didn't commit: %w", err)
|
||||||
}
|
}
|
||||||
|
if s.noSend {
|
||||||
|
return sigMsg.Cid(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// push to mpool
|
// push to mpool
|
||||||
_, err = s.api.MpoolPush(ctx, sigMsg)
|
_, err = s.api.MpoolPush(ctx, sigMsg)
|
||||||
|
Loading…
Reference in New Issue
Block a user