Skip to content

Commit

Permalink
rust: autogenerate code from the new docs
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Dec 13, 2022
1 parent 0d93f84 commit c718593
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 420 deletions.
1 change: 0 additions & 1 deletion compile_commands.json

This file was deleted.

654 changes: 294 additions & 360 deletions contrib/pyln-testing/pyln/testing/node_pb2.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions doc/lightning-listpeerchannels.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ The objects in the *channels* array will have at least these fields:
peer, or a theft attempt).
* `"CLOSED"`: The channel closure has been confirmed deeply.
The channel will eventually be removed from this array.
* *state_changes*: An array of objects describing prior state change events.
* *state\_changes*: An array of objects describing prior state change events.
* *opener*: A string `"local"` or `"remote`" describing which side opened this
channel.
* *closer*: A string `"local"` or `"remote`" describing which side
Expand All @@ -186,9 +186,9 @@ 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
* *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-
* *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.

Expand Down Expand Up @@ -268,7 +268,7 @@ state, or in various circumstances:
your funds, if you close unilaterally.
* *max\_accepted\_htlcs*: The maximum number of HTLCs you will accept on
this channel.
* *in\_payments_offered*: The number of incoming HTLCs offered over this
* *in\_payments\_offered*: The number of incoming HTLCs offered over this
channel.
* *in\_offered\_msat*: A string describing the total amount of all incoming
HTLCs offered over this channel;
Expand All @@ -288,9 +288,9 @@ state, or in various circumstances:
* *out\_fulfilled\_msat*: A string describing the total amount of all
outgoing HTLCs offered *and successfully claimed* over this channel;
a number followed by a string unit.
* *scratch_txid*: The txid of the latest transaction (what we would sign and
* *scratch\_txid*: The txid of the latest transaction (what we would sign and
send to chain if the channel were to fail now).
* *last_tx_fee*: The fee on that latest transaction.
* *last\_tx\_fee*: The fee on that latest transaction.
* *feerate*: An object containing the latest feerate as both *perkw* and *perkb*.
* *htlcs*: An array of objects describing the HTLCs currently in-flight
in the channel.
Expand Down
32 changes: 15 additions & 17 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1910,9 +1910,22 @@ static void channel_watch_inflight(struct lightningd *ld,
funding_spent);
}


static void json_add_peerchannels(struct lightningd *ld,
struct json_stream *response,
struct peer *peer);
struct peer *peer)
{
struct channel *channel;
json_add_uncommitted_channel(response, peer);

list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
json_add_unsaved_channel(response, peer, channel);
else
json_add_channel(ld, response, NULL, peer, channel);
}
}


