mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 17:14:22 +01:00
Explicit error message when disconnect fails
Whether the peer is not connected or not gossiping.
This commit is contained in:
committed by
Christian Decker
parent
9a2950628d
commit
30b290cb8f
@@ -1029,8 +1029,8 @@ static struct io_plan *disconnect_peer(struct io_conn *conn, struct daemon *daem
|
||||
} else {
|
||||
status_trace("disconnect_peer: peer %s %s",
|
||||
type_to_string(trc, struct pubkey, &id),
|
||||
!peer ? "not found" : "not local to this daemon");
|
||||
msg = towire_gossipctl_peer_disconnect_replyfail(msg);
|
||||
!peer ? "not connected" : "not gossiping");
|
||||
msg = towire_gossipctl_peer_disconnect_replyfail(msg, peer ? true : false);
|
||||
daemon_conn_send(&daemon->master, take(msg));
|
||||
}
|
||||
return daemon_conn_read_next(conn, &daemon->master);
|
||||
|
||||
@@ -222,3 +222,4 @@ gossipctl_peer_disconnect_reply,3123
|
||||
|
||||
# Gossipd -> master: reply to gossip_peer_disconnect if we couldn't find the peer.
|
||||
gossipctl_peer_disconnect_replyfail,3223
|
||||
gossipctl_peer_disconnect_replyfail,,isconnected,bool
|
||||
|
||||
|
@@ -880,11 +880,16 @@ static void gossip_peer_disconnected (struct subd *gossip,
|
||||
const u8 *resp,
|
||||
const int *fds,
|
||||
struct command *cmd) {
|
||||
bool isconnected;
|
||||
|
||||
if (!fromwire_gossipctl_peer_disconnect_reply(resp)) {
|
||||
if (!fromwire_gossipctl_peer_disconnect_replyfail(resp))
|
||||
if (!fromwire_gossipctl_peer_disconnect_replyfail(resp, &isconnected))
|
||||
fatal("Gossip daemon gave invalid reply %s",
|
||||
tal_hex(gossip, resp));
|
||||
command_fail(cmd, "Peer not connected");
|
||||
if (isconnected)
|
||||
command_fail(cmd, "Peer is not in gossip mode");
|
||||
else
|
||||
command_fail(cmd, "Peer not connected");
|
||||
} else {
|
||||
/* Successfully disconnected */
|
||||
command_success(cmd, null_response(cmd));
|
||||
|
||||
@@ -3821,15 +3821,18 @@ class LightningDTests(BaseLightningDTests):
|
||||
assert l2.rpc.getpeer(l1.info['id']) is None
|
||||
|
||||
# Make sure you cannot disconnect after disconnecting
|
||||
self.assertRaises(ValueError, l1.rpc.disconnect, l2.info['id'])
|
||||
self.assertRaises(ValueError, l2.rpc.disconnect, l1.info['id'])
|
||||
self.assertRaisesRegex(ValueError, "Peer not connected",
|
||||
l1.rpc.disconnect, l2.info['id'])
|
||||
self.assertRaisesRegex(ValueError, "Peer not connected",
|
||||
l2.rpc.disconnect, l1.info['id'])
|
||||
|
||||
# Fund channel l1 -> l3
|
||||
self.fund_channel(l1, l3, 10**6)
|
||||
bitcoind.generate_block(5)
|
||||
|
||||
# disconnecting a non gossiping peer results in error
|
||||
self.assertRaises(ValueError, l1.rpc.disconnect, l3.info['id'])
|
||||
self.assertRaisesRegex(ValueError, "Peer is not in gossip mode",
|
||||
l1.rpc.disconnect, l3.info['id'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -383,7 +383,7 @@ u8 *towire_gossipctl_peer_disconnect(const tal_t *ctx UNNEEDED, const struct pub
|
||||
bool fromwire_gossipctl_peer_disconnect_reply(const void *p UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_gossipctl_peer_disconnect_reply called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_gossipctl_peer_disconnect_replyfail*/
|
||||
bool fromwire_gossipctl_peer_disconnect_replyfail(const void *p UNNEEDED)
|
||||
bool fromwire_gossipctl_peer_disconnect_replyfail(const void *p UNNEEDED, bool *isconnected UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_gossipctl_peer_disconnect_replyfail called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user