multi: add unsafedisconnect as a dev config

This commit adds a new dev config `unsafedisconnect` as we sometimes
want to disconnect nodes in our itests.
This commit is contained in:
yyforyongyu committed 2024-02-01 21:21:18 +08:00
1 parent 9adec89fa8
commit 1057eb729d
4 files changed
+37 -6

No files matched your search

+17 -5
View File
@@ -1747,15 +1747,27 @@ func (r *rpcServer) DisconnectPeer(ctx context.Context,
// In order to avoid erroneously disconnecting from a peer that we have
// an active channel with, if we have any channels active with this
// peer, then we'll disallow disconnecting from them.
if len(nodeChannels) > 0 {
return nil, fmt.Errorf("cannot disconnect from peer(%x), "+
"all active channels with the peer need to be closed "+
"first", pubKeyBytes)
if len(nodeChannels) != 0 {
// If we are not in a dev environment or the configed dev value
// `unsafedisconnect` is false, we return an error since there
// are active channels.
if !r.cfg.Dev.GetUnsafeDisconnect() {
return nil, fmt.Errorf("cannot disconnect from "+
"peer(%x), still has %d active channels",
pubKeyBytes, len(nodeChannels))
}
// We are in a dev environment, print a warning log and
// disconnect.
rpcsLog.Warnf("UnsafeDisconnect mode, disconnecting from "+
"peer(%x) while there are %d active channels",
pubKeyBytes, len(nodeChannels))
}
// With all initial validation complete, we'll now request that the
// server disconnects from the peer.
if err := r.server.DisconnectPeer(peerPubKey); err != nil {
err = r.server.DisconnectPeer(peerPubKey)
if err != nil {
return nil, fmt.Errorf("unable to disconnect peer: %v", err)
}