Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6059e8e
liquidity-ads: import from spec
niftynei Jun 10, 2021
23bcfad
lease_rates: parse them out of node_announcements
niftynei May 27, 2021
e4a4bc6
gossip/liquidity-ad: node_ann comparison, optional TLV check
niftynei May 28, 2021
30818b5
gossipd: signal whether node_ann is updated, are we starting up?
niftynei May 28, 2021
cb2e5d9
setleaserates: new RPC to pass in lease rates
niftynei May 28, 2021
913c93c
option_will_fund: print out lease rates in listnodes
niftynei May 26, 2021
f4f571f
libplugin: add u16_option parsing
niftynei May 29, 2021
421dca9
gossipd: turn off lease offers if the rates are empty
niftynei Jun 10, 2021
35f9fcc
funder: make policy a pointer, most places
niftynei May 26, 2021
d7e5933
funder-liqudity-ads: support options + setliquidity ad
niftynei May 26, 2021
14df559
contrib: offer a liquidity-ad lease in developer mode
niftynei May 29, 2021
f9570fe
tests: add test for setting/updating node announce
niftynei May 26, 2021
3431dba
psbt: promote weight calculation methods to 'library'
niftynei Jun 8, 2021
1d92dbb
amount: add 'is_zero' helper
niftynei Jun 8, 2021
c7f1e1a
hsmd: method to sign liquidity ad offer
niftynei Jun 8, 2021
c4590ab
liquidity-ads: pipe through request to funder, update policy
niftynei Jun 8, 2021
ff00057
liquidity-ad: request amount, pass through to dualopend
niftynei Jun 8, 2021
7ec2d65
liquidity-ad: pipe `request_amt` all the way out to fundchannel
niftynei Jun 8, 2021
91ea471
liquidity-ad: fill in acceptance response
niftynei Jun 8, 2021
3b90c5b
dualopend, openchannel_init: pull out feerate parsing logic
niftynei Jun 11, 2021
414dafd
rpc: add queryrates
niftynei Jun 11, 2021
724e364
channel-lease: validate accepter's sig on lease terms
niftynei Jun 14, 2021
bba10e1
lease-rates: calculate the fee owed to peer for the funds lease
niftynei Jun 14, 2021
6b3299b
lease-rates: add to accepter's side on accepter pathway
niftynei Jun 14, 2021
8ac2853
script: add csv_lock to scripts
niftynei Jun 15, 2021
659d3ab
lease_rates: add csv lock to modify anchor scripts
niftynei Jun 16, 2021
96fcb07
lease_rates: pass in 'lease_expiry' and 'csv' to commitments/channel
niftynei Jun 16, 2021
9ed0d22
onchaind: add recovery scans for option-will-fund
niftynei Jun 16, 2021
215869b
lease_rates: persist channel's lease info
niftynei Jun 17, 2021
d8d5316
fixup: fold into next commit
niftynei Jul 6, 2021
0f79556
liquidity-ads: persist channel blockheight states to disk
niftynei Jun 22, 2021
2812b24
channel: wire blockheight updates from channeld in to database
niftynei Jun 22, 2021
123f95f
liquidity-ad: wire in csv updates to commitment txs
niftynei Jun 22, 2021
6e4344a
chaintopology: new command 'parsefeerate'
niftynei Jun 23, 2021
64d7f44
libplugin: add synchronous rpc call handler that returns an error
niftynei Jun 23, 2021
7887ad9
channel lease: set csv_lock for commitment transactions
niftynei Jul 2, 2021
7a7df1b
channel utxo: persist the 'csv' lock value to database
niftynei Jul 2, 2021
9955e5d
utxo: don't add outputs that aren't currently eligible to be spent
niftynei Jul 2, 2021
18745a5
channeld: don't forget channels that we've put funds into
niftynei Jul 2, 2021
b0e4e7f
channel lease: fail leased channel if peer offline + blockheight behind
niftynei Jul 2, 2021
971041f
close: param to force-close a leased channel
niftynei Jul 2, 2021
5aa490f
channel lease: update the blockheight on reconnect, also
niftynei Jul 2, 2021
34e9ee9
lease rates: helpers for parsing, serializing + equating lease_rates
niftynei Jul 2, 2021
2d9ef33
channel leases: pass expected lease rates around in compat form
niftynei Jul 2, 2021
06307ae
channel leases: add expected lease fee to opening PSBT
niftynei Jul 2, 2021
e7a5740
channel-lease: reject if we're not currently advertising liquidity
niftynei Jul 6, 2021
b39164f
nit: better error messages on dualopend's check_balances failures
niftynei Jul 6, 2021
eeaf436
channel-leases: add lease fee to accepter's funding earlier up
niftynei Jul 6, 2021
83596b8
dualopend: hold onto open_tlv for longer than the tmpctx persists
niftynei Jul 6, 2021
e34e62e
lease-channels: tests for the test gods
niftynei Jul 6, 2021
fbadcf0
queryrates: make it dev-only
niftynei Jul 6, 2021
a87c3df
fixup! channel-lease: reject if we're not currently advertising liqui…
niftynei Jul 7, 2021
6187448
reestablish_tlvs: don't lose them btw tmpctx cleanup
niftynei Jul 7, 2021
913b611
fixup! lease-channels: tests for the test gods
niftynei Jul 7, 2021
a29d952
fixup! funder: make policy a pointer, most places
niftynei Jul 7, 2021
4e1946f
fixup! liquidity-ads: persist channel blockheight states to disk
niftynei Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,27 @@ struct amount_sat psbt_compute_fee(const struct wally_psbt *psbt)

return fee;
}

