Skip to content

Commit 07b8452

Browse files
authored
Merge pull request #10443 from ellemouton/backport-fixMissingEdge
[backport] localchans: populate FundingScript for missing edges
2 parents c6467a6 + 53994da commit 07b8452

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

docs/release-notes/release-notes-0.20.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
* [Fix potential sql tx exhaustion
5959
issue](https://github.com/lightningnetwork/lnd/pull/10428) in LND which might
6060
happen when running postgres with a limited number of connections configured.
61+
62+
* Fix a bug where [missing edges for own channels could not be added to the
63+
graph DB](https://github.com/lightningnetwork/lnd/pull/10443)
64+
due to validation checks in the graph Builder that were resurfaced after the
65+
graph refactor work.
6166

6267
# New Features
6368

funding/manager.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
13611361
}
13621362

13631363
txid := &channel.FundingOutpoint.Hash
1364-
fundingScript, err := makeFundingScript(channel)
1364+
fundingScript, err := MakeFundingScript(channel)
13651365
if err != nil {
13661366
log.Errorf("unable to create funding script for "+
13671367
"ChannelPoint(%v): %v",
@@ -3037,9 +3037,9 @@ func (f *Manager) waitForFundingWithTimeout(
30373037
}
30383038
}
30393039

3040-
// makeFundingScript re-creates the funding script for the funding transaction
3040+
// MakeFundingScript re-creates the funding script for the funding transaction
30413041
// of the target channel.
3042-
func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
3042+
func MakeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) {
30433043
localKey := channel.LocalChanCfg.MultiSigKey.PubKey
30443044
remoteKey := channel.RemoteChanCfg.MultiSigKey.PubKey
30453045

@@ -3086,7 +3086,7 @@ func (f *Manager) waitForFundingConfirmation(
30863086
// Register with the ChainNotifier for a notification once the funding
30873087
// transaction reaches `numConfs` confirmations.
30883088
txid := completeChan.FundingOutpoint.Hash
3089-
fundingScript, err := makeFundingScript(completeChan)
3089+
fundingScript, err := MakeFundingScript(completeChan)
30903090
if err != nil {
30913091
log.Errorf("unable to create funding script for "+
30923092
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
@@ -3802,7 +3802,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
38023802
shortChanID.ToUint64(), completeChan.FundingOutpoint,
38033803
numConfs)
38043804

3805-
fundingScript, err := makeFundingScript(completeChan)
3805+
fundingScript, err := MakeFundingScript(completeChan)
38063806
if err != nil {
38073807
return fmt.Errorf("unable to create funding script "+
38083808
"for ChannelPoint(%v): %v",

routing/localchans/manager.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/lightningnetwork/lnd/channeldb"
1414
"github.com/lightningnetwork/lnd/discovery"
1515
"github.com/lightningnetwork/lnd/fn/v2"
16+
"github.com/lightningnetwork/lnd/funding"
1617
"github.com/lightningnetwork/lnd/graph/db/models"
1718
"github.com/lightningnetwork/lnd/lnrpc"
1819
"github.com/lightningnetwork/lnd/lnwire"
@@ -321,12 +322,19 @@ func (r *Manager) createEdge(channel *channeldb.OpenChannel,
321322
shortChanID = channel.ZeroConfRealScid()
322323
}
323324

325+
fundingScript, err := funding.MakeFundingScript(channel)
326+
if err != nil {
327+
return nil, nil, fmt.Errorf("unable to create funding "+
328+
"script: %v", err)
329+
}
330+
324331
info := &models.ChannelEdgeInfo{
325-
ChannelID: shortChanID.ToUint64(),
326-
ChainHash: channel.ChainHash,
327-
Features: lnwire.EmptyFeatureVector(),
328-
Capacity: channel.Capacity,
329-
ChannelPoint: channel.FundingOutpoint,
332+
ChannelID: shortChanID.ToUint64(),
333+
ChainHash: channel.ChainHash,
334+
Features: lnwire.EmptyFeatureVector(),
335+
Capacity: channel.Capacity,
336+
ChannelPoint: channel.FundingOutpoint,
337+
FundingScript: fn.Some(fundingScript),
330338
}
331339

332340
copy(info.NodeKey1Bytes[:], nodeKey1Bytes)

routing/localchans/manager_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/btcsuite/btcd/wire"
1414
"github.com/lightningnetwork/lnd/channeldb"
1515
"github.com/lightningnetwork/lnd/discovery"
16+
"github.com/lightningnetwork/lnd/fn/v2"
17+
"github.com/lightningnetwork/lnd/funding"
1618
"github.com/lightningnetwork/lnd/graph/db/models"
1719
"github.com/lightningnetwork/lnd/keychain"
1820
"github.com/lightningnetwork/lnd/lnrpc"
@@ -385,6 +387,10 @@ func TestCreateEdgeLower(t *testing.T) {
385387
Index: 0,
386388
},
387389
}
390+
391+
fundingScript, err := funding.MakeFundingScript(channel)
392+
require.NoError(t, err)
393+
388394
expectedInfo := &models.ChannelEdgeInfo{
389395
ChannelID: 8,
390396
ChainHash: channel.ChainHash,
@@ -399,6 +405,7 @@ func TestCreateEdgeLower(t *testing.T) {
399405
remoteMultisigKey.SerializeCompressed()),
400406
AuthProof: nil,
401407
ExtraOpaqueData: nil,
408+
FundingScript: fn.Some(fundingScript),
402409
}
403410
expectedEdge := &models.ChannelEdgePolicy{
404411
ChannelID: 8,
@@ -473,6 +480,10 @@ func TestCreateEdgeHigher(t *testing.T) {
473480
Index: 0,
474481
},
475482
}
483+
484+
fundingScript, err := funding.MakeFundingScript(channel)
485+
require.NoError(t, err)
486+
476487
expectedInfo := &models.ChannelEdgeInfo{
477488
ChannelID: 8,
478489
ChainHash: channel.ChainHash,
@@ -487,6 +498,7 @@ func TestCreateEdgeHigher(t *testing.T) {
487498
localMultisigKey.SerializeCompressed()),
488499
AuthProof: nil,
489500
ExtraOpaqueData: nil,
501+
FundingScript: fn.Some(fundingScript),
490502
}
491503
expectedEdge := &models.ChannelEdgePolicy{
492504
ChannelID: 8,

0 commit comments

Comments
 (0)