Merge pull request #6655 from Crypt-iQ/disconnectpeerfix
server.go: replace call to removePeer with Disconnect in DisconnectPeer
This commit is contained in:
3 files changed
+29
-6
No files matched your search
@@ -34,10 +34,14 @@
|
|||||||
* [Update the urfave/cli package](https://github.com/lightningnetwork/lnd/pull/6682) because
|
* [Update the urfave/cli package](https://github.com/lightningnetwork/lnd/pull/6682) because
|
||||||
of a flag parsing bug.
|
of a flag parsing bug.
|
||||||
|
|
||||||
|
* [DisconnectPeer no longer interferes with the peerTerminationWatcher. This previously caused
|
||||||
|
force closes.](https://github.com/lightningnetwork/lnd/pull/6655)
|
||||||
|
|
||||||
# Contributors (Alphabetical Order)
|
# Contributors (Alphabetical Order)
|
||||||
|
|
||||||
* Elle Mouton
|
* Elle Mouton
|
||||||
* ErikEk
|
* ErikEk
|
||||||
|
* Eugene Siegel
|
||||||
* Oliver Gugger
|
* Oliver Gugger
|
||||||
* Priyansh Rastogi
|
* Priyansh Rastogi
|
||||||
* Yong Yu
|
* Yong Yu
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// testSwitchCircuitPersistence creates a multihop network to ensure the sender
|
// testSwitchCircuitPersistence creates a multihop network to ensure the sender
|
||||||
@@ -451,13 +452,23 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("htlc mismatch: %v", predErr)
|
t.Fatalf("htlc mismatch: %v", predErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peerReq := &lnrpc.PeerEventSubscription{}
|
||||||
|
peerClient, err := dave.SubscribePeerEvents(ctxb, peerReq)
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
|
||||||
// First, disconnect Dave and Alice so that their link is broken.
|
// First, disconnect Dave and Alice so that their link is broken.
|
||||||
if err := net.DisconnectNodes(dave, net.Alice); err != nil {
|
if err := net.DisconnectNodes(dave, net.Alice); err != nil {
|
||||||
t.Fatalf("unable to disconnect alice from dave: %v", err)
|
t.Fatalf("unable to disconnect alice from dave: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait to receive the PEER_OFFLINE event before reconnecting them.
|
||||||
|
peerEvent, err := peerClient.Recv()
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
require.Equal(t.t, lnrpc.PeerEvent_PEER_OFFLINE, peerEvent.GetType())
|
||||||
|
|
||||||
// Then, reconnect them to ensure Dave doesn't just fail back the htlc.
|
// Then, reconnect them to ensure Dave doesn't just fail back the htlc.
|
||||||
net.ConnectNodes(t.t, dave, net.Alice)
|
// We use EnsureConnected here in case they have already re-connected.
|
||||||
|
net.EnsureConnected(t.t, dave, net.Alice)
|
||||||
|
|
||||||
// Wait to ensure that the payment remain are not failed back after
|
// Wait to ensure that the payment remain are not failed back after
|
||||||
// reconnecting. All node should report the number payments initiated
|
// reconnecting. All node should report the number payments initiated
|
||||||
@@ -476,6 +487,16 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to disconnect alice from dave: %v", err)
|
t.Fatalf("unable to disconnect alice from dave: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait to receive the PEER_ONLINE and then the PEER_OFFLINE event
|
||||||
|
// before advancing.
|
||||||
|
peerEvent2, err := peerClient.Recv()
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
require.Equal(t.t, lnrpc.PeerEvent_PEER_ONLINE, peerEvent2.GetType())
|
||||||
|
|
||||||
|
peerEvent3, err := peerClient.Recv()
|
||||||
|
require.NoError(t.t, err)
|
||||||
|
require.Equal(t.t, lnrpc.PeerEvent_PEER_OFFLINE, peerEvent3.GetType())
|
||||||
|
|
||||||
// Now restart carol without hodl mode, to settle back the outstanding
|
// Now restart carol without hodl mode, to settle back the outstanding
|
||||||
// payments.
|
// payments.
|
||||||
carol.SetExtraArgs(nil)
|
carol.SetExtraArgs(nil)
|
||||||
|
|||||||
@@ -4217,11 +4217,9 @@ func (s *server) DisconnectPeer(pubKey *btcec.PublicKey) error {
|
|||||||
delete(s.persistentPeers, pubStr)
|
delete(s.persistentPeers, pubStr)
|
||||||
delete(s.persistentPeersBackoff, pubStr)
|
delete(s.persistentPeersBackoff, pubStr)
|
||||||
|
|
||||||
// Remove the current peer from the server's internal state and signal
|
// Remove the peer by calling Disconnect. Previously this was done with
|
||||||
// that the peer termination watcher does not need to execute for this
|
// removePeer, which bypassed the peerTerminationWatcher.
|
||||||
// peer.
|
peer.Disconnect(fmt.Errorf("server: DisconnectPeer called"))
|
||||||
s.removePeer(peer)
|
|
||||||
s.ignorePeerTermination[peer] = struct{}{}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user