From f40338c277925ca80a007466336592e57380e962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 6 Jan 2022 18:02:34 +0100 Subject: [PATCH] paych: Better off-chain errors --- markets/retrievaladapter/client.go | 1 + paychmgr/simple.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/markets/retrievaladapter/client.go b/markets/retrievaladapter/client.go index 60f41ca296d..97a157b19cd 100644 --- a/markets/retrievaladapter/client.go +++ b/markets/retrievaladapter/client.go @@ -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 { diff --git a/paychmgr/simple.go b/paychmgr/simple.go index ffb13b6c233..ef0f81b8748 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -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 @@ -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) @@ -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 @@ -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 }