fix: when waiting for deal commit messages, ignore unsuccessful messages

This commit is contained in:
Dirk McCormick 2020-12-14 12:30:52 +01:00
parent 65b921c62c
commit dc8ff27b36
3 changed files with 61 additions and 5 deletions

View File

@ -75,6 +75,11 @@ func OnDealSectorPreCommitted(ctx context.Context, api getCurrentDealInfoAPI, ev
return false, err
}
// Ignore the pre-commit message if it was not executed successfully
if rec.ExitCode != 0 {
return true, nil
}
// Extract the message parameters
var params miner.SectorPreCommitInfo
if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil {
@ -175,6 +180,11 @@ func OnDealSectorCommitted(ctx context.Context, api getCurrentDealInfoAPI, event
return false, err
}
// Ignore the prove-commit message if it was not executed successfully
if rec.ExitCode != 0 {
return true, nil
}
// Get the deal info
_, sd, err := GetCurrentDealInfo(ctx, ts, api, dealID, proposal, publishCid)
if err != nil {

View File

@ -114,6 +114,25 @@ func TestOnDealSectorPreCommitted(t *testing.T) {
expectedCBIsActive: false,
expectedCBSectorNumber: sectorNumber,
},
"ignores unsuccessful pre-commit message": {
checkTsDeals: map[abi.DealID]*api.MarketDeal{
startDealID: unfinishedDeal,
},
matchStates: []matchState{
{
msg: makeMessage(t, provider, miner.Methods.PreCommitSector, &miner.SectorPreCommitInfo{
SectorNumber: sectorNumber,
SealedCID: sealedCid,
DealIDs: []abi.DealID{startDealID},
}),
deals: map[abi.DealID]*api.MarketDeal{
startDealID: unfinishedDeal,
},
receipt: &types.MessageReceipt{ExitCode: 1},
},
},
expectedCBCallCount: 0,
},
"error on deal in check": {
checkTsDeals: map[abi.DealID]*api.MarketDeal{},
searchMessageErr: errors.New("something went wrong"),
@ -179,7 +198,7 @@ func TestOnDealSectorPreCommitted(t *testing.T) {
matchMessages[i] = matchMessage{
curH: 5,
msg: ms.msg,
msgReceipt: nil,
msgReceipt: ms.receipt,
ts: matchTs,
}
}
@ -297,6 +316,23 @@ func TestOnDealSectorCommitted(t *testing.T) {
},
expectedCBCallCount: 1,
},
"ignores unsuccessful prove-commit message": {
checkTsDeals: map[abi.DealID]*api.MarketDeal{
startDealID: unfinishedDeal,
},
matchStates: []matchState{
{
msg: makeMessage(t, provider, miner.Methods.ProveCommitSector, &miner.ProveCommitSectorParams{
SectorNumber: sectorNumber,
}),
deals: map[abi.DealID]*api.MarketDeal{
startDealID: successDeal,
},
receipt: &types.MessageReceipt{ExitCode: 1},
},
},
expectedCBCallCount: 0,
},
"error on deal in check": {
checkTsDeals: map[abi.DealID]*api.MarketDeal{},
searchMessageErr: errors.New("something went wrong"),
@ -361,7 +397,7 @@ func TestOnDealSectorCommitted(t *testing.T) {
matchMessages[i] = matchMessage{
curH: 5,
msg: ms.msg,
msgReceipt: nil,
msgReceipt: ms.receipt,
ts: matchTs,
}
}
@ -397,8 +433,9 @@ func TestOnDealSectorCommitted(t *testing.T) {
}
type matchState struct {
msg *types.Message
deals map[abi.DealID]*api.MarketDeal
msg *types.Message
receipt *types.MessageReceipt
deals map[abi.DealID]*api.MarketDeal
}
type matchMessage struct {
@ -434,7 +471,11 @@ func (fe *fakeEvents) Called(check events.CheckFunc, msgHnd events.MsgHandler, r
return err
}
if matched {
more, err := msgHnd(matchMessage.msg, matchMessage.msgReceipt, matchMessage.ts, matchMessage.curH)
receipt := matchMessage.msgReceipt
if receipt == nil {
receipt = &types.MessageReceipt{ExitCode: 0}
}
more, err := msgHnd(matchMessage.msg, receipt, matchMessage.ts, matchMessage.curH)
if err != nil {
return err
}

View File

@ -73,6 +73,11 @@ func (pcs *paymentChannelSettler) check(ts *types.TipSet) (done bool, more bool,
}
func (pcs *paymentChannelSettler) messageHandler(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) {
// Ignore unsuccessful settle messages
if rec.ExitCode != 0 {
return true, nil
}
bestByLane, err := paychmgr.BestSpendableByLane(pcs.ctx, pcs.api, msg.To)
if err != nil {
return true, err