From a808665f3fe9e1fc6e8d205aaede459798925c54 Mon Sep 17 00:00:00 2001 From: 0x5459 <0x5459@protonmail.com> Date: Tue, 23 Apr 2024 19:16:02 +0800 Subject: [PATCH] fix: handle compatibility issues for legacy deals --- .../modules/impl/commitmgr/params.go | 2 +- damocles-manager/modules/sealer/sealer.go | 17 ++++++++++++++--- damocles-manager/modules/sealer/sealer_cli.go | 2 +- damocles-manager/modules/util/piece/piece.go | 7 ++++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/damocles-manager/modules/impl/commitmgr/params.go b/damocles-manager/modules/impl/commitmgr/params.go index d85202c0..3f32369a 100644 --- a/damocles-manager/modules/impl/commitmgr/params.go +++ b/damocles-manager/modules/impl/commitmgr/params.go @@ -71,7 +71,7 @@ func (p PreCommitProcessor) preCommitInfo( DealIDs: sector.DealIDs(), // DDO deal will be passed later in the Commit message } - if len(sector.Pieces) > 0 { + if len(sector.Pieces) > 0 || len(sector.LegacyPieces) > 0 { params.UnsealedCid = §or.Pre.CommD } diff --git a/damocles-manager/modules/sealer/sealer.go b/damocles-manager/modules/sealer/sealer.go index aef98875..2fd65c04 100644 --- a/damocles-manager/modules/sealer/sealer.go +++ b/damocles-manager/modules/sealer/sealer.go @@ -462,6 +462,15 @@ func (s *Sealer) ReportFinalized(ctx context.Context, sid abi.SectorID) (core.Me func (s *Sealer) ReportAborted(ctx context.Context, sid abi.SectorID, reason string) (core.Meta, error) { err := s.state.Finalize(ctx, sid, func(st *core.SectorState) (bool, error) { + if dealCount := len(st.LegacyPieces); dealCount > 0 { + err := s.deal.ReleaseLegacyDeal(ctx, sid, st.LegacyPieces) + if err != nil { + return false, fmt.Errorf("release legacy deals in sector: %w", err) + } + + sectorLogger(sid).Infow("legacy deals released", "count", dealCount) + } + if dealCount := len(st.Pieces); dealCount > 0 { err := s.deal.Release(ctx, sid, st.Pieces) if err != nil { @@ -616,15 +625,17 @@ func (s *Sealer) SubmitSnapUpProof( return resp, sectorStateErr(err) } - if len(state.Pieces) != len(snapupInfo.Pieces) { - desc = fmt.Sprintf("pieces count not match: %d != %d", len(state.Pieces), len(snapupInfo.Pieces)) + pieceInfos := state.PieceInfos() + + if len(pieceInfos) != len(snapupInfo.Pieces) { + desc = fmt.Sprintf("pieces count not match: %d != %d", len(pieceInfos), len(snapupInfo.Pieces)) resp.Res = core.SubmitRejected resp.Desc = &desc return resp, nil } for pi, pid := range snapupInfo.Pieces { - if localPID := state.Pieces[pi].Piece.PieceCID; !pid.Equals(state.Pieces[pi].Piece.PieceCID) { + if localPID := pieceInfos[pi].Cid; !pid.Equals(pieceInfos[pi].Cid) { desc = fmt.Sprintf("#%d piece cid not match: %s != %s", pi, localPID, pid) resp.Res = core.SubmitRejected resp.Desc = &desc diff --git a/damocles-manager/modules/sealer/sealer_cli.go b/damocles-manager/modules/sealer/sealer_cli.go index f709e7ac..53fab4e0 100644 --- a/damocles-manager/modules/sealer/sealer_cli.go +++ b/damocles-manager/modules/sealer/sealer_cli.go @@ -39,7 +39,7 @@ func (s *Sealer) RestoreSector(ctx context.Context, sid abi.SectorID, forced boo var onRestore func(st *core.SectorState) (bool, error) if !forced { onRestore = func(st *core.SectorState) (bool, error) { - if len(st.Pieces) != 0 { + if len(st.PieceInfos()) != 0 { return false, fmt.Errorf("sector with deals can not be normally restored") } diff --git a/damocles-manager/modules/util/piece/piece.go b/damocles-manager/modules/util/piece/piece.go index 6938f379..6e39aad0 100644 --- a/damocles-manager/modules/util/piece/piece.go +++ b/damocles-manager/modules/util/piece/piece.go @@ -26,10 +26,11 @@ func ProcessPieces( lookupID core.LookupID, forceDDO bool, ) ([]miner13.PieceActivationManifest, []abi.DealID, error) { - pams := make([]miner13.PieceActivationManifest, 0, len(sector.Pieces)) - dealIDs := make([]abi.DealID, 0, len(sector.Pieces)) - sectorPieces := sector.SectorPiece() + + pams := make([]miner13.PieceActivationManifest, 0, len(sectorPieces)) + dealIDs := make([]abi.DealID, 0, len(sectorPieces)) + hasDDO := forceDDO if !forceDDO { for _, piece := range sectorPieces {