multi: set invoice feature bits using feature manager

This commit is contained in:
Conner Fromknecht 2019-12-10 13:09:52 -08:00
parent a168f37b9c
commit 1367187454
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
5 changed files with 33 additions and 14 deletions

@ -47,6 +47,10 @@ type AddInvoiceConfig struct {
// ChanDB is a global boltdb instance which is needed to access the // ChanDB is a global boltdb instance which is needed to access the
// channel graph. // channel graph.
ChanDB *channeldb.DB 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. // 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 // Set our desired invoice features and add them to our list of options.
// features. invoiceFeatures := cfg.GenInvoiceFeatures()
invoiceFeatures := lnwire.NewFeatureVector(
lnwire.NewRawFeatureVector(), lnwire.Features,
)
options = append(options, zpay32.Features(invoiceFeatures)) options = append(options, zpay32.Features(invoiceFeatures))
// Generate and set a random payment address for this invoice. If the // Generate and set a random payment address for this invoice. If the

@ -50,4 +50,8 @@ type Config struct {
// ChanDB is a global boltdb instance which is needed to access the // ChanDB is a global boltdb instance which is needed to access the
// channel graph. // channel graph.
ChanDB *channeldb.DB ChanDB *channeldb.DB
// GenInvoiceFeatures returns a feature containing feature bits that
// should be advertised on freshly generated invoices.
GenInvoiceFeatures func() *lnwire.FeatureVector
} }

@ -246,13 +246,14 @@ func (s *Server) AddHoldInvoice(ctx context.Context,
invoice *AddHoldInvoiceRequest) (*AddHoldInvoiceResp, error) { invoice *AddHoldInvoiceRequest) (*AddHoldInvoiceResp, error) {
addInvoiceCfg := &AddInvoiceConfig{ addInvoiceCfg := &AddInvoiceConfig{
AddInvoice: s.cfg.InvoiceRegistry.AddInvoice, AddInvoice: s.cfg.InvoiceRegistry.AddInvoice,
IsChannelActive: s.cfg.IsChannelActive, IsChannelActive: s.cfg.IsChannelActive,
ChainParams: s.cfg.ChainParams, ChainParams: s.cfg.ChainParams,
NodeSigner: s.cfg.NodeSigner, NodeSigner: s.cfg.NodeSigner,
MaxPaymentMSat: s.cfg.MaxPaymentMSat, MaxPaymentMSat: s.cfg.MaxPaymentMSat,
DefaultCLTVExpiry: s.cfg.DefaultCLTVExpiry, DefaultCLTVExpiry: s.cfg.DefaultCLTVExpiry,
ChanDB: s.cfg.ChanDB, ChanDB: s.cfg.ChanDB,
GenInvoiceFeatures: s.cfg.GenInvoiceFeatures,
} }
hash, err := lntypes.MakeHash(invoice.Hash) hash, err := lntypes.MakeHash(invoice.Hash)

@ -36,6 +36,7 @@ import (
"github.com/lightningnetwork/lnd/channelnotifier" "github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
@ -549,6 +550,10 @@ func newRPCServer(s *server, macService *macaroons.Service,
MaxTotalTimelock: cfg.MaxOutgoingCltvExpiry, MaxTotalTimelock: cfg.MaxOutgoingCltvExpiry,
} }
genInvoiceFeatures := func() *lnwire.FeatureVector {
return s.featureMgr.Get(feature.SetInvoice)
}
var ( var (
subServers []lnrpc.SubServer subServers []lnrpc.SubServer
subServerPerms []lnrpc.MacaroonPerms subServerPerms []lnrpc.MacaroonPerms
@ -561,7 +566,7 @@ func newRPCServer(s *server, macService *macaroons.Service,
s.cc, networkDir, macService, atpl, invoiceRegistry, s.cc, networkDir, macService, atpl, invoiceRegistry,
s.htlcSwitch, activeNetParams.Params, s.chanRouter, s.htlcSwitch, activeNetParams.Params, s.chanRouter,
routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower, routerBackend, s.nodeSigner, s.chanDB, s.sweeper, tower,
s.towerClient, cfg.net.ResolveTCPAddr, s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -3633,6 +3638,9 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
MaxPaymentMSat: MaxPaymentMSat, MaxPaymentMSat: MaxPaymentMSat,
DefaultCLTVExpiry: defaultDelta, DefaultCLTVExpiry: defaultDelta,
ChanDB: r.server.chanDB, ChanDB: r.server.chanDB,
GenInvoiceFeatures: func() *lnwire.FeatureVector {
return r.server.featureMgr.Get(feature.SetInvoice)
},
} }
value, err := lnrpc.UnmarshallAmt(invoice.Value, invoice.ValueMsat) value, err := lnrpc.UnmarshallAmt(invoice.Value, invoice.ValueMsat)

@ -18,6 +18,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc" "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc" "github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/netann" "github.com/lightningnetwork/lnd/netann"
"github.com/lightningnetwork/lnd/routing" "github.com/lightningnetwork/lnd/routing"
@ -92,7 +93,8 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
sweeper *sweep.UtxoSweeper, sweeper *sweep.UtxoSweeper,
tower *watchtower.Standalone, tower *watchtower.Standalone,
towerClient wtclient.Client, 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 // First, we'll use reflect to obtain a version of the config struct
// that allows us to programmatically inspect its fields. // that allows us to programmatically inspect its fields.
@ -210,6 +212,9 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
subCfgValue.FieldByName("ChanDB").Set( subCfgValue.FieldByName("ChanDB").Set(
reflect.ValueOf(chanDB), reflect.ValueOf(chanDB),
) )
subCfgValue.FieldByName("GenInvoiceFeatures").Set(
reflect.ValueOf(genInvoiceFeatures),
)
case *routerrpc.Config: case *routerrpc.Config:
subCfgValue := extractReflectValue(subCfg) subCfgValue := extractReflectValue(subCfg)