fundingmanager: populate additional edge info after adding to graph

This commit serves as another stop-gap for light clients since they are
unable to obtain the capacity and channel point of graph edges. Since
they're aware of these things for their own channels, they can populate
the information within the graph themselves once each channel has been
successfully added to the graph.
This commit is contained in:
Wilmer Paulino 2019-04-17 13:26:11 -07:00
parent aed0c2a90e
commit 760f38736e
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
3 changed files with 30 additions and 16 deletions

@ -17,6 +17,7 @@ import (
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
@ -253,10 +254,13 @@ type fundingConfig struct {
// announcement from the backing Lightning Network node.
CurrentNodeAnnouncement func() (lnwire.NodeAnnouncement, error)
// SendAnnouncement is used by the FundingManager to send
// announcement messages to the Gossiper to possibly broadcast
// to the greater network.
SendAnnouncement func(msg lnwire.Message) chan error
// SendAnnouncement is used by the FundingManager to send announcement
// messages to the Gossiper to possibly broadcast to the greater
// network. A set of optional message fields can be provided to populate
// any information within the graph that is not included in the gossip
// message.
SendAnnouncement func(msg lnwire.Message,
optionalFields ...discovery.OptionalMsgField) chan error
// NotifyWhenOnline allows the FundingManager to register with a
// subsystem that will notify it when the peer comes online. This is
@ -2140,7 +2144,10 @@ func (f *fundingManager) addToRouterGraph(completeChan *channeldb.OpenChannel,
// Send ChannelAnnouncement and ChannelUpdate to the gossiper to add
// to the Router's topology.
errChan := f.cfg.SendAnnouncement(ann.chanAnn)
errChan := f.cfg.SendAnnouncement(
ann.chanAnn, discovery.ChannelCapacity(completeChan.Capacity),
discovery.ChannelPoint(completeChan.FundingOutpoint),
)
select {
case err := <-errChan:
if err != nil {

@ -23,6 +23,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
@ -288,7 +289,9 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
SignMessage: func(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error) {
return testSig, nil
},
SendAnnouncement: func(msg lnwire.Message) chan error {
SendAnnouncement: func(msg lnwire.Message,
_ ...discovery.OptionalMsgField) chan error {
errChan := make(chan error, 1)
select {
case sentAnnouncements <- msg:
@ -413,7 +416,9 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
msg []byte) (*btcec.Signature, error) {
return testSig, nil
},
SendAnnouncement: func(msg lnwire.Message) chan error {
SendAnnouncement: func(msg lnwire.Message,
_ ...discovery.OptionalMsgField) chan error {
errChan := make(chan error, 1)
select {
case aliceAnnounceChan <- msg:
@ -1168,13 +1173,13 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
recreateAliceFundingManager(t, alice)
// Intentionally make the channel announcements fail
alice.fundingMgr.cfg.SendAnnouncement =
func(msg lnwire.Message) chan error {
errChan := make(chan error, 1)
errChan <- fmt.Errorf("intentional error in " +
"SendAnnouncement")
return errChan
}
alice.fundingMgr.cfg.SendAnnouncement = func(msg lnwire.Message,
_ ...discovery.OptionalMsgField) chan error {
errChan := make(chan error, 1)
errChan <- fmt.Errorf("intentional error in SendAnnouncement")
return errChan
}
fundingLockedAlice := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked",

@ -880,9 +880,11 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) {
return s.genNodeAnnouncement(true)
},
SendAnnouncement: func(msg lnwire.Message) chan error {
SendAnnouncement: func(msg lnwire.Message,
optionalFields ...discovery.OptionalMsgField) chan error {
return s.authGossiper.ProcessLocalAnnouncement(
msg, privKey.PubKey(),
msg, privKey.PubKey(), optionalFields...,
)
},
NotifyWhenOnline: s.NotifyWhenOnline,