From 13671874542b0ed3d21e159081d822b176b620b4 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 10 Dec 2019 13:09:52 -0800 Subject: [PATCH] multi: set invoice feature bits using feature manager --- lnrpc/invoicesrpc/addinvoice.go | 11 ++++++----- lnrpc/invoicesrpc/config_active.go | 4 ++++ lnrpc/invoicesrpc/invoices_server.go | 15 ++++++++------- rpcserver.go | 10 +++++++++- subrpcserver_config.go | 7 ++++++- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index 6fe149b1b..28b48e547 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -47,6 +47,10 @@ type AddInvoiceConfig struct { // ChanDB is a global boltdb instance which is needed to access the // channel graph. ChanDB *channeldb.DB + + // GenInvoiceFeatures returns a feature containing feature bits that + // should be advertised on freshly generated invoices. + GenInvoiceFeatures func() *lnwire.FeatureVector } // AddInvoiceData contains the required data to create a new invoice. @@ -363,11 +367,8 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, } - // Set a blank feature vector, as our invoice generation forbids nil - // features. - invoiceFeatures := lnwire.NewFeatureVector( - lnwire.NewRawFeatureVector(), lnwire.Features, - ) + // Set our desired invoice features and add them to our list of options. + invoiceFeatures := cfg.GenInvoiceFeatures() options = append(options, zpay32.Features(invoiceFeatures)) // Generate and set a random payment address for this invoice. If the diff --git a/lnrpc/invoicesrpc/config_active.go b/lnrpc/invoicesrpc/config_active.go index 0bb311a18..b347ecd54 100644 --- a/lnrpc/invoicesrpc/config_active.go +++ b/lnrpc/invoicesrpc/config_active.go @@ -50,4 +50,8 @@ type Config struct { // ChanDB is a global boltdb instance which is needed to access the // channel graph. ChanDB *channeldb.DB + + // GenInvoiceFeatures returns a feature containing feature bits that + // should be advertised on freshly generated invoices. + GenInvoiceFeatures func() *lnwire.FeatureVector } diff --git a/lnrpc/invoicesrpc/invoices_server.go b/lnrpc/invoicesrpc/invoices_server.go index 9aff9a330..87cdc0261 100644 --- a/lnrpc/invoicesrpc/invoices_server.go +++ b/lnrpc/invoicesrpc/invoices_server.go @@ -246,13 +246,14 @@ func (s *Server) AddHoldInvoice(ctx context.Context, invoice *AddHoldInvoiceRequest) (*AddHoldInvoiceResp, error) { addInvoiceCfg := &AddInvoiceConfig{ - AddInvoice: s.cfg.InvoiceRegistry.AddInvoice, - IsChannelActive: s.cfg.IsChannelActive, - ChainParams: s.cfg.ChainParams, - NodeSigner: s.cfg.NodeSigner, - MaxPaymentMSat: s.cfg.MaxPaymentMSat, - DefaultCLTVExpiry: s.cfg.DefaultCLTVExpiry, - ChanDB: s.cfg.ChanDB, + AddInvoice: s.cfg.InvoiceRegistry.AddInvoice, + IsChannelActive: s.cfg.IsChannelActive, + ChainParams: s.cfg.ChainParams, + NodeSigner: s.cfg.NodeSigner, + MaxPaymentMSat: s.cfg.MaxPaymentMSat, + DefaultCLTVExpiry: s.cfg.DefaultCLTVExpiry, + ChanDB: s.cfg.ChanDB, + GenInvoiceFeatures: s.cfg.GenInvoiceFeatures, } hash, err := lntypes.MakeHash(invoice.Hash) diff --git a/rpcserver.go b/rpcserver.go index 33d294545..d5461a6e6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -36,6 +36,7 @@ import ( "github.com/lightningnetwork/lnd/channelnotifier" "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/discovery" + "github.com/lightningnetwork/lnd/feature" "github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/invoices" @@ -549,6 +550,10 @@ func newRPCServer(s *server, macService *macaroons.Service, MaxTotalTimelock: cfg.MaxOutgoingCltvExpiry, } + genInvoiceFeatures := func() *lnwire.FeatureVector { + return s.featureMgr.Get(feature.SetInvoice) + } + var ( subServers []lnrpc.SubServer subServerPerms []lnrpc.MacaroonPerms @@ -561,7 +566,7 @@ func newRPCServer(s *server, macService *macaroons.Service, s.cc, networkDir, macService, atpl, invoiceRegistry, s.htlcSwitch, activeNetParams.Params, s.chanRouter, routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower, - s.towerClient, cfg.net.ResolveTCPAddr, + s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures, ) if err != nil { return nil, err @@ -3633,6 +3638,9 @@ func (r *rpcServer) AddInvoice(ctx context.Context, MaxPaymentMSat: MaxPaymentMSat, DefaultCLTVExpiry: defaultDelta, ChanDB: r.server.chanDB, + GenInvoiceFeatures: func() *lnwire.FeatureVector { + return r.server.featureMgr.Get(feature.SetInvoice) + }, } value, err := lnrpc.UnmarshallAmt(invoice.Value, invoice.ValueMsat) diff --git a/subrpcserver_config.go b/subrpcserver_config.go index d00e3a43d..ff7a0be7c 100644 --- a/subrpcserver_config.go +++ b/subrpcserver_config.go @@ -18,6 +18,7 @@ import ( "github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc" "github.com/lightningnetwork/lnd/lnrpc/wtclientrpc" + "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/netann" "github.com/lightningnetwork/lnd/routing" @@ -92,7 +93,8 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl, sweeper *sweep.UtxoSweeper, tower *watchtower.Standalone, towerClient wtclient.Client, - tcpResolver lncfg.TCPResolver) error { + tcpResolver lncfg.TCPResolver, + genInvoiceFeatures func() *lnwire.FeatureVector) error { // First, we'll use reflect to obtain a version of the config struct // that allows us to programmatically inspect its fields. @@ -210,6 +212,9 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl, subCfgValue.FieldByName("ChanDB").Set( reflect.ValueOf(chanDB), ) + subCfgValue.FieldByName("GenInvoiceFeatures").Set( + reflect.ValueOf(genInvoiceFeatures), + ) case *routerrpc.Config: subCfgValue := extractReflectValue(subCfg)