diff --git a/itest/lnd_max_htlcs_test.go b/itest/lnd_max_htlcs_test.go index a9bee5ae4..971537adf 100644 --- a/itest/lnd_max_htlcs_test.go +++ b/itest/lnd_max_htlcs_test.go @@ -20,6 +20,17 @@ func testMaxHtlcPathfind(ht *lntest.HarnessTest) { maxHtlcs := 5 alice, bob := ht.Alice, ht.Bob + + // Restart nodes with the new flag so they understand the new payment + // status. + ht.RestartNodeWithExtraArgs(alice, []string{ + "--routerrpc.usestatusinitiated", + }) + ht.RestartNodeWithExtraArgs(bob, []string{ + "--routerrpc.usestatusinitiated", + }) + + ht.EnsureConnected(alice, bob) chanPoint := ht.OpenChannel( alice, bob, lntest.OpenChannelParams{ Amt: 1000000, diff --git a/lnrpc/routerrpc/config.go b/lnrpc/routerrpc/config.go index adcc84e80..ec70b6d46 100644 --- a/lnrpc/routerrpc/config.go +++ b/lnrpc/routerrpc/config.go @@ -10,9 +10,18 @@ import ( // The fields with struct tags are meant to be parsed as normal configuration // options, while if able to be populated, the latter fields MUST also be // specified. +// +//nolint:lll type Config struct { RoutingConfig + // UseStatusInitiated is a boolean that indicates whether the router + // should use the new status code `Payment_INITIATED`. + // + // TODO(yy): remove this config after the new status code is fully + // deployed to the network(v0.20.0). + UseStatusInitiated bool `long:"usestatusinitiated" description:"If true, the router will send Payment_INITIATED for new payments, otherwise Payment_In_FLIGHT will be sent for compatibility concerns."` + // RouterMacPath is the path for the router macaroon. If unspecified // then we assume that the macaroon will be found under the network // directory, named DefaultRouterMacFilename. diff --git a/lnrpc/routerrpc/router_backend.go b/lnrpc/routerrpc/router_backend.go index 549443f0f..49d080a32 100644 --- a/lnrpc/routerrpc/router_backend.go +++ b/lnrpc/routerrpc/router_backend.go @@ -98,6 +98,13 @@ type RouterBackend struct { // SetChannelAuto exposes the ability to restore automatic channel state // management after manually setting channel status. SetChannelAuto func(wire.OutPoint) error + + // UseStatusInitiated is a boolean that indicates whether the router + // should use the new status code `Payment_INITIATED`. + // + // TODO(yy): remove this config after the new status code is fully + // deployed to the network(v0.20.0). + UseStatusInitiated bool } // MissionControl defines the mission control dependencies of routerrpc. @@ -1542,7 +1549,9 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) ( msatValue := int64(payment.Info.Value) satValue := int64(payment.Info.Value.ToSatoshis()) - status, err := convertPaymentStatus(payment.Status) + status, err := convertPaymentStatus( + payment.Status, r.UseStatusInitiated, + ) if err != nil { return nil, err } @@ -1589,12 +1598,18 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) ( // convertPaymentStatus converts a channeldb.PaymentStatus to the type expected // by the RPC. -func convertPaymentStatus(dbStatus channeldb.PaymentStatus) ( +func convertPaymentStatus(dbStatus channeldb.PaymentStatus, useInit bool) ( lnrpc.Payment_PaymentStatus, error) { switch dbStatus { case channeldb.StatusInitiated: - return lnrpc.Payment_INITIATED, nil + // If the client understands the new status, return it. + if useInit { + return lnrpc.Payment_INITIATED, nil + } + + // Otherwise remain the old behavior. + return lnrpc.Payment_IN_FLIGHT, nil case channeldb.StatusInFlight: return lnrpc.Payment_IN_FLIGHT, nil diff --git a/rpcserver.go b/rpcserver.go index fa23f0485..27921e5d7 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -715,7 +715,8 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service, SetChannelDisabled: func(outpoint wire.OutPoint) error { return s.chanStatusMgr.RequestDisable(outpoint, true) }, - SetChannelAuto: s.chanStatusMgr.RequestAuto, + SetChannelAuto: s.chanStatusMgr.RequestAuto, + UseStatusInitiated: subServerCgs.RouterRPC.UseStatusInitiated, } genInvoiceFeatures := func() *lnwire.FeatureVector { diff --git a/sample-lnd.conf b/sample-lnd.conf index 9bc1a2a84..0b7531e66 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -1201,6 +1201,10 @@ ; failures in channels. ; routerrpc.bimodal.decaytime=168h +; If set, the router will send `Payment_INITIATED` for new payments, otherwise +; `Payment_In_FLIGHT` will be sent for compatibility concerns. +; routerrpc.usestatusinitiated=false + [workers]