lp: test cli, titled sql
This commit is contained in:
parent
1ae7bc7cef
commit
ec43903ad6
@ -43,7 +43,7 @@ func main() {
|
|||||||
runCmd,
|
runCmd,
|
||||||
stopCmd,
|
stopCmd,
|
||||||
configCmd,
|
configCmd,
|
||||||
provingCmd,
|
testCmd,
|
||||||
//backupCmd,
|
//backupCmd,
|
||||||
//lcli.WithCategory("chain", actorCmd),
|
//lcli.WithCategory("chain", actorCmd),
|
||||||
//lcli.WithCategory("storage", sectorsCmd),
|
//lcli.WithCategory("storage", sectorsCmd),
|
||||||
|
@ -17,31 +17,30 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/provider"
|
"github.com/filecoin-project/lotus/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
var provingCmd = &cli.Command{
|
var testCmd = &cli.Command{
|
||||||
Name: "proving",
|
Name: "test",
|
||||||
Usage: "Utility functions for proving sectors",
|
Usage: "Utility functions for testing",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
//provingInfoCmd,
|
//provingInfoCmd,
|
||||||
provingCompute,
|
wdPostCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var provingCompute = &cli.Command{
|
var wdPostCmd = &cli.Command{
|
||||||
Name: "compute",
|
Name: "window-post",
|
||||||
Usage: "Compute a proof-of-spacetime for a sector (requires the sector to be pre-sealed)",
|
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{
|
Subcommands: []*cli.Command{
|
||||||
provingComputeWindowPoStCmd,
|
wdPostHereCmd,
|
||||||
scheduleWindowPostCmd,
|
wdPostTaskCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var scheduleWindowPostCmd = &cli.Command{
|
var wdPostTaskCmd = &cli.Command{
|
||||||
Name: "test-window-post",
|
Name: "task",
|
||||||
Usage: "FOR TESTING: a way to test the windowpost scheduler. Use with 1 lotus-provider running only",
|
Aliases: []string{"scheduled", "schedule", "async", "asynchronous"},
|
||||||
|
Usage: "Test the windowpost scheduler by running it on the next available lotus-provider. ",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "i_have_set_LOTUS_PROVDER_NO_SEND_to_true",
|
|
||||||
},
|
|
||||||
&cli.Uint64Flag{
|
&cli.Uint64Flag{
|
||||||
Name: "deadline",
|
Name: "deadline",
|
||||||
Usage: "deadline to compute WindowPoSt for ",
|
Usage: "deadline to compute WindowPoSt for ",
|
||||||
@ -56,10 +55,6 @@ var scheduleWindowPostCmd = &cli.Command{
|
|||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
ctx := context.Background()
|
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)
|
deps, err := getDeps(ctx, cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -97,19 +92,24 @@ var scheduleWindowPostCmd = &cli.Command{
|
|||||||
log.Error("inserting wdpost_partition_tasks: ", err)
|
log.Error("inserting wdpost_partition_tasks: ", err)
|
||||||
return false, xerrors.Errorf("inserting wdpost_partition_tasks: %w", 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
|
return true, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("writing SQL transaction: %w", err)
|
return xerrors.Errorf("writing SQL transaction: %w", err)
|
||||||
}
|
}
|
||||||
log.Infof("Inserted task %v", did)
|
log.Infof("Inserted task %v", did)
|
||||||
|
log.Infof("Check your lotus-provider logs for more details.")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var provingComputeWindowPoStCmd = &cli.Command{
|
var wdPostHereCmd = &cli.Command{
|
||||||
Name: "windowed-post",
|
Name: "here",
|
||||||
Aliases: []string{"window-post"},
|
Aliases: []string{"cli"},
|
||||||
Usage: "Compute WindowPoSt for performance and configuration testing.",
|
Usage: "Compute WindowPoSt for performance and configuration testing.",
|
||||||
Description: `Note: This command is intended to be used to verify PoSt compute performance.
|
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.`,
|
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)
|
return xerrors.Errorf("cannot read entries: %w", err)
|
||||||
}
|
}
|
||||||
for _, l := range landedEntries {
|
for _, l := range landedEntries {
|
||||||
landed[l.Entry] = true
|
landed[l.Entry[:8]] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dir, err := fs.ReadDir("sql")
|
dir, err := fs.ReadDir("sql")
|
||||||
@ -261,7 +261,11 @@ func (db *DB) upgrade() error {
|
|||||||
}
|
}
|
||||||
for _, e := range dir {
|
for _, e := range dir {
|
||||||
name := e.Name()
|
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.")
|
logger.Debug("DB Schema " + name + " already applied.")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -283,7 +287,7 @@ func (db *DB) upgrade() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark Completed.
|
// 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 {
|
if err != nil {
|
||||||
logger.Error("Cannot update base: " + err.Error())
|
logger.Error("Cannot update base: " + err.Error())
|
||||||
return xerrors.Errorf("cannot insert into base: %w", err)
|
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(dtypes.NetworkName), modules.NetworkName),
|
||||||
Override(new(modules.Genesis), modules.ErrorGenesis),
|
Override(new(modules.Genesis), modules.ErrorGenesis),
|
||||||
Override(new(dtypes.AfterGenesisSet), modules.SetGenesis),
|
Override(new(dtypes.AfterGenesisSet), modules.SetGenesis),
|
||||||
|
Override(SetGenesisKey, modules.DoSetGenesis),
|
||||||
Override(new(beacon.Schedule), modules.RandomSchedule),
|
Override(new(beacon.Schedule), modules.RandomSchedule),
|
||||||
|
|
||||||
// Network bootstrap
|
// Network bootstrap
|
||||||
|
@ -2,7 +2,6 @@ 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"
|
||||||
@ -19,6 +18,10 @@ import (
|
|||||||
|
|
||||||
var log = logging.Logger("lpmessage")
|
var log = logging.Logger("lpmessage")
|
||||||
|
|
||||||
|
type str string // makes ctx value collissions impossible
|
||||||
|
|
||||||
|
var CtxTaskID str = "task_id"
|
||||||
|
|
||||||
type SenderAPI interface {
|
type SenderAPI interface {
|
||||||
StateAccountKey(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error)
|
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)
|
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
|
api SenderAPI
|
||||||
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.
|
||||||
@ -50,7 +52,6 @@ func NewSender(api SenderAPI, signer SignerAPI, db *harmonydb.DB) *Sender {
|
|||||||
api: api,
|
api: api,
|
||||||
signer: signer,
|
signer: signer,
|
||||||
db: db,
|
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 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
|
// start db tx
|
||||||
c, err := s.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
|
c, err := s.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
|
||||||
// assign nonce (max(api.MpoolGetNonce, db nonce+1))
|
// 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)
|
return false, xerrors.Errorf("marshaling message: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.noSend {
|
if noSend {
|
||||||
log.Errorw("SKIPPED SENDING MESSAGE PER ENVIRONMENT VARIABLE - NOT PRODUCTION SAFE",
|
log.Errorw("SKIPPED SENDING MESSAGE PER ENVIRONMENT VARIABLE - NOT PRODUCTION SAFE",
|
||||||
"from_key", fromA.String(),
|
"from_key", fromA.String(),
|
||||||
"nonce", msg.Nonce,
|
"nonce", msg.Nonce,
|
||||||
@ -167,7 +176,7 @@ 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 {
|
if noSend {
|
||||||
return sigMsg.Cid(), nil
|
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)
|
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 {
|
if err != nil {
|
||||||
return false, xerrors.Errorf("sending proof message: %w", err)
|
return false, xerrors.Errorf("sending proof message: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set message_cid in the wdpost_proofs entry
|
// 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 {
|
if err != nil {
|
||||||
return true, xerrors.Errorf("updating wdpost_proofs: %w", err)
|
return true, xerrors.Errorf("updating wdpost_proofs: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user