From 1ae7bc7cef8cc22d30bde50795441cdc85ebc673 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Fri, 17 Nov 2023 07:43:58 -0600 Subject: [PATCH] lp test fixes --- cmd/lotus-provider/proving.go | 22 ++++++++++++++++------ lib/harmony/harmonydb/userfuncs.go | 6 ++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/lotus-provider/proving.go b/cmd/lotus-provider/proving.go index 584988469..63c6bdb4d 100644 --- a/cmd/lotus-provider/proving.go +++ b/cmd/lotus-provider/proving.go @@ -69,30 +69,40 @@ var scheduleWindowPostCmd = &cli.Command{ if err != nil { return xerrors.Errorf("cannot get chainhead %w", err) } - ht := ts.Height() - maddr, err := address.IDFromAddress(address.Address(deps.maddrs[0])) + + addr, err := address.NewFromString(deps.cfg.Addresses.MinerAddresses[0]) + if err != nil { + return xerrors.Errorf("cannot get miner address %w", err) + } + maddr, err := address.IDFromAddress(addr) 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')`) + 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)`) 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, 1, cctx.Uint64("deadline"), 0) + id, maddr, ht, cctx.Uint64("deadline"), 0) if err != nil { + log.Error("inserting wdpost_partition_tasks: ", err) return false, xerrors.Errorf("inserting wdpost_partition_tasks: %w", err) } return true, nil }) + if err != nil { + return xerrors.Errorf("writing SQL transaction: %w", err) + } + log.Infof("Inserted task %v", did) return nil }, } diff --git a/lib/harmony/harmonydb/userfuncs.go b/lib/harmony/harmonydb/userfuncs.go index ffab5903c..788ca4a34 100644 --- a/lib/harmony/harmonydb/userfuncs.go +++ b/lib/harmony/harmonydb/userfuncs.go @@ -111,7 +111,9 @@ func (db *DB) BeginTransaction(ctx context.Context, f func(*Tx) (commit bool, er var commit bool defer func() { // Panic clean-up. if !commit { - retErr = tx.Rollback(ctx) + if tmp := tx.Rollback(ctx); tmp != nil { + retErr = tmp + } } }() commit, err = f(&Tx{tx, ctx}) @@ -119,7 +121,7 @@ func (db *DB) BeginTransaction(ctx context.Context, f func(*Tx) (commit bool, er return false, err } if commit { - err := tx.Commit(ctx) + err = tx.Commit(ctx) if err != nil { return false, err }