From 50ed73de298719382c5291a893a79f08c134a380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 15 Apr 2024 17:48:45 +0200 Subject: [PATCH] fix: curio: Check deal start epoch passed in PrecommitSubmit (#11873) --- curiosrc/seal/task_submit_precommit.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/curiosrc/seal/task_submit_precommit.go b/curiosrc/seal/task_submit_precommit.go index 0f896cb93..d42bcbe0d 100644 --- a/curiosrc/seal/task_submit_precommit.go +++ b/curiosrc/seal/task_submit_precommit.go @@ -101,6 +101,11 @@ func (s *SubmitPrecommitTask) Do(taskID harmonytask.TaskID, stillOwned func() bo // 2. Prepare message params + head, err := s.api.ChainHead(ctx) + if err != nil { + return false, xerrors.Errorf("getting chain head: %w", err) + } + params := miner.PreCommitSectorBatchParams2{} expiration := sectorParams.TicketEpoch + miner12.MaxSectorExpirationExtension @@ -119,12 +124,13 @@ func (s *SubmitPrecommitTask) Do(taskID harmonytask.TaskID, stillOwned func() bo PieceCID string `db:"piece_cid"` PieceSize int64 `db:"piece_size"` - F05DealID int64 `db:"f05_deal_id"` - F05DealEndEpoch int64 `db:"f05_deal_end_epoch"` + F05DealID int64 `db:"f05_deal_id"` + F05DealEndEpoch int64 `db:"f05_deal_end_epoch"` + F05DealStartEpoch int64 `db:"f05_deal_start_epoch"` } err = s.db.Select(ctx, &pieces, ` - SELECT piece_index, piece_cid, piece_size, f05_deal_id, f05_deal_end_epoch + SELECT piece_index, piece_cid, piece_size, f05_deal_id, f05_deal_end_epoch, f05_deal_start_epoch FROM sectors_sdr_initial_pieces WHERE sp_id = $1 AND sector_number = $2 ORDER BY piece_index ASC`, sectorParams.SpID, sectorParams.SectorNumber) if err != nil { @@ -139,6 +145,17 @@ func (s *SubmitPrecommitTask) Do(taskID harmonytask.TaskID, stillOwned func() bo params.Sectors[0].UnsealedCid = &unsealedCID params.Sectors[0].Expiration = abi.ChainEpoch(pieces[0].F05DealEndEpoch) + if abi.ChainEpoch(pieces[0].F05DealStartEpoch) < head.Height() { + // deal start epoch is in the past, can't precommit this sector anymore + _, perr := s.db.Exec(ctx, `UPDATE sectors_sdr_pipeline + SET failed = TRUE, failed_at = NOW(), failed_reason = 'past-start-epoch', failed_reason_msg = 'precommit: start epoch is in the past' + WHERE task_id_precommit_msg = $1`, taskID) + if perr != nil { + return false, xerrors.Errorf("persisting precommit start epoch expiry: %w", perr) + } + return true, xerrors.Errorf("deal start epoch is in the past") + } + for _, p := range pieces { params.Sectors[0].DealIDs = append(params.Sectors[0].DealIDs, abi.DealID(p.F05DealID)) }