From 760f38736e2ef2d4492cf10525ad246a3c374e57 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 17 Apr 2019 13:26:11 -0700 Subject: [PATCH] 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. --- fundingmanager.go | 17 ++++++++++++----- fundingmanager_test.go | 23 ++++++++++++++--------- server.go | 6 ++++-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 49b560a5..6a7e642c 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -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 { diff --git a/fundingmanager_test.go b/fundingmanager_test.go index debd16eb..08e0b557 100644 --- a/fundingmanager_test.go +++ b/fundingmanager_test.go @@ -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", diff --git a/server.go b/server.go index 77713711..50b8fd9e 100644 --- a/server.go +++ b/server.go @@ -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,