Skip to content

Commit

Permalink
paych: Better off-chain errors
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jan 6, 2022
1 parent 63b9a46 commit f40338c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions markets/retrievaladapter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (rcn *retrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, c
OffChain: rcn.forceOffChain,
})
if err != nil {
log.Errorw("paych get failed", "error", err)
return address.Undef, cid.Undef, err
}
if ci.WaitSentinel == cid.Undef {
Expand Down
13 changes: 8 additions & 5 deletions paychmgr/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ func (m *mergedFundsReq) completeAmount(avail types.BigInt, channelInfo *Channel
// can't fill, so OffChain want an error
if r.isActive() {
failed = types.BigAdd(failed, r.amt)
r.onComplete(&paychFundsRes{channel: *channelInfo.Channel, err: xerrors.Errorf("not enough available funds in the payment channel")})
r.onComplete(&paychFundsRes{
channel: *channelInfo.Channel,
err: xerrors.Errorf("not enough funds available in the payment channel %s; add funds with 'lotus paych add-funds %s %s %s'", channelInfo.Channel, channelInfo.from(), channelInfo.to(), types.FIL(r.amt).Unitless()),
})
}
next = i + 1
continue
Expand All @@ -212,7 +215,7 @@ func (m *mergedFundsReq) completeAmount(avail types.BigInt, channelInfo *Channel
return nil, used, failed
}

func (m *mergedFundsReq) failOffChain(msg string) (*paychFundsRes, types.BigInt) {
func (m *mergedFundsReq) failOffChainNoChannel(from, to address.Address) (*paychFundsRes, types.BigInt) {
next := 0
freed := types.NewInt(0)

Expand All @@ -225,13 +228,13 @@ func (m *mergedFundsReq) failOffChain(msg string) (*paychFundsRes, types.BigInt)
if !r.isActive() {
continue
}
r.onComplete(&paychFundsRes{err: xerrors.New(msg)})
r.onComplete(&paychFundsRes{err: xerrors.Errorf("payment channel doesn't exist, create with 'lotus paych add-funds %s %s %s'", from, to, types.FIL(r.amt).Unitless())})
next = i + 1
}

m.reqs = m.reqs[next:]
if len(m.reqs) == 0 {
return &paychFundsRes{err: xerrors.New(msg)}, freed
return &paychFundsRes{err: xerrors.Errorf("payment channel doesn't exist, create with 'lotus paych add-funds %s %s 0'", from, to)}, freed
}

return nil, freed
Expand Down Expand Up @@ -440,7 +443,7 @@ func (ca *channelAccessor) processTask(merged *mergedFundsReq, amt, avail types.

// If a channel has not yet been created, create one.
if channelInfo == nil {
res, freed := merged.failOffChain("payment channel doesn't exist")
res, freed := merged.failOffChainNoChannel(ca.from, ca.to)
if res != nil {
return res
}
Expand Down

0 comments on commit f40338c

Please sign in to comment.