diff --git a/cmd/lotus-provider/proving.go b/cmd/lotus-provider/proving.go index bbe816e80..e58a82b17 100644 --- a/cmd/lotus-provider/proving.go +++ b/cmd/lotus-provider/proving.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "time" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -74,17 +75,13 @@ var wdPostTaskCmd = &cli.Command{ if err != nil { return xerrors.Errorf("cannot get miner id %w", err) } - did, err := deps.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) { - _, err = tx.Exec(`INSERT INTO harmony_task (name, posted_time, added_by) VALUES ('WdPost', CURRENT_TIMESTAMP, 123)`) + var id int64 + _, err = deps.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) { + err = tx.QueryRow(`INSERT INTO harmony_task (name, posted_time, added_by) VALUES ('WdPost', CURRENT_TIMESTAMP, 123) RETURNING id`).Scan(&id) if err != nil { log.Error("inserting harmony_task: ", err) 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 { - log.Error("getting inserted id: ", err) - 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, cctx.Uint64("deadline"), 0) @@ -101,8 +98,17 @@ var wdPostTaskCmd = &cli.Command{ 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.") + fmt.Printf("Inserted task %v. Waiting for success ", id) + var result string + for { + time.Sleep(time.Second) + deps.db.QueryRow(ctx, `SELECT result FROM harmony_test WHERE task_id=$1`, id).Scan(&result) + if result != "" { + break + } + fmt.Print(".") + } + log.Infof("Result:", result) return nil }, } diff --git a/lib/harmony/harmonydb/sql/20231120-testing1.sql b/lib/harmony/harmonydb/sql/20231120-testing1.sql index 0aeb4fc58..22f629a47 100644 --- a/lib/harmony/harmonydb/sql/20231120-testing1.sql +++ b/lib/harmony/harmonydb/sql/20231120-testing1.sql @@ -2,5 +2,6 @@ CREATE TABLE harmony_test ( task_id bigint constraint harmony_test_pk primary key, - options text + options text, + result text ); \ No newline at end of file diff --git a/provider/lpmessage/sender.go b/provider/lpmessage/sender.go index f75f2a4b8..73e0e753e 100644 --- a/provider/lpmessage/sender.go +++ b/provider/lpmessage/sender.go @@ -2,6 +2,7 @@ package lpmessage import ( "context" + "encoding/json" "github.com/google/uuid" "github.com/ipfs/go-cid" @@ -149,15 +150,22 @@ func (s *Sender) Send(ctx context.Context, msg *types.Message, mss *api.MessageS } if 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, - ) + + data, err := json.MarshalIndent(map[string]any{ + "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, + }, "", " ") + if err != nil { + return false, xerrors.Errorf("marshaling message: %w", err) + } + id := ctx.Value(CtxTaskID) + tx.Exec(`UPDATE harmony_test SET result=$1 WHERE task_id=$2`, string(data), id) + log.Infof("SKIPPED sending test message to chain. Query harmony_test WHERE task_id= %v", id) return true, nil // nothing committed } // write to db