Skip to content

Commit

Permalink
multi: adding no_padding flag to queryroutes lncli, rpc calls
Browse files Browse the repository at this point in the history
This commit adds a no_padding option to queryroutes lncli and rpc
calls. This allows a caller to force lnd to omit any block padding
that would otherwise be added as a safety measure.
  • Loading branch information
Crypt-iQ committed Jul 22, 2019
1 parent 0769362 commit 76a2790
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 512 deletions.
5 changes: 5 additions & 0 deletions cmd/lncli/commands.go
Expand Up @@ -3001,6 +3001,10 @@ var queryRoutesCommand = cli.Command{
Name: "use_mc",
Usage: "use mission control probabilities",
},
cli.BoolFlag{
Name: "no_padding",
Usage: "if true, omit block padding in the returned route",
},
},
Action: actionDecorator(queryRoutes),
}
Expand Down Expand Up @@ -3051,6 +3055,7 @@ func queryRoutes(ctx *cli.Context) error {
FeeLimit: feeLimit,
FinalCltvDelta: int32(ctx.Int("final_cltv_delta")),
UseMissionControl: ctx.Bool("use_mc"),
NoPadding: ctx.Bool("no_padding"),
}

route, err := client.QueryRoutes(ctxb, req)
Expand Down
8 changes: 5 additions & 3 deletions lnrpc/routerrpc/router_backend.go
Expand Up @@ -40,7 +40,7 @@ type RouterBackend struct {
// routes.
FindRoute func(source, target route.Vertex,
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
finalExpiry ...uint16) (*route.Route, error)
noPadding bool, finalExpiry ...uint16) (*route.Route, error)

MissionControl MissionControl

Expand Down Expand Up @@ -177,6 +177,8 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
},
}

noPadding := in.NoPadding

// 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.
Expand All @@ -187,11 +189,11 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,

