liquidity-ad: wire in csv updates to commitment txs

This commit is contained in:
niftynei 2021-06-22 16:49:04 -05:00 committed by neil saitug
parent 67b8a22aa7
commit 2532aa003a
5 changed files with 44 additions and 5 deletions

View File

@ -90,6 +90,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct pubkey *remote_funding_key,
enum side opener,
u16 to_self_delay,
u32 lease_expiry,
u32 blockheight,
const struct keyset *keyset,
u32 feerate_per_kw,
struct amount_sat dust_limit,
@ -234,9 +236,16 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
* output](#to_local-output).
*/
if (amount_msat_greater_eq_sat(self_pay, dust_limit)) {
/* BOLT- #3:
* In a leased channel, the `to_local` output that
* pays the `accepter` node is modified so that its
* CSV is equal to the greater of the
* `to_self_delay` or the `lease_end` - `blockheight`.
*/
u8 *wscript = to_self_wscript(tmpctx,
to_self_delay,
1, /* FIXME: csv_lock */
lease_expiry > blockheight ?
lease_expiry - blockheight : 0,
keyset);
u8 *p2wsh = scriptpubkey_p2wsh(tx, wscript);
struct amount_sat amount = amount_msat_to_sat_round_down(self_pay);
@ -278,9 +287,22 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
* Otherwise, this output is a simple P2WPKH to `remotepubkey`.
*/
if (option_anchor_outputs) {
/* FIXME: use csv_lock */
/* BOLT- #3:
* ##### Leased channel (`option_will_fund`)
*
* If a `lease` applies to the channel, the
* `to_remote` output of the `initiator`
* ensures the `leasor` funds are not
* spendable until the lease expires.
*
* <remote_pubkey> OP_CHECKSIGVERIFY
* MAX(1, lease_end - blockheight)
* OP_CHECKSEQUENCEVERIFY
*/
u32 csv_lock = lease_expiry > blockheight ?
lease_expiry - blockheight : 1;
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, 1));
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, csv_lock));
} else {
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
&keyset->other_payment_key);

View File

@ -58,6 +58,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct pubkey *remote_funding_key,
enum side opener,
u16 to_self_delay,
u32 lease_expiry,
u32 blockheight,
const struct keyset *keyset,
u32 feerate_per_kw,
struct amount_sat dust_limit,

View File

@ -341,8 +341,10 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
&channel->funding_pubkey[side],
&channel->funding_pubkey[!side],
channel->opener,
channel->config[!side].to_self_delay, &keyset,
channel_feerate(channel, side),
channel->config[!side].to_self_delay,
channel->lease_expiry,
channel_blockheight(channel, side),
&keyset, channel_feerate(channel, side),
channel->config[side].dust_limit, channel->view[side].owed[side],
channel->view[side].owed[!side], committed, htlcmap, direct_outputs,
commitment_number ^ channel->commitment_number_obscurer,

View File

@ -800,6 +800,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -815,6 +816,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
REMOTE, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -863,6 +865,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -878,6 +881,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
REMOTE, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -914,6 +918,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -930,6 +935,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
REMOTE, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -972,6 +978,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw-1,
dust_limit,
@ -1020,6 +1027,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -1094,6 +1102,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -1148,6 +1157,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,
@ -1163,6 +1173,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
REMOTE, to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw,
dust_limit,

View File

@ -534,6 +534,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, remote_config->to_self_delay,
0, 0, /* No lease */
&keyset,
feerate_per_kw[LOCAL],
local_config->dust_limit,
@ -664,6 +665,7 @@ int main(int argc, const char *argv[])
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL, remote_config->to_self_delay,
0, 0, /* No lease */
&keyset, feerate_per_kw[LOCAL], local_config->dust_limit,
to_local, to_remote, htlcs, &htlc_map, NULL,
0x2bb038521914 ^ 42,