Merge pull request #11483 from filecoin-project/phi-backport-11482

fix: lotus-provider: Fix winning PoSt
This commit is contained in:
Andrew Jackson (Ajax) 2023-12-05 11:35:47 -06:00 committed by GitHub
commit 58c6ddacb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,8 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/rand" "crypto/rand"
"database/sql"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"errors"
"time" "time"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
@ -579,12 +577,13 @@ func (t *WinPostTask) mineBasic(ctx context.Context) {
taskFn(func(id harmonytask.TaskID, tx *harmonydb.Tx) (shouldCommit bool, seriousError error) { taskFn(func(id harmonytask.TaskID, tx *harmonydb.Tx) (shouldCommit bool, seriousError error) {
// First we check if the mining base includes blocks we may have mined previously to avoid getting slashed // First we check if the mining base includes blocks we may have mined previously to avoid getting slashed
// select mining_tasks where epoch==base_epoch if win=true to maybe get base block cid which has to be included in our tipset // select mining_tasks where epoch==base_epoch if win=true to maybe get base block cid which has to be included in our tipset
var baseBlockCid string var baseBlockCids []string
err := tx.QueryRow(`SELECT mined_cid FROM mining_tasks WHERE epoch = $1 AND sp_id = $2 AND won = true`, baseEpoch, spID).Scan(&baseBlockCid) err := tx.Select(&baseBlockCids, `SELECT mined_cid FROM mining_tasks WHERE epoch = $1 AND sp_id = $2 AND won = true`, baseEpoch, spID)
if err != nil && !errors.Is(err, sql.ErrNoRows) { if err != nil {
return false, xerrors.Errorf("querying mining_tasks: %w", err) return false, xerrors.Errorf("querying mining_tasks: %w", err)
} }
if baseBlockCid != "" { if len(baseBlockCids) >= 1 {
baseBlockCid := baseBlockCids[0]
c, err := cid.Parse(baseBlockCid) c, err := cid.Parse(baseBlockCid)
if err != nil { if err != nil {
return false, xerrors.Errorf("parsing mined_cid: %w", err) return false, xerrors.Errorf("parsing mined_cid: %w", err)