Skip to content

Commit

Permalink
lease_rates: pass in 'lease_expiry' and 'csv' to commitments/channel
Browse files Browse the repository at this point in the history
  • Loading branch information
niftynei committed Jul 20, 2021
1 parent c9d2748 commit 5989433
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions channeld/full_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])),
Expand All @@ -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])),
Expand Down
5 changes: 4 additions & 1 deletion common/initial_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions common/initial_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand All @@ -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.
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions common/utxo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions common/utxo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions devtools/mkcommit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hsmd/libhsmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions openingd/dualopend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5989433

Please sign in to comment.