Browse Source

lightnind: _ dev-disconnect argument to suppress commit timer.

Required for catching daemon in exact state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
ce160d9b17
  1. 8
      channeld/channel.c
  2. 3
      common/crypto_sync.c
  3. 3
      common/cryptomsg.c
  4. 7
      common/dev_disconnect.c
  5. 24
      common/dev_disconnect.h
  6. 2
      lightningd/peer_control.c
  7. 2
      lightningd/test/run-cryptomsg.c

8
channeld/channel.c

@ -20,6 +20,7 @@
#include <common/daemon_conn.h> #include <common/daemon_conn.h>
#include <common/debug.h> #include <common/debug.h>
#include <common/derive_basepoints.h> #include <common/derive_basepoints.h>
#include <common/dev_disconnect.h>
#include <common/htlc_tx.h> #include <common/htlc_tx.h>
#include <common/key_derive.h> #include <common/key_derive.h>
#include <common/msg_queue.h> #include <common/msg_queue.h>
@ -618,6 +619,13 @@ static void send_commit(struct peer *peer)
u8 *msg; u8 *msg;
const struct htlc **changed_htlcs; const struct htlc **changed_htlcs;
/* Hack to suppress all commit sends if dev_disconnect says to */
if (dev_suppress_commit) {
peer->commit_timer = NULL;
tal_free(tmpctx);
return;
}
/* FIXME: Document this requirement in BOLT 2! */ /* FIXME: Document this requirement in BOLT 2! */
/* We can't send two commits in a row. */ /* We can't send two commits in a row. */
if (channel_awaiting_revoke_and_ack(peer->channel)) { if (channel_awaiting_revoke_and_ack(peer->channel)) {

3
common/crypto_sync.c

@ -28,7 +28,8 @@ bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
case DEV_DISCONNECT_BLACKHOLE: case DEV_DISCONNECT_BLACKHOLE:
dev_blackhole_fd(fd); dev_blackhole_fd(fd);
break; break;
default: case DEV_DISCONNECT_SUPPRESS_COMMIT:
case DEV_DISCONNECT_NORMAL:
break; break;
} }
ret = write_all(fd, enc, tal_len(enc)); ret = write_all(fd, enc, tal_len(enc));

3
common/cryptomsg.c

@ -355,7 +355,8 @@ struct io_plan *peer_write_message(struct io_conn *conn,
case DEV_DISCONNECT_BLACKHOLE: case DEV_DISCONNECT_BLACKHOLE:
dev_blackhole_fd(io_conn_fd(conn)); dev_blackhole_fd(io_conn_fd(conn));
break; break;
default: case DEV_DISCONNECT_SUPPRESS_COMMIT:
case DEV_DISCONNECT_NORMAL:
break; break;
} }

7
common/dev_disconnect.c

@ -16,6 +16,8 @@ static int dev_disconnect_fd = -1;
static char dev_disconnect_line[200]; static char dev_disconnect_line[200];
static int dev_disconnect_count, dev_disconnect_len; static int dev_disconnect_count, dev_disconnect_len;
bool dev_suppress_commit;
void dev_disconnect_init(int fd) void dev_disconnect_init(int fd)
{ {
int r; int r;
@ -44,7 +46,7 @@ void dev_disconnect_init(int fd)
dev_disconnect_fd = fd; dev_disconnect_fd = fd;
} }
char dev_disconnect(int pkt_type) enum dev_disconnect dev_disconnect(int pkt_type)
{ {
if (!streq(wire_type_name(pkt_type), dev_disconnect_line+1)) if (!streq(wire_type_name(pkt_type), dev_disconnect_line+1))
return DEV_DISCONNECT_NORMAL; return DEV_DISCONNECT_NORMAL;
@ -58,6 +60,9 @@ char dev_disconnect(int pkt_type)
lseek(dev_disconnect_fd, dev_disconnect_len+1, SEEK_CUR); lseek(dev_disconnect_fd, dev_disconnect_len+1, SEEK_CUR);
status_trace("dev_disconnect: %s", dev_disconnect_line); status_trace("dev_disconnect: %s", dev_disconnect_line);
if (dev_disconnect_line[0] == DEV_DISCONNECT_SUPPRESS_COMMIT)
dev_suppress_commit = true;
return dev_disconnect_line[0]; return dev_disconnect_line[0];
} }

24
common/dev_disconnect.h

@ -3,14 +3,23 @@
#include "config.h" #include "config.h"
#include <stdbool.h> #include <stdbool.h>
#define DEV_DISCONNECT_BEFORE '-' enum dev_disconnect {
#define DEV_DISCONNECT_AFTER '+' /* Do nothing. */
#define DEV_DISCONNECT_DROPPKT '@' DEV_DISCONNECT_NORMAL = 0,
#define DEV_DISCONNECT_BLACKHOLE '0' /* Close connection before sending packet (and fail write). */
#define DEV_DISCONNECT_NORMAL 0 DEV_DISCONNECT_BEFORE = '-',
/* Close connection after sending packet. */
DEV_DISCONNECT_AFTER = '+',
/* Close connection after dropping packet. */
DEV_DISCONNECT_DROPPKT = '@',
/* Swallow all writes from now on, and do no more reads. */
DEV_DISCONNECT_BLACKHOLE = '0',
/* Disable commit timer after sending this. */
DEV_DISCONNECT_SUPPRESS_COMMIT = '_'
};
/* Force a close fd before or after a certain packet type */ /* Force a close fd before or after a certain packet type */
char dev_disconnect(int pkt_type); enum dev_disconnect dev_disconnect(int pkt_type);
/* Make next write on fd fail as if they'd disconnected. */ /* Make next write on fd fail as if they'd disconnected. */
void dev_sabotage_fd(int fd); void dev_sabotage_fd(int fd);
@ -21,4 +30,7 @@ void dev_blackhole_fd(int fd);
/* For debug code to set in daemon. */ /* For debug code to set in daemon. */
void dev_disconnect_init(int fd); void dev_disconnect_init(int fd);
/* Hack for channeld to do DEV_DISCONNECT_SUPPRESS_COMMIT. */
extern bool dev_suppress_commit;
#endif /* LIGHTNING_COMMON_DEV_DISCONNECT_H */ #endif /* LIGHTNING_COMMON_DEV_DISCONNECT_H */

2
lightningd/peer_control.c

@ -253,7 +253,7 @@ static void peer_start_closingd(struct peer *peer,
bool reconnected); bool reconnected);
/* FIXME: Fake NOP dev_disconnect/dev_sabotage_fd for below. */ /* FIXME: Fake NOP dev_disconnect/dev_sabotage_fd for below. */
char dev_disconnect(int pkt_type) enum dev_disconnect dev_disconnect(int pkt_type)
{ {
return DEV_DISCONNECT_NORMAL; return DEV_DISCONNECT_NORMAL;
} }

2
lightningd/test/run-cryptomsg.c

@ -48,7 +48,7 @@ void dev_sabotage_fd(int fd UNNEEDED)
{ fprintf(stderr, "dev_sabotage_fd called!\n"); abort(); } { fprintf(stderr, "dev_sabotage_fd called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */
char dev_disconnect(int pkt_type) enum dev_disconnect dev_disconnect(int pkt_type)
{ {
return DEV_DISCONNECT_NORMAL; return DEV_DISCONNECT_NORMAL;
} }

Loading…
Cancel
Save