Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Aug 10, 2021
2 parents d3d8292 + 405b914 commit f0a7cfd
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 34 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.10.1rc2] - 2021-07-30: "<awaiting name selection>"
## [0.10.1] - 2021-08-09: "eltoo: Ethereum Layer Too"

This release named by @nalinbhardwaj.

NOTE ONE: Both the dual-funding and offers protocols have changed, and
are incompatible with older releses (they're both still draft)
are incompatible with older releases (they're both still draft) #reckless

NOTE TWO: `rebalance` and `drain` plugins will need to be redownloaded as
older versions will no longer work -- `payment_secret` is now compulsory.



### Added

- JSON-RPC: `invoice` now outputs explicit `payment_secret` as its own field. ([#4646])
Expand Down Expand Up @@ -1390,7 +1389,7 @@ There predate the BOLT specifications, and are only of vague historic interest:
6. [0.5.1] - 2016-10-21
7. [0.5.2] - 2016-11-21: "Bitcoin Savings & Trust Daily Interest II"

[0.10.1rc1]: https://github.com/ElementsProject/lightning/releases/tag/v0.10.1rc1
[0.10.1]: https://github.com/ElementsProject/lightning/releases/tag/v0.10.1
[0.10.0]: https://github.com/ElementsProject/lightning/releases/tag/v0.10.0
[0.9.2]: https://github.com/ElementsProject/lightning/releases/tag/v0.9.2
[0.9.1]: https://github.com/ElementsProject/lightning/releases/tag/v0.9.1
Expand Down
6 changes: 4 additions & 2 deletions doc/lightning-close.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/lightning-close.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ proposes a closing fee of 3000 satoshi and our estimate shows it must be 4000:
insist on our fee as much as possible.
* "100%": our next proposal will be 3000. This is the most relaxed case when
we quickly accept the peer's proposal.

The default is "50%".

*wrong_funding_txid* can only be specified if both sides have offered
Expand Down
5 changes: 4 additions & 1 deletion doc/lightning-openchannel_bump.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions doc/lightning-openchannel_bump.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ is not met.
funding transaction. Defaults to 1/64th greater than the last
feerate used for this channel.

Warning: bumping a leased channel will lose the lease.

RETURN VALUE
------------

Expand Down
2 changes: 1 addition & 1 deletion external/lnprototest
13 changes: 12 additions & 1 deletion plugins/funder.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ struct open_info {
struct amount_sat requested_lease;
};

static struct open_info *new_open_info(const tal_t *ctx)
{
struct open_info *info = tal(ctx, struct open_info);

info->requested_lease = AMOUNT_SAT(0);
info->lease_blockheight = 0;
info->node_blockheight = 0;

return info;
}

static struct command_result *
psbt_funded(struct command *cmd,
const char *buf,
Expand Down Expand Up @@ -641,7 +652,7 @@ json_rbf_channel_call(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
struct open_info *info = tal(cmd, struct open_info);
struct open_info *info = new_open_info(cmd);
u64 feerate_our_max, feerate_our_min;
const char *err;
struct out_req *req;
Expand Down
4 changes: 1 addition & 3 deletions plugins/funder_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ default_funder_policy(const tal_t *ctx,
0, /* fuzz_factor */
AMOUNT_SAT(0), /* reserve_tank */
100,
/* Defaults to true iif we're advertising
* offers */
false,
true, /* Leases-only by default */
NULL);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/test/run-funder_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ int main(int argc, const char *argv[])
AMOUNT_SAT(50000),
AMOUNT_SAT(50000),
AMOUNT_SAT(100000),
AMOUNT_SAT(0),
AMOUNT_SAT(100000),
&our_funds);
assert(amount_sat_eq(empty, our_funds));
assert(!err);
Expand Down
13 changes: 3 additions & 10 deletions tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from utils import (
only_one, sync_blockheight, wait_for, TIMEOUT,
account_balance, first_channel_id, closing_fee, TEST_NETWORK,
scriptpubkey_addr
scriptpubkey_addr, calc_lease_fee
)

import os
Expand Down Expand Up @@ -718,14 +718,6 @@ def test_penalty_outhtlc(node_factory, bitcoind, executor, chainparams):
assert account_balance(l2, channel_id) == 0


# check that the fee paid is correct
def calc_lease_fee(amt, feerate, rates):
fee = rates['lease_fee_base_msat']
fee += amt * rates['lease_fee_basis'] // 10
fee += rates['funding_weight'] * feerate
return fee


@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
@pytest.mark.slow_test
Expand Down Expand Up @@ -857,7 +849,8 @@ def test_channel_lease_unilat_closes(node_factory, bitcoind):
l2-l3: l2 leases funds from l3; l3 goes to chain unilaterally
'''
opts = {'funder-policy': 'match', 'funder-policy-mod': 100,
'lease-fee-base-msat': '100sat', 'lease-fee-basis': 100}
'lease-fee-base-msat': '100sat', 'lease-fee-basis': 100,
'funder-lease-requests-only': False}

l1, l2, l3 = node_factory.get_nodes(3, opts=opts)
# Allow l2 some warnings
Expand Down
9 changes: 6 additions & 3 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def test_disconnect_fundee_v2(node_factory):
l2 = node_factory.get_node(disconnect=disconnects,
options={'funder-policy': 'match',
'funder-policy-mod': 100,
'funder-fuzz-percent': 0})
'funder-fuzz-percent': 0,
'funder-lease-requests-only': False})

l1.fundwallet(2000000)
l2.fundwallet(2000000)
Expand Down Expand Up @@ -1697,10 +1698,12 @@ def test_multifunding_v2_exclusive(node_factory, bitcoind):
options = [{},
{'funder-policy': 'match',
'funder-policy-mod': 100,
'funder-fuzz-percent': 0},
'funder-fuzz-percent': 0,
'funder-lease-requests-only': False},
{'funder-policy': 'match',
'funder-policy-mod': 100,
'funder-fuzz-percent': 0},
'funder-fuzz-percent': 0,
'funder-lease-requests-only': False},
{}]
l1, l2, l3, l4 = node_factory.get_nodes(4, opts=options)

Expand Down
91 changes: 87 additions & 4 deletions tests/test_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fixtures import TEST_NETWORK
from pyln.client import RpcError, Millisatoshi
from utils import (
only_one, wait_for, sync_blockheight, first_channel_id
only_one, wait_for, sync_blockheight, first_channel_id, calc_lease_fee
)

import pytest
Expand Down Expand Up @@ -334,6 +334,85 @@ def test_v2_rbf_single(node_factory, bitcoind, chainparams):
l1.daemon.wait_for_log('sendrawtx exit 0')


@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_liquidity_ad(node_factory, bitcoind, chainparams):

opts = {'funder-policy': 'match', 'funder-policy-mod': 100,
'lease-fee-base-msat': '100sat', 'lease-fee-basis': 100,
'may_reconnect': True}
l1, l2 = node_factory.get_nodes(2, opts=opts)

# what happens when we RBF?
feerate = 2000
amount = 500000
l1.fundwallet(20000000)
l2.fundwallet(20000000)

# l1 leases a channel from l2
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
l1.daemon.wait_for_log('disconnect')
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
chan_id = l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
feerate='{}perkw'.format(feerate),
compact_lease=rates['compact_lease'])['channel_id']

vins = [x for x in l1.rpc.listfunds()['outputs'] if x['reserved']]
assert only_one(vins)
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['output'])]

# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')

est_fees = calc_lease_fee(amount, feerate, rates)

# This should be the accepter's amount
fundings = only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['funding']
assert Millisatoshi(est_fees + amount * 1000) == Millisatoshi(fundings['remote_msat'])

# rbf the lease with a higher amount
rate = int(find_next_feerate(l1, l2)[:-5])
# We 4x the feerate to beat the min-relay fee
next_feerate = '{}perkw'.format(rate * 4)

# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(amount, next_feerate, startweight,
prev_utxos, reservedok=True,
min_witness_weight=110,
excess_as_change=True)['psbt']

# do the bump
bump = l1.rpc.openchannel_bump(chan_id, amount, initpsbt,
funding_feerate=next_feerate)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
# Sign our inputs, and continue
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)

# what happens when the channel opens?
bitcoind.generate_block(6)
l1.daemon.wait_for_log('to CHANNELD_NORMAL')

# This should be the accepter's amount
fundings = only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['funding']
# FIXME: The lease goes away :(
assert Millisatoshi(0) == Millisatoshi(fundings['remote_msat'])

wait_for(lambda: [c['active'] for c in l1.rpc.listchannels(l1.get_channel_scid(l2))['channels']] == [True, True])

# send some payments, mine a block or two
inv = l2.rpc.invoice(10**4, '1', 'no_1')
l1.rpc.pay(inv['bolt11'])

# l2 attempts to close a channel that it leased, should succeed
# (channel isnt leased)
l2.rpc.close(l1.get_channel_scid(l2))
l1.daemon.wait_for_log('State changed from CLOSINGD_SIGEXCHANGE to CLOSINGD_COMPLETE')


@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_multi(node_factory, bitcoind, chainparams):
Expand Down Expand Up @@ -1047,6 +1126,7 @@ def test_funder_options(node_factory, bitcoind):
assert funder_opts['reserve_tank_msat'] == Millisatoshi('0msat')
assert funder_opts['fuzz_percent'] == 0
assert funder_opts['fund_probability'] == 100
assert funder_opts['leases_only']

# l2 funds a chanenl with us. We don't contribute
l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
Expand All @@ -1066,7 +1146,8 @@ def test_funder_options(node_factory, bitcoind):
'per_channel_max_msat': '10000000000msat',
'reserve_tank_msat': '3000000msat',
'fund_probability': 99,
'fuzz_percent': 0})
'fuzz_percent': 0,
'leases_only': False})

assert funder_opts['policy'] == 'available'
assert funder_opts['policy_mod'] == 100
Expand Down Expand Up @@ -1126,7 +1207,8 @@ def test_funder_contribution_limits(node_factory, bitcoind):
'min_their_funding_msat': '1000msat',
'per_channel_min_msat': '1000000msat',
'fund_probability': 100,
'fuzz_percent': 0})
'fuzz_percent': 0,
'leases_only': False})

# Set our contribution to 50k sat, should only use 7 of 12 available utxos
l3.rpc.call('funderupdate',
Expand All @@ -1136,7 +1218,8 @@ def test_funder_contribution_limits(node_factory, bitcoind):
'per_channel_min_msat': '1000sat',
'per_channel_max_msat': '500000sat',
'fund_probability': 100,
'fuzz_percent': 0})
'fuzz_percent': 0,
'leases_only': False})

l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l1.fundchannel(l2, 10**7)
Expand Down
7 changes: 7 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ def move_matches(exp, mv):
return True


def calc_lease_fee(amt, feerate, rates):
fee = rates['lease_fee_base_msat']
fee += amt * rates['lease_fee_basis'] // 10
fee += rates['funding_weight'] * feerate
return fee


def check_coin_moves(n, account_id, expected_moves, chainparams):
moves = n.rpc.call('listcoinmoves_plugin')['coin_moves']
node_id = n.info['id']
Expand Down
2 changes: 1 addition & 1 deletion wallet/db_postgres_sqlgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wallet/db_sqlite3_sqlgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wallet/statements_gettextgen.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ static bool deep_enough(u32 maxheight, const struct utxo *utxo,
if (utxo->close_info) {
u32 csv_free = *utxo->blockheight + utxo->close_info->csv;
assert(csv_free > *utxo->blockheight);
if (csv_free < current_blockheight)
if (current_blockheight < csv_free)
return false;
}
return *utxo->blockheight <= maxheight;
Expand Down

0 comments on commit f0a7cfd

Please sign in to comment.