discovery+lnwallet: add fetchPKScript helper to gossiper

This commit makes an lnwallet.BlockChainIO available to the gossiper and
uses it to construct a helper that can be used to fetch the pk script
for a given SCID. This will be used for channel announcement
verification in an upcoming commit.
This commit is contained in:
Elle Mouton 2024-09-02 12:10:13 +02:00
parent 9be84c1bdc
commit a6bf76a0b7
No known key found for this signature in database
GPG key ID: D7D916376026F177
3 changed files with 36 additions and 0 deletions

View file

@ -171,6 +171,10 @@ type Config struct {
// order to be included in the LN graph. // order to be included in the LN graph.
Graph graph.ChannelGraphSource Graph graph.ChannelGraphSource
// ChainIO represents an abstraction over a source that can query the
// blockchain.
ChainIO lnwallet.BlockChainIO
// ChanSeries is an interfaces that provides access to a time series // ChanSeries is an interfaces that provides access to a time series
// view of the current known channel graph. Each GossipSyncer enabled // view of the current known channel graph. Each GossipSyncer enabled
// peer will utilize this in order to create and respond to channel // peer will utilize this in order to create and respond to channel
@ -1930,6 +1934,13 @@ func (d *AuthenticatedGossiper) processRejectedEdge(
return announcements, nil return announcements, nil
} }
// fetchPKScript fetches the output script for the given SCID.
func (d *AuthenticatedGossiper) fetchPKScript(chanID *lnwire.ShortChannelID) (
[]byte, error) {
return lnwallet.FetchPKScriptWithQuit(d.cfg.ChainIO, chanID, d.quit)
}
// addNode processes the given node announcement, and adds it to our channel // addNode processes the given node announcement, and adds it to our channel
// graph. // graph.
func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement, func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement,

View file

@ -21,6 +21,7 @@ import (
"github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanvalidate"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -737,3 +738,26 @@ func FetchFundingTx(chain BlockChainIO,
return fundingBlock.Transactions[chanID.TxIndex].Copy(), nil return fundingBlock.Transactions[chanID.TxIndex].Copy(), nil
} }
// FetchPKScriptWithQuit fetches the output script for the given SCID and exits
// early with an error if the provided quit channel is closed before
// completion.
func FetchPKScriptWithQuit(chain BlockChainIO, chanID *lnwire.ShortChannelID,
quit chan struct{}) ([]byte, error) {
tx, err := FetchFundingTxWrapper(chain, chanID, quit)
if err != nil {
return nil, err
}
outputLocator := chanvalidate.ShortChanIDChanLocator{
ID: *chanID,
}
output, _, err := outputLocator.Locate(tx)
if err != nil {
return nil, err
}
return output.PkScript, nil
}

View file

@ -1042,6 +1042,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
s.authGossiper = discovery.New(discovery.Config{ s.authGossiper = discovery.New(discovery.Config{
Graph: s.graphBuilder, Graph: s.graphBuilder,
ChainIO: s.cc.ChainIO,
Notifier: s.cc.ChainNotifier, Notifier: s.cc.ChainNotifier,
ChainHash: *s.cfg.ActiveNetParams.GenesisHash, ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
Broadcast: s.BroadcastMessage, Broadcast: s.BroadcastMessage,