daemon: don't restart newhtlc/failhtlc/fulfill htlc commands on reconnect,

These low level commands we restarted on reconnect for ease of
testing.  Don't do that, and check that we're connected when those
commands occur.

This introduces subtle issues with --manual-commit --reconnect: restarting
node1 also forgets uncommitted things from node2, requiring reordering for
some tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-08-30 20:11:57 +09:30
parent 92187ae5e7
commit d964ad2d94
2 changed files with 78 additions and 75 deletions

View File

@@ -1837,42 +1837,6 @@ static void retransmit_updates(struct peer *peer)
assert(!peer->feechanges[SENT_FEECHANGE]);
}
/* FIXME: Maybe it would be neater to remember all pay commands, and simply
* re-run them after reconnect if they didn't get committed. */
static void resend_local_requests(struct peer *peer)
{
struct htlc_map_iter it;
struct htlc *h;
for (h = htlc_map_first(&peer->htlcs, &it);
h;
h = htlc_map_next(&peer->htlcs, &it)) {
switch (h->state) {
case SENT_ADD_HTLC:
/* We removed everything which was routed. */
assert(!h->src);
log_debug(peer->log, "Re-sending local add HTLC %"PRIu64,
h->id);
queue_pkt_htlc_add(peer, h);
remote_changes_pending(peer);
break;
case SENT_REMOVE_HTLC:
/* We removed everything which was routed. */
assert(!h->src);
log_debug(peer->log, "Re-sending local %s HTLC %"PRIu64,
h->r ? "fulfill" : "fail", h->id);
if (h->r)
queue_pkt_htlc_fulfill(peer, h);
else
queue_pkt_htlc_fail(peer, h);
remote_changes_pending(peer);
break;
default:
break;
}
}
}
/* BOLT #2:
*
* On disconnection, a node MUST reverse any uncommitted changes sent by the
@@ -1926,13 +1890,6 @@ again:
h = htlc_map_next(&peer->htlcs, &it)) {
switch (h->state) {
case SENT_ADD_HTLC:
/* FIXME: re-submit these after connect, instead? */
/* Keep local adds. */
if (!h->src) {
if (!cstate_add_htlc(peer->remote.staging_cstate, h))
fatal("Could not add HTLC?");
break;
}
/* Adjust counter to lowest HTLC removed */
if (peer->htlc_id_counter > h->id) {
log_debug(peer->log,
@@ -1955,17 +1912,6 @@ again:
SENT_ADD_ACK_REVOCATION);
break;
case SENT_REMOVE_HTLC:
/* Keep local removes. */
/* FIXME: re-submit these after connect, instead? */
if (!h->src) {
if (h->r) {
cstate_fulfill_htlc(peer->remote.staging_cstate,
h);
} else {
cstate_fail_htlc(peer->remote.staging_cstate, h);
}
break;
}
log_debug(peer->log, "Undoing %s %"PRIu64,
htlc_state_name(h->state), h->id);
htlc_undostate(h, SENT_REMOVE_HTLC,
@@ -2061,8 +2007,6 @@ static void retransmit_pkts(struct peer *peer, s64 ack)
ack++;
}
resend_local_requests(peer);
/* We might need to re-propose HTLCs which were from other peers. */
retry_all_routing(peer);
}
@@ -4197,7 +4141,7 @@ static void json_getpeers(struct command *cmd,
json_add_pubkey(response, cmd->dstate->secpctx,
"peerid", p->id);
json_add_bool(response, "connected", p->conn && !p->fake_close);
json_add_bool(response, "connected", p->connected);
/* FIXME: Report anchor. */
@@ -4352,6 +4296,11 @@ static void json_newhtlc(struct command *cmd,
return;
}
if (!peer->connected) {
command_fail(cmd, "peer not connected");
return;
}
if (!json_tok_u64(buffer, msatoshistok, &msatoshis)) {
command_fail(cmd, "'%.*s' is not a valid number",
(int)(msatoshistok->end - msatoshistok->start),
@@ -4427,6 +4376,11 @@ static void json_fulfillhtlc(struct command *cmd,
return;
}
if (!peer->connected) {
command_fail(cmd, "peer not connected");
return;
}
if (!json_tok_u64(buffer, idtok, &id)) {
command_fail(cmd, "'%.*s' is not a valid id",
(int)(idtok->end - idtok->start),
@@ -4508,6 +4462,11 @@ static void json_failhtlc(struct command *cmd,
return;
}
if (!peer->connected) {
command_fail(cmd, "peer not connected");
return;
}
if (!json_tok_u64(buffer, idtok, &id)) {
command_fail(cmd, "'%.*s' is not a valid id",
(int)(idtok->end - idtok->start),
@@ -4566,6 +4525,11 @@ static void json_commit(struct command *cmd,
return;
}
if (!peer->connected) {
command_fail(cmd, "peer not connected");
return;
}
if (!state_can_commit(peer->state)) {
command_fail(cmd, "peer in state %s", state_name(peer->state));
return;
@@ -4677,6 +4641,7 @@ static void json_disconnect(struct command *cmd,
* one side to freak out. We just ensure we ignore it. */
log_debug(peer->log, "Pretending connection is closed");
peer->fake_close = true;
peer->connected = false;
set_peer_state(peer, STATE_ERR_BREAKDOWN, "json_disconnect", false);
peer_breakdown(peer);