if in.FinalCltvDelta == 0 {
route, findErr = r.FindRoute(
sourcePubKey, targetPubKey, amtMSat, restrictions,
sourcePubKey, targetPubKey, amtMSat, restrictions, noPadding,
)
} else {
route, findErr = r.FindRoute(
sourcePubKey, targetPubKey, amtMSat, restrictions,
sourcePubKey, targetPubKey, amtMSat, restrictions, noPadding,
uint16(in.FinalCltvDelta),
)
}
Expand Down
2 changes: 1 addition & 1 deletion lnrpc/routerrpc/router_backend_test.go
Expand Up @@ -74,7 +74,7 @@ func testQueryRoutes(t *testing.T, useMissionControl bool) {

findRoute := func(source, target route.Vertex,
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
finalExpiry ...uint16) (*route.Route, error) {
noPadding bool, finalExpiry ...uint16) (*route.Route, error) {

if int64(amt) != request.Amt*1000 {
t.Fatal("unexpected amount")
Expand Down
5 changes: 4 additions & 1 deletion lnrpc/routerrpc/router_server.go
Expand Up @@ -243,13 +243,16 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
// TODO: Change this into behaviour that makes more sense.
feeLimit := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)

// Add block padding
noPadding := false

// Finally, we'll query for a route to the destination that can carry
// that target amount, we'll only request a single route.
route, err := s.cfg.Router.FindRoute(
s.cfg.RouterBackend.SelfNode, destNode, amtMsat,
&routing.RestrictParams{
FeeLimit: feeLimit,
},
}, noPadding,
)
if err != nil {
return nil, err
Expand Down
1,011 changes: 512 additions & 499 deletions lnrpc/rpc.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lnrpc/rpc.proto
Expand Up @@ -1657,6 +1657,12 @@ message QueryRoutesRequest {
the optimal route.
*/
bool use_mission_control = 9;

/**
If no_padding = true, then no block padding will be added to the returned
route.
*/
bool no_padding = 10;
}

message EdgeLocator {
Expand Down
8 changes: 8 additions & 0 deletions lnrpc/rpc.swagger.json
Expand Up @@ -730,6 +730,14 @@
"required": false,
"type": "boolean",
"format": "boolean"
},
{
"name": "no_padding",
"description": "*\nIf no_padding = true, then no block padding will be added to the returned\nroute.",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
}
],
"tags": [
Expand Down
4 changes: 2 additions & 2 deletions routing/pathfind_test.go
Expand Up @@ -1685,7 +1685,7 @@ func TestPathFindSpecExample(t *testing.T) {
carol := ctx.aliases["C"]
const amt lnwire.MilliSatoshi = 4999999
route, err := ctx.router.FindRoute(
bobNode.PubKeyBytes, carol, amt, noRestrictions,
bobNode.PubKeyBytes, carol, amt, noRestrictions, noPadding,
)
if err != nil {
t.Fatalf("unable to find route: %v", err)
Expand Down Expand Up @@ -1744,7 +1744,7 @@ func TestPathFindSpecExample(t *testing.T) {

// We'll now request a route from A -> B -> C.
route, err = ctx.router.FindRoute(
source.PubKeyBytes, carol, amt, noRestrictions,
source.PubKeyBytes, carol, amt, noRestrictions, noPadding,
)
if err != nil {
t.Fatalf("unable to find routes: %v", err)
Expand Down
9 changes: 6 additions & 3 deletions routing/router.go
Expand Up @@ -1437,7 +1437,7 @@ type routingMsg struct {
// particular target destination to which it is able to send `amt` after
// factoring in channel capacities and cumulative fees along the route.
func (r *ChannelRouter) FindRoute(source, target route.Vertex,
amt lnwire.MilliSatoshi, restrictions *RestrictParams,
amt lnwire.MilliSatoshi, restrictions *RestrictParams, noPadding bool,
finalExpiry ...uint16) (*route.Route, error) {

var finalCLTVDelta uint16
Expand All @@ -1448,8 +1448,11 @@ func (r *ChannelRouter) FindRoute(source, target route.Vertex,
}

// Add BlockPadding to the finalCltvDelta so that the receiving node
// does not reject the HTLC if a block is mined while its in-flight.
finalCLTVDelta += BlockPadding
// does not reject the HTLC if a block is mined while its in-flight. If the
// noPadding option is set in the call, then don't add padding.
if !noPadding {
finalCLTVDelta += BlockPadding
}

log.Debugf("Searching for path to %x, sending %v", target, amt)

Expand Down
9 changes: 6 additions & 3 deletions routing/router_test.go
Expand Up @@ -227,10 +227,11 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
FeeLimit: lnwire.NewMSatFromSatoshis(10),
ProbabilitySource: noProbabilitySource,
}
noPadding := false

route, err := ctx.router.FindRoute(
ctx.router.selfNode.PubKeyBytes,
target, paymentAmt, restrictions,
target, paymentAmt, restrictions, noPadding,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
Expand Down Expand Up @@ -1076,6 +1077,8 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
func TestAddEdgeUnknownVertexes(t *testing.T) {
t.Parallel()

const noPadding = false

const startingBlockHeight = 101
ctx, cleanUp, err := createTestCtxFromFile(startingBlockHeight,
basicGraphFilePath)
Expand Down Expand Up @@ -1269,7 +1272,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
copy(targetPubKeyBytes[:], targetNode.SerializeCompressed())
_, err = ctx.router.FindRoute(
ctx.router.selfNode.PubKeyBytes,
targetPubKeyBytes, paymentAmt, noRestrictions,
targetPubKeyBytes, paymentAmt, noRestrictions, noPadding,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
Expand Down Expand Up @@ -1312,7 +1315,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
// updated.
_, err = ctx.router.FindRoute(
ctx.router.selfNode.PubKeyBytes,
targetPubKeyBytes, paymentAmt, noRestrictions,
targetPubKeyBytes, paymentAmt, noRestrictions, noPadding,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
Expand Down

0 comments on commit 76a2790

Please sign in to comment.