mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 03:01:52 +01:00
multi: add tapscript root to chan ann (temp)
Needed so the router can validate the musig2 output w/ a custom tweak.
This commit is contained in:
parent
2ba7a531ae
commit
3f4fa79cf5
@ -8,6 +8,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
)
|
||||
|
||||
// ChannelEdgeInfo represents a fully authenticated channel along with all its
|
||||
@ -62,6 +63,8 @@ type ChannelEdgeInfo struct {
|
||||
// the value output in the outpoint that created this channel.
|
||||
Capacity btcutil.Amount
|
||||
|
||||
TapscriptRoot fn.Option[chainhash.Hash]
|
||||
|
||||
// ExtraOpaqueData is the set of data that was appended to this
|
||||
// message, some of which we may not actually know how to iterate or
|
||||
// parse. By holding onto this data, we ensure that we're able to
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
@ -82,9 +83,10 @@ var (
|
||||
// can provide that serve useful when processing a specific network
|
||||
// announcement.
|
||||
type optionalMsgFields struct {
|
||||
capacity *btcutil.Amount
|
||||
channelPoint *wire.OutPoint
|
||||
remoteAlias *lnwire.ShortChannelID
|
||||
capacity *btcutil.Amount
|
||||
channelPoint *wire.OutPoint
|
||||
remoteAlias *lnwire.ShortChannelID
|
||||
tapscriptRoot fn.Option[chainhash.Hash]
|
||||
}
|
||||
|
||||
// apply applies the optional fields within the functional options.
|
||||
@ -115,6 +117,12 @@ func ChannelPoint(op wire.OutPoint) OptionalMsgField {
|
||||
}
|
||||
}
|
||||
|
||||
func TapscriptRoot(root fn.Option[chainhash.Hash]) OptionalMsgField {
|
||||
return func(f *optionalMsgFields) {
|
||||
f.tapscriptRoot = root
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteAlias is an optional field that lets the gossiper know that a locally
|
||||
// sent channel update is actually an update for the peer that should replace
|
||||
// the ShortChannelID field with the remote's alias. This is only used for
|
||||
@ -2500,6 +2508,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
||||
BitcoinKey2Bytes: ann.BitcoinKey2,
|
||||
AuthProof: proof,
|
||||
Features: featureBuf.Bytes(),
|
||||
TapscriptRoot: nMsg.optionalMsgFields.tapscriptRoot,
|
||||
ExtraOpaqueData: ann.ExtraOpaqueData,
|
||||
}
|
||||
|
||||
|
@ -3478,6 +3478,7 @@ func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
|
||||
errChan := f.cfg.SendAnnouncement(
|
||||
ann.chanAnn, discovery.ChannelCapacity(completeChan.Capacity),
|
||||
discovery.ChannelPoint(completeChan.FundingOutpoint),
|
||||
discovery.TapscriptRoot(completeChan.TapscriptRoot),
|
||||
)
|
||||
select {
|
||||
case err := <-errChan:
|
||||
@ -4406,9 +4407,9 @@ func (f *Manager) announceChannel(localIDKey, remoteIDKey *btcec.PublicKey,
|
||||
//
|
||||
// We can pass in zeroes for the min and max htlc policy, because we
|
||||
// only use the channel announcement message from the returned struct.
|
||||
ann, err := f.newChanAnnouncement(localIDKey, remoteIDKey,
|
||||
localFundingKey, remoteFundingKey, shortChanID, chanID,
|
||||
0, 0, nil, chanType,
|
||||
ann, err := f.newChanAnnouncement(
|
||||
localIDKey, remoteIDKey, localFundingKey, remoteFundingKey,
|
||||
shortChanID, chanID, 0, 0, nil, chanType,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("can't generate channel announcement: %v", err)
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-errors/errors"
|
||||
@ -22,6 +23,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
@ -1503,8 +1505,8 @@ func (r *ChannelRouter) addZombieEdge(chanID uint64) error {
|
||||
// segwit v1 (taproot) channels.
|
||||
//
|
||||
// TODO(roasbeef: export and use elsewhere?
|
||||
func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
|
||||
chanFeatures []byte) ([]byte, error) {
|
||||
func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte, chanFeatures []byte,
|
||||
tapscriptRoot fn.Option[chainhash.Hash]) ([]byte, error) {
|
||||
|
||||
legacyFundingScript := func() ([]byte, error) {
|
||||
witnessScript, err := input.GenMultiSigScript(
|
||||
@ -1550,8 +1552,15 @@ func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var fundingOpts []input.FundingScriptOpt
|
||||
tapscriptRoot.WhenSome(func(root chainhash.Hash) {
|
||||
fundingOpts = append(
|
||||
fundingOpts, input.WithTapscriptRoot(root),
|
||||
)
|
||||
})
|
||||
|
||||
fundingScript, _, _, err := input.GenTaprootFundingScript(
|
||||
pubKey1, pubKey2, 0,
|
||||
pubKey1, pubKey2, 0, fundingOpts...,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1676,7 +1685,7 @@ func (r *ChannelRouter) processUpdate(msg interface{},
|
||||
// reality.
|
||||
fundingPkScript, err := makeFundingScript(
|
||||
msg.BitcoinKey1Bytes[:], msg.BitcoinKey2Bytes[:],
|
||||
msg.Features,
|
||||
msg.Features, msg.TapscriptRoot,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user