2020-11-05 05:11:08 +00:00
|
|
|
package storageadapter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
2020-11-30 14:16:13 +00:00
|
|
|
"sync"
|
2020-11-05 05:11:08 +00:00
|
|
|
|
2021-01-21 10:54:32 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-11-05 05:11:08 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-bitfield"
|
2020-11-05 05:11:08 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-04-20 21:34:28 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/builtin"
|
2023-08-08 13:12:50 +00:00
|
|
|
miner2 "github.com/filecoin-project/go-state-types/builtin/v11/miner"
|
2022-04-20 21:34:28 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/builtin/v8/miner"
|
2022-11-16 01:57:23 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/builtin/v9/market"
|
2021-01-21 10:54:32 +00:00
|
|
|
|
2020-11-05 05:11:08 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2022-06-14 15:00:51 +00:00
|
|
|
lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
2020-11-05 05:11:08 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/events"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2022-06-14 19:23:17 +00:00
|
|
|
pipeline "github.com/filecoin-project/lotus/storage/pipeline"
|
2020-11-05 05:11:08 +00:00
|
|
|
)
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
type eventsCalledAPI interface {
|
2021-08-04 00:10:30 +00:00
|
|
|
Called(ctx context.Context, check events.CheckFunc, msgHnd events.MsgHandler, rev events.RevertHandler, confidence int, timeout abi.ChainEpoch, mf events.MsgMatchFunc) error
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
type dealInfoAPI interface {
|
2022-06-17 16:25:59 +00:00
|
|
|
GetCurrentDealInfo(ctx context.Context, tsk types.TipSetKey, proposal *market.DealProposal, publishCid cid.Cid) (pipeline.CurrentDealInfo, error)
|
2021-01-08 15:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type diffPreCommitsAPI interface {
|
2022-04-20 21:34:28 +00:00
|
|
|
diffPreCommits(ctx context.Context, actor address.Address, pre, cur types.TipSetKey) (*lminer.PreCommitChanges, error)
|
2021-01-08 15:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SectorCommittedManager struct {
|
|
|
|
ev eventsCalledAPI
|
|
|
|
dealInfo dealInfoAPI
|
|
|
|
dpc diffPreCommitsAPI
|
|
|
|
}
|
|
|
|
|
2022-06-16 11:15:49 +00:00
|
|
|
func NewSectorCommittedManager(ev eventsCalledAPI, tskAPI pipeline.CurrentDealInfoAPI, dpcAPI diffPreCommitsAPI) *SectorCommittedManager {
|
2022-06-14 19:23:17 +00:00
|
|
|
dim := &pipeline.CurrentDealInfoManager{
|
2022-06-16 11:15:49 +00:00
|
|
|
CDAPI: tskAPI,
|
2021-01-08 15:28:38 +00:00
|
|
|
}
|
|
|
|
return newSectorCommittedManager(ev, dim, dpcAPI)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSectorCommittedManager(ev eventsCalledAPI, dealInfo dealInfoAPI, dpcAPI diffPreCommitsAPI) *SectorCommittedManager {
|
|
|
|
return &SectorCommittedManager{
|
|
|
|
ev: ev,
|
|
|
|
dealInfo: dealInfo,
|
|
|
|
dpc: dpcAPI,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mgr *SectorCommittedManager) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, proposal market.DealProposal, publishCid cid.Cid, callback storagemarket.DealSectorPreCommittedCallback) error {
|
2020-11-30 14:16:13 +00:00
|
|
|
// Ensure callback is only called once
|
|
|
|
var once sync.Once
|
|
|
|
cb := func(sectorNumber abi.SectorNumber, isActive bool, err error) {
|
|
|
|
once.Do(func() {
|
|
|
|
callback(sectorNumber, isActive, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
// First check if the deal is already active, and if so, bail out
|
2021-08-04 00:10:30 +00:00
|
|
|
checkFunc := func(ctx context.Context, ts *types.TipSet) (done bool, more bool, err error) {
|
2021-01-08 15:28:38 +00:00
|
|
|
dealInfo, isActive, err := mgr.checkIfDealAlreadyActive(ctx, ts, &proposal, publishCid)
|
2020-11-05 05:11:08 +00:00
|
|
|
if err != nil {
|
2020-11-20 16:30:17 +00:00
|
|
|
// Note: the error returned from here will end up being returned
|
|
|
|
// from OnDealSectorPreCommitted so no need to call the callback
|
|
|
|
// with the error
|
2022-09-16 18:30:05 +00:00
|
|
|
return false, false, xerrors.Errorf("failed to check deal activity: %w", err)
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
if isActive {
|
|
|
|
// Deal is already active, bail out
|
|
|
|
cb(0, true, nil)
|
2020-11-05 05:11:08 +00:00
|
|
|
return true, false, nil
|
|
|
|
}
|
|
|
|
|
2021-01-21 14:33:52 +00:00
|
|
|
// Check that precommits which landed between when the deal was published
|
|
|
|
// and now don't already contain the deal we care about.
|
|
|
|
// (this can happen when the precommit lands vary quickly (in tests), or
|
|
|
|
// when the client node was down after the deal was published, and when
|
|
|
|
// the precommit containing it landed on chain)
|
|
|
|
|
2022-06-16 09:12:33 +00:00
|
|
|
diff, err := mgr.dpc.diffPreCommits(ctx, provider, dealInfo.PublishMsgTipSet, ts.Key())
|
2021-01-21 10:54:32 +00:00
|
|
|
if err != nil {
|
2022-09-16 18:30:05 +00:00
|
|
|
return false, false, xerrors.Errorf("failed to diff precommits: %w", err)
|
2021-01-21 10:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, info := range diff.Added {
|
|
|
|
for _, d := range info.Info.DealIDs {
|
2021-01-08 15:28:38 +00:00
|
|
|
if d == dealInfo.DealID {
|
2021-01-21 10:54:32 +00:00
|
|
|
cb(info.Info.SectorNumber, false, nil)
|
|
|
|
return true, false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
// Not yet active, start matching against incoming messages
|
2020-11-05 05:11:08 +00:00
|
|
|
return false, true, nil
|
|
|
|
}
|
|
|
|
|
2020-11-25 09:39:42 +00:00
|
|
|
// Watch for a pre-commit message to the provider.
|
|
|
|
matchEvent := func(msg *types.Message) (bool, error) {
|
2023-08-08 13:12:50 +00:00
|
|
|
matched := msg.To == provider && (msg.Method == builtin.MethodsMiner.PreCommitSector ||
|
|
|
|
msg.Method == builtin.MethodsMiner.PreCommitSectorBatch ||
|
|
|
|
msg.Method == builtin.MethodsMiner.PreCommitSectorBatch2 ||
|
|
|
|
msg.Method == builtin.MethodsMiner.ProveReplicaUpdates)
|
2020-11-25 09:39:42 +00:00
|
|
|
return matched, nil
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:35:11 +00:00
|
|
|
// The deal must be accepted by the deal proposal start epoch, so timeout
|
|
|
|
// if the chain reaches that epoch
|
|
|
|
timeoutEpoch := proposal.StartEpoch + 1
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
// Check if the message params included the deal ID we're looking for.
|
2020-11-05 05:11:08 +00:00
|
|
|
called := func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
2020-11-20 16:30:17 +00:00
|
|
|
cb(0, false, xerrors.Errorf("handling applied event: %w", err))
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
|
|
|
}()
|
2020-11-20 16:30:17 +00:00
|
|
|
|
2020-12-01 11:35:11 +00:00
|
|
|
// If the deal hasn't been activated by the proposed start epoch, the
|
|
|
|
// deal will timeout (when msg == nil it means the timeout epoch was reached)
|
2020-11-20 16:30:17 +00:00
|
|
|
if msg == nil {
|
2021-01-08 15:28:38 +00:00
|
|
|
err = xerrors.Errorf("deal with piece CID %s was not activated by proposed deal start epoch %d", proposal.PieceCID, proposal.StartEpoch)
|
2020-12-01 11:35:11 +00:00
|
|
|
return false, err
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 11:30:52 +00:00
|
|
|
// Ignore the pre-commit message if it was not executed successfully
|
|
|
|
if rec.ExitCode != 0 {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
// When there is a reorg, the deal ID may change, so get the
|
2020-11-20 16:30:17 +00:00
|
|
|
// current deal ID from the publish message CID
|
2022-06-16 09:12:33 +00:00
|
|
|
res, err := mgr.dealInfo.GetCurrentDealInfo(ctx, ts.Key(), &proposal, publishCid)
|
2020-11-20 16:30:17 +00:00
|
|
|
if err != nil {
|
2022-09-16 18:30:05 +00:00
|
|
|
return false, xerrors.Errorf("failed to get dealinfo: %w", err)
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|
2020-11-05 05:11:08 +00:00
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
// If this is a replica update method that succeeded the deal is active
|
2022-04-20 21:34:28 +00:00
|
|
|
if msg.Method == builtin.MethodsMiner.ProveReplicaUpdates {
|
2021-12-08 17:11:19 +00:00
|
|
|
sn, err := dealSectorInReplicaUpdateSuccess(msg, rec, res)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if sn != nil {
|
|
|
|
cb(*sn, true, nil)
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
// Didn't find the deal ID in this message, so keep looking
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2021-05-19 18:07:20 +00:00
|
|
|
// Extract the message parameters
|
2021-05-25 14:07:45 +00:00
|
|
|
sn, err := dealSectorInPreCommitMsg(msg, res)
|
|
|
|
if err != nil {
|
2022-09-16 18:30:05 +00:00
|
|
|
return false, xerrors.Errorf("failed to extract message params: %w", err)
|
2021-05-25 14:07:45 +00:00
|
|
|
}
|
2021-05-19 18:07:20 +00:00
|
|
|
|
2021-05-25 14:07:45 +00:00
|
|
|
if sn != nil {
|
|
|
|
cb(*sn, false, nil)
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
2020-11-20 16:30:17 +00:00
|
|
|
|
|
|
|
// Didn't find the deal ID in this message, so keep looking
|
|
|
|
return true, nil
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
revert := func(ctx context.Context, ts *types.TipSet) error {
|
2020-11-20 16:30:17 +00:00
|
|
|
log.Warn("deal pre-commit reverted; TODO: actually handle this!")
|
2020-11-05 05:11:08 +00:00
|
|
|
// TODO: Just go back to DealSealing?
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-04 00:10:30 +00:00
|
|
|
if err := mgr.ev.Called(ctx, checkFunc, called, revert, int(build.MessageConfidence+1), timeoutEpoch, matchEvent); err != nil {
|
2020-11-20 16:30:17 +00:00
|
|
|
return xerrors.Errorf("failed to set up called handler: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
func (mgr *SectorCommittedManager) OnDealSectorCommitted(ctx context.Context, provider address.Address, sectorNumber abi.SectorNumber, proposal market.DealProposal, publishCid cid.Cid, callback storagemarket.DealSectorCommittedCallback) error {
|
2020-11-30 14:16:13 +00:00
|
|
|
// Ensure callback is only called once
|
|
|
|
var once sync.Once
|
|
|
|
cb := func(err error) {
|
|
|
|
once.Do(func() {
|
|
|
|
callback(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
// First check if the deal is already active, and if so, bail out
|
2021-08-04 00:10:30 +00:00
|
|
|
checkFunc := func(ctx context.Context, ts *types.TipSet) (done bool, more bool, err error) {
|
2021-01-08 15:28:38 +00:00
|
|
|
_, isActive, err := mgr.checkIfDealAlreadyActive(ctx, ts, &proposal, publishCid)
|
2020-11-20 16:30:17 +00:00
|
|
|
if err != nil {
|
|
|
|
// Note: the error returned from here will end up being returned
|
|
|
|
// from OnDealSectorCommitted so no need to call the callback
|
|
|
|
// with the error
|
|
|
|
return false, false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if isActive {
|
|
|
|
// Deal is already active, bail out
|
|
|
|
cb(nil)
|
|
|
|
return true, false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not yet active, start matching against incoming messages
|
|
|
|
return false, true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Match a prove-commit sent to the provider with the given sector number
|
2020-11-05 05:11:08 +00:00
|
|
|
matchEvent := func(msg *types.Message) (matched bool, err error) {
|
2021-05-19 18:07:20 +00:00
|
|
|
if msg.To != provider {
|
2020-11-05 05:11:08 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2021-05-25 14:07:45 +00:00
|
|
|
return sectorInCommitMsg(msg, sectorNumber)
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|
2020-11-05 05:11:08 +00:00
|
|
|
|
2020-12-01 11:35:11 +00:00
|
|
|
// The deal must be accepted by the deal proposal start epoch, so timeout
|
|
|
|
// if the chain reaches that epoch
|
|
|
|
timeoutEpoch := proposal.StartEpoch + 1
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
called := func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
cb(xerrors.Errorf("handling applied event: %w", err))
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
2020-11-20 16:30:17 +00:00
|
|
|
}()
|
2020-11-05 05:11:08 +00:00
|
|
|
|
2020-12-01 11:35:11 +00:00
|
|
|
// If the deal hasn't been activated by the proposed start epoch, the
|
|
|
|
// deal will timeout (when msg == nil it means the timeout epoch was reached)
|
2020-11-20 16:30:17 +00:00
|
|
|
if msg == nil {
|
2021-01-08 15:28:38 +00:00
|
|
|
err := xerrors.Errorf("deal with piece CID %s was not activated by proposed deal start epoch %d", proposal.PieceCID, proposal.StartEpoch)
|
2020-12-01 11:35:11 +00:00
|
|
|
return false, err
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 11:30:52 +00:00
|
|
|
// Ignore the prove-commit message if it was not executed successfully
|
|
|
|
if rec.ExitCode != 0 {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2020-11-20 16:30:17 +00:00
|
|
|
// Get the deal info
|
2022-06-16 09:12:33 +00:00
|
|
|
res, err := mgr.dealInfo.GetCurrentDealInfo(ctx, ts.Key(), &proposal, publishCid)
|
2020-11-20 16:30:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("failed to look up deal on chain: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the deal is active
|
2021-01-08 15:28:38 +00:00
|
|
|
if res.MarketDeal.State.SectorStartEpoch < 1 {
|
|
|
|
return false, xerrors.Errorf("deal wasn't active: deal=%d, parentState=%s, h=%d", res.DealID, ts.ParentState(), ts.Height())
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
log.Infof("Storage deal %d activated at epoch %d", res.DealID, res.MarketDeal.State.SectorStartEpoch)
|
2020-11-20 16:30:17 +00:00
|
|
|
|
|
|
|
cb(nil)
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
revert := func(ctx context.Context, ts *types.TipSet) error {
|
|
|
|
log.Warn("deal activation reverted; TODO: actually handle this!")
|
|
|
|
// TODO: Just go back to DealSealing?
|
|
|
|
return nil
|
2020-11-05 05:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 00:10:30 +00:00
|
|
|
if err := mgr.ev.Called(ctx, checkFunc, called, revert, int(build.MessageConfidence+1), timeoutEpoch, matchEvent); err != nil {
|
2020-11-05 05:11:08 +00:00
|
|
|
return xerrors.Errorf("failed to set up called handler: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-20 16:30:17 +00:00
|
|
|
|
2022-06-14 19:23:17 +00:00
|
|
|
func dealSectorInReplicaUpdateSuccess(msg *types.Message, rec *types.MessageReceipt, res pipeline.CurrentDealInfo) (*abi.SectorNumber, error) {
|
2021-12-08 17:11:19 +00:00
|
|
|
var params miner.ProveReplicaUpdatesParams
|
|
|
|
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
|
|
|
|
return nil, xerrors.Errorf("unmarshal prove replica update: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var seekUpdate miner.ReplicaUpdate
|
|
|
|
var found bool
|
|
|
|
for _, update := range params.Updates {
|
|
|
|
for _, did := range update.Deals {
|
|
|
|
if did == res.DealID {
|
|
|
|
seekUpdate = update
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that this update passed validation steps
|
|
|
|
var successBf bitfield.BitField
|
|
|
|
if err := successBf.UnmarshalCBOR(bytes.NewReader(rec.Return)); err != nil {
|
|
|
|
return nil, xerrors.Errorf("unmarshal return value: %w", err)
|
|
|
|
}
|
|
|
|
success, err := successBf.IsSet(uint64(seekUpdate.SectorID))
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("failed to check success of replica update: %w", err)
|
|
|
|
}
|
|
|
|
if !success {
|
|
|
|
return nil, xerrors.Errorf("replica update %d failed", seekUpdate.SectorID)
|
|
|
|
}
|
|
|
|
return &seekUpdate.SectorID, nil
|
|
|
|
}
|
|
|
|
|
2021-05-25 14:07:45 +00:00
|
|
|
// dealSectorInPreCommitMsg tries to find a sector containing the specified deal
|
2022-06-14 19:23:17 +00:00
|
|
|
func dealSectorInPreCommitMsg(msg *types.Message, res pipeline.CurrentDealInfo) (*abi.SectorNumber, error) {
|
2021-05-25 14:07:45 +00:00
|
|
|
switch msg.Method {
|
2022-04-20 21:34:28 +00:00
|
|
|
case builtin.MethodsMiner.PreCommitSector:
|
2021-05-25 14:07:45 +00:00
|
|
|
var params miner.SectorPreCommitInfo
|
|
|
|
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
|
|
|
|
return nil, xerrors.Errorf("unmarshal pre commit: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check through the deal IDs associated with this message
|
|
|
|
for _, did := range params.DealIDs {
|
|
|
|
if did == res.DealID {
|
|
|
|
// Found the deal ID in this message. Callback with the sector ID.
|
|
|
|
return ¶ms.SectorNumber, nil
|
|
|
|
}
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
case builtin.MethodsMiner.PreCommitSectorBatch:
|
|
|
|
var params miner.PreCommitSectorBatchParams
|
2021-05-25 14:07:45 +00:00
|
|
|
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
|
|
|
|
return nil, xerrors.Errorf("unmarshal pre commit: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, precommit := range params.Sectors {
|
|
|
|
// Check through the deal IDs associated with this message
|
|
|
|
for _, did := range precommit.DealIDs {
|
2023-08-08 13:12:50 +00:00
|
|
|
if did == res.DealID {
|
|
|
|
// Found the deal ID in this message. Callback with the sector ID.
|
|
|
|
return &precommit.SectorNumber, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case builtin.MethodsMiner.PreCommitSectorBatch2:
|
|
|
|
var params miner2.PreCommitSectorBatchParams2
|
|
|
|
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
|
|
|
|
return nil, xerrors.Errorf("unmarshal pre commit: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, precommit := range params.Sectors {
|
|
|
|
// Check through the deal IDs associated with this message
|
|
|
|
for _, did := range precommit.DealIDs {
|
2021-05-25 14:07:45 +00:00
|
|
|
if did == res.DealID {
|
|
|
|
// Found the deal ID in this message. Callback with the sector ID.
|
|
|
|
return &precommit.SectorNumber, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil, xerrors.Errorf("unexpected method %d", msg.Method)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// sectorInCommitMsg checks if the provided message commits specified sector
|
|
|
|
func sectorInCommitMsg(msg *types.Message, sectorNumber abi.SectorNumber) (bool, error) {
|
|
|
|
switch msg.Method {
|
2022-04-20 21:34:28 +00:00
|
|
|
case builtin.MethodsMiner.ProveCommitSector:
|
2021-05-25 14:07:45 +00:00
|
|
|
var params miner.ProveCommitSectorParams
|
|
|
|
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
|
|
|
|
return false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return params.SectorNumber == sectorNumber, nil
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
case builtin.MethodsMiner.ProveCommitAggregate:
|
|
|
|
var params miner.ProveCommitAggregateParams
|
2021-05-25 14:07:45 +00:00
|
|
|
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
|
|
|
|
return false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
set, err := params.SectorNumbers.IsSet(uint64(sectorNumber))
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("checking if sectorNumber is set in commit aggregate message: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return set, nil
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 19:23:17 +00:00
|
|
|
func (mgr *SectorCommittedManager) checkIfDealAlreadyActive(ctx context.Context, ts *types.TipSet, proposal *market.DealProposal, publishCid cid.Cid) (pipeline.CurrentDealInfo, bool, error) {
|
2022-06-16 09:12:33 +00:00
|
|
|
res, err := mgr.dealInfo.GetCurrentDealInfo(ctx, ts.Key(), proposal, publishCid)
|
2020-11-20 16:30:17 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: This may be fine for some errors
|
2021-01-08 15:28:38 +00:00
|
|
|
return res, false, xerrors.Errorf("failed to look up deal on chain: %w", err)
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
// Sector was slashed
|
|
|
|
if res.MarketDeal.State.SlashEpoch > 0 {
|
|
|
|
return res, false, xerrors.Errorf("deal %d was slashed at epoch %d", res.DealID, res.MarketDeal.State.SlashEpoch)
|
2020-11-30 14:16:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
// Sector with deal is already active
|
|
|
|
if res.MarketDeal.State.SectorStartEpoch > 0 {
|
|
|
|
return res, true, nil
|
2020-11-30 14:16:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 15:28:38 +00:00
|
|
|
return res, false, nil
|
2020-11-20 16:30:17 +00:00
|
|
|
}
|