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.
This commit is contained in:
parent
d89f51d1d0
commit
e8f47cf882
@ -47,6 +47,9 @@ type AddInvoiceConfig struct {
|
|||||||
// channel graph.
|
// channel graph.
|
||||||
ChanDB *channeldb.DB
|
ChanDB *channeldb.DB
|
||||||
|
|
||||||
|
// Graph holds a reference to the ChannelGraph database.
|
||||||
|
Graph *channeldb.ChannelGraph
|
||||||
|
|
||||||
// GenInvoiceFeatures returns a feature containing feature bits that
|
// GenInvoiceFeatures returns a feature containing feature bits that
|
||||||
// should be advertised on freshly generated invoices.
|
// should be advertised on freshly generated invoices.
|
||||||
GenInvoiceFeatures func() *lnwire.FeatureVector
|
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
|
// chanCanBeHopHint returns true if the target channel is eligible to be a hop
|
||||||
// hint.
|
// hint.
|
||||||
func chanCanBeHopHint(channel *channeldb.OpenChannel,
|
func chanCanBeHopHint(channel *channeldb.OpenChannel, cfg *AddInvoiceConfig) (
|
||||||
graph *channeldb.ChannelGraph,
|
*channeldb.ChannelEdgePolicy, bool) {
|
||||||
cfg *AddInvoiceConfig) (*channeldb.ChannelEdgePolicy, bool) {
|
|
||||||
|
|
||||||
// Since we're only interested in our private channels, we'll skip
|
// Since we're only interested in our private channels, we'll skip
|
||||||
// public ones.
|
// public ones.
|
||||||
@ -359,7 +361,7 @@ func chanCanBeHopHint(channel *channeldb.OpenChannel,
|
|||||||
// channels.
|
// channels.
|
||||||
var remotePub [33]byte
|
var remotePub [33]byte
|
||||||
copy(remotePub[:], channel.IdentityPub.SerializeCompressed())
|
copy(remotePub[:], channel.IdentityPub.SerializeCompressed())
|
||||||
isRemoteNodePublic, err := graph.IsPublicNode(remotePub)
|
isRemoteNodePublic, err := cfg.Graph.IsPublicNode(remotePub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to determine if node %x "+
|
log.Errorf("Unable to determine if node %x "+
|
||||||
"is advertised: %v", remotePub, err)
|
"is advertised: %v", remotePub, err)
|
||||||
@ -375,7 +377,7 @@ func chanCanBeHopHint(channel *channeldb.OpenChannel,
|
|||||||
|
|
||||||
// Fetch the policies for each end of the channel.
|
// Fetch the policies for each end of the channel.
|
||||||
chanID := channel.ShortChanID().ToUint64()
|
chanID := channel.ShortChanID().ToUint64()
|
||||||
info, p1, p2, err := graph.FetchChannelEdgesByID(chanID)
|
info, p1, p2, err := cfg.Graph.FetchChannelEdgesByID(chanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to fetch the routing "+
|
log.Errorf("Unable to fetch the routing "+
|
||||||
"policies for the edges of the channel "+
|
"policies for the edges of the channel "+
|
||||||
@ -423,8 +425,6 @@ func selectHopHints(amtMSat lnwire.MilliSatoshi, cfg *AddInvoiceConfig,
|
|||||||
openChannels []*channeldb.OpenChannel,
|
openChannels []*channeldb.OpenChannel,
|
||||||
numMaxHophints int) []func(*zpay32.Invoice) {
|
numMaxHophints int) []func(*zpay32.Invoice) {
|
||||||
|
|
||||||
graph := cfg.ChanDB.ChannelGraph()
|
|
||||||
|
|
||||||
// We'll add our hop hints in two passes, first we'll add all channels
|
// 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
|
// that are eligible to be hop hints, and also have a local balance
|
||||||
// above the payment amount.
|
// above the payment amount.
|
||||||
@ -433,9 +433,7 @@ func selectHopHints(amtMSat lnwire.MilliSatoshi, cfg *AddInvoiceConfig,
|
|||||||
hopHints := make([]func(*zpay32.Invoice), 0, numMaxHophints)
|
hopHints := make([]func(*zpay32.Invoice), 0, numMaxHophints)
|
||||||
for _, channel := range openChannels {
|
for _, channel := range openChannels {
|
||||||
// If this channel can't be a hop hint, then skip it.
|
// If this channel can't be a hop hint, then skip it.
|
||||||
edgePolicy, canBeHopHint := chanCanBeHopHint(
|
edgePolicy, canBeHopHint := chanCanBeHopHint(channel, cfg)
|
||||||
channel, graph, cfg,
|
|
||||||
)
|
|
||||||
if edgePolicy == nil || !canBeHopHint {
|
if edgePolicy == nil || !canBeHopHint {
|
||||||
continue
|
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.
|
// If the channel can't be a hop hint, then we'll skip it.
|
||||||
// Otherwise, we'll use the policy information to populate the
|
// Otherwise, we'll use the policy information to populate the
|
||||||
// hop hint.
|
// hop hint.
|
||||||
remotePolicy, canBeHopHint := chanCanBeHopHint(
|
remotePolicy, canBeHopHint := chanCanBeHopHint(channel, cfg)
|
||||||
channel, graph, cfg,
|
|
||||||
)
|
|
||||||
if !canBeHopHint || remotePolicy == nil {
|
if !canBeHopHint || remotePolicy == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -4736,6 +4736,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
|
|||||||
NodeSigner: r.server.nodeSigner,
|
NodeSigner: r.server.nodeSigner,
|
||||||
DefaultCLTVExpiry: defaultDelta,
|
DefaultCLTVExpiry: defaultDelta,
|
||||||
ChanDB: r.server.remoteChanDB,
|
ChanDB: r.server.remoteChanDB,
|
||||||
|
Graph: r.server.localChanDB.ChannelGraph(),
|
||||||
GenInvoiceFeatures: func() *lnwire.FeatureVector {
|
GenInvoiceFeatures: func() *lnwire.FeatureVector {
|
||||||
return r.server.featureMgr.Get(feature.SetInvoice)
|
return r.server.featureMgr.Get(feature.SetInvoice)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user