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. 36
      daemon/peer.c
  2. 4
      daemon/peer.h
  3. 5
      state.c

36
daemon/peer.c

@ -91,23 +91,15 @@ static bool peer_uncommitted_changes(const struct peer *peer)
!= 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");
if (peer->commit_jsoncmd)
command_success(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);
log_debug(peer->log, "peer_update_complete");
if (peer->commit_jsoncmd) {
command_success(peer->commit_jsoncmd,
null_response(peer->commit_jsoncmd));
peer->commit_jsoncmd = NULL;
}
/* Simply unset it: it will free itself. */
peer->commit_jsoncmd = NULL;
/* Have we got more changes in the meantime? */
if (peer_uncommitted_changes(peer)) {
log_debug(peer->log, "peer_update_complete: more changes!");
@ -133,6 +125,11 @@ static void set_peer_state(struct peer *peer, enum state newstate,
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 (peer->closing.their_sig) {
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);
if (!err) {
set_peer_state(peer, STATE_CLEARING, __func__);
peer_update_complete(peer, NULL);
} else
peer_update_complete(peer, "bad revocation");
peer_update_complete(peer);
}
}
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) {
err = accept_pkt_revocation(peer, pkt);
if (!err) {
peer_update_complete(peer, NULL);
peer_update_complete(peer);
set_peer_state(peer, STATE_NORMAL, __func__);
}
break;
}
/* Fall thru. */
default:
if (peer->state == STATE_NORMAL_COMMITTING)
peer_update_complete(peer, err->error->problem);
return peer_received_unexpected_pkt(conn, peer, pkt);
}
if (err) {
if (peer->state == STATE_NORMAL_COMMITTING)
peer_update_complete(peer, err->error->problem);
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,
const union htlc_staging *stage);
/* Peer has recieved revocation, or problem (if non-NULL). */
void peer_update_complete(struct peer *peer, const char *problem);
/* Peer has recieved revocation. */
void peer_update_complete(struct peer *peer);
/* Peer has completed open, or problem (if non-NULL). */
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);
goto err_breakdown;
err_breakdown_maybe_committing:
if (peer->state == STATE_NORMAL_COMMITTING)
peer_update_complete(peer, "bad packet");
err_breakdown:
queue_pkt_err(peer, err);
breakdown:
@ -268,7 +265,7 @@ breakdown:
accept_clearing:
err = accept_pkt_close_clearing(peer, pkt);
if (err)
goto err_breakdown_maybe_committing;
goto err_breakdown;
/* If we've sent commit, we're still waiting for it when clearing. */
if (peer->state == STATE_NORMAL_COMMITTING)

Loading…
Cancel
Save