From e8f47cf882172d900dbfcddd2fc0d7343c02bf0c Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Mon, 26 Oct 2020 14:14:15 +0100 Subject: [PATCH] invoices: channel graph reference was wrongly retrieved from remote db This commit fixes a bug where we tried to use the graph from the remote db instance whereas it lives in the local db instance. --- lnrpc/invoicesrpc/addinvoice.go | 22 +++++++++------------- rpcserver.go | 1 + 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index afa7e708..7628c4ad 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -47,6 +47,9 @@ type AddInvoiceConfig struct { // channel graph. ChanDB *channeldb.DB + // Graph holds a reference to the ChannelGraph database. + Graph *channeldb.ChannelGraph + // GenInvoiceFeatures returns a feature containing feature bits that // should be advertised on freshly generated invoices. GenInvoiceFeatures func() *lnwire.FeatureVector @@ -330,9 +333,8 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, // chanCanBeHopHint returns true if the target channel is eligible to be a hop // hint. -func chanCanBeHopHint(channel *channeldb.OpenChannel, - graph *channeldb.ChannelGraph, - cfg *AddInvoiceConfig) (*channeldb.ChannelEdgePolicy, bool) { +func chanCanBeHopHint(channel *channeldb.OpenChannel, cfg *AddInvoiceConfig) ( + *channeldb.ChannelEdgePolicy, bool) { // Since we're only interested in our private channels, we'll skip // public ones. @@ -359,7 +361,7 @@ func chanCanBeHopHint(channel *channeldb.OpenChannel, // channels. var remotePub [33]byte copy(remotePub[:], channel.IdentityPub.SerializeCompressed()) - isRemoteNodePublic, err := graph.IsPublicNode(remotePub) + isRemoteNodePublic, err := cfg.Graph.IsPublicNode(remotePub) if err != nil { log.Errorf("Unable to determine if node %x "+ "is advertised: %v", remotePub, err) @@ -375,7 +377,7 @@ func chanCanBeHopHint(channel *channeldb.OpenChannel, // Fetch the policies for each end of the channel. chanID := channel.ShortChanID().ToUint64() - info, p1, p2, err := graph.FetchChannelEdgesByID(chanID) + info, p1, p2, err := cfg.Graph.FetchChannelEdgesByID(chanID) if err != nil { log.Errorf("Unable to fetch the routing "+ "policies for the edges of the channel "+ @@ -423,8 +425,6 @@ func selectHopHints(amtMSat lnwire.MilliSatoshi, cfg *AddInvoiceConfig, openChannels []*channeldb.OpenChannel, numMaxHophints int) []func(*zpay32.Invoice) { - graph := cfg.ChanDB.ChannelGraph() - // We'll add our hop hints in two passes, first we'll add all channels // that are eligible to be hop hints, and also have a local balance // above the payment amount. @@ -433,9 +433,7 @@ func selectHopHints(amtMSat lnwire.MilliSatoshi, cfg *AddInvoiceConfig, hopHints := make([]func(*zpay32.Invoice), 0, numMaxHophints) for _, channel := range openChannels { // If this channel can't be a hop hint, then skip it. - edgePolicy, canBeHopHint := chanCanBeHopHint( - channel, graph, cfg, - ) + edgePolicy, canBeHopHint := chanCanBeHopHint(channel, cfg) if edgePolicy == nil || !canBeHopHint { continue } @@ -485,9 +483,7 @@ func selectHopHints(amtMSat lnwire.MilliSatoshi, cfg *AddInvoiceConfig, // If the channel can't be a hop hint, then we'll skip it. // Otherwise, we'll use the policy information to populate the // hop hint. - remotePolicy, canBeHopHint := chanCanBeHopHint( - channel, graph, cfg, - ) + remotePolicy, canBeHopHint := chanCanBeHopHint(channel, cfg) if !canBeHopHint || remotePolicy == nil { continue } diff --git a/rpcserver.go b/rpcserver.go index 41c57a2f..8d39547f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4736,6 +4736,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context, NodeSigner: r.server.nodeSigner, DefaultCLTVExpiry: defaultDelta, ChanDB: r.server.remoteChanDB, + Graph: r.server.localChanDB.ChannelGraph(), GenInvoiceFeatures: func() *lnwire.FeatureVector { return r.server.featureMgr.Get(feature.SetInvoice) },