mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
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:
7
state.c
7
state.c
@@ -613,6 +613,8 @@ enum command_status state(const tal_t *ctx,
|
|||||||
|
|
||||||
case STATE_WAIT_FOR_CLOSE_COMPLETE:
|
case STATE_WAIT_FOR_CLOSE_COMPLETE:
|
||||||
if (input_is(input, PKT_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);
|
err = accept_pkt_close_complete(ctx, peer, idata->pkt);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_start_unilateral_close_already_closing;
|
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);
|
change_peer_cond(peer, PEER_CLOSING, PEER_CLOSED);
|
||||||
return next_state(peer, cstatus, STATE_CLOSE_WAIT_CLOSE);
|
return next_state(peer, cstatus, STATE_CLOSE_WAIT_CLOSE);
|
||||||
} else if (input_is(input, PKT_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 */
|
/* We can use the sig just like CLOSE_COMPLETE */
|
||||||
err = accept_pkt_simultaneous_close(ctx, peer,
|
err = accept_pkt_simultaneous_close(ctx, peer,
|
||||||
idata->pkt);
|
idata->pkt);
|
||||||
@@ -633,6 +637,8 @@ enum command_status state(const tal_t *ctx,
|
|||||||
set_peer_cond(peer, PEER_CLOSED);
|
set_peer_cond(peer, PEER_CLOSED);
|
||||||
return next_state(peer, cstatus, STATE_CLOSE_WAIT_CLOSE);
|
return next_state(peer, cstatus, STATE_CLOSE_WAIT_CLOSE);
|
||||||
} else if (input_is(input, PKT_ERROR)) {
|
} else if (input_is(input, PKT_ERROR)) {
|
||||||
|
peer_unwatch_close_timeout(peer,
|
||||||
|
INPUT_CLOSE_COMPLETE_TIMEOUT);
|
||||||
peer_unexpected_pkt(peer, idata->pkt);
|
peer_unexpected_pkt(peer, idata->pkt);
|
||||||
goto start_unilateral_close_already_closing;
|
goto start_unilateral_close_already_closing;
|
||||||
} else if (input_is_pkt(input)) {
|
} 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");
|
err = pkt_err(ctx, "Close timed out");
|
||||||
goto err_start_unilateral_close_already_closing;
|
goto err_start_unilateral_close_already_closing;
|
||||||
}
|
}
|
||||||
|
peer_unwatch_close_timeout(peer, INPUT_CLOSE_COMPLETE_TIMEOUT);
|
||||||
goto fail_during_close;
|
goto fail_during_close;
|
||||||
|
|
||||||
case STATE_WAIT_FOR_CLOSE_ACK:
|
case STATE_WAIT_FOR_CLOSE_ACK:
|
||||||
|
|||||||
28
state.h
28
state.h
@@ -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_watch_close: watch for close tx until it's "irreversible" (or timedout)
|
||||||
* @peer: the state data for this peer.
|
* @peer: the state data for this peer.
|
||||||
* @done: the input to give when tx is completely buried.
|
* @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
|
* Once this fires we consider the channel completely closed and stop
|
||||||
* watching (eg 100 txs down).
|
* watching (eg 100 txs down).
|
||||||
*
|
*
|
||||||
* This is used for watching a mutual close, or for a transaction we sent
|
* This is used for watching a mutual close.
|
||||||
* (such as a steal, or spend of their close, etc).
|
|
||||||
*/
|
*/
|
||||||
void peer_watch_close(struct peer *peer,
|
void peer_watch_close(struct peer *peer,
|
||||||
enum state_input done, enum state_input timedout);
|
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_watch_our_htlc_outputs: HTLC outputs from our commit tx to watch.
|
||||||
* @peer: the state data for this peer.
|
* @peer: the state data for this peer.
|
||||||
|
|||||||
@@ -1268,6 +1268,13 @@ void peer_watch_close(struct peer *peer,
|
|||||||
add_event(peer, timedout);
|
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,
|
bool peer_watch_our_htlc_outputs(struct peer *peer,
|
||||||
const struct bitcoin_tx *tx,
|
const struct bitcoin_tx *tx,
|
||||||
enum state_input tous_timeout,
|
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");
|
"cond CLOSE with anchor");
|
||||||
}
|
}
|
||||||
if (new->cond == PEER_CLOSED) {
|
if (new->cond == PEER_CLOSED) {
|
||||||
/* FIXME: Move to state core */
|
/* Should not have pending close timeout. */
|
||||||
/* Can no longer receive packet timeouts, either. */
|
if (have_event(new->core.event_notifies,
|
||||||
remove_event_(&new->core.event_notifies,
|
INPUT_CLOSE_COMPLETE_TIMEOUT))
|
||||||
INPUT_CLOSE_COMPLETE_TIMEOUT);
|
return tal_fmt(NULL, "CLOSED with pending close timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == PKT_ERROR) {
|
if (input == PKT_ERROR) {
|
||||||
|
|||||||
Reference in New Issue
Block a user