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

feat: fees on listpeers rpc output #4247

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions doc/lightning-listpeers.7

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

7 changes: 6 additions & 1 deletion doc/lightning-listpeers.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ The objects in the *channels* array will have at least these fields:
a number followed by a string unit.
* *total\_msat*: A string describing the total capacity of the channel;
a number followed by a string unit.
* *fee_base_msat*: The fixed routing fee we charge for forwards going out over
this channel, regardless of payment size.
* *fee_proportional_millionths*: The proportional routing fees in ppm (parts-
per-millionths) we charge for forwards going out over this channel.
* *features*: An array of feature names supported by this channel.

These fields may exist if the channel has gotten beyond the `"OPENINGD"`
Expand Down Expand Up @@ -238,7 +242,8 @@ Michael Hawkins <<michael.hawkins@protonmail.com>>.
SEE ALSO
--------

lightning-connect(7), lightning-fundchannel\_start(7)
lightning-connect(7), lightning-fundchannel\_start(7),
lightning-setchannelfee(7)

RESOURCES
---------
Expand Down
6 changes: 6 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,12 @@ static void json_add_channel(struct lightningd *ld,
json_add_amount_msat_compat(response, funding_msat,
"msatoshi_total", "total_msat");

/* routing fees */
json_add_amount_msat_only(response, "fee_base_msat",
amount_msat(channel->feerate_base));
json_add_u32(response, "fee_proportional_millionths",
channel->feerate_ppm);

/* channel config */
json_add_amount_sat_compat(response,
channel->our_config.dust_limit,
Expand Down
6 changes: 6 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ void json_add_amount_msat_compat(struct json_stream *result UNNEEDED,
const char *msatfieldname)

{ fprintf(stderr, "json_add_amount_msat_compat called!\n"); abort(); }
/* Generated stub for json_add_amount_msat_only */
void json_add_amount_msat_only(struct json_stream *result UNNEEDED,
const char *msatfieldname UNNEEDED,
struct amount_msat msat)

{ fprintf(stderr, "json_add_amount_msat_only called!\n"); abort(); }
/* Generated stub for json_add_amount_sat_compat */
void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
struct amount_sat sat UNNEEDED,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,9 @@ def test_setchannelfee_usage(node_factory, bitcoind):
# - check values in local nodes listchannels output
# - json throws exception on negative values
# - checks if peer id can be used instead of scid
# - checks fee_base_msat and fee_proportional_millionths in `listpeers` out
DEF_BASE = 10
DEF_BASE_MSAT = Millisatoshi(DEF_BASE)
DEF_PPM = 100

l1, l2, l3 = node_factory.get_nodes(3,
Expand All @@ -1852,6 +1854,10 @@ def channel_get_fees(scid):
db_fees = l1.db_query('SELECT feerate_base, feerate_ppm FROM channels;')
assert(db_fees[0]['feerate_base'] == DEF_BASE)
assert(db_fees[0]['feerate_ppm'] == DEF_PPM)
# this is also what listpeers should return
peers = l1.rpc.listpeers()['peers']
assert peers[0]['channels'][0]['fee_base_msat'] == DEF_BASE_MSAT
assert peers[0]['channels'][0]['fee_proportional_millionths'] == DEF_PPM

# custom setchannelfee scid <base> <ppm>
result = l1.rpc.setchannelfee(scid, 1337, 137)
Expand All @@ -1868,6 +1874,10 @@ def channel_get_fees(scid):
db_fees = channel_get_fees(scid)
assert(db_fees[0]['feerate_base'] == 1337)
assert(db_fees[0]['feerate_ppm'] == 137)
# also check for updated values in `listpeers`
peers = l1.rpc.listpeers()['peers']
assert peers[0]['channels'][0]['fee_base_msat'] == Millisatoshi(1337)
assert peers[0]['channels'][0]['fee_proportional_millionths'] == 137

# wait for gossip and check if l1 sees new fees in listchannels
wait_for(lambda: [c['base_fee_millisatoshi'] for c in l1.rpc.listchannels(scid)['channels']] == [DEF_BASE, 1337])
Expand Down Expand Up @@ -1899,6 +1909,10 @@ def channel_get_fees(scid):
db_fees = channel_get_fees(scid)
assert(db_fees[0]['feerate_base'] == 0)
assert(db_fees[0]['feerate_ppm'] == 0)
# also check for updated values in `listpeers`
peers = l1.rpc.listpeers()['peers']
assert peers[0]['channels'][0]['fee_base_msat'] == Millisatoshi(0)
assert peers[0]['channels'][0]['fee_proportional_millionths'] == 0

# disable and check for global values to be returned
result = l1.rpc.setchannelfee(scid)
Expand All @@ -1908,6 +1922,10 @@ def channel_get_fees(scid):
db_fees = channel_get_fees(scid)
assert(db_fees[0]['feerate_base'] == DEF_BASE)
assert(db_fees[0]['feerate_ppm'] == DEF_PPM)
# also check for updated values in `listpeers`
peers = l1.rpc.listpeers()['peers']
assert peers[0]['channels'][0]['fee_base_msat'] == DEF_BASE_MSAT
assert peers[0]['channels'][0]['fee_proportional_millionths'] == DEF_PPM

# check also peer id can be used
result = l1.rpc.setchannelfee(l2.info['id'], 42, 43)
Expand Down