Merge pull request #6679 from filecoin-project/fix/get-retrieval-pricing-input-error

Get retrieval pricing input should not error out on a deal state fetch
This commit is contained in:
Łukasz Magiera 2021-07-05 16:18:48 +02:00 committed by GitHub
commit 5e5de9b41b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"io" "io"
"github.com/filecoin-project/lotus/api/v1api" "github.com/filecoin-project/lotus/api/v1api"
"github.com/hashicorp/go-multierror"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
@ -135,10 +136,14 @@ func (rpn *retrievalProviderNode) GetRetrievalPricingInput(ctx context.Context,
} }
tsk := head.Key() tsk := head.Key()
var mErr error
for _, dealID := range storageDeals { for _, dealID := range storageDeals {
ds, err := rpn.full.StateMarketStorageDeal(ctx, dealID, tsk) ds, err := rpn.full.StateMarketStorageDeal(ctx, dealID, tsk)
if err != nil { if err != nil {
return resp, xerrors.Errorf("failed to look up deal %d on chain: err=%w", dealID, err) log.Warnf("failed to look up deal %d on chain: err=%w", dealID, err)
mErr = multierror.Append(mErr, err)
continue
} }
if ds.Proposal.VerifiedDeal { if ds.Proposal.VerifiedDeal {
resp.VerifiedDeal = true resp.VerifiedDeal = true
@ -158,7 +163,11 @@ func (rpn *retrievalProviderNode) GetRetrievalPricingInput(ctx context.Context,
// Note: The piece size can never actually be zero. We only use it to here // Note: The piece size can never actually be zero. We only use it to here
// to assert that we didn't find a matching piece. // to assert that we didn't find a matching piece.
if resp.PieceSize == 0 { if resp.PieceSize == 0 {
return resp, xerrors.New("failed to find matching piece") if mErr == nil {
return resp, xerrors.New("failed to find matching piece")
}
return resp, xerrors.Errorf("failed to fetch storage deal state: %w", mErr)
} }
return resp, nil return resp, nil

View File

@ -66,6 +66,31 @@ func TestGetPricingInput(t *testing.T) {
expectedErrorStr: "failed to find matching piece", expectedErrorStr: "failed to find matching piece",
}, },
"error when fails to fetch deal state": {
fFnc: func(n *mocks.MockFullNode) {
out1 := &api.MarketDeal{
Proposal: market.DealProposal{
PieceCID: pcid,
PieceSize: paddedSize,
},
}
out2 := &api.MarketDeal{
Proposal: market.DealProposal{
PieceCID: testnet.GenerateCids(1)[0],
VerifiedDeal: true,
},
}
n.EXPECT().ChainHead(gomock.Any()).Return(tsk, nil).Times(1)
gomock.InOrder(
n.EXPECT().StateMarketStorageDeal(gomock.Any(), deals[0], key).Return(out1, xerrors.New("error 1")),
n.EXPECT().StateMarketStorageDeal(gomock.Any(), deals[1], key).Return(out2, xerrors.New("error 2")),
)
},
expectedErrorStr: "failed to fetch storage deal state",
},
"verified is true even if one deal is verified and we get the correct piecesize": { "verified is true even if one deal is verified and we get the correct piecesize": {
fFnc: func(n *mocks.MockFullNode) { fFnc: func(n *mocks.MockFullNode) {
out1 := &api.MarketDeal{ out1 := &api.MarketDeal{
@ -92,6 +117,32 @@ func TestGetPricingInput(t *testing.T) {
expectedVerified: true, expectedVerified: true,
}, },
"success even if one deal state fetch errors out but the other deal is verified and has the required piececid": {
fFnc: func(n *mocks.MockFullNode) {
out1 := &api.MarketDeal{
Proposal: market.DealProposal{
PieceCID: testnet.GenerateCids(1)[0],
},
}
out2 := &api.MarketDeal{
Proposal: market.DealProposal{
PieceCID: pcid,
PieceSize: paddedSize,
VerifiedDeal: true,
},
}
n.EXPECT().ChainHead(gomock.Any()).Return(tsk, nil).Times(1)
gomock.InOrder(
n.EXPECT().StateMarketStorageDeal(gomock.Any(), deals[0], key).Return(out1, xerrors.New("some error")),
n.EXPECT().StateMarketStorageDeal(gomock.Any(), deals[1], key).Return(out2, nil),
)
},
expectedPieceSize: unpaddedSize,
expectedVerified: true,
},
"verified is false if both deals are unverified and we get the correct piece size": { "verified is false if both deals are unverified and we get the correct piece size": {
fFnc: func(n *mocks.MockFullNode) { fFnc: func(n *mocks.MockFullNode) {
out1 := &api.MarketDeal{ out1 := &api.MarketDeal{