Add constant and percentage-based fee limits to payments
- Extend SendRequest and QueryRoutesRequest protos - newRoute function takes fee limit and cuts off routes that exceed it - queryRoutes, payInvoice and sendPayment commands take the feeLimit inputs and pass them down to newRoute - When no feeLimit is included, don't enforce any feeLimits at all (by setting feeLimit to maxValue)
This commit is contained in:
1 parent
80b531db62
commit
6746609ec6
10 files changed
+537
-402
No files matched your search
+9
-3
@@ -1259,7 +1259,8 @@ func pruneChannelFromRoutes(routes []*Route, skipChan uint64) []*Route {
|
||||
// initial set of paths as it's possible we drop a route if it can't handle the
|
||||
// total payment flow after fees are calculated.
|
||||
func pathsToFeeSortedRoutes(source Vertex, paths [][]*ChannelHop, finalCLTVDelta uint16,
|
||||
amt lnwire.MilliSatoshi, currentHeight uint32) ([]*Route, error) {
|
||||
amt lnwire.MilliSatoshi, feeLimit btcutil.Amount,
|
||||
currentHeight uint32) ([]*Route, error) {
|
||||
|
||||
validRoutes := make([]*Route, 0, len(paths))
|
||||
for _, path := range paths {
|
||||
@@ -1268,6 +1269,7 @@ func pathsToFeeSortedRoutes(source Vertex, paths [][]*ChannelHop, finalCLTVDelta
|
||||
// by our KSP algorithm.
|
||||
route, err := newRoute(
|
||||
amt, source, path[1:], currentHeight, finalCLTVDelta,
|
||||
feeLimit,
|
||||
)
|
||||
if err != nil {
|
||||
// TODO(roasbeef): report straw breaking edge?
|
||||
@@ -1316,7 +1318,8 @@ func pathsToFeeSortedRoutes(source Vertex, paths [][]*ChannelHop, finalCLTVDelta
|
||||
// route that will be ranked the highest is the one with the lowest cumulative
|
||||
// fee along the route.
|
||||
func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
|
||||
amt lnwire.MilliSatoshi, numPaths uint32, finalExpiry ...uint16) ([]*Route, error) {
|
||||
amt lnwire.MilliSatoshi, feeLimit btcutil.Amount, numPaths uint32,
|
||||
finalExpiry ...uint16) ([]*Route, error) {
|
||||
|
||||
var finalCLTVDelta uint16
|
||||
if len(finalExpiry) == 0 {
|
||||
@@ -1402,7 +1405,7 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
|
||||
// factored in.
|
||||
sourceVertex := Vertex(r.selfNode.PubKeyBytes)
|
||||
validRoutes, err := pathsToFeeSortedRoutes(
|
||||
sourceVertex, shortestPaths, finalCLTVDelta, amt,
|
||||
sourceVertex, shortestPaths, finalCLTVDelta, amt, feeLimit,
|
||||
uint32(currentHeight),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -1502,6 +1505,9 @@ type LightningPayment struct {
|
||||
// milli-satoshis.
|
||||
Amount lnwire.MilliSatoshi
|
||||
|
||||
// FeeLimit is a user-specified maximum fee for this payment in satoshis.
|
||||
FeeLimit btcutil.Amount
|
||||
|
||||
// PaymentHash is the r-hash value to use within the HTLC extended to
|
||||
// the first hop.
|
||||
PaymentHash [32]byte
|
||||
|
||||
Reference in new issue
Block a user