mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
channel lease: set csv_lock for commitment transactions
If the channel is under lease, the lessor's (accepter, really) funds have a CSV lock that reflects the length of the remainder of the lease.
This commit is contained in:
parent
43ae30df21
commit
16c6ef546a
@ -108,6 +108,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
struct amount_msat total_pay;
|
struct amount_msat total_pay;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
size_t i, n, untrimmed;
|
size_t i, n, untrimmed;
|
||||||
|
/* Is this the lessor ? */
|
||||||
|
enum side lessor = !opener;
|
||||||
u32 *cltvs;
|
u32 *cltvs;
|
||||||
bool to_local, to_remote;
|
bool to_local, to_remote;
|
||||||
struct htlc *dummy_to_local = (struct htlc *)0x01,
|
struct htlc *dummy_to_local = (struct htlc *)0x01,
|
||||||
@ -115,6 +117,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
const u8 *funding_wscript = bitcoin_redeem_2of2(tmpctx,
|
const u8 *funding_wscript = bitcoin_redeem_2of2(tmpctx,
|
||||||
local_funding_key,
|
local_funding_key,
|
||||||
remote_funding_key);
|
remote_funding_key);
|
||||||
|
u32 csv_lock = lease_expiry > blockheight ?
|
||||||
|
lease_expiry - blockheight : 1;
|
||||||
|
|
||||||
if (!amount_msat_add(&total_pay, self_pay, other_pay))
|
if (!amount_msat_add(&total_pay, self_pay, other_pay))
|
||||||
abort();
|
abort();
|
||||||
@ -244,8 +248,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
*/
|
*/
|
||||||
u8 *wscript = to_self_wscript(tmpctx,
|
u8 *wscript = to_self_wscript(tmpctx,
|
||||||
to_self_delay,
|
to_self_delay,
|
||||||
lease_expiry > blockheight ?
|
side == lessor ? csv_lock : 0,
|
||||||
lease_expiry - blockheight : 0,
|
|
||||||
keyset);
|
keyset);
|
||||||
u8 *p2wsh = scriptpubkey_p2wsh(tx, wscript);
|
u8 *p2wsh = scriptpubkey_p2wsh(tx, wscript);
|
||||||
struct amount_sat amount = amount_msat_to_sat_round_down(self_pay);
|
struct amount_sat amount = amount_msat_to_sat_round_down(self_pay);
|
||||||
@ -287,6 +290,11 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
* Otherwise, this output is a simple P2WPKH to `remotepubkey`.
|
* Otherwise, this output is a simple P2WPKH to `remotepubkey`.
|
||||||
*/
|
*/
|
||||||
if (option_anchor_outputs) {
|
if (option_anchor_outputs) {
|
||||||
|
const u8 *redeem
|
||||||
|
= anchor_to_remote_redeem(tmpctx,
|
||||||
|
&keyset->other_payment_key,
|
||||||
|
(!side) == lessor ?
|
||||||
|
csv_lock : 1);
|
||||||
/* BOLT- #3:
|
/* BOLT- #3:
|
||||||
* ##### Leased channel (`option_will_fund`)
|
* ##### Leased channel (`option_will_fund`)
|
||||||
*
|
*
|
||||||
@ -299,10 +307,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
* MAX(1, lease_end - blockheight)
|
* MAX(1, lease_end - blockheight)
|
||||||
* OP_CHECKSEQUENCEVERIFY
|
* OP_CHECKSEQUENCEVERIFY
|
||||||
*/
|
*/
|
||||||
u32 csv_lock = lease_expiry > blockheight ?
|
scriptpubkey = scriptpubkey_p2wsh(tmpctx, redeem);
|
||||||
lease_expiry - blockheight : 1;
|
|
||||||
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
|
|
||||||
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, csv_lock));
|
|
||||||
} else {
|
} else {
|
||||||
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
|
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
|
||||||
&keyset->other_payment_key);
|
&keyset->other_payment_key);
|
||||||
|
@ -98,6 +98,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
bool to_local, to_remote;
|
bool to_local, to_remote;
|
||||||
struct amount_msat total_pay;
|
struct amount_msat total_pay;
|
||||||
struct amount_sat amount;
|
struct amount_sat amount;
|
||||||
|
enum side lessor = !opener;
|
||||||
u32 sequence;
|
u32 sequence;
|
||||||
void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE;
|
void *dummy_local = (void *)LOCAL, *dummy_remote = (void *)REMOTE;
|
||||||
const void *output_order[NUM_SIDES];
|
const void *output_order[NUM_SIDES];
|
||||||
@ -211,7 +212,8 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
*/
|
*/
|
||||||
if (amount_msat_greater_eq_sat(self_pay, dust_limit)) {
|
if (amount_msat_greater_eq_sat(self_pay, dust_limit)) {
|
||||||
u8 *wscript = to_self_wscript(tmpctx,
|
u8 *wscript = to_self_wscript(tmpctx,
|
||||||
to_self_delay, csv_lock,
|
to_self_delay,
|
||||||
|
side == lessor ? csv_lock : 0,
|
||||||
keyset);
|
keyset);
|
||||||
amount = amount_msat_to_sat_round_down(self_pay);
|
amount = amount_msat_to_sat_round_down(self_pay);
|
||||||
int pos = bitcoin_tx_add_output(
|
int pos = bitcoin_tx_add_output(
|
||||||
@ -245,8 +247,11 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
|
|
||||||
amount = amount_msat_to_sat_round_down(other_pay);
|
amount = amount_msat_to_sat_round_down(other_pay);
|
||||||
if (option_anchor_outputs) {
|
if (option_anchor_outputs) {
|
||||||
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
|
const u8 *redeem
|
||||||
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, csv_lock));
|
= anchor_to_remote_redeem(tmpctx,
|
||||||
|
&keyset->other_payment_key,
|
||||||
|
(!side) == lessor ? csv_lock : 1);
|
||||||
|
scriptpubkey = scriptpubkey_p2wsh(tmpctx, redeem);
|
||||||
} else {
|
} else {
|
||||||
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
|
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
|
||||||
&keyset->other_payment_key);
|
&keyset->other_payment_key);
|
||||||
|
Loading…
Reference in New Issue
Block a user