mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
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:
parent
a675f4c24e
commit
4e503f7d0a
13 changed files with 646 additions and 364 deletions
|
@ -752,8 +752,12 @@
|
|||
"ListPeers.peers[].channels[].feerate.perkw": 1
|
||||
},
|
||||
"ListpeersPeersChannelsFunding": {
|
||||
"ListPeers.peers[].channels[].funding.fee_paid_msat": 5,
|
||||
"ListPeers.peers[].channels[].funding.fee_rcvd_msat": 6,
|
||||
"ListPeers.peers[].channels[].funding.local_funds_msat": 4,
|
||||
"ListPeers.peers[].channels[].funding.local_msat": 1,
|
||||
"ListPeers.peers[].channels[].funding.pushed_msat": 3,
|
||||
"ListPeers.peers[].channels[].funding.remote_funds_msat": 7,
|
||||
"ListPeers.peers[].channels[].funding.remote_msat": 2
|
||||
},
|
||||
"ListpeersPeersChannelsHtlcs": {
|
||||
|
|
|
@ -232,9 +232,13 @@ message ListpeersPeersChannelsInflight {
|
|||
}
|
||||
|
||||
message ListpeersPeersChannelsFunding {
|
||||
Amount local_msat = 1;
|
||||
Amount remote_msat = 2;
|
||||
Amount pushed_msat = 3;
|
||||
optional Amount local_msat = 1;
|
||||
optional Amount remote_msat = 2;
|
||||
optional Amount pushed_msat = 3;
|
||||
Amount local_funds_msat = 4;
|
||||
Amount remote_funds_msat = 7;
|
||||
optional Amount fee_paid_msat = 5;
|
||||
optional Amount fee_rcvd_msat = 6;
|
||||
}
|
||||
|
||||
message ListpeersPeersChannelsAlias {
|
||||
|
|
|
@ -1097,12 +1097,20 @@ pub mod responses {
|
|||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct ListpeersPeersChannelsFunding {
|
||||
#[serde(alias = "local_msat")]
|
||||
pub local_msat: Amount,
|
||||
#[serde(alias = "remote_msat")]
|
||||
pub remote_msat: Amount,
|
||||
#[serde(alias = "pushed_msat")]
|
||||
pub pushed_msat: Amount,
|
||||
#[serde(alias = "local_msat", skip_serializing_if = "Option::is_none")]
|
||||
pub local_msat: Option<Amount>,
|
||||
#[serde(alias = "remote_msat", skip_serializing_if = "Option::is_none")]
|
||||
pub remote_msat: Option<Amount>,
|
||||
#[serde(alias = "pushed_msat", skip_serializing_if = "Option::is_none")]
|
||||
pub pushed_msat: Option<Amount>,
|
||||
#[serde(alias = "local_funds_msat")]
|
||||
pub local_funds_msat: Amount,
|
||||
#[serde(alias = "remote_funds_msat")]
|
||||
pub remote_funds_msat: Amount,
|
||||
#[serde(alias = "fee_paid_msat", skip_serializing_if = "Option::is_none")]
|
||||
pub fee_paid_msat: Option<Amount>,
|
||||
#[serde(alias = "fee_rcvd_msat", skip_serializing_if = "Option::is_none")]
|
||||
pub fee_rcvd_msat: Option<Amount>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
|
|
|
@ -102,6 +102,10 @@ def listpeers_peers_channels_funding2py(m):
|
|||
"local_msat": amount2msat(m.local_msat), # PrimitiveField in generate_composite
|
||||
"remote_msat": amount2msat(m.remote_msat), # PrimitiveField in generate_composite
|
||||
"pushed_msat": amount2msat(m.pushed_msat), # PrimitiveField in generate_composite
|
||||
"local_funds_msat": amount2msat(m.local_funds_msat), # PrimitiveField in generate_composite
|
||||
"remote_funds_msat": amount2msat(m.remote_funds_msat), # PrimitiveField in generate_composite
|
||||
"fee_paid_msat": amount2msat(m.fee_paid_msat), # PrimitiveField in generate_composite
|
||||
"fee_rcvd_msat": amount2msat(m.fee_rcvd_msat), # PrimitiveField in generate_composite
|
||||
})
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -71,9 +71,13 @@ On success, an object containing **peers** is returned. It is an array of objec
|
|||
- **private** (boolean, optional): if False, we will not announce this channel
|
||||
- **closer** (string, optional): Who initiated the channel close (one of "local", "remote")
|
||||
- **funding** (object, optional):
|
||||
- **local_msat** (msat): Amount of channel we funded
|
||||
- **remote_msat** (msat): Amount of channel they funded
|
||||
- **pushed_msat** (msat): Amount pushed from opener to peer
|
||||
- **local_funds_msat** (msat): Amount of channel we funded
|
||||
- **remote_funds_msat** (msat): Amount of channel they funded
|
||||
- **local_msat** (msat, optional): Amount of channel we funded (deprecated)
|
||||
- **remote_msat** (msat, optional): Amount of channel they funded (deprecated)
|
||||
- **pushed_msat** (msat, optional): Amount pushed from opener to peer
|
||||
- **fee_paid_msat** (msat, optional): Amount we paid peer at open
|
||||
- **fee_rcvd_msat** (msat, optional): Amount we were paid by peer at open
|
||||
- **to_us_msat** (msat, optional): how much of channel is owed to us
|
||||
- **min_to_us_msat** (msat, optional): least amount owed to us ever
|
||||
- **max_to_us_msat** (msat, optional): most amount owed to us ever
|
||||
|
@ -384,4 +388,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
|
|||
RFC site (BOLT \#9):
|
||||
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>
|
||||
|
||||
[comment]: # ( SHA256STAMP:c26d3094925387ee935efc6351400bca374c361e5956ff13f10b228773f8e389)
|
||||
[comment]: # ( SHA256STAMP:971c71befa1b6968a66b65e2aab4a2d1707f14c9af5d6ebc2dc00604d1d91294)
|
||||
|
|
|
@ -337,22 +337,37 @@
|
|||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"local_msat",
|
||||
"remote_msat",
|
||||
"pushed_msat"
|
||||
"local_funds_msat",
|
||||
"remote_funds_msat"
|
||||
],
|
||||
"properties": {
|
||||
"local_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount of channel we funded"
|
||||
"description": "Amount of channel we funded (deprecated)"
|
||||
},
|
||||
"remote_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount of channel they funded"
|
||||
"description": "Amount of channel they funded (deprecated)"
|
||||
},
|
||||
"pushed_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount pushed from opener to peer"
|
||||
},
|
||||
"local_funds_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount of channel we funded"
|
||||
},
|
||||
"remote_funds_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount of channel they funded"
|
||||
},
|
||||
"fee_paid_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount we paid peer at open"
|
||||
},
|
||||
"fee_rcvd_msat": {
|
||||
"type": "msat",
|
||||
"description": "Amount we were paid by peer at open"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -679,7 +679,7 @@ static void json_add_channel(struct lightningd *ld,
|
|||
const struct channel *channel)
|
||||
{
|
||||
struct channel_stats channel_stats;
|
||||
struct amount_msat funding_msat, peer_msats, our_msats;
|
||||
struct amount_msat funding_msat;
|
||||
struct amount_sat peer_funded_sats;
|
||||
struct state_change_entry *state_changes;
|
||||
u32 feerate;
|
||||
|
@ -831,25 +831,73 @@ static void json_add_channel(struct lightningd *ld,
|
|||
&channel->our_funds));
|
||||
peer_funded_sats = AMOUNT_SAT(0);
|
||||
}
|
||||
if (!amount_sat_to_msat(&peer_msats, peer_funded_sats)) {
|
||||
log_broken(channel->log,
|
||||
"Overflow converting peer sats %s to msat",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&peer_funded_sats));
|
||||
peer_msats = AMOUNT_MSAT(0);
|
||||
}
|
||||
if (!amount_sat_to_msat(&our_msats, channel->our_funds)) {
|
||||
log_broken(channel->log,
|
||||
"Overflow converting peer sats %s to msat",
|
||||
type_to_string(tmpctx, struct amount_sat,
|
||||
&channel->our_funds));
|
||||
our_msats = AMOUNT_MSAT(0);
|
||||
}
|
||||
|
||||
json_object_start(response, "funding");
|
||||
json_add_sat_only(response, "local_msat", channel->our_funds);
|
||||
json_add_sat_only(response, "remote_msat", peer_funded_sats);
|
||||
json_add_amount_msat_only(response, "pushed_msat", channel->push);
|
||||
|
||||
if (deprecated_apis) {
|
||||
json_add_sat_only(response, "local_msat", channel->our_funds);
|
||||
json_add_sat_only(response, "remote_msat", peer_funded_sats);
|
||||
json_add_amount_msat_only(response, "pushed_msat", channel->push);
|
||||
}
|
||||
|
||||
if (channel->lease_commit_sig) {
|
||||
struct amount_sat funds, total;
|
||||
if (!amount_msat_to_sat(&funds, channel->push)) {
|
||||
log_broken(channel->log,
|
||||
"Can't convert channel->push %s to sats"
|
||||
" (lease fees?)",
|
||||
type_to_string(tmpctx, struct amount_msat,
|
||||
&channel->push));
|
||||
funds = AMOUNT_SAT(0);
|
||||
}
|
||||
|
||||
if (channel->opener == LOCAL) {
|
||||
if (!amount_sat_add(&total, funds, channel->our_funds)) {
|
||||
log_broken(channel->log,
|
||||
"Overflow adding our_funds to push");
|
||||
total = channel->our_funds;
|
||||
}
|
||||
json_add_sat_only(response, "local_funds_msat", total);
|
||||
|
||||
if (!amount_sat_sub(&total, peer_funded_sats, funds)) {
|
||||
log_broken(channel->log,
|
||||
"Underflow sub'ing push from"
|
||||
" peer's funds");
|
||||
total = peer_funded_sats;
|
||||
}
|
||||
json_add_sat_only(response, "remote_funds_msat", total);
|
||||
|
||||
json_add_amount_msat_only(response, "fee_paid_msat",
|
||||
channel->push);
|
||||
} else {
|
||||
if (!amount_sat_add(&total, peer_funded_sats, funds)) {
|
||||
log_broken(channel->log,
|
||||
"Overflow adding peer funds to push");
|
||||
total = peer_funded_sats;
|
||||
}
|
||||
json_add_sat_only(response, "remote_funds_msat", total);
|
||||
|
||||
if (!amount_sat_sub(&total, channel->our_funds, funds)) {
|
||||
log_broken(channel->log,
|
||||
"Underflow sub'ing push from"
|
||||
" our_funds");
|
||||
total = channel->our_funds;
|
||||
}
|
||||
json_add_sat_only(response, "local_funds_msat", total);
|
||||
json_add_amount_msat_only(response, "fee_rcvd_msat",
|
||||
channel->push);
|
||||
}
|
||||
|
||||
} else {
|
||||
json_add_sat_only(response, "local_funds_msat",
|
||||
channel->our_funds);
|
||||
json_add_sat_only(response, "remote_funds_msat",
|
||||
peer_funded_sats);
|
||||
if (!deprecated_apis)
|
||||
json_add_amount_msat_only(response, "pushed_msat",
|
||||
channel->push);
|
||||
}
|
||||
|
||||
json_object_end(response);
|
||||
|
||||
if (!amount_sat_to_msat(&funding_msat, channel->funding_sats)) {
|
||||
|
|
|
@ -546,6 +546,62 @@ static void try_update_open_fees(struct command *cmd,
|
|||
|
||||
}
|
||||
|
||||
static void find_push_amts(const char *buf,
|
||||
const jsmntok_t *curr_chan,
|
||||
bool is_opener,
|
||||
struct amount_msat *push_credit,
|
||||
struct amount_msat *push_debit,
|
||||
bool *is_leased)
|
||||
{
|
||||
const char *err;
|
||||
struct amount_msat push_amt;
|
||||
|
||||
/* Try to pull out fee_rcvd_msat */
|
||||
err = json_scan(tmpctx, buf, curr_chan,
|
||||
"{funding:{fee_rcvd_msat:%}}",
|
||||
JSON_SCAN(json_to_msat,
|
||||
push_credit));
|
||||
|
||||
if (!err) {
|
||||
*is_leased = true;
|
||||
*push_debit = AMOUNT_MSAT(0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Try to pull out fee_paid_msat */
|
||||
err = json_scan(tmpctx, buf, curr_chan,
|
||||
"{funding:{fee_paid_msat:%}}",
|
||||
JSON_SCAN(json_to_msat,
|
||||
push_debit));
|
||||
if (!err) {
|
||||
*is_leased = true;
|
||||
*push_credit = AMOUNT_MSAT(0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Try to pull out pushed amt? */
|
||||
err = json_scan(tmpctx, buf, curr_chan,
|
||||
"{funding:{pushed_msat:%}}",
|
||||
JSON_SCAN(json_to_msat, &push_amt));
|
||||
|
||||
if (!err) {
|
||||
*is_leased = false;
|
||||
if (is_opener) {
|
||||
*push_credit = AMOUNT_MSAT(0);
|
||||
*push_debit = push_amt;
|
||||
} else {
|
||||
*push_credit = push_amt;
|
||||
*push_debit = AMOUNT_MSAT(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Nothing pushed nor fees paid */
|
||||
*is_leased = false;
|
||||
*push_credit = AMOUNT_MSAT(0);
|
||||
*push_debit = AMOUNT_MSAT(0);
|
||||
}
|
||||
|
||||
static bool new_missed_channel_account(struct command *cmd,
|
||||
const char *buf,
|
||||
const jsmntok_t *result,
|
||||
|
@ -579,26 +635,24 @@ static bool new_missed_channel_account(struct command *cmd,
|
|||
assert(chan_arr_tok->type == JSMN_ARRAY);
|
||||
json_for_each_arr(j, curr_chan, chan_arr_tok) {
|
||||
struct bitcoin_outpoint opt;
|
||||
struct amount_msat amt, remote_amt, push_amt,
|
||||
struct amount_msat amt, remote_amt,
|
||||
push_credit, push_debit;
|
||||
char *opener, *chan_id;
|
||||
enum mvt_tag *tags;
|
||||
bool ok;
|
||||
bool ok, is_opener, is_leased;
|
||||
|
||||
err = json_scan(tmpctx, buf, curr_chan,
|
||||
"{channel_id:%,"
|
||||
"funding_txid:%,"
|
||||
"funding_outnum:%,"
|
||||
"funding:{local_msat:%,"
|
||||
"remote_msat:%,"
|
||||
"pushed_msat:%},"
|
||||
"funding:{local_funds_msat:%,"
|
||||
"remote_funds_msat:%},"
|
||||
"opener:%}",
|
||||
JSON_SCAN_TAL(tmpctx, json_strdup, &chan_id),
|
||||
JSON_SCAN(json_to_txid, &opt.txid),
|
||||
JSON_SCAN(json_to_number, &opt.n),
|
||||
JSON_SCAN(json_to_msat, &amt),
|
||||
JSON_SCAN(json_to_msat, &remote_amt),
|
||||
JSON_SCAN(json_to_msat, &push_amt),
|
||||
JSON_SCAN_TAL(tmpctx, json_strdup, &opener));
|
||||
if (err)
|
||||
plugin_err(cmd->plugin,
|
||||
|
@ -615,7 +669,8 @@ static bool new_missed_channel_account(struct command *cmd,
|
|||
chain_ev = tal(cmd, struct chain_event);
|
||||
chain_ev->tag = mvt_tag_str(CHANNEL_OPEN);
|
||||
chain_ev->debit = AMOUNT_MSAT(0);
|
||||
ok = amount_msat_add(&chain_ev->output_value, amt, remote_amt);
|
||||
ok = amount_msat_add(&chain_ev->output_value,
|
||||
amt, remote_amt);
|
||||
assert(ok);
|
||||
chain_ev->currency = tal_strdup(chain_ev, currency);
|
||||
chain_ev->origin_acct = NULL;
|
||||
|
@ -633,24 +688,18 @@ static bool new_missed_channel_account(struct command *cmd,
|
|||
tags = tal_arr(chain_ev, enum mvt_tag, 1);
|
||||
tags[0] = CHANNEL_OPEN;
|
||||
|
||||
is_opener = streq(opener, "local");
|
||||
|
||||
/* Leased/pushed channels have some extra work */
|
||||
if (streq(opener, "local")) {
|
||||
tal_arr_expand(&tags, OPENER);
|
||||
ok = amount_msat_add(&amt, amt, push_amt);
|
||||
push_credit = AMOUNT_MSAT(0);
|
||||
push_debit = push_amt;
|
||||
} else {
|
||||
ok = amount_msat_sub(&amt, amt, push_amt);
|
||||
push_credit = push_amt;
|
||||
push_debit = AMOUNT_MSAT(0);
|
||||
}
|
||||
find_push_amts(buf, curr_chan, is_opener,
|
||||
&push_credit, &push_debit,
|
||||
&is_leased);
|
||||
|
||||
/* We assume pushes are all leases, even
|
||||
* though they might just be pushes */
|
||||
if (!amount_msat_zero(push_amt))
|
||||
if (is_leased)
|
||||
tal_arr_expand(&tags, LEASED);
|
||||
if (is_opener)
|
||||
tal_arr_expand(&tags, OPENER);
|
||||
|
||||
assert(ok);
|
||||
chain_ev->credit = amt;
|
||||
db_begin_transaction(db);
|
||||
if (!log_chain_event(db, acct, chain_ev))
|
||||
|
@ -668,12 +717,15 @@ static bool new_missed_channel_account(struct command *cmd,
|
|||
try_update_open_fees(cmd, acct);
|
||||
|
||||
/* We log a channel event for the push amt */
|
||||
if (!amount_msat_zero(push_amt)) {
|
||||
if (!amount_msat_zero(push_credit)
|
||||
|| !amount_msat_zero(push_debit)) {
|
||||
struct channel_event *chan_ev;
|
||||
char *chan_tag;
|
||||
|
||||
chan_tag = tal_fmt(tmpctx, "%s",
|
||||
mvt_tag_str(LEASE_FEE));
|
||||
mvt_tag_str(
|
||||
is_leased ?
|
||||
LEASE_FEE : PUSHED));
|
||||
|
||||
chan_ev = new_channel_event(tmpctx,
|
||||
chan_tag,
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from fixtures import * # noqa: F401,F403
|
||||
from decimal import Decimal
|
||||
from pyln.client import Millisatoshi, RpcError
|
||||
from pyln.client import Millisatoshi
|
||||
from fixtures import TEST_NETWORK
|
||||
from utils import (
|
||||
sync_blockheight, wait_for, only_one
|
||||
sync_blockheight, wait_for, only_one, first_channel_id
|
||||
)
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
import pytest
|
||||
import unittest
|
||||
|
@ -324,6 +325,144 @@ def test_bookkeeping_rbf_withdraw(node_factory, bitcoind):
|
|||
assert len(fees) == 1
|
||||
|
||||
|
||||
@pytest.mark.openchannel('v2')
|
||||
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "turns off bookkeeper at start")
|
||||
@unittest.skipIf(TEST_NETWORK != 'regtest', "network fees hardcoded")
|
||||
def test_bookkeeping_missed_chans_leases(node_factory, bitcoind):
|
||||
"""
|
||||
Test that a lease is correctly recorded if bookkeeper was off
|
||||
"""
|
||||
|
||||
coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py"
|
||||
opts = {'funder-policy': 'match', 'funder-policy-mod': 100,
|
||||
'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
|
||||
'plugin': str(coin_mvt_plugin),
|
||||
'disable-plugin': 'bookkeeper'}
|
||||
l1, l2 = node_factory.get_nodes(2, opts=opts)
|
||||
|
||||
open_amt = 500000
|
||||
feerate = 2000
|
||||
lease_fee = 6432000
|
||||
invoice_msat = 11000000
|
||||
|
||||
l1.fundwallet(open_amt * 1000)
|
||||
l2.fundwallet(open_amt * 1000)
|
||||
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
||||
|
||||
# l1 leases a channel from l2
|
||||
compact_lease = l2.rpc.funderupdate()['compact_lease']
|
||||
txid = l1.rpc.fundchannel(l2.info['id'], open_amt, request_amt=open_amt,
|
||||
feerate='{}perkw'.format(feerate),
|
||||
compact_lease=compact_lease)['txid']
|
||||
bitcoind.generate_block(1, wait_for_mempool=[txid])
|
||||
wait_for(lambda: l1.channel_state(l2) == 'CHANNELD_NORMAL')
|
||||
scid = l1.get_channel_scid(l2)
|
||||
l1.wait_channel_active(scid)
|
||||
channel_id = first_channel_id(l1, l2)
|
||||
|
||||
l1.pay(l2, invoice_msat)
|
||||
l1.daemon.wait_for_log(r'coin movement:.*\'invoice\'')
|
||||
|
||||
# Now turn the bookkeeper on and restart
|
||||
l1.stop()
|
||||
l2.stop()
|
||||
del l1.daemon.opts['disable-plugin']
|
||||
del l2.daemon.opts['disable-plugin']
|
||||
l1.start()
|
||||
l2.start()
|
||||
|
||||
# Wait for the balance snapshot to fire/finish
|
||||
l1.daemon.wait_for_log('Snapshot balances updated')
|
||||
l2.daemon.wait_for_log('Snapshot balances updated')
|
||||
|
||||
def _check_events(node, channel_id, exp_events):
|
||||
chan_events = [ev for ev in node.rpc.bkpr_listaccountevents()['events'] if ev['account'] == channel_id]
|
||||
assert len(chan_events) == len(exp_events)
|
||||
for ev, exp in zip(chan_events, exp_events):
|
||||
assert ev['tag'] == exp[0]
|
||||
assert ev['credit_msat'] == Millisatoshi(exp[1])
|
||||
assert ev['debit_msat'] == Millisatoshi(exp[2])
|
||||
|
||||
# l1 events
|
||||
exp_events = [('channel_open', open_amt * 1000 + lease_fee, 0),
|
||||
('onchain_fee', 1408000, 0),
|
||||
('lease_fee', 0, lease_fee),
|
||||
('journal_entry', 0, invoice_msat)]
|
||||
_check_events(l1, channel_id, exp_events)
|
||||
|
||||
exp_events = [('channel_open', open_amt * 1000, 0),
|
||||
('onchain_fee', 980000, 0),
|
||||
('lease_fee', lease_fee, 0),
|
||||
('journal_entry', invoice_msat, 0)]
|
||||
_check_events(l2, channel_id, exp_events)
|
||||
|
||||
|
||||
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "turns off bookkeeper at start")
|
||||
@unittest.skipIf(TEST_NETWORK != 'regtest', "network fees hardcoded")
|
||||
@pytest.mark.openchannel('v1', 'Uses push-msat')
|
||||
def test_bookkeeping_missed_chans_pushed(node_factory, bitcoind):
|
||||
"""
|
||||
Test for a push_msat value in a missed channel open.
|
||||
"""
|
||||
coin_mvt_plugin = Path(__file__).parent / "plugins" / "coin_movements.py"
|
||||
l1, l2 = node_factory.get_nodes(2, opts={'disable-plugin': 'bookkeeper',
|
||||
'plugin': str(coin_mvt_plugin)})
|
||||
|
||||
# Double check there's no bookkeeper plugin on
|
||||
assert l1.daemon.opts['disable-plugin'] == 'bookkeeper'
|
||||
assert l2.daemon.opts['disable-plugin'] == 'bookkeeper'
|
||||
|
||||
open_amt = 10**7
|
||||
push_amt = 10**6 * 1000
|
||||
invoice_msat = 11000000
|
||||
|
||||
l1.fundwallet(200000000)
|
||||
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
|
||||
txid = l1.rpc.fundchannel(l2.info['id'], open_amt, push_msat=push_amt)['txid']
|
||||
bitcoind.generate_block(1, wait_for_mempool=[txid])
|
||||
wait_for(lambda: l1.channel_state(l2) == 'CHANNELD_NORMAL')
|
||||
scid = l1.get_channel_scid(l2)
|
||||
l1.wait_channel_active(scid)
|
||||
channel_id = first_channel_id(l1, l2)
|
||||
|
||||
# Send l2 funds via the channel
|
||||
l1.pay(l2, invoice_msat)
|
||||
l1.daemon.wait_for_log(r'coin movement:.*\'invoice\'')
|
||||
|
||||
# Now turn the bookkeeper on and restart
|
||||
l1.stop()
|
||||
l2.stop()
|
||||
del l1.daemon.opts['disable-plugin']
|
||||
del l2.daemon.opts['disable-plugin']
|
||||
l1.start()
|
||||
l2.start()
|
||||
|
||||
# Wait for the balance snapshot to fire/finish
|
||||
l1.daemon.wait_for_log('Snapshot balances updated')
|
||||
l2.daemon.wait_for_log('Snapshot balances updated')
|
||||
|
||||
def _check_events(node, channel_id, exp_events):
|
||||
chan_events = [ev for ev in node.rpc.bkpr_listaccountevents()['events'] if ev['account'] == channel_id]
|
||||
assert len(chan_events) == len(exp_events)
|
||||
for ev, exp in zip(chan_events, exp_events):
|
||||
assert ev['tag'] == exp[0]
|
||||
assert ev['credit_msat'] == Millisatoshi(exp[1])
|
||||
assert ev['debit_msat'] == Millisatoshi(exp[2])
|
||||
|
||||
# l1 events
|
||||
exp_events = [('channel_open', open_amt * 1000, 0),
|
||||
('onchain_fee', 5257000, 0),
|
||||
('pushed', 0, push_amt),
|
||||
('journal_entry', 0, invoice_msat)]
|
||||
_check_events(l1, channel_id, exp_events)
|
||||
|
||||
# l2 events
|
||||
exp_events = [('channel_open', 0, 0),
|
||||
('pushed', push_amt, 0),
|
||||
('journal_entry', invoice_msat, 0)]
|
||||
_check_events(l2, channel_id, exp_events)
|
||||
|
||||
|
||||
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "turns off bookkeeper at start")
|
||||
def test_bookkeeping_onchaind_txs(node_factory, bitcoind):
|
||||
"""
|
||||
|
@ -336,8 +475,6 @@ def test_bookkeeping_onchaind_txs(node_factory, bitcoind):
|
|||
|
||||
# Double check there's no bookkeeper plugin on
|
||||
assert l1.daemon.opts['disable-plugin'] == 'bookkeeper'
|
||||
with pytest.raises(RpcError):
|
||||
l1.rpc.listincome()
|
||||
|
||||
# Send l2 funds via the channel
|
||||
l1.pay(l2, 11000000)
|
||||
|
|
|
@ -801,7 +801,9 @@ def test_channel_lease_post_expiry(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']
|
||||
|
||||
bitcoind.generate_block(6)
|
||||
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
|
||||
|
@ -925,7 +927,8 @@ def test_channel_lease_unilat_closes(node_factory, bitcoind):
|
|||
|
||||
# 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) == Millisatoshi(fundings['remote_funds_msat'])
|
||||
assert Millisatoshi(est_fees + amount * 1000) == Millisatoshi(fundings['local_funds_msat'])
|
||||
|
||||
bitcoind.generate_block(6)
|
||||
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
|
||||
|
|
|
@ -3391,7 +3391,7 @@ def test_wumbo_channels(node_factory, bitcoind):
|
|||
wait_for(lambda: 'CHANNELD_NORMAL' in [c['state'] for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels']])
|
||||
|
||||
# Exact amount depends on fees, but it will be wumbo!
|
||||
amount = [c['funding']['local_msat'] for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'] if c['state'] == 'CHANNELD_NORMAL'][0]
|
||||
amount = [c['funding']['local_funds_msat'] for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'] if c['state'] == 'CHANNELD_NORMAL'][0]
|
||||
assert amount > Millisatoshi(str((1 << 24) - 1) + "sat")
|
||||
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Reference in a new issue