mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
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:
parent
f39c568c94
commit
e46bd8e177
6 changed files with 46 additions and 1 deletions
|
@ -63,6 +63,12 @@ func (p *mockPeer) RemoteFeatures() *lnwire.FeatureVector {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *mockPeer) AddPendingChannel(_ lnwire.ChannelID,
|
||||||
|
_ <-chan struct{}) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// mockMessageStore is an in-memory implementation of the MessageStore interface
|
// mockMessageStore is an in-memory implementation of the MessageStore interface
|
||||||
// used for the gossiper's unit tests.
|
// used for the gossiper's unit tests.
|
||||||
type mockMessageStore struct {
|
type mockMessageStore struct {
|
||||||
|
|
|
@ -2172,7 +2172,16 @@ func (f *Manager) continueFundingAccept(resCtx *reservationWithCtx,
|
||||||
log.Infof("Generated ChannelPoint(%v) for pending_id(%x)", outPoint,
|
log.Infof("Generated ChannelPoint(%v) for pending_id(%x)", outPoint,
|
||||||
pendingChanID[:])
|
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{
|
fundingCreated := &lnwire.FundingCreated{
|
||||||
PendingChannelID: pendingChanID,
|
PendingChannelID: pendingChanID,
|
||||||
FundingPoint: *outPoint,
|
FundingPoint: *outPoint,
|
||||||
|
@ -2294,6 +2303,14 @@ func (f *Manager) handleFundingCreated(peer lnpeer.Peer,
|
||||||
return
|
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{
|
fundingSigned := &lnwire.FundingSigned{
|
||||||
ChanID: channelID,
|
ChanID: channelID,
|
||||||
CommitSig: ourCommitSig,
|
CommitSig: ourCommitSig,
|
||||||
|
|
|
@ -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,
|
func createTestWallet(cdb *channeldb.ChannelStateDB, netParams *chaincfg.Params,
|
||||||
notifier chainntnfs.ChainNotifier, wc lnwallet.WalletController,
|
notifier chainntnfs.ChainNotifier, wc lnwallet.WalletController,
|
||||||
signer input.Signer, keyRing keychain.SecretKeyRing,
|
signer input.Signer, keyRing keychain.SecretKeyRing,
|
||||||
|
|
|
@ -1888,6 +1888,12 @@ func (m *mockPeer) RemoteFeatures() *lnwire.FeatureVector {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockPeer) AddPendingChannel(_ lnwire.ChannelID,
|
||||||
|
_ <-chan struct{}) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func newSingleLinkTestHarness(t *testing.T, chanAmt, chanReserve btcutil.Amount) (
|
func newSingleLinkTestHarness(t *testing.T, chanAmt, chanReserve btcutil.Amount) (
|
||||||
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
||||||
func() (*lnwallet.LightningChannel, error), error) {
|
func() (*lnwallet.LightningChannel, error), error) {
|
||||||
|
|
|
@ -672,6 +672,12 @@ func (s *mockServer) AddNewChannel(channel *channeldb.OpenChannel,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *mockServer) AddPendingChannel(_ lnwire.ChannelID,
|
||||||
|
cancel <-chan struct{}) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *mockServer) WipeChannel(*wire.OutPoint) {}
|
func (s *mockServer) WipeChannel(*wire.OutPoint) {}
|
||||||
|
|
||||||
func (s *mockServer) LocalFeatures() *lnwire.FeatureVector {
|
func (s *mockServer) LocalFeatures() *lnwire.FeatureVector {
|
||||||
|
|
|
@ -27,6 +27,10 @@ type Peer interface {
|
||||||
// to be added if the cancel channel is closed.
|
// to be added if the cancel channel is closed.
|
||||||
AddNewChannel(channel *channeldb.OpenChannel, cancel <-chan struct{}) error
|
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
|
// WipeChannel removes the channel uniquely identified by its channel
|
||||||
// point from all indexes associated with the peer.
|
// point from all indexes associated with the peer.
|
||||||
WipeChannel(*wire.OutPoint)
|
WipeChannel(*wire.OutPoint)
|
||||||
|
|
Loading…
Add table
Reference in a new issue