Skip to content

Commit

Permalink
multi: add AddPendingChannel to peer interface
Browse files Browse the repository at this point in the history
The funding manager has been updated to use `AddPendingChannel`. Note
that we track the pending channel before it's confirmed as the peer may
have a block height in the future(from our view), thus they may start
operating in this channel before we consider it as fully open.

The mocked peers have been updated to implement the new interface method.
  • Loading branch information
yyforyongyu committed Aug 8, 2023
1 parent f39c568 commit e46bd8e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions discovery/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion funding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions funding/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions htlcswitch/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions htlcswitch/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions lnpeer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e46bd8e

Please sign in to comment.