Browse Source

daemon: always terminate waiting manual update command on failure.

We missed some cases, resulting in hanging commands.  Just check whenever
we fail.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
b4f0d32b09
  1. 30
      daemon/peer.c
  2. 4
      daemon/peer.h
  3. 5
      state.c

30
daemon/peer.c

@ -91,22 +91,14 @@ static bool peer_uncommitted_changes(const struct peer *peer)
!= peer->remote.commit->cstate->changes; != peer->remote.commit->cstate->changes;
} }
void peer_update_complete(struct peer *peer, const char *problem) void peer_update_complete(struct peer *peer)
{ {
if (!problem) {
log_debug(peer->log, "peer_update_complete"); log_debug(peer->log, "peer_update_complete");
if (peer->commit_jsoncmd) if (peer->commit_jsoncmd) {
command_success(peer->commit_jsoncmd, command_success(peer->commit_jsoncmd,
null_response(peer->commit_jsoncmd)); null_response(peer->commit_jsoncmd));
} else {
log_unusual(peer->log, "peer_update_complete failed: %s",
problem);
if (peer->commit_jsoncmd)
command_fail(peer->commit_jsoncmd, "%s", problem);
}
/* Simply unset it: it will free itself. */
peer->commit_jsoncmd = NULL; peer->commit_jsoncmd = NULL;
}
/* Have we got more changes in the meantime? */ /* Have we got more changes in the meantime? */
if (peer_uncommitted_changes(peer)) { if (peer_uncommitted_changes(peer)) {
@ -133,6 +125,11 @@ static void set_peer_state(struct peer *peer, enum state newstate,
static void peer_breakdown(struct peer *peer) static void peer_breakdown(struct peer *peer)
{ {
if (peer->commit_jsoncmd) {
command_fail(peer->commit_jsoncmd, "peer breakdown");
peer->commit_jsoncmd = NULL;
}
/* If we have a closing tx, use it. */ /* If we have a closing tx, use it. */
if (peer->closing.their_sig) { if (peer->closing.their_sig) {
log_unusual(peer->log, "Peer breakdown: sending close tx"); log_unusual(peer->log, "Peer breakdown: sending close tx");
@ -342,9 +339,8 @@ static struct io_plan *clearing_pkt_in(struct io_conn *conn, struct peer *peer)
err = accept_pkt_revocation(peer, pkt); err = accept_pkt_revocation(peer, pkt);
if (!err) { if (!err) {
set_peer_state(peer, STATE_CLEARING, __func__); set_peer_state(peer, STATE_CLEARING, __func__);
peer_update_complete(peer, NULL); peer_update_complete(peer);
} else }
peer_update_complete(peer, "bad revocation");
} }
break; break;
@ -491,21 +487,17 @@ static struct io_plan *normal_pkt_in(struct io_conn *conn, struct peer *peer)
if (peer->state == STATE_NORMAL_COMMITTING) { if (peer->state == STATE_NORMAL_COMMITTING) {
err = accept_pkt_revocation(peer, pkt); err = accept_pkt_revocation(peer, pkt);
if (!err) { if (!err) {
peer_update_complete(peer, NULL); peer_update_complete(peer);
set_peer_state(peer, STATE_NORMAL, __func__); set_peer_state(peer, STATE_NORMAL, __func__);
} }
break; break;
} }
/* Fall thru. */ /* Fall thru. */
default: default:
if (peer->state == STATE_NORMAL_COMMITTING)
peer_update_complete(peer, err->error->problem);
return peer_received_unexpected_pkt(conn, peer, pkt); return peer_received_unexpected_pkt(conn, peer, pkt);
} }
if (err) { if (err) {
if (peer->state == STATE_NORMAL_COMMITTING)
peer_update_complete(peer, err->error->problem);
return peer_comms_err(conn, peer, err); return peer_comms_err(conn, peer, err);
} }

4
daemon/peer.h

@ -227,8 +227,8 @@ void remote_changes_pending(struct peer *peer);
void add_unacked(struct peer_visible_state *which, void add_unacked(struct peer_visible_state *which,
const union htlc_staging *stage); const union htlc_staging *stage);
/* Peer has recieved revocation, or problem (if non-NULL). */ /* Peer has recieved revocation. */
void peer_update_complete(struct peer *peer, const char *problem); void peer_update_complete(struct peer *peer);
/* Peer has completed open, or problem (if non-NULL). */ /* Peer has completed open, or problem (if non-NULL). */
void peer_open_complete(struct peer *peer, const char *problem); void peer_open_complete(struct peer *peer, const char *problem);

5
state.c

@ -257,9 +257,6 @@ unexpected_pkt:
err = pkt_err_unexpected(peer, pkt); err = pkt_err_unexpected(peer, pkt);
goto err_breakdown; goto err_breakdown;
err_breakdown_maybe_committing:
if (peer->state == STATE_NORMAL_COMMITTING)
peer_update_complete(peer, "bad packet");
err_breakdown: err_breakdown:
queue_pkt_err(peer, err); queue_pkt_err(peer, err);
breakdown: breakdown:
@ -268,7 +265,7 @@ breakdown:
accept_clearing: accept_clearing:
err = accept_pkt_close_clearing(peer, pkt); err = accept_pkt_close_clearing(peer, pkt);
if (err) if (err)
goto err_breakdown_maybe_committing; goto err_breakdown;
/* If we've sent commit, we're still waiting for it when clearing. */ /* If we've sent commit, we're still waiting for it when clearing. */
if (peer->state == STATE_NORMAL_COMMITTING) if (peer->state == STATE_NORMAL_COMMITTING)

Loading…
Cancel
Save