Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liquidity ads #4639

Merged
merged 56 commits into from
Jul 20, 2021
Merged
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
463626d
liquidity-ads: import from spec
niftynei Jun 10, 2021
b5fc2ac
lease_rates: parse them out of node_announcements
niftynei May 27, 2021
cdb934e
gossip/liquidity-ad: node_ann comparison, optional TLV check
niftynei May 28, 2021
cbfd35e
gossipd: signal whether node_ann is updated, are we starting up?
niftynei May 28, 2021
1adadee
setleaserates: new RPC to pass in lease rates
niftynei May 28, 2021
de11c5d
option_will_fund: print out lease rates in listnodes
niftynei May 26, 2021
0227cd1
libplugin: add u16_option parsing
niftynei May 29, 2021
e4b4020
gossipd: turn off lease offers if the rates are empty
niftynei Jun 10, 2021
d93b193
funder: make policy a pointer, most places
niftynei May 26, 2021
5e5987b
funder_policy: set default to 0
niftynei Jul 14, 2021
3e40c83
funder-liqudity-ads: support options + setliquidity ad
niftynei May 26, 2021
5c5e7a1
contrib: offer a liquidity-ad lease in developer mode
niftynei May 29, 2021
8aedc13
tests: add test for setting/updating node announce
niftynei May 26, 2021
1dd656c
amount: add 'is_zero' helper
niftynei Jun 8, 2021
c94b4e6
hsmd: method to sign liquidity ad offer
niftynei Jun 8, 2021
03fb9e3
liquidity-ads: pipe through request to funder, update policy
niftynei Jun 8, 2021
26e739a
liquidity-ad: request amount, pass through to dualopend
niftynei Jun 8, 2021
25499e0
liquidity-ad: pipe `request_amt` all the way out to fundchannel
niftynei Jun 8, 2021
93a848f
liquidity-ad: fill in acceptance response
niftynei Jun 8, 2021
3210dd8
dualopend, openchannel_init: pull out feerate parsing logic
niftynei Jun 11, 2021
a4968b6
rpc: add queryrates
niftynei Jun 11, 2021
9f3d9ad
channel-lease: validate accepter's sig on lease terms
niftynei Jun 14, 2021
f1b0660
lease-rates: calculate the fee owed to peer for the funds lease
niftynei Jun 14, 2021
ade8db8
lease-rates: add to accepter's side on accepter pathway
niftynei Jun 14, 2021
d834de2
script: add csv_lock to scripts
niftynei Jun 15, 2021
bb25dad
lease_rates: add csv lock to modify anchor scripts
niftynei Jun 16, 2021
fd331ef
lease_rates: pass in 'lease_expiry' and 'csv' to commitments/channel
niftynei Jun 16, 2021
de7d3a0
onchaind: add recovery scans for option-will-fund
niftynei Jun 16, 2021
f707bdb
lease_rates: persist channel's lease info
niftynei Jun 17, 2021
817e5ce
liquidity-ads: persist channel blockheight states to disk
niftynei Jun 22, 2021
1e6950b
channel: wire blockheight updates from channeld in to database
niftynei Jun 22, 2021
2493bcc
liquidity-ad: wire in csv updates to commitment txs
niftynei Jun 22, 2021
3ab59fb
chaintopology: new command 'parsefeerate'
niftynei Jun 23, 2021
484bcbe
channel lease: set csv_lock for commitment transactions
niftynei Jul 2, 2021
7d756e0
channel utxo: persist the 'csv' lock value to database
niftynei Jul 2, 2021
4ff926a
utxo: don't add outputs that aren't currently eligible to be spent
niftynei Jul 2, 2021
27657cf
channeld: don't forget channels that we've put funds into
niftynei Jul 2, 2021
9c39e6a
channel lease: fail leased channel if peer offline + blockheight behind
niftynei Jul 2, 2021
8097937
close: param to force-close a leased channel
niftynei Jul 2, 2021
74ccf75
channel lease: update the blockheight on reconnect, also
niftynei Jul 2, 2021
8666cbb
lease rates: helpers for parsing, serializing + equating lease_rates
niftynei Jul 2, 2021
85fbd28
channel leases: pass expected lease rates around in compat form
niftynei Jul 2, 2021
93854d5
channel leases: add expected lease fee to opening PSBT
niftynei Jul 2, 2021
6e7b36b
channel-lease: reject if we're not currently advertising liquidity
niftynei Jul 6, 2021
02644be
nit: better error messages on dualopend's check_balances failures
niftynei Jul 6, 2021
1d6f313
channel-leases: add lease fee to accepter's funding earlier up
niftynei Jul 6, 2021
64123f1
dualopend: hold onto open_tlv for longer than the tmpctx persists
niftynei Jul 6, 2021
86dacd9
lease-channels: tests for the test gods
niftynei Jul 6, 2021
8729d6b
queryrates: make it dev-only
niftynei Jul 6, 2021
7049c30
reestablish_tlvs: don't lose them btw tmpctx cleanup
niftynei Jul 7, 2021
48a46a3
overflows: helpers for integer assignment overflows.
rustyrussell Jul 11, 2021
26474c7
lease_rates, funder: use overflow helpers
rustyrussell Jul 11, 2021
4a967ba
gossipd: de-duplicate code.
rustyrussell Jul 11, 2021
f8f4e43
lease_rates: lease_rates_eq.
rustyrussell Jul 11, 2021
103d3f1
common/lease_rates: more things const.
rustyrussell Jul 11, 2021
7be8e71
printlogs for failing tests
niftynei Jul 20, 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
54 changes: 47 additions & 7 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,36 @@ u8 **bitcoin_witness_sig_and_element(const tal_t *ctx,
* OP_ENDIF
* OP_CHECKSIG
*/
/* 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 lease_remaining,
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(lease_remaining, to_self_delay));
add_op(&script, OP_CHECKSEQUENCEVERIFY);
add_op(&script, OP_DROP);
add_push_key(&script, local_delayedkey);
Expand Down
9 changes: 5 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,8 @@ 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 lease_remaining,
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