size_t psbt_input_weight(const struct wally_psbt *psbt, size_t in)
{
size_t weight;

/* txid + txout + sequence */
weight = (32 + 4 + 4) * 4;
weight +=
(psbt->inputs[in].redeem_script_len +
(varint_t) varint_size(psbt->inputs[in].redeem_script_len)) * 4;

/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #3:
*
* The minimum witness weight for an input is 110.
*/
weight += 110;
return weight;
}

size_t psbt_output_weight(const struct wally_psbt *psbt, size_t outnum)
{
return (8 + psbt->tx->outputs[outnum].script_len +
varint_size(psbt->tx->outputs[outnum].script_len)) * 4;
}
4 changes: 4 additions & 0 deletions bitcoin/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,8 @@ struct wally_psbt *psbt_from_bytes(const tal_t *ctx, const u8 *bytes,
void towire_wally_psbt(u8 **pptr, const struct wally_psbt *psbt);
struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx,
const u8 **cursor, size_t *max);

/* Calculate the weight of a psbt input or output */
size_t psbt_input_weight(const struct wally_psbt *psbt, size_t in);
size_t psbt_output_weight(const struct wally_psbt *psbt, size_t outnum);
#endif /* LIGHTNING_BITCOIN_PSBT_H */
55 changes: 47 additions & 8 deletions bitcoin/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
/* To push 0-75 bytes onto stack. */
#define OP_PUSHBYTES(val) (val)

#define max(a, b) ((a) > (b) ? (a) : (b))

/* Bitcoin's OP_HASH160 is RIPEMD(SHA256()) */
static void hash160(struct ripemd160 *redeemhash, const void *mem, size_t len)
{
Expand Down Expand Up @@ -327,13 +329,24 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
* block csv lock.
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
*/
/* 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
*/

u8 *anchor_to_remote_redeem(const tal_t *ctx,
const struct pubkey *remote_key)
const struct pubkey *remote_key,
u32 csv_lock)
{
u8 *script = tal_arr(ctx, u8, 0);
add_push_key(&script, remote_key);
add_op(&script, OP_CHECKSIGVERIFY);
add_number(&script, 1);
add_number(&script, csv_lock);
add_op(&script, OP_CHECKSEQUENCEVERIFY);

assert(is_anchor_witness_script(script, tal_bytelen(script)));
Expand All @@ -342,15 +355,21 @@ u8 *anchor_to_remote_redeem(const tal_t *ctx,

bool is_anchor_witness_script(const u8 *script, size_t script_len)
{
if (script_len != 34 + 1 + 1 + 1)
size_t len = 34 + 1 + 1 + 1;
/* With option_will_fund, the pushbytes can be up to 2 bytes more
*
* <remote_pubkey> OP_CHECKSIGVERIFY
* MAX(1, lease_end - blockheight)
* OP_CHECKSEQUENCEVERIFY
*/
if (script_len < len || script_len > len + 2)
return false;
if (script[0] != OP_PUSHBYTES(33))
return false;
if (script[34] != OP_CHECKSIGVERIFY)
return false;
if (script[35] != 0x51)
return false;
if (script[36] != OP_CHECKSEQUENCEVERIFY)
/* FIXME: check for push value */
if (script[script_len - 1] != OP_CHECKSEQUENCEVERIFY)
return false;
return true;
}
Expand Down Expand Up @@ -510,15 +529,35 @@ u8 **bitcoin_witness_sig_and_element(const tal_t *ctx,
* OP_ENDIF
* OP_CHECKSIG
*/
u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay,
/* BOLT- #3
* ##### Leased channel (`option_will_fund`)
* If a `lease` applies to the channel, the `to_local` output of the `accepter`
* ensures the `leasor` funds are not spendable until the lease expires.
*
* 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`.
*
* OP_IF
* # Penalty transaction
* <revocationpubkey>
* OP_ELSE
* MAX(`to_self_delay`, `lease_end` - `blockheight`)
* OP_CHECKSEQUENCEVERIFY
* OP_DROP
* <local_delayedpubkey>
* OP_ENDIF
* OP_CHECKSIG
*/
u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay, u32 csv,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey)
{
u8 *script = tal_arr(ctx, u8, 0);
add_op(&script, OP_IF);
add_push_key(&script, revocation_pubkey);
add_op(&script, OP_ELSE);
add_number(&script, to_self_delay);
add_number(&script, max(csv, to_self_delay));
add_op(&script, OP_CHECKSEQUENCEVERIFY);
add_op(&script, OP_DROP);
add_push_key(&script, local_delayedkey);
Expand Down
8 changes: 4 additions & 4 deletions bitcoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ u8 *scriptpubkey_p2wpkh_derkey(const tal_t *ctx, const u8 der[33]);
u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
const u8 *wprog, size_t wprog_size);

/* To-remotekey with csv 1 delay. */
/* To-remotekey with csv max(lease_expiry - blockheight, 1) delay. */
u8 *anchor_to_remote_redeem(const tal_t *ctx,
const struct pubkey *remote_key);
const struct pubkey *remote_key,
u32 csv_lock);

/* Create a witness which spends the 2of2. */
u8 **bitcoin_witness_2of2(const tal_t *ctx,
Expand All @@ -90,8 +91,7 @@ u8 **bitcoin_witness_sig_and_element(const tal_t *ctx,
const u8 *witnessscript);

/* BOLT #3 to-local output */
u8 *bitcoin_wscript_to_local(const tal_t *ctx,
u16 to_self_delay,
u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay, u32 csv,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey);

Expand Down
1 change: 1 addition & 0 deletions channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CHANNELD_COMMON_OBJS := \
common/billboard.o \
common/bip32.o \
common/blinding.o \
common/blockheight_states.o \
common/channel_config.o \
common/channel_id.o \
common/crypto_state.o \
Expand Down
Loading