From 69c3e246e171c229c4d06b3a20666c6a1e8bb4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 4 Sep 2024 02:26:53 +0200 Subject: [PATCH] Deal with #191 --- tasks/unseal/task_unseal_decode.go | 61 +++++++++++++++++++++++++++--- tasks/unseal/task_unseal_sdr.go | 9 +++-- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/tasks/unseal/task_unseal_decode.go b/tasks/unseal/task_unseal_decode.go index 571c27ad..2d961ba9 100644 --- a/tasks/unseal/task_unseal_decode.go +++ b/tasks/unseal/task_unseal_decode.go @@ -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" @@ -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, §orMeta, ` - 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 { @@ -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 + // + + var sectorPieces []struct { + PieceNum int64 `db:"piece_num"` + PieceCID string `db:"piece_cid"` + PieceSize int64 `db:"piece_size"` // padded + } + err = t.db.Select(ctx, §orPieces, ` + 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) + + // + } else { + commD, err = cid.Decode(smeta.CurUnsealedCID) + if err != nil { + return false, xerrors.Errorf("decoding CurUnsealedCID: %w", err) + } + } sref := storiface.SectorRef{ ID: abi.SectorID{ @@ -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) } diff --git a/tasks/unseal/task_unseal_sdr.go b/tasks/unseal/task_unseal_sdr.go index 67461ad3..25cb2ff3 100644 --- a/tasks/unseal/task_unseal_sdr.go +++ b/tasks/unseal/task_unseal_sdr.go @@ -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, §orMeta, ` - 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 { @@ -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) }