mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
lightnind: _ dev-disconnect argument to suppress commit timer.
Required for catching daemon in exact state. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
5957dd9303
commit
ce160d9b17
@ -20,6 +20,7 @@
|
||||
#include <common/daemon_conn.h>
|
||||
#include <common/debug.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/dev_disconnect.h>
|
||||
#include <common/htlc_tx.h>
|
||||
#include <common/key_derive.h>
|
||||
#include <common/msg_queue.h>
|
||||
@ -618,6 +619,13 @@ static void send_commit(struct peer *peer)
|
||||
u8 *msg;
|
||||
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! */
|
||||
/* We can't send two commits in a row. */
|
||||
if (channel_awaiting_revoke_and_ack(peer->channel)) {
|
||||
|
@ -28,7 +28,8 @@ bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
|
||||
case DEV_DISCONNECT_BLACKHOLE:
|
||||
dev_blackhole_fd(fd);
|
||||
break;
|
||||
default:
|
||||
case DEV_DISCONNECT_SUPPRESS_COMMIT:
|
||||
case DEV_DISCONNECT_NORMAL:
|
||||
break;
|
||||
}
|
||||
ret = write_all(fd, enc, tal_len(enc));
|
||||
|
@ -355,7 +355,8 @@ struct io_plan *peer_write_message(struct io_conn *conn,
|
||||
case DEV_DISCONNECT_BLACKHOLE:
|
||||
dev_blackhole_fd(io_conn_fd(conn));
|
||||
break;
|
||||
default:
|
||||
case DEV_DISCONNECT_SUPPRESS_COMMIT:
|
||||
case DEV_DISCONNECT_NORMAL:
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@ static int dev_disconnect_fd = -1;
|
||||
static char dev_disconnect_line[200];
|
||||
static int dev_disconnect_count, dev_disconnect_len;
|
||||
|
||||
bool dev_suppress_commit;
|
||||
|
||||
void dev_disconnect_init(int fd)
|
||||
{
|
||||
int r;
|
||||
@ -44,7 +46,7 @@ void dev_disconnect_init(int 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))
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
@ -58,6 +60,9 @@ char dev_disconnect(int pkt_type)
|
||||
lseek(dev_disconnect_fd, dev_disconnect_len+1, SEEK_CUR);
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
|
@ -3,14 +3,23 @@
|
||||
#include "config.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DEV_DISCONNECT_BEFORE '-'
|
||||
#define DEV_DISCONNECT_AFTER '+'
|
||||
#define DEV_DISCONNECT_DROPPKT '@'
|
||||
#define DEV_DISCONNECT_BLACKHOLE '0'
|
||||
#define DEV_DISCONNECT_NORMAL 0
|
||||
enum dev_disconnect {
|
||||
/* Do nothing. */
|
||||
DEV_DISCONNECT_NORMAL = 0,
|
||||
/* Close connection before sending packet (and fail write). */
|
||||
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 */
|
||||
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. */
|
||||
void dev_sabotage_fd(int fd);
|
||||
@ -21,4 +30,7 @@ void dev_blackhole_fd(int fd);
|
||||
/* For debug code to set in daemon. */
|
||||
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 */
|
||||
|
@ -253,7 +253,7 @@ static void peer_start_closingd(struct peer *peer,
|
||||
bool reconnected);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ void dev_sabotage_fd(int fd UNNEEDED)
|
||||
{ fprintf(stderr, "dev_sabotage_fd called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
char dev_disconnect(int pkt_type)
|
||||
enum dev_disconnect dev_disconnect(int pkt_type)
|
||||
{
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user