From c32cbd940a88841cd5cc64e1f3041939845d127b Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 11 Dec 2025 17:46:25 +0200 Subject: [PATCH 1/3] funding: export MakeFundingScript So that we can re-use this helper else where. --- funding/manager.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index 8176e6aa222..616ddd83a53 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -1361,7 +1361,7 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel, } txid := &channel.FundingOutpoint.Hash - fundingScript, err := makeFundingScript(channel) + fundingScript, err := MakeFundingScript(channel) if err != nil { log.Errorf("unable to create funding script for "+ "ChannelPoint(%v): %v", @@ -3037,9 +3037,9 @@ func (f *Manager) waitForFundingWithTimeout( } } -// makeFundingScript re-creates the funding script for the funding transaction +// MakeFundingScript re-creates the funding script for the funding transaction // of the target channel. -func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) { +func MakeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) { localKey := channel.LocalChanCfg.MultiSigKey.PubKey remoteKey := channel.RemoteChanCfg.MultiSigKey.PubKey @@ -3086,7 +3086,7 @@ func (f *Manager) waitForFundingConfirmation( // Register with the ChainNotifier for a notification once the funding // transaction reaches `numConfs` confirmations. txid := completeChan.FundingOutpoint.Hash - fundingScript, err := makeFundingScript(completeChan) + fundingScript, err := MakeFundingScript(completeChan) if err != nil { log.Errorf("unable to create funding script for "+ "ChannelPoint(%v): %v", completeChan.FundingOutpoint, @@ -3802,7 +3802,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel, shortChanID.ToUint64(), completeChan.FundingOutpoint, numConfs) - fundingScript, err := makeFundingScript(completeChan) + fundingScript, err := MakeFundingScript(completeChan) if err != nil { return fmt.Errorf("unable to create funding script "+ "for ChannelPoint(%v): %v", From 7d695f581f2c183f64a6326504ba801ff9ecff07 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 11 Dec 2025 17:46:48 +0200 Subject: [PATCH 2/3] localchans: populate funding script for missing edges When creating a missing edge, we need to populate the funding script too so that the graph builder can update its ChainView appropriately. We use the MakeFundingScript helper from the funding package which ensures that we are using the same logic for creating a funding script as is used for any of the channels that we own. --- routing/localchans/manager.go | 18 +++++++++++++----- routing/localchans/manager_test.go | 12 ++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/routing/localchans/manager.go b/routing/localchans/manager.go index b1d281187d1..a48486e7b90 100644 --- a/routing/localchans/manager.go +++ b/routing/localchans/manager.go @@ -13,6 +13,7 @@ import ( "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/discovery" "github.com/lightningnetwork/lnd/fn/v2" + "github.com/lightningnetwork/lnd/funding" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwire" @@ -321,12 +322,19 @@ func (r *Manager) createEdge(channel *channeldb.OpenChannel, shortChanID = channel.ZeroConfRealScid() } + fundingScript, err := funding.MakeFundingScript(channel) + if err != nil { + return nil, nil, fmt.Errorf("unable to create funding "+ + "script: %v", err) + } + info := &models.ChannelEdgeInfo{ - ChannelID: shortChanID.ToUint64(), - ChainHash: channel.ChainHash, - Features: lnwire.EmptyFeatureVector(), - Capacity: channel.Capacity, - ChannelPoint: channel.FundingOutpoint, + ChannelID: shortChanID.ToUint64(), + ChainHash: channel.ChainHash, + Features: lnwire.EmptyFeatureVector(), + Capacity: channel.Capacity, + ChannelPoint: channel.FundingOutpoint, + FundingScript: fn.Some(fundingScript), } copy(info.NodeKey1Bytes[:], nodeKey1Bytes) diff --git a/routing/localchans/manager_test.go b/routing/localchans/manager_test.go index a2e7164b20b..5df344bbae2 100644 --- a/routing/localchans/manager_test.go +++ b/routing/localchans/manager_test.go @@ -13,6 +13,8 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/discovery" + "github.com/lightningnetwork/lnd/fn/v2" + "github.com/lightningnetwork/lnd/funding" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnrpc" @@ -385,6 +387,10 @@ func TestCreateEdgeLower(t *testing.T) { Index: 0, }, } + + fundingScript, err := funding.MakeFundingScript(channel) + require.NoError(t, err) + expectedInfo := &models.ChannelEdgeInfo{ ChannelID: 8, ChainHash: channel.ChainHash, @@ -399,6 +405,7 @@ func TestCreateEdgeLower(t *testing.T) { remoteMultisigKey.SerializeCompressed()), AuthProof: nil, ExtraOpaqueData: nil, + FundingScript: fn.Some(fundingScript), } expectedEdge := &models.ChannelEdgePolicy{ ChannelID: 8, @@ -473,6 +480,10 @@ func TestCreateEdgeHigher(t *testing.T) { Index: 0, }, } + + fundingScript, err := funding.MakeFundingScript(channel) + require.NoError(t, err) + expectedInfo := &models.ChannelEdgeInfo{ ChannelID: 8, ChainHash: channel.ChainHash, @@ -487,6 +498,7 @@ func TestCreateEdgeHigher(t *testing.T) { localMultisigKey.SerializeCompressed()), AuthProof: nil, ExtraOpaqueData: nil, + FundingScript: fn.Some(fundingScript), } expectedEdge := &models.ChannelEdgePolicy{ ChannelID: 8, From 53994daf1337e65252c488127440d0d1ac639acd Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 9 Dec 2025 11:20:25 +0200 Subject: [PATCH 3/3] docs: update release notes --- docs/release-notes/release-notes-0.20.1.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/release-notes-0.20.1.md b/docs/release-notes/release-notes-0.20.1.md index b1c00de9562..90c0496461e 100644 --- a/docs/release-notes/release-notes-0.20.1.md +++ b/docs/release-notes/release-notes-0.20.1.md @@ -58,6 +58,11 @@ * [Fix potential sql tx exhaustion issue](https://github.com/lightningnetwork/lnd/pull/10428) in LND which might happen when running postgres with a limited number of connections configured. + +* Fix a bug where [missing edges for own channels could not be added to the + graph DB](https://github.com/lightningnetwork/lnd/pull/10443) + due to validation checks in the graph Builder that were resurfaced after the + graph refactor work. # New Features