diff --git a/state.c b/state.c index ebce11adc..309b0d2cd 100644 --- a/state.c +++ b/state.c @@ -528,7 +528,8 @@ enum state state(const enum state state, const struct state_data *sdata, bitcoin_commit(effect, sdata)); set_effect(effect, watch, bitcoin_watch_delayed(effect, - BITCOIN_ANCHOR_OURCOMMIT_DELAYPASSED)); + effect->broadcast, + BITCOIN_ANCHOR_OURCOMMIT_DELAYPASSED)); /* They could still close. */ return STATE_CLOSE_WAIT_CLOSE_OURCOMMIT; } @@ -612,7 +613,7 @@ enum state state(const enum state state, const struct state_data *sdata, set_effect(effect, broadcast, bitcoin_spend_ours(effect, sdata)); set_effect(effect, watch, - bitcoin_watch(effect, + bitcoin_watch(effect, effect->broadcast, BITCOIN_SPEND_OURS_DONE)); bits &= ~STATE_CLOSE_OURCOMMIT_BIT; bits |= STATE_CLOSE_SPENDOURS_BIT; @@ -631,7 +632,7 @@ enum state state(const enum state state, const struct state_data *sdata, set_effect(effect, broadcast, bitcoin_spend_theirs(effect, sdata)); set_effect(effect, watch, - bitcoin_watch(effect, + bitcoin_watch(effect, effect->broadcast, BITCOIN_SPEND_THEIRS_DONE)); bits |= STATE_CLOSE_SPENDTHEM_BIT; return base + bits; @@ -643,7 +644,8 @@ enum state state(const enum state state, const struct state_data *sdata, return STATE_ERR_INFORMATION_LEAK; set_effect(effect, broadcast, steal); set_effect(effect, watch, - bitcoin_watch(effect, BITCOIN_STEAL_DONE)); + bitcoin_watch(effect, effect->broadcast, + BITCOIN_STEAL_DONE)); bits |= STATE_CLOSE_STEAL_BIT; return base + bits; } else if (input_is(input, BITCOIN_ANCHOR_UNSPENT)) @@ -716,7 +718,7 @@ start_unilateral_close: set_effect(effect, stop_commands, true); set_effect(effect, broadcast, bitcoin_commit(effect, sdata)); set_effect(effect, watch, - bitcoin_watch_delayed(effect, + bitcoin_watch_delayed(effect, effect->broadcast, BITCOIN_ANCHOR_OURCOMMIT_DELAYPASSED)); return STATE_CLOSE_WAIT_OURCOMMIT; @@ -731,7 +733,8 @@ them_unilateral: set_effect(effect, stop_commands, true); set_effect(effect, broadcast, bitcoin_spend_theirs(effect, sdata)); set_effect(effect, watch, - bitcoin_watch(effect, BITCOIN_SPEND_THEIRS_DONE)); + bitcoin_watch(effect, effect->broadcast, + BITCOIN_SPEND_THEIRS_DONE)); return STATE_CLOSE_WAIT_SPENDTHEM; accept_update: @@ -825,7 +828,8 @@ fail_during_close: set_effect(effect, broadcast, bitcoin_spend_theirs(effect, sdata)); set_effect(effect, watch, - bitcoin_watch(effect, BITCOIN_SPEND_THEIRS_DONE)); + bitcoin_watch(effect, effect->broadcast, + BITCOIN_SPEND_THEIRS_DONE)); /* Expect either close or spendthem to complete */ return STATE_CLOSE_WAIT_SPENDTHEM_CLOSE; } else if (input_is(input, BITCOIN_ANCHOR_OTHERSPEND)) { @@ -834,7 +838,8 @@ fail_during_close: return STATE_ERR_INFORMATION_LEAK; set_effect(effect, broadcast, steal); set_effect(effect, watch, - bitcoin_watch(effect, BITCOIN_STEAL_DONE)); + bitcoin_watch(effect, effect->broadcast, + BITCOIN_STEAL_DONE)); /* Expect either close or steal to complete */ return STATE_CLOSE_WAIT_STEAL_CLOSE; } else if (input_is(input, BITCOIN_ANCHOR_UNSPENT)) { @@ -857,6 +862,7 @@ old_commit_spotted: if (!steal) return STATE_ERR_INFORMATION_LEAK; set_effect(effect, broadcast, steal); - set_effect(effect, watch, bitcoin_watch(effect, BITCOIN_STEAL_DONE)); + set_effect(effect, watch, + bitcoin_watch(effect, effect->broadcast, BITCOIN_STEAL_DONE)); return STATE_CLOSE_WAIT_STEAL; } diff --git a/state.h b/state.h index fbec0147a..8e8b2e0c2 100644 --- a/state.h +++ b/state.h @@ -200,21 +200,27 @@ struct watch *bitcoin_unwatch_anchor_depth(const tal_t *ctx, /** * bitcoin_watch_delayed: watch this (commit) tx, tell me when I can spend it - * @effect: both the context to tal the watch off, and tx we're watching. + * @effect: the context to tal the watch off + * @tx: the tx we're watching. * @canspend: the input to give when commit reaches spendable depth. + * + * Note that this tx may be malleated, as it's dual-signed. */ struct watch *bitcoin_watch_delayed(const struct state_effect *effect, + const struct bitcoin_tx *tx, enum state_input canspend); /** * bitcoin_watch: watch this tx until it's "irreversible" - * @effect: both the context to tal the watch off, and tx we're watching. + * @effect: the context to tal the watch off + * @tx: the tx we're watching. * @done: the input to give when tx is completely buried. * * The tx should be immalleable by BIP62; once this fires we consider * the channel completely closed and stop watching (eg 100 txs down). */ struct watch *bitcoin_watch(const struct state_effect *effect, + const struct bitcoin_tx *tx, enum state_input done); /** diff --git a/test/test_state_coverage.c b/test/test_state_coverage.c index 213020d4c..b0e31719f 100644 --- a/test/test_state_coverage.c +++ b/test/test_state_coverage.c @@ -441,11 +441,12 @@ struct watch *bitcoin_unwatch_anchor_depth(const tal_t *ctx, /* Wait for our commit to be spendable. */ struct watch *bitcoin_watch_delayed(const struct state_effect *effect, + const struct bitcoin_tx *tx, enum state_input canspend) { struct watch *watch = talz(effect, struct watch); - assert(bitcoin_tx_is(effect->broadcast, "our commit")); + assert(bitcoin_tx_is(tx, "our commit")); add_event(&watch->events, canspend); return watch; } @@ -453,16 +454,17 @@ struct watch *bitcoin_watch_delayed(const struct state_effect *effect, /* Wait for commit to be very deeply buried (so we no longer need to * even watch) */ struct watch *bitcoin_watch(const struct state_effect *effect, + const struct bitcoin_tx *tx, enum state_input done) { struct watch *watch = talz(effect, struct watch); if (done == BITCOIN_STEAL_DONE) - assert(bitcoin_tx_is(effect->broadcast, "steal")); + assert(bitcoin_tx_is(tx, "steal")); else if (done == BITCOIN_SPEND_THEIRS_DONE) - assert(bitcoin_tx_is(effect->broadcast, "spend their commit")); + assert(bitcoin_tx_is(tx, "spend their commit")); else if (done == BITCOIN_SPEND_OURS_DONE) - assert(bitcoin_tx_is(effect->broadcast, "spend our commit")); + assert(bitcoin_tx_is(tx, "spend our commit")); else errx(1, "Unknown watch effect %s", input_name(done)); add_event(&watch->events, done);