bkpr/listpeeers: add lease_fees back to funds; separate out in listpeers

First, how we record "our_funds" and then apply pushes vs lease_fees
(for liquidity ad buys/sales) was exactly opposite.

For pushes we were reporting the total funded into the channel, with the
push representing how much we'd later moved to the peer.

For lease_fees we were rerporting the total in the channel, with the
push representing how much was already moved to the peer.

We fix this (from a view perspective) by re-adding lease fees to what's
reported in the channel funding totals. Since this is now new behavior
(for leased channel values), we added new fields so we can take the old
field names thru a deprecation cycle.

We also make it possible to differentiate btw a push and a lease_fee
(before they were all the same), by adding to new fields to `listpeers`:
`fee_paid_msat` and `fee_rcvd_msat`.

This allows us to avoid math in the bookkeeper, instead we just pick
the numbers out directly and record them.

Fixes #5472

Changelog-Added: JSON-RPC: `listpeers` now has a few new fields for `funding` (`remote_funds_msat`, `local_funds_msat`, `fee_paid_msat`, `fee_rcvd_msat`).
Changelog-Deprecated: JSON-RPC: `listpeers`.`funded` fields `local_msat` and `remote_msat` are now deprecated.
This commit is contained in:
niftynei
2022-07-28 22:44:17 -05:00
committed by Rusty Russell
parent a675f4c24e
commit 4e503f7d0a
13 changed files with 646 additions and 364 deletions

View File

@@ -376,7 +376,10 @@ def test_v2_rbf_liquidity_ad(node_factory, bitcoind, chainparams):
# 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'])
assert Millisatoshi(amount * 1000) == fundings['remote_funds_msat']
assert Millisatoshi(est_fees + amount * 1000) == fundings['local_funds_msat']
assert Millisatoshi(est_fees) == fundings['fee_paid_msat']
assert 'fee_rcvd_msat' not in fundings
# rbf the lease with a higher amount
rate = int(find_next_feerate(l1, l2)[:-5])
@@ -406,7 +409,7 @@ def test_v2_rbf_liquidity_ad(node_factory, bitcoind, chainparams):
# 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'])
assert Millisatoshi(0) == Millisatoshi(fundings['remote_funds_msat'])
wait_for(lambda: [c['active'] for c in l1.rpc.listchannels(l1.get_channel_scid(l2))['channels']] == [True, True])
@@ -1103,8 +1106,8 @@ def test_funder_options(node_factory, bitcoind):
l2.fundchannel(l1, 10**6)
chan_info = only_one(only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['channels'])
# l1 contributed nothing
assert chan_info['funding']['remote_msat'] == Millisatoshi('0msat')
assert chan_info['funding']['local_msat'] != Millisatoshi('0msat')
assert chan_info['funding']['remote_funds_msat'] == Millisatoshi('0msat')
assert chan_info['funding']['local_funds_msat'] != Millisatoshi('0msat')
# Change all the options
funder_opts = l1.rpc.call('funderupdate',
@@ -1136,8 +1139,8 @@ def test_funder_options(node_factory, bitcoind):
l3.fundchannel(l1, 10**6)
chan_info = only_one(only_one(l3.rpc.listpeers(l1.info['id'])['peers'])['channels'])
# l1 contributed all its funds!
assert chan_info['funding']['remote_msat'] == Millisatoshi('9994255000msat')
assert chan_info['funding']['local_msat'] == Millisatoshi('1000000000msat')
assert chan_info['funding']['remote_funds_msat'] == Millisatoshi('9994255000msat')
assert chan_info['funding']['local_funds_msat'] == Millisatoshi('1000000000msat')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')