listpeers: clean up JSON output.

In general, it's better to omit a field than put in a 'null', and
putting variable-named fields in an object is also a bad idea.

This is reflected in how hard this is to express in JSON schema, too.

Others:
1. Remove the obsolete "funding": "LOCAL" from unopened channels, but add
   "opener": "local" as used in normal channels.
2. htlc cltv_expiry is a u16.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `listfunds` `channels` `funding_allocation_msat` and `funding_msat`: use `funding`.
Changelog-Deprecated: JSON-RPC: `listfunds` `channels` `last_tx_fee`: use `last_tx_fee_msat`.
Changelog-Deprecated: JSON-RPC: `listfunds` `channels` `closer` is now omitted if it does not apply, not JSON `null`.
This commit is contained in:
Rusty Russell
2021-06-16 10:30:17 +09:30
parent edee0793d3
commit d8136d856b
4 changed files with 34 additions and 24 deletions

View File

@@ -51,7 +51,7 @@ void json_add_uncommitted_channel(struct json_stream *response,
json_object_start(response, NULL);
json_add_string(response, "state", "OPENINGD");
json_add_string(response, "owner", "lightning_openingd");
json_add_string(response, "funding", "LOCAL");
json_add_string(response, "opener", "local");
if (uc->transient_billboard) {
json_array_start(response, "status");
json_add_string(response, NULL, uc->transient_billboard);

View File

@@ -498,7 +498,7 @@ static void json_add_htlcs(struct lightningd *ld,
json_add_u64(response, "id", hin->key.id);
json_add_amount_msat_compat(response, hin->msat,
"msatoshi", "amount_msat");
json_add_u64(response, "expiry", hin->cltv_expiry);
json_add_u32(response, "expiry", hin->cltv_expiry);
json_add_sha256(response, "payment_hash", &hin->payment_hash);
json_add_string(response, "state",
htlc_state_name(hin->hstate));
@@ -744,8 +744,11 @@ static void json_add_channel(struct lightningd *ld,
bitcoin_txid(channel->last_tx, &txid);
json_add_txid(response, "scratch_txid", &txid);
if (deprecated_apis)
json_add_amount_sat_only(response, "last_tx_fee",
bitcoin_tx_compute_fee(channel->last_tx));
json_add_amount_sat_only(response, "last_tx_fee_msat",
bitcoin_tx_compute_fee(channel->last_tx));
}
json_object_start(response, "feerate");
@@ -847,7 +850,7 @@ static void json_add_channel(struct lightningd *ld,
if (channel->closer != NUM_SIDES)
json_add_string(response, "closer", channel->closer == LOCAL ?
"local" : "remote");
else
else if (deprecated_apis)
json_add_null(response, "closer");
json_array_start(response, "features");
@@ -882,6 +885,7 @@ static void json_add_channel(struct lightningd *ld,
our_msats = AMOUNT_MSAT(0);
}
if (deprecated_apis) {
json_object_start(response, "funding_allocation_msat");
json_add_u64(response, node_id_to_hexstr(tmpctx, &p->id),
peer_msats.millisatoshis); /* Raw: JSON field */
@@ -897,6 +901,12 @@ static void json_add_channel(struct lightningd *ld,
node_id_to_hexstr(tmpctx, &ld->id),
channel->our_funds);
json_object_end(response);
}
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_object_end(response);
if (!amount_sat_to_msat(&funding_msat, channel->funding)) {
log_broken(channel->log,

View File

@@ -1895,7 +1895,7 @@ def test_multifunding_feerates(node_factory, bitcoind):
assert only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['feerate']['perkw'] == commitment_tx_feerate_int
assert only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['feerate']['perkb'] == commitment_tx_feerate_int * 4
txfee = only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['last_tx_fee']
txfee = only_one(only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'])['last_tx_fee_msat']
# We get the expected close txid, force close the channel, then fish
# the details about the transaction out of the mempoool entry
@@ -1923,7 +1923,7 @@ def test_multifunding_feerates(node_factory, bitcoind):
expected_fee += 330
assert expected_fee == entry['fees']['base'] * 10 ** 8
assert Millisatoshi(str(expected_fee) + 'sat') == Millisatoshi(txfee)
assert Millisatoshi(str(expected_fee) + 'sat') == txfee
def test_multifunding_param_failures(node_factory):
@@ -3326,8 +3326,8 @@ 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_msat'][l1.info['id']] for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels'] if c['state'] == 'CHANNELD_NORMAL'][0]
assert Millisatoshi(amount) > Millisatoshi(str((1 << 24) - 1) + "sat")
amount = [c['funding']['local_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")
@pytest.mark.openchannel('v1')

View File

@@ -720,9 +720,9 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind):
# check channel 'opener' and 'closer' within this testcase ...
assert(l1.rpc.listpeers()['peers'][0]['channels'][0]['opener'] == 'local')
assert(l2.rpc.listpeers()['peers'][0]['channels'][0]['opener'] == 'remote')
# the 'closer' should be null initially
assert(l2.rpc.listpeers()['peers'][0]['channels'][0]['closer'] is None)
assert(l2.rpc.listpeers()['peers'][0]['channels'][0]['closer'] is None)
# the 'closer' should be missing initially
assert 'closer' not in l1.rpc.listpeers()['peers'][0]['channels'][0]
assert 'closer' not in l2.rpc.listpeers()['peers'][0]['channels'][0]
event1 = wait_for_event(l1)
event2 = wait_for_event(l2)