multi: add AddPendingChannel to peer interface

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.
This commit is contained in:
yyforyongyu 2023-03-16 21:25:17 +08:00
parent f39c568c94
commit e46bd8e177
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
6 changed files with 46 additions and 1 deletions

View file

@ -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 {

View file

@ -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,

View file

@ -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,

View file

@ -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) {

View file

@ -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 {

View file

@ -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)