From 1b098d4f10df0e4f2d3b78d9cf30c2972b2a6e68 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 11 Feb 2021 18:05:13 -0800 Subject: [PATCH] routing: if MaxShardAmt is set, then use that as a ceiling for our splits In this commit, we thread through the necessary state to allow users to set a max shard amount. If this value is set, then this'll effectively serve as a ceiling for all our split attempts. If we need to split, we'll first try to use `paymentAmt/2`, if that's bigger than `MaxShardAmt, then we'll use the latter instead. Ideally in the future we have a dynamic way to automatically set both the `MaxShardAmt` as well as `MaxParts` for users. Until then exposing these two new fields will allow us to experiment with setting them automatically using the RPC interface, and also give users a bit more control over how we attempt to route payments, akin to coin control for on-chain payments. Fixes #4730 --- routing/payment_session.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/routing/payment_session.go b/routing/payment_session.go index 4b766d4c0207..c1fe6e827657 100644 --- a/routing/payment_session.go +++ b/routing/payment_session.go @@ -298,6 +298,15 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi, // route, try it for half the amount. maxAmt /= 2 + // If this shard ends up being too large, then we'll + // clamp it down to the max shard size if that's set. + // + // TODO(roasbeef): extend the integrated routing tets w/ info + maxShardActive := p.payment.MaxShardAmt != nil + if maxShardActive && *p.payment.MaxShardAmt > maxAmt { + maxAmt = *p.payment.MaxShardAmt + } + // Put a lower bound on the minimum shard size. if maxAmt < p.minShardAmt { p.log.Debugf("not splitting because minimum "+