Skip to content

Commit

Permalink
Merge pull request #7346 from filecoin-project/nonsense/add-missing-c…
Browse files Browse the repository at this point in the history
…ontinue-to-err-GetCurrentDealInfo

GetCurrentDealInfo err: handle correctly err case
  • Loading branch information
jennijuju authored Sep 18, 2021
2 parents 6df17bc + 6059535 commit 38f7cbc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions extern/storage-sealing/states_failed.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func (m *Sealing) HandleRecoverDealIDs(ctx Context, sector SectorInfo) error {
res, err := m.DealInfo.GetCurrentDealInfo(ctx.Context(), tok, dp, *p.DealInfo.PublishCid)
if err != nil {
failed[i] = xerrors.Errorf("getting current deal info for piece %d: %w", i, err)
continue
}

if res.MarketDeal.Proposal.PieceCID != p.Piece.PieceCID {
Expand Down
59 changes: 59 additions & 0 deletions extern/storage-sealing/states_failed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sealing_test
import (
"bytes"
"context"
"errors"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -20,6 +21,64 @@ import (
"github.com/filecoin-project/lotus/extern/storage-sealing/mocks"
)

func TestStateRecoverDealIDsErredDealInfo(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

ctx := context.Background()

api := mocks.NewMockSealingAPI(mockCtrl)

fakeSealing := &sealing.Sealing{
Api: api,
DealInfo: &sealing.CurrentDealInfoManager{CDAPI: api},
}

sctx := mocks.NewMockContext(mockCtrl)
sctx.EXPECT().Context().AnyTimes().Return(ctx)

api.EXPECT().ChainHead(ctx).Times(1).Return(nil, abi.ChainEpoch(10), nil)

var dealId abi.DealID = 12
dealProposal := market.DealProposal{
PieceCID: idCid("newPieceCID"),
}

api.EXPECT().StateMarketStorageDealProposal(ctx, dealId, nil).Return(dealProposal, nil)

pc := idCid("publishCID")

// expect GetCurrentDealInfo
{
api.EXPECT().StateSearchMsg(ctx, pc).Return(&sealing.MsgLookup{
Receipt: sealing.MessageReceipt{
ExitCode: exitcode.Ok,
Return: cborRet(&market.PublishStorageDealsReturn{
IDs: []abi.DealID{dealId},
}),
},
}, nil)
api.EXPECT().StateMarketStorageDeal(ctx, dealId, nil).Return(nil, errors.New("deal may not have completed sealing or slashed"))
}

sctx.EXPECT().Send(sealing.SectorRemove{}).Return(nil)

err := fakeSealing.HandleRecoverDealIDs(sctx, sealing.SectorInfo{
Pieces: []sealing.Piece{
{
DealInfo: &api2.PieceDealInfo{
DealID: dealId,
PublishCid: &pc,
},
Piece: abi.PieceInfo{
PieceCID: idCid("oldPieceCID"),
},
},
},
})
require.NoError(t, err)
}

func TestStateRecoverDealIDs(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand Down

0 comments on commit 38f7cbc

Please sign in to comment.