From 3daa0b5e630e4573861e68eaa79014b904c373a0 Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Thu, 3 Sep 2020 08:20:08 +0200 Subject: [PATCH] fix: paych - clarify behaviour of current available funds for non-existent channel --- paychmgr/simple.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 99fd23334..dc089d3fa 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -301,12 +301,10 @@ func (ca *channelAccessor) msgWaitComplete(mcid cid.Cid, err error) { func (ca *channelAccessor) currentAvailableFunds(queuedAmt types.BigInt) (*api.ChannelAvailableFunds, error) { channelInfo, err := ca.store.OutboundActiveByFromTo(ca.from, ca.to) - if err != nil && err != ErrChannelNotTracked { - return nil, err - } - - if channelInfo == nil { - // Channel does not exist + if err == ErrChannelNotTracked { + // If the channel does not exist we still want to return an empty + // ChannelAvailableFunds, so that clients can check for the existence + // of a channel between from / to without getting an error. return &api.ChannelAvailableFunds{ Channel: nil, ConfirmedAmt: types.NewInt(0), @@ -316,6 +314,9 @@ func (ca *channelAccessor) currentAvailableFunds(queuedAmt types.BigInt) (*api.C VoucherReedeemedAmt: types.NewInt(0), }, nil } + if err != nil { + return nil, err + } // The channel may have a pending create or add funds message waitSentinel := channelInfo.CreateMsg