@@ -23,6 +23,7 @@ import (
2323 "github.com/btcsuite/btcd/wire"
2424 "github.com/lightningnetwork/lnd/fn/v2"
2525 "github.com/lightningnetwork/lnd/graph/db/models"
26+ "github.com/lightningnetwork/lnd/input"
2627 "github.com/lightningnetwork/lnd/kvdb"
2728 "github.com/lightningnetwork/lnd/lntest/wait"
2829 "github.com/lightningnetwork/lnd/lnwire"
@@ -209,6 +210,10 @@ var versionedTests = []versionedTest{
209210 name : "channel view" ,
210211 test : testChannelView ,
211212 },
213+ {
214+ name : "channel view taproot v1 round trip" ,
215+ test : testChannelViewTaprootV1RoundTrip ,
216+ },
212217}
213218
214219// TestVersionedDBs runs various tests against both v1 and v2 versioned
@@ -3897,6 +3902,70 @@ func testChannelView(t *testing.T, v lnwire.GossipVersion) {
38973902 assertChanViewEqual (t , channelView , edgePoints )
38983903}
38993904
3905+ // testChannelViewTaprootV1RoundTrip tests that a taproot channel persisted as a
3906+ // v1 edge can be read back from ChannelView() with the correct taproot funding
3907+ // script.
3908+ func testChannelViewTaprootV1RoundTrip (t * testing.T , v lnwire.GossipVersion ) {
3909+ t .Parallel ()
3910+
3911+ if v != lnwire .GossipVersion1 {
3912+ t .Skip ("only relevant for v1 taproot workaround channels" )
3913+ }
3914+
3915+ ctx := t .Context ()
3916+ graph := NewVersionedGraph (MakeTestGraph (t ), v )
3917+
3918+ node1 := createTestVertex (t , v )
3919+ require .NoError (t , graph .AddNode (ctx , node1 ))
3920+ node2 := createTestVertex (t , v )
3921+ require .NoError (t , graph .AddNode (ctx , node2 ))
3922+
3923+ node1Pub , err := node1 .PubKey ()
3924+ require .NoError (t , err )
3925+ node2Pub , err := node2 .PubKey ()
3926+ require .NoError (t , err )
3927+
3928+ node1Vertex := route .NewVertex (node1Pub )
3929+ node2Vertex := route .NewVertex (node2Pub )
3930+ outpoint := wire.OutPoint {
3931+ Hash : rev ,
3932+ Index : 1 ,
3933+ }
3934+
3935+ // Persist a synthetic v1 channel that advertises the taproot staging
3936+ // bit. This reproduces the serialization path exercised by older graph
3937+ // entries.
3938+ edgeInfo , err := models .NewV1Channel (
3939+ 1 , * chaincfg .MainNetParams .GenesisHash ,
3940+ node1Vertex , node2Vertex ,
3941+ & models.ChannelV1Fields {
3942+ BitcoinKey1Bytes : node1Vertex ,
3943+ BitcoinKey2Bytes : node2Vertex ,
3944+ ExtraOpaqueData : make ([]byte , 0 ),
3945+ },
3946+ models .WithChannelPoint (outpoint ),
3947+ models .WithCapacity (9000 ),
3948+ models .WithFeatures (lnwire .NewRawFeatureVector (
3949+ lnwire .SimpleTaprootChannelsRequiredStaging ,
3950+ )),
3951+ )
3952+ require .NoError (t , err )
3953+ require .NoError (t , graph .AddChannelEdge (ctx , edgeInfo ))
3954+
3955+ // The fix should make ChannelView reconstruct the taproot funding
3956+ // script for v1 channels that advertise the taproot staging bit.
3957+ expectedScript , _ , err := input .GenTaprootFundingScript (
3958+ node1Pub , node2Pub , 0 , fn .None [chainhash.Hash ](),
3959+ )
3960+ require .NoError (t , err )
3961+
3962+ channelView , err := graph .ChannelView (ctx )
3963+ require .NoError (t , err )
3964+ require .Len (t , channelView , 1 )
3965+ require .Equal (t , expectedScript , channelView [0 ].FundingPkScript )
3966+ require .Equal (t , outpoint , channelView [0 ].OutPoint )
3967+ }
3968+
39003969// testIncompleteChannelPolicies tests that a channel that only has a policy
39013970// specified on one end is properly returned in ForEachChannel calls from
39023971// both sides.
0 commit comments