diff --git a/discovery/mock_test.go b/discovery/mock_test.go index 0040ab8b6..3d3ee8229 100644 --- a/discovery/mock_test.go +++ b/discovery/mock_test.go @@ -63,6 +63,12 @@ func (p *mockPeer) RemoteFeatures() *lnwire.FeatureVector { return nil } +func (p *mockPeer) AddPendingChannel(_ lnwire.ChannelID, + _ <-chan struct{}) error { + + return nil +} + // mockMessageStore is an in-memory implementation of the MessageStore interface // used for the gossiper's unit tests. type mockMessageStore struct { diff --git a/funding/manager.go b/funding/manager.go index f243a8037..554c3ab06 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -2172,7 +2172,16 @@ func (f *Manager) continueFundingAccept(resCtx *reservationWithCtx, log.Infof("Generated ChannelPoint(%v) for pending_id(%x)", outPoint, pendingChanID[:]) - var err error + // Before sending FundingCreated sent, we notify Brontide to keep track + // of this pending open channel. + err := resCtx.peer.AddPendingChannel(channelID, f.quit) + if err != nil { + pubKey := resCtx.peer.IdentityKey().SerializeCompressed() + log.Errorf("Unable to add pending channel %v with peer %x: %v", + channelID, pubKey, err) + } + + // Send the FundingCreated msg. fundingCreated := &lnwire.FundingCreated{ PendingChannelID: pendingChanID, FundingPoint: *outPoint, @@ -2294,6 +2303,14 @@ func (f *Manager) handleFundingCreated(peer lnpeer.Peer, return } + // Before sending FundingSigned, we notify Brontide first to keep track + // of this pending open channel. + if err := peer.AddPendingChannel(channelID, f.quit); err != nil { + pubKey := peer.IdentityKey().SerializeCompressed() + log.Errorf("Unable to add pending channel %v with peer %x: %v", + channelID, pubKey, err) + } + fundingSigned := &lnwire.FundingSigned{ ChanID: channelID, CommitSig: ourCommitSig, diff --git a/funding/manager_test.go b/funding/manager_test.go index 1ca66904b..0360bd4b5 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -321,6 +321,12 @@ func (n *testNode) AddNewChannel(channel *channeldb.OpenChannel, } } +func (n *testNode) AddPendingChannel(_ lnwire.ChannelID, + quit <-chan struct{}) error { + + return nil +} + func createTestWallet(cdb *channeldb.ChannelStateDB, netParams *chaincfg.Params, notifier chainntnfs.ChainNotifier, wc lnwallet.WalletController, signer input.Signer, keyRing keychain.SecretKeyRing, diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 6817ff930..e691ecec1 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1888,6 +1888,12 @@ func (m *mockPeer) RemoteFeatures() *lnwire.FeatureVector { return nil } +func (m *mockPeer) AddPendingChannel(_ lnwire.ChannelID, + _ <-chan struct{}) error { + + return nil +} + func newSingleLinkTestHarness(t *testing.T, chanAmt, chanReserve btcutil.Amount) ( ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error, func() (*lnwallet.LightningChannel, error), error) { diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index bb36eda20..e339d8d52 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -672,6 +672,12 @@ func (s *mockServer) AddNewChannel(channel *channeldb.OpenChannel, return nil } +func (s *mockServer) AddPendingChannel(_ lnwire.ChannelID, + cancel <-chan struct{}) error { + + return nil +} + func (s *mockServer) WipeChannel(*wire.OutPoint) {} func (s *mockServer) LocalFeatures() *lnwire.FeatureVector { diff --git a/lnpeer/peer.go b/lnpeer/peer.go index 465a41cb9..c9217ce82 100644 --- a/lnpeer/peer.go +++ b/lnpeer/peer.go @@ -27,6 +27,10 @@ type Peer interface { // to be added if the cancel channel is closed. AddNewChannel(channel *channeldb.OpenChannel, cancel <-chan struct{}) error + // AddPendingChannel adds a pending open channel ID to the peer. The + // channel should fail to be added if the cancel chan is closed. + AddPendingChannel(cid lnwire.ChannelID, cancel <-chan struct{}) error + // WipeChannel removes the channel uniquely identified by its channel // point from all indexes associated with the peer. WipeChannel(*wire.OutPoint)