Skip to content

Commit

Permalink
Deal with #191
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Sep 4, 2024
1 parent 4445520 commit a0b3dd7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
61 changes: 55 additions & 6 deletions tasks/unseal/task_unseal_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unseal
import (
"context"
"github.com/filecoin-project/curio/lib/passcall"
"github.com/filecoin-project/go-commp-utils/nonffi"
"math/rand/v2"
"time"

Expand Down Expand Up @@ -65,12 +66,13 @@ func (t *TaskUnsealDecode) Do(taskID harmonytask.TaskID, stillOwned func() bool)
sectorParams := sectorParamsArr[0]

var sectorMeta []struct {
TicketValue []byte `db:"ticket_value"`
OrigSealedCID string `db:"orig_sealed_cid"`
CurSealedCID string `db:"cur_sealed_cid"`
TicketValue []byte `db:"ticket_value"`
OrigSealedCID string `db:"orig_sealed_cid"`
CurSealedCID string `db:"cur_sealed_cid"`
CurUnsealedCID string `db:"cur_unsealed_cid"`
}
err = t.db.Select(ctx, &sectorMeta, `
SELECT ticket_value, orig_sealed_cid, cur_sealed_cid
SELECT ticket_value, orig_sealed_cid, cur_sealed_cid, cur_unsealed_cid
FROM sectors_meta
WHERE sp_id = $1 AND sector_num = $2`, sectorParams.SpID, sectorParams.SectorNumber)
if err != nil {
Expand All @@ -90,6 +92,53 @@ func (t *TaskUnsealDecode) Do(taskID harmonytask.TaskID, stillOwned func() bool)
if err != nil {
return false, xerrors.Errorf("decoding CurSealedCID: %w", err)
}
var commD cid.Cid
if smeta.CurUnsealedCID == "" || smeta.CurUnsealedCID == "b" {
// https://github.com/filecoin-project/curio/issues/191
// <workaround>

var sectorPieces []struct {
PieceNum int64 `db:"piece_num"`
PieceCID string `db:"piece_cid"`
PieceSize int64 `db:"piece_size"` // padded
}
err = t.db.Select(ctx, &sectorPieces, `
SELECT piece_num, piece_cid, piece_size
FROM sectors_meta_pieces
WHERE sp_id = $1 AND sector_num = $2
ORDER BY piece_num`, sectorParams.SpID, sectorParams.SectorNumber)
if err != nil {
return false, xerrors.Errorf("getting sector pieces: %w", err)
}

spt := abi.RegisteredSealProof(sectorParams.RegSealProof)
var pieceInfos []abi.PieceInfo
for _, p := range sectorPieces {
c, err := cid.Decode(p.PieceCID)
if err != nil {
return false, xerrors.Errorf("decoding piece cid: %w", err)
}

pieceInfos = append(pieceInfos, abi.PieceInfo{
Size: abi.PaddedPieceSize(p.PieceSize),
PieceCID: c,
})
}

commD, err = nonffi.GenerateUnsealedCID(spt, pieceInfos)
if err != nil {
return false, xerrors.Errorf("generating unsealed cid: %w", err)
}

log.Warnw("workaround for issue #191", "task", taskID, "commD", commD, "commK", commK, "commR", commR)

// </workaround>
} else {
commD, err = cid.Decode(smeta.CurUnsealedCID)
if err != nil {
return false, xerrors.Errorf("decoding CurUnsealedCID: %w", err)
}
}

sref := storiface.SectorRef{
ID: abi.SectorID{
Expand All @@ -100,9 +149,9 @@ func (t *TaskUnsealDecode) Do(taskID harmonytask.TaskID, stillOwned func() bool)
}

isSnap := commK != commR
log.Infow("unseal decode", "snap", isSnap, "task", taskID, "commK", commK, "commR", commR)
log.Infow("unseal decode", "snap", isSnap, "task", taskID, "commK", commK, "commR", commR, "commD", commD)
if isSnap {
err := t.sc.DecodeSnap(ctx, taskID, commR, commK, sref)
err := t.sc.DecodeSnap(ctx, taskID, commD, commK, sref)
if err != nil {
return false, xerrors.Errorf("DecodeSnap: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions tasks/unseal/task_unseal_sdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func (t *TaskUnsealSdr) Do(taskID harmonytask.TaskID, stillOwned func() bool) (d
sectorParams := sectorParamsArr[0]

var sectorMeta []struct {
TicketValue []byte `db:"ticket_value"`
CurUnsealedCID string `db:"cur_unsealed_cid"`
TicketValue []byte `db:"ticket_value"`
OrigUnsealedCID string `db:"orig_unsealed_cid"`
}
err = t.db.Select(ctx, &sectorMeta, `
SELECT ticket_value, cur_unsealed_cid
SELECT ticket_value, orig_unsealed_cid
FROM sectors_meta
WHERE sp_id = $1 AND sector_num = $2`, sectorParams.SpID, sectorParams.SectorNumber)
if err != nil {
Expand All @@ -85,7 +85,8 @@ func (t *TaskUnsealSdr) Do(taskID harmonytask.TaskID, stillOwned func() bool) (d
return false, xerrors.Errorf("expected 1 sector meta, got %d", len(sectorMeta))
}

commD, err := cid.Decode(sectorMeta[0].CurUnsealedCID)
// NOTE: Even for snap sectors for SDR we need the original unsealed CID
commD, err := cid.Decode(sectorMeta[0].OrigUnsealedCID)
if err != nil {
return false, xerrors.Errorf("decoding commd: %w", err)
}
Expand Down

0 comments on commit a0b3dd7

Please sign in to comment.