Skip to content

Commit

Permalink
fix: curio: Check deal start epoch passed in PrecommitSubmit (#11873)
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored Apr 15, 2024
1 parent ae15eb1 commit 50ed73d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions curiosrc/seal/task_submit_precommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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))
}
Expand Down

0 comments on commit 50ed73d

Please sign in to comment.