mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 22:50:58 +02:00
autopilot+pilot: refactor connection logic out of OpenChannel
In this commit, we refactor the existing connection logic outside of the ChanController's OpenChannel method. We do this as previously it was possible for peers to stall us while attempting to connect to them. In order to remedy this, we now attempt to connect the peer before tracking them in our set of pending opens.
This commit is contained in:
@@ -77,7 +77,6 @@ var _ AttachmentHeuristic = (*mockHeuristic)(nil)
|
||||
type openChanIntent struct {
|
||||
target *btcec.PublicKey
|
||||
amt btcutil.Amount
|
||||
addrs []net.Addr
|
||||
private bool
|
||||
}
|
||||
|
||||
@@ -86,13 +85,12 @@ type mockChanController struct {
|
||||
private bool
|
||||
}
|
||||
|
||||
func (m *mockChanController) OpenChannel(target *btcec.PublicKey, amt btcutil.Amount,
|
||||
addrs []net.Addr) error {
|
||||
func (m *mockChanController) OpenChannel(target *btcec.PublicKey,
|
||||
amt btcutil.Amount) error {
|
||||
|
||||
m.openChanSignals <- openChanIntent{
|
||||
target: target,
|
||||
amt: amt,
|
||||
addrs: addrs,
|
||||
private: m.private,
|
||||
}
|
||||
|
||||
@@ -142,6 +140,12 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return 0, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -230,8 +234,8 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
||||
type mockFailingChanController struct {
|
||||
}
|
||||
|
||||
func (m *mockFailingChanController) OpenChannel(target *btcec.PublicKey, amt btcutil.Amount,
|
||||
addrs []net.Addr) error {
|
||||
func (m *mockFailingChanController) OpenChannel(target *btcec.PublicKey,
|
||||
amt btcutil.Amount) error {
|
||||
return errors.New("failure")
|
||||
}
|
||||
|
||||
@@ -276,6 +280,12 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return 0, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -366,6 +376,12 @@ func TestAgentChannelCloseSignal(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return 0, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -490,6 +506,12 @@ func TestAgentBalanceUpdate(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return walletBalance, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -606,6 +628,12 @@ func TestAgentImmediateAttach(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return walletBalance, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -698,10 +726,6 @@ func TestAgentImmediateAttach(t *testing.T) {
|
||||
self.SerializeCompressed(),
|
||||
openChan.target.SerializeCompressed())
|
||||
}
|
||||
if len(openChan.addrs) != 1 {
|
||||
t.Fatalf("should have single addr, instead have: %v",
|
||||
len(openChan.addrs))
|
||||
}
|
||||
case <-time.After(time.Second * 10):
|
||||
t.Fatalf("channel not opened in time")
|
||||
}
|
||||
@@ -743,6 +767,12 @@ func TestAgentPrivateChannels(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return walletBalance, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -869,6 +899,12 @@ func TestAgentPendingChannelState(t *testing.T) {
|
||||
WalletBalance: func() (btcutil.Amount, error) {
|
||||
return walletBalance, nil
|
||||
},
|
||||
ConnectToPeer: func(*btcec.PublicKey, []net.Addr) (bool, error) {
|
||||
return false, nil
|
||||
},
|
||||
DisconnectPeer: func(*btcec.PublicKey) error {
|
||||
return nil
|
||||
},
|
||||
Graph: memGraph,
|
||||
MaxPendingOpens: 10,
|
||||
}
|
||||
@@ -949,10 +985,6 @@ func TestAgentPendingChannelState(t *testing.T) {
|
||||
nodeKey.SerializeCompressed(),
|
||||
openChan.target.SerializeCompressed())
|
||||
}
|
||||
if len(openChan.addrs) != 1 {
|
||||
t.Fatalf("should have single addr, instead have: %v",
|
||||
len(openChan.addrs))
|
||||
}
|
||||
case <-time.After(time.Second * 10):
|
||||
t.Fatalf("channel wasn't opened in time")
|
||||
}
|
||||
|
Reference in New Issue
Block a user