static void json_add_peer(struct lightningd *ld,
struct json_stream *response,
Expand Down Expand Up @@ -2043,21 +2056,6 @@ static const struct json_command staticbackup_command = {
AUTODATA(json_command, &staticbackup_command);


static void json_add_peerchannels(struct lightningd *ld,
struct json_stream *response,
struct peer *peer)
{
struct channel *channel;
json_add_uncommitted_channel(response, peer);

list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
json_add_unsaved_channel(response, peer, channel);
else
json_add_channel(ld, response, NULL, peer, channel);
}
}

static struct command_result *json_listpeerchannels(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
Expand All @@ -2067,7 +2065,7 @@ static struct command_result *json_listpeerchannels(struct command *cmd,
struct peer *peer;
struct json_stream *response;

/* FIME: filter by status */
/* FIXME(vincenzopalazzo): filter by status */
if (!param(cmd, buffer, params,
p_opt("id", param_node_id, &peer_id),
NULL))
Expand Down
5 changes: 2 additions & 3 deletions plugins/bkpr/bookkeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ static bool new_missed_channel_account(struct command *cmd,
const jsmntok_t *curr_chan, *chan_arr_tok;

chan_arr_tok = json_get_member(buf, result, "channels");
assert(chan_arr_tok && chan_arr_tok->type == JSMN_ARRAY);
assert(chan_arr_tok->type == JSMN_ARRAY);

json_for_each_arr(i, curr_chan, chan_arr_tok) {
struct bitcoin_outpoint opt;
Expand Down Expand Up @@ -907,7 +907,6 @@ static struct command_result *listpeerchannels_multi_done(struct command *cmd,
static char *do_account_close_checks(const tal_t *ctx,
struct chain_event *e,
struct account *acct)

{
struct account *closed_acct;

Expand Down Expand Up @@ -1545,7 +1544,7 @@ parse_and_log_chain_move(struct command *cmd,

plugin_log(cmd->plugin, LOG_DBG,
"channel event received but no open for channel %s."
" Calling `listpeerchannls` to fetch missing info",
" Calling `listpeerchannels` to fetch missing info",
acct->name);

info = tal(cmd, struct event_info);
Expand Down
6 changes: 2 additions & 4 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -2357,9 +2357,7 @@ local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer,
assert(channels);

json_for_each_arr(j, channel, channels) {
/* FIXME: we can skip the channel if the peer is not connected in this case? */
peer_connected = json_get_member(buffer, channel, "peer_connected");
assert(peer_connected);

struct channel_hint h;
spendsats = json_get_member(buffer, channel, "spendable_msat");
Expand Down Expand Up @@ -3294,9 +3292,9 @@ static struct listpeers_channel **json_listpeerchannels_to_listchannel(const tal
assert(channel);
tal_arr_expand(&channels, channel);
if (!peer_id)
peer_id = channel->peer_id;
peer_id = &channel->peer_id;
else
if (*single_peer && !node_id_eq(peer_id, channel->peer_id))
if (*single_peer && !node_id_eq(peer_id, &channel->peer_id))
*single_peer = false;
}

Expand Down
3 changes: 1 addition & 2 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1838,8 +1838,7 @@ struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,

json_to_bool(buffer, privtok, &chan->private);
json_to_bool(buffer, peer_connectedtok, &chan->peer_connected);
chan->peer_id = tal(chan, struct node_id);
json_to_node_id(buffer, peer_idtok, chan->peer_id);
json_to_node_id(buffer, peer_idtok, &chan->peer_id);
chan->state = json_strdup(chan, buffer, statetok);
json_to_txid(buffer, ftxidtok, &chan->funding_txid);
if (scidtok != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/libplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ struct listpeers_channel {
struct amount_msat total_msat;
struct amount_msat spendable_msat;
bool peer_connected;
struct node_id *peer_id;
struct node_id peer_id;
/* TODO Add fields as we need them. */
};

Expand Down
9 changes: 5 additions & 4 deletions plugins/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ static void json_add_halfchan(struct json_stream *response,
json_add_num(response, "message_flags", message_flags);
json_add_num(response, "channel_flags", channel_flags);

json_add_bool(response, "active", c->half[dir].enabled && !local_disable);
json_add_bool(response, "active",
c->half[dir].enabled && !local_disable);
json_add_num(response, "last_update", timestamp);
json_add_num(response, "base_fee_millisatoshi", fee_base_msat);
json_add_num(response, "fee_per_millionth",
Expand All @@ -292,13 +293,12 @@ struct listchannels_opts {
struct short_channel_id *scid;
};


/* We record which local channels are valid; we could record which are
* invalid, but our testsuite has some weirdness where it has local
* channels in the store it knows nothing about. */
static struct node_map *local_connected(const tal_t *ctx,
const char *buf,
const jsmntok_t *result)
const jsmntok_t *result)
{
size_t i;
const jsmntok_t *channel, *channels = json_get_member(buf, result, "channels");
Expand Down Expand Up @@ -375,7 +375,8 @@ static struct command_result *listpeerchannels_done(struct command *cmd,
for (size_t i = 0; i < dst->num_chans; i++) {
int dir;
c = gossmap_nth_chan(gossmap, dst, i, &dir);
json_add_halfchan(js, gossmap, connected, c, 1 << !dir);
json_add_halfchan(js, gossmap, connected,
c, 1 << !dir);
}
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion tests/test_bookkeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from db import Sqlite3Db
from fixtures import TEST_NETWORK
from utils import (
sync_blockheight, wait_for, only_one, first_channel_id, TIMEOUT
sync_blockheight, wait_for, only_one,
first_channel_id, TIMEOUT
)

from pathlib import Path
Expand Down
4 changes: 1 addition & 3 deletions tests/test_closing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
)

import os
import logging
import queue
import pytest
import re
Expand Down Expand Up @@ -1196,8 +1195,7 @@ def test_penalty_htlc_tx_fulfill(node_factory, bitcoind, chainparams):

# push some money so that 1 + 4 can both send htlcs
inv = l2.rpc.invoice(10**9 // 2, '1', 'balancer')
res = l1.rpc.pay(inv['bolt11'])
logging.info(f"Result pay command {res}")
l1.rpc.pay(inv['bolt11'])
l1.rpc.waitsendpay(inv['payment_hash'])

inv = l4.rpc.invoice(10**9 // 2, '1', 'balancer')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4302,5 +4302,5 @@ def test_peer_disconnected_reflected_in_channel_state(node_factory):
l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True})
l2.stop()

wait_for(lambda: only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'] is False)
wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['peer_connected'] is False)
assert only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'] is False
assert only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['peer_connected'] is False
16 changes: 0 additions & 16 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,3 @@ def scriptpubkey_addr(scriptpubkey):
# Modern bitcoin (at least, git master)
return scriptpubkey['address']
return None


def trace_pay_command(rpc_pay_call, node):
"""Utility function that run the function and prints information
about the channels, and payment status to catch some unrelated error
otherwise return the result of the lambda function.
"""
try:
return rpc_pay_call()
except RpcError as rpc_err:
# Enable the trace with --log-cli-level=INFO
# and void to put other info inside the normal console log.
logging.info(node.rpc.listfunds())
logging.info(node.rpc.paystatus())
logging.info(node.rpc.listpeerchannels())
raise rpc_err

0 comments on commit c718593

Please sign in to comment.