state: add peer_unwatch_close_timeout() call.

This tell us to disarm the INPUT_CLOSE_COMPLETE_TIMEOUT: either we hit
an error and are going to unilateral close, or we received their signature
successfully.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-01-22 06:41:47 +10:30
parent 144ab3bef4
commit 6a7a046f60
3 changed files with 43 additions and 7 deletions

View File

@ -613,6 +613,8 @@ enum command_status state(const tal_t *ctx,
case STATE_WAIT_FOR_CLOSE_COMPLETE:
if (input_is(input, PKT_CLOSE_COMPLETE)) {
peer_unwatch_close_timeout(peer,
INPUT_CLOSE_COMPLETE_TIMEOUT);
err = accept_pkt_close_complete(ctx, peer, idata->pkt);
if (err)
goto err_start_unilateral_close_already_closing;
@ -622,6 +624,8 @@ enum command_status state(const tal_t *ctx,
change_peer_cond(peer, PEER_CLOSING, PEER_CLOSED);
return next_state(peer, cstatus, STATE_CLOSE_WAIT_CLOSE);
} else if (input_is(input, PKT_CLOSE)) {
peer_unwatch_close_timeout(peer,
INPUT_CLOSE_COMPLETE_TIMEOUT);
/* We can use the sig just like CLOSE_COMPLETE */
err = accept_pkt_simultaneous_close(ctx, peer,
idata->pkt);
@ -633,6 +637,8 @@ enum command_status state(const tal_t *ctx,
set_peer_cond(peer, PEER_CLOSED);
return next_state(peer, cstatus, STATE_CLOSE_WAIT_CLOSE);
} else if (input_is(input, PKT_ERROR)) {
peer_unwatch_close_timeout(peer,
INPUT_CLOSE_COMPLETE_TIMEOUT);
peer_unexpected_pkt(peer, idata->pkt);
goto start_unilateral_close_already_closing;
} else if (input_is_pkt(input)) {
@ -643,6 +649,7 @@ enum command_status state(const tal_t *ctx,
err = pkt_err(ctx, "Close timed out");
goto err_start_unilateral_close_already_closing;
}
peer_unwatch_close_timeout(peer, INPUT_CLOSE_COMPLETE_TIMEOUT);
goto fail_during_close;
case STATE_WAIT_FOR_CLOSE_ACK:

28
state.h
View File

@ -237,17 +237,39 @@ void peer_watch_tx(struct peer *peer,
* peer_watch_close: watch for close tx until it's "irreversible" (or timedout)
* @peer: the state data for this peer.
* @done: the input to give when tx is completely buried.
* @timedout: the input to give if we time out.
* @timedout: the input to give if we time out (they don't provide sig).
*
* Once this fires we consider the channel completely closed and stop
* watching (eg 100 txs down).
*
* This is used for watching a mutual close, or for a transaction we sent
* (such as a steal, or spend of their close, etc).
* This is used for watching a mutual close.
*/
void peer_watch_close(struct peer *peer,
enum state_input done, enum state_input timedout);
/**
* peer_unwatch_close_timeout: remove timeout for the close transaction
* @peer: the state data for this peer.
* @timeout: the input to give if anchor doesn't reach depth in time.
*
* This is called once we have successfully received their signature.
*/
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout);
/**
* peer_watch_anchor: create a watch for the anchor transaction.
* @peer: the state data for this peer.
* @depthok: the input to give when anchor reaches expected depth.
* @timeout: the input to give if anchor doesn't reach depth in time.
* @unspent: the input to give if anchor is unspent after @depthok.
* @theyspent: the input to give if they spend anchor with their commit tx.
* @otherspent: the input to give if they spend anchor otherwise.
*
* @depthok can be INPUT_NONE if it's our anchor (we don't time
* ourselves out).
*/
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout);
/**
* peer_watch_our_htlc_outputs: HTLC outputs from our commit tx to watch.
* @peer: the state data for this peer.

View File

@ -1268,6 +1268,13 @@ void peer_watch_close(struct peer *peer,
add_event(peer, timedout);
}
void peer_unwatch_close_timeout(struct peer *peer, enum state_input timedout)
{
assert(timedout == INPUT_CLOSE_COMPLETE_TIMEOUT);
if (!mapping_inputs)
remove_event(peer, timedout);
}
bool peer_watch_our_htlc_outputs(struct peer *peer,
const struct bitcoin_tx *tx,
enum state_input tous_timeout,
@ -1523,10 +1530,10 @@ static const char *check_changes(const struct peer *old, struct peer *new,
"cond CLOSE with anchor");
}
if (new->cond == PEER_CLOSED) {
/* FIXME: Move to state core */
/* Can no longer receive packet timeouts, either. */
remove_event_(&new->core.event_notifies,
INPUT_CLOSE_COMPLETE_TIMEOUT);
/* Should not have pending close timeout. */
if (have_event(new->core.event_notifies,
INPUT_CLOSE_COMPLETE_TIMEOUT))
return tal_fmt(NULL, "CLOSED with pending close timeout");
}
if (input == PKT_ERROR) {