lp: test cli, titled sql
This commit is contained in:
parent
1ae7bc7cef
commit
ec43903ad6
@ -43,7 +43,7 @@ func main() {
|
||||
runCmd,
|
||||
stopCmd,
|
||||
configCmd,
|
||||
provingCmd,
|
||||
testCmd,
|
||||
//backupCmd,
|
||||
//lcli.WithCategory("chain", actorCmd),
|
||||
//lcli.WithCategory("storage", sectorsCmd),
|
||||
|
@ -17,31 +17,30 @@ import (
|
||||
"github.com/filecoin-project/lotus/provider"
|
||||
)
|
||||
|
||||
var provingCmd = &cli.Command{
|
||||
Name: "proving",
|
||||
Usage: "Utility functions for proving sectors",
|
||||
var testCmd = &cli.Command{
|
||||
Name: "test",
|
||||
Usage: "Utility functions for testing",
|
||||
Subcommands: []*cli.Command{
|
||||
//provingInfoCmd,
|
||||
provingCompute,
|
||||
wdPostCmd,
|
||||
},
|
||||
}
|
||||
|
||||
var provingCompute = &cli.Command{
|
||||
Name: "compute",
|
||||
Usage: "Compute a proof-of-spacetime for a sector (requires the sector to be pre-sealed)",
|
||||
var wdPostCmd = &cli.Command{
|
||||
Name: "window-post",
|
||||
Aliases: []string{"wd", "windowpost", "wdpost"},
|
||||
Usage: "Compute a proof-of-spacetime for a sector (requires the sector to be pre-sealed). These will not send to the chain.",
|
||||
Subcommands: []*cli.Command{
|
||||
provingComputeWindowPoStCmd,
|
||||
scheduleWindowPostCmd,
|
||||
wdPostHereCmd,
|
||||
wdPostTaskCmd,
|
||||
},
|
||||
}
|
||||
|
||||
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",
|
||||
var wdPostTaskCmd = &cli.Command{
|
||||
Name: "task",
|
||||
Aliases: []string{"scheduled", "schedule", "async", "asynchronous"},
|
||||
Usage: "Test the windowpost scheduler by running it on the next available lotus-provider. ",
|
||||
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 ",
|
||||
@ -56,10 +55,6 @@ var scheduleWindowPostCmd = &cli.Command{
|
||||
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
|
||||
@ -97,19 +92,24 @@ var scheduleWindowPostCmd = &cli.Command{
|
||||
log.Error("inserting wdpost_partition_tasks: ", err)
|
||||
return false, xerrors.Errorf("inserting wdpost_partition_tasks: %w", err)
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO harmony_test (task_id) VALUES ($1)", id)
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("inserting into harmony_tests: %w", err)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("writing SQL transaction: %w", err)
|
||||
}
|
||||
log.Infof("Inserted task %v", did)
|
||||
log.Infof("Check your lotus-provider logs for more details.")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var provingComputeWindowPoStCmd = &cli.Command{
|
||||
Name: "windowed-post",
|
||||
Aliases: []string{"window-post"},
|
||||
var wdPostHereCmd = &cli.Command{
|
||||
Name: "here",
|
||||
Aliases: []string{"cli"},
|
||||
Usage: "Compute WindowPoSt for performance and configuration testing.",
|
||||
Description: `Note: This command is intended to be used to verify PoSt compute performance.
|
||||
It will not send any messages to the chain. Since it can compute any deadline, output may be incorrectly timed for the chain.`,
|
||||
|
@ -246,7 +246,7 @@ func (db *DB) upgrade() error {
|
||||
return xerrors.Errorf("cannot read entries: %w", err)
|
||||
}
|
||||
for _, l := range landedEntries {
|
||||
landed[l.Entry] = true
|
||||
landed[l.Entry[:8]] = true
|
||||
}
|
||||
}
|
||||
dir, err := fs.ReadDir("sql")
|
||||
@ -261,7 +261,11 @@ func (db *DB) upgrade() error {
|
||||
}
|
||||
for _, e := range dir {
|
||||
name := e.Name()
|
||||
if landed[name] || !strings.HasSuffix(name, ".sql") {
|
||||
if !strings.HasSuffix(name, ".sql") {
|
||||
logger.Debug("Must have only SQL files here, found: " + name)
|
||||
continue
|
||||
}
|
||||
if landed[name[:8]] {
|
||||
logger.Debug("DB Schema " + name + " already applied.")
|
||||
continue
|
||||
}
|
||||
@ -283,7 +287,7 @@ func (db *DB) upgrade() error {
|
||||
}
|
||||
|
||||
// Mark Completed.
|
||||
_, err = db.Exec(context.Background(), "INSERT INTO base (entry) VALUES ($1)", name)
|
||||
_, err = db.Exec(context.Background(), "INSERT INTO base (entry) VALUES ($1)", name[:8])
|
||||
if err != nil {
|
||||
logger.Error("Cannot update base: " + err.Error())
|
||||
return xerrors.Errorf("cannot insert into base: %w", err)
|
||||
|
6
lib/harmony/harmonydb/sql/20231120-testing1.sql
Normal file
6
lib/harmony/harmonydb/sql/20231120-testing1.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE TABLE harmony_test (
|
||||
task_id bigint
|
||||
constraint harmony_test_pk
|
||||
primary key,
|
||||
options text
|
||||
);
|
@ -60,6 +60,7 @@ var ChainNode = Options(
|
||||
Override(new(dtypes.NetworkName), modules.NetworkName),
|
||||
Override(new(modules.Genesis), modules.ErrorGenesis),
|
||||
Override(new(dtypes.AfterGenesisSet), modules.SetGenesis),
|
||||
Override(SetGenesisKey, modules.DoSetGenesis),
|
||||
Override(new(beacon.Schedule), modules.RandomSchedule),
|
||||
|
||||
// Network bootstrap
|
||||
|
@ -2,7 +2,6 @@ package lpmessage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -19,6 +18,10 @@ import (
|
||||
|
||||
var log = logging.Logger("lpmessage")
|
||||
|
||||
type str string // makes ctx value collissions impossible
|
||||
|
||||
var CtxTaskID str = "task_id"
|
||||
|
||||
type SenderAPI interface {
|
||||
StateAccountKey(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error)
|
||||
GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error)
|
||||
@ -40,8 +43,7 @@ type Sender struct {
|
||||
api SenderAPI
|
||||
signer SignerAPI
|
||||
|
||||
db *harmonydb.DB
|
||||
noSend bool // For early testing with only 1 lotus-provider
|
||||
db *harmonydb.DB
|
||||
}
|
||||
|
||||
// NewSender creates a new Sender.
|
||||
@ -50,7 +52,6 @@ func NewSender(api SenderAPI, signer SignerAPI, db *harmonydb.DB) *Sender {
|
||||
api: api,
|
||||
signer: signer,
|
||||
db: db,
|
||||
noSend: os.Getenv("LOTUS_PROVDER_NO_SEND") != "",
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,6 +103,14 @@ func (s *Sender) Send(ctx context.Context, msg *types.Message, mss *api.MessageS
|
||||
|
||||
var sigMsg *types.SignedMessage
|
||||
|
||||
var idCount int
|
||||
err = s.db.QueryRow(ctx, `SELECT COUNT(*) FROM harmony_test WHERE task_id=$1`,
|
||||
ctx.Value(CtxTaskID)).Scan(&idCount)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("reading harmony_test: %w", err)
|
||||
}
|
||||
noSend := idCount == 1
|
||||
|
||||
// start db tx
|
||||
c, err := s.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
|
||||
// assign nonce (max(api.MpoolGetNonce, db nonce+1))
|
||||
@ -139,7 +148,7 @@ func (s *Sender) Send(ctx context.Context, msg *types.Message, mss *api.MessageS
|
||||
return false, xerrors.Errorf("marshaling message: %w", err)
|
||||
}
|
||||
|
||||
if s.noSend {
|
||||
if noSend {
|
||||
log.Errorw("SKIPPED SENDING MESSAGE PER ENVIRONMENT VARIABLE - NOT PRODUCTION SAFE",
|
||||
"from_key", fromA.String(),
|
||||
"nonce", msg.Nonce,
|
||||
@ -167,7 +176,7 @@ 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 {
|
||||
if noSend {
|
||||
return sigMsg.Cid(), nil
|
||||
}
|
||||
|
||||
|
@ -149,14 +149,15 @@ func (w *WdPostSubmitTask) Do(taskID harmonytask.TaskID, stillOwned func() bool)
|
||||
return false, xerrors.Errorf("preparing proof message: %w", err)
|
||||
}
|
||||
|
||||
smsg, err := w.sender.Send(context.Background(), msg, mss, "wdpost")
|
||||
ctx := context.WithValue(context.Background(), lpmessage.CtxTaskID, taskID)
|
||||
smsg, err := w.sender.Send(ctx, msg, mss, "wdpost")
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("sending proof message: %w", err)
|
||||
}
|
||||
|
||||
// set message_cid in the wdpost_proofs entry
|
||||
|
||||
_, err = w.db.Exec(context.Background(), `UPDATE wdpost_proofs SET message_cid = $1 WHERE sp_id = $2 AND proving_period_start = $3 AND deadline = $4 AND partition = $5`, smsg.String(), spID, pps, deadline, partition)
|
||||
_, err = w.db.Exec(ctx, `UPDATE wdpost_proofs SET message_cid = $1 WHERE sp_id = $2 AND proving_period_start = $3 AND deadline = $4 AND partition = $5`, smsg.String(), spID, pps, deadline, partition)
|
||||
if err != nil {
|
||||
return true, xerrors.Errorf("updating wdpost_proofs: %w", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user