graph/db: add FundingPKScript method on ChannelEdgeInfo

Add FundingPKScript() method that returns the funding output's
pkScript for the channel. The implementation is version-aware:

- V1: generates a 2-of-2 multisig P2WSH script from the two bitcoin
  keys
- V2: will use taproot script (to be implemented)

This encapsulates the script generation logic and makes it clear
which bitcoin keys are being used. Replaces direct calls to
genMultiSigP2WSH with the cleaner method call.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:22 +02:00
1 parent 44f4171415
commit 06a669bc89
4 files changed
+38 -17

No files matched your search

+3 -8
View File
@@ -2044,14 +2044,9 @@ func TestGraphPruning(t *testing.T) {
t.Fatalf("unable to add node: %v", err)
}
btcKey1 := edgeInfo.BitcoinKey1Bytes.UnwrapOr(route.Vertex{})
btcKey2 := edgeInfo.BitcoinKey2Bytes.UnwrapOr(route.Vertex{})
pkScript, err := genMultiSigP2WSH(
btcKey1[:], btcKey2[:],
)
if err != nil {
t.Fatalf("unable to gen multi-sig p2wsh: %v", err)
}
pkScript, err := edgeInfo.FundingPKScript()
require.NoError(t, err)
edgePoints = append(edgePoints, EdgePoint{
FundingPkScript: pkScript,
OutPoint: op,
+1 -9
View File
@@ -4112,15 +4112,7 @@ func (c *KVStore) ChannelView() ([]EdgePoint, error) {
return err
}
btcKey1 := edgeInfo.BitcoinKey1Bytes.UnwrapOr(
route.Vertex{},
)
btcKey2 := edgeInfo.BitcoinKey2Bytes.UnwrapOr(
route.Vertex{},
)
pkScript, err := genMultiSigP2WSH(
btcKey1[:], btcKey2[:],
)
pkScript, err := edgeInfo.FundingPKScript()
if err != nil {
return err
}
+33
View File
@@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)
@@ -200,6 +201,38 @@ func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
}
}
// FundingPKScript returns the funding output's pkScript for the channel.
func (c *ChannelEdgeInfo) FundingPKScript() ([]byte, error) {
switch c.Version {
case lnwire.GossipVersion1:
btc1Key, err := c.BitcoinKey1Bytes.UnwrapOrErr(
fmt.Errorf("missing bitcoin key 1"),
)
if err != nil {
return nil, err
}
btc2Key, err := c.BitcoinKey2Bytes.UnwrapOrErr(
fmt.Errorf("missing bitcoin key 2"),
)
if err != nil {
return nil, err
}
witnessScript, err := input.GenMultiSigScript(
btc1Key[:], btc2Key[:],
)
if err != nil {
return nil, err
}
return input.WitnessScriptHash(witnessScript)
default:
return nil, fmt.Errorf("unsupported channel version: %d",
c.Version)
}
}
// ToChannelAnnouncement converts the ChannelEdgeInfo to a
// lnwire.ChannelAnnouncement1 message. Returns an error if AuthProof is nil
// or if the version is not v1.
+1
View File
@@ -2768,6 +2768,7 @@ func (s *SQLStore) ChannelView() ([]EdgePoint, error) {
handleChannel := func(_ context.Context,
channel sqlc.ListChannelsPaginatedRow) error {
// TODO(elle): update to handle V2 channels.
pkScript, err := genMultiSigP2WSH(
channel.BitcoinKey1, channel.BitcoinKey2,
)