diff --git a/channeld/channeld.c b/channeld/channeld.c index f5a052426..5bee06853 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3568,6 +3568,7 @@ static void init_channel(struct peer *peer) &funding_txid, funding_txout, minimum_depth, + 0, /* FIXME: channel lease_expiry */ funding, local_msat, take(fee_states), diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 59665eeb4..3418dee06 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -95,6 +95,7 @@ struct channel *new_full_channel(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, + u32 lease_expiry, struct amount_sat funding, struct amount_msat local_msat, const struct fee_states *fee_states, @@ -113,6 +114,7 @@ struct channel *new_full_channel(const tal_t *ctx, funding_txid, funding_txout, minimum_depth, + lease_expiry, funding, local_msat, fee_states, diff --git a/channeld/full_channel.h b/channeld/full_channel.h index e23deb3b1..c7151ddb6 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -17,6 +17,7 @@ struct existing_htlc; * @funding_txid: The commitment transaction id. * @funding_txout: The commitment transaction output number. * @minimum_depth: The minimum confirmations needed for funding transaction. + * @lease_expiry: The block the lease on this channel expires at; 0 if no lease. * @funding: The commitment transaction amount. * @local_msat: The amount for the local side (remainder goes to remote) * @fee_states: The fee update states. @@ -37,6 +38,7 @@ struct channel *new_full_channel(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, + u32 lease_expiry, struct amount_sat funding, struct amount_msat local_msat, const struct fee_states *fee_states, diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 89eb791e7..e21350a64 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -481,6 +481,7 @@ int main(int argc, const char *argv[]) derive_channel_id(&cid, &funding_txid, funding_output_index); lchannel = new_full_channel(tmpctx, &cid, &funding_txid, funding_output_index, 0, + 0, /* No channel lease */ funding_amount, to_local, take(new_fee_states(NULL, LOCAL, &feerate_per_kw[LOCAL])), @@ -492,6 +493,7 @@ int main(int argc, const char *argv[]) false, false, LOCAL); rchannel = new_full_channel(tmpctx, &cid, &funding_txid, funding_output_index, 0, + 0, /* No channel lease */ funding_amount, to_remote, take(new_fee_states(NULL, REMOTE, &feerate_per_kw[REMOTE])), diff --git a/common/initial_channel.c b/common/initial_channel.c index 15b59f306..31b133ddf 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -20,6 +20,7 @@ struct channel *new_initial_channel(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, + u32 lease_expiry, struct amount_sat funding, struct amount_msat local_msatoshi, const struct fee_states *fee_states TAKES, @@ -41,6 +42,7 @@ struct channel *new_initial_channel(const tal_t *ctx, channel->funding_txout = funding_txout; channel->funding = funding; channel->minimum_depth = minimum_depth; + channel->lease_expiry = lease_expiry; if (!amount_sat_sub_msat(&remote_msatoshi, channel->funding, local_msatoshi)) return tal_free(channel); @@ -120,7 +122,8 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, 0 ^ channel->commitment_number_obscurer, direct_outputs, side, - 0, /* FIXME: csv lock? */ + /* FIXME: is not the csv lock ?! */ + channel->lease_expiry, channel->option_anchor_outputs, err_reason); diff --git a/common/initial_channel.h b/common/initial_channel.h index 09f2e86a1..187286ff0 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -70,6 +70,9 @@ struct channel { /* Is this using option_anchor_outputs? */ bool option_anchor_outputs; + + /* When the lease expires for the funds in this channel */ + u32 lease_expiry; }; /** @@ -79,6 +82,7 @@ struct channel { * @funding_txid: The commitment transaction id. * @funding_txout: The commitment transaction output number. * @minimum_depth: The minimum confirmations needed for funding transaction. + * @lease_expiry: Block the lease expires * @funding_satoshis: The commitment transaction amount. * @local_msatoshi: The amount for the local side (remainder goes to remote) * @fee_states: The fee update states. @@ -99,6 +103,7 @@ struct channel *new_initial_channel(const tal_t *ctx, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, + u32 lease_expiry, struct amount_sat funding, struct amount_msat local_msatoshi, const struct fee_states *fee_states TAKES, diff --git a/common/utxo.c b/common/utxo.c index b561d42b9..227773205 100644 --- a/common/utxo.c +++ b/common/utxo.c @@ -31,6 +31,7 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo) if (utxo->close_info->commitment_point) towire_pubkey(pptr, utxo->close_info->commitment_point); towire_bool(pptr, utxo->close_info->option_anchor_outputs); + towire_u32(pptr, utxo->close_info->csv); } } @@ -59,6 +60,7 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max) utxo->close_info->commitment_point = NULL; utxo->close_info->option_anchor_outputs = fromwire_bool(ptr, max); + utxo->close_info->csv = fromwire_u32(ptr, max); } else { utxo->close_info = NULL; } diff --git a/common/utxo.h b/common/utxo.h index bcf07fb6f..2f3c63764 100644 --- a/common/utxo.h +++ b/common/utxo.h @@ -20,6 +20,7 @@ struct unilateral_close_info { bool option_anchor_outputs; /* NULL if this is an option_static_remotekey commitment */ struct pubkey *commitment_point; + u32 csv; }; /* Possible states for tracked outputs in the database. Not sure yet diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index 2b1eccaf0..8f0ba013a 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -394,6 +394,7 @@ int main(int argc, char *argv[]) channel = new_full_channel(NULL, &cid, &funding_txid, funding_outnum, 1, + 0, /* Defaults to no lease */ funding_amount, local_msat, take(new_fee_states(NULL, fee_payer, diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index b51433b55..b1db7aac5 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -391,7 +391,7 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt) const u8 *wscript = anchor_to_remote_redeem(tmpctx, &pubkey, - 1); /* FIXME: lease csv ? */ + utxo->close_info->csv); psbt_input_set_witscript(psbt, j, wscript); psbt_input_set_wit_utxo(psbt, j, scriptpubkey_p2wsh(psbt, wscript), diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 0567e4cae..573d0b0d6 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -1672,6 +1672,7 @@ static void revert_channel_state(struct state *state) &tx_state->funding_txid, tx_state->funding_txout, state->minimum_depth, + tx_state->lease_expiry, total, our_msats, take(new_fee_states( @@ -1768,6 +1769,7 @@ static u8 *accepter_commits(struct state *state, &tx_state->funding_txid, tx_state->funding_txout, state->minimum_depth, + tx_state->lease_expiry, total, our_msats, take(new_fee_states( @@ -2356,6 +2358,7 @@ static u8 *opener_commits(struct state *state, &tx_state->funding_txid, tx_state->funding_txout, state->minimum_depth, + tx_state->lease_expiry, total, our_msats, take(new_fee_states(NULL, LOCAL, @@ -3732,6 +3735,7 @@ int main(int argc, char *argv[]) &state->tx_state->funding_txid, state->tx_state->funding_txout, state->minimum_depth, + state->tx_state->lease_expiry, total_funding, our_msat, fee_states, diff --git a/openingd/openingd.c b/openingd/openingd.c index 8ebb3da94..22c07ee27 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -510,6 +510,7 @@ static bool funder_finalize_channel_setup(struct state *state, &state->funding_txid, state->funding_txout, state->minimum_depth, + 0, /* No lease lock */ state->funding, local_msat, take(new_fee_states(NULL, LOCAL, @@ -1000,6 +1001,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) &state->funding_txid, state->funding_txout, state->minimum_depth, + 0, /* No channel lease */ state->funding, state->push_msat, take(new_fee_states(NULL, REMOTE,