mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-21 22:57:10 +02:00
multi: extend QueryRoutes RPC with CLTV limit field
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
math "math"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
@@ -169,6 +170,26 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
ignoredPairs[pair] = struct{}{}
|
||||
}
|
||||
|
||||
// Since QueryRoutes allows having a different source other than
|
||||
// ourselves, we'll only apply our max time lock if we are the source.
|
||||
maxTotalTimelock := r.MaxTotalTimelock
|
||||
if sourcePubKey != r.SelfNode {
|
||||
maxTotalTimelock = math.MaxUint32
|
||||
}
|
||||
cltvLimit, err := ValidateCLTVLimit(in.CltvLimit, maxTotalTimelock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We need to subtract the final delta before passing it into path
|
||||
// finding. The optimal path is independent of the final cltv delta and
|
||||
// the path finding algorithm is unaware of this value.
|
||||
finalCLTVDelta := uint16(zpay32.DefaultFinalCLTVDelta)
|
||||
if in.FinalCltvDelta != 0 {
|
||||
finalCLTVDelta = uint16(in.FinalCltvDelta)
|
||||
}
|
||||
cltvLimit -= uint32(finalCLTVDelta)
|
||||
|
||||
var destTLV map[uint64][]byte
|
||||
restrictions := &routing.RestrictParams{
|
||||
FeeLimit: feeLimit,
|
||||
@@ -196,6 +217,7 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
)
|
||||
},
|
||||
DestPayloadTLV: len(destTLV) != 0,
|
||||
CltvLimit: cltvLimit,
|
||||
}
|
||||
|
||||
// If we have any TLV records destined for the final hop, then we'll
|
||||
@@ -209,24 +231,12 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
|
||||
// Query the channel router for a possible path to the destination that
|
||||
// can carry `in.Amt` satoshis _including_ the total fee required on
|
||||
// the route.
|
||||
var (
|
||||
route *route.Route
|
||||
findErr error
|
||||
route, err := r.FindRoute(
|
||||
sourcePubKey, targetPubKey, amtMSat, restrictions,
|
||||
destTlvRecords, finalCLTVDelta,
|
||||
)
|
||||
|
||||
if in.FinalCltvDelta == 0 {
|
||||
route, findErr = r.FindRoute(
|
||||
sourcePubKey, targetPubKey, amtMSat, restrictions,
|
||||
destTlvRecords,
|
||||
)
|
||||
} else {
|
||||
route, findErr = r.FindRoute(
|
||||
sourcePubKey, targetPubKey, amtMSat, restrictions,
|
||||
destTlvRecords, uint16(in.FinalCltvDelta),
|
||||
)
|
||||
}
|
||||
if findErr != nil {
|
||||
return nil, findErr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// For each valid route, we'll convert the result into the format
|
||||
|
Reference in New Issue
Block a user