sendcustommsg: promote to non-dev

Enable non-dev builds to send custom messages.

Preserves 'dev-' for compat-enabled builds.

Changelog-Changed: JSON-RPC: moved dev-sendcustommsg to sendcustommsg
This commit is contained in:
niftynei 2021-07-13 16:04:30 -05:00 committed by neil saitug
parent 28553e9bea
commit 8654c817da
18 changed files with 51 additions and 81 deletions

View file

@ -75,7 +75,7 @@ endif
ifeq ($(COMPAT),1)
# We support compatibility with pre-0.6.
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1 -DCOMPAT_V072=1 -DCOMPAT_V073=1 -DCOMPAT_V080=1 -DCOMPAT_V081=1 -DCOMPAT_V082=1 -DCOMPAT_V090=1
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1 -DCOMPAT_V072=1 -DCOMPAT_V073=1 -DCOMPAT_V080=1 -DCOMPAT_V081=1 -DCOMPAT_V082=1 -DCOMPAT_V090=1 -DCOMPAT_V0100=1
endif
# (method=thread to support xdist)

View file

@ -1944,7 +1944,6 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
*/
static bool channeld_handle_custommsg(const u8 *msg)
{
#if DEVELOPER
enum peer_wire type = fromwire_peektype(msg);
if (type % 2 == 1 && !peer_wire_is_defined(type)) {
/* The message is not part of the messages we know how to
@ -1955,9 +1954,6 @@ static bool channeld_handle_custommsg(const u8 *msg)
} else {
return false;
}
#else
return false;
#endif
}
static void handle_unexpected_tx_sigs(struct peer *peer, const u8 *msg)
@ -3305,17 +3301,6 @@ static void handle_dev_memleak(struct peer *peer, const u8 *msg)
found_leak)));
}
/* We were told to send a custommsg to the peer by `lightningd`. All the
* verification is done on the side of `lightningd` so we should be good to
* just forward it here. */
static void channeld_send_custommsg(struct peer *peer, const u8 *msg)
{
u8 *inner;
if (!fromwire_custommsg_out(tmpctx, msg, &inner))
master_badmsg(WIRE_CUSTOMMSG_OUT, msg);
sync_crypto_write(peer->pps, take(inner));
}
#if EXPERIMENTAL_FEATURES
static void handle_dev_quiesce(struct peer *peer, const u8 *msg)
{
@ -3333,6 +3318,17 @@ static void handle_dev_quiesce(struct peer *peer, const u8 *msg)
#endif /* EXPERIMENTAL_FEATURES */
#endif /* DEVELOPER */
/* We were told to send a custommsg to the peer by `lightningd`. All the
* verification is done on the side of `lightningd` so we should be good to
* just forward it here. */
static void channeld_send_custommsg(struct peer *peer, const u8 *msg)
{
u8 *inner;
if (!fromwire_custommsg_out(tmpctx, msg, &inner))
master_badmsg(WIRE_CUSTOMMSG_OUT, msg);
sync_crypto_write(peer->pps, take(inner));
}
static void req_in(struct peer *peer, const u8 *msg)
{
enum channeld_wire t = fromwire_peektype(msg);
@ -3412,13 +3408,9 @@ static void req_in(struct peer *peer, const u8 *msg)
/* Now handle common messages. */
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_OUT:
channeld_send_custommsg(peer, msg);
return;
#else
case WIRE_CUSTOMMSG_OUT:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_IN:
break;

View file

@ -114,7 +114,6 @@ static u8 *closing_read_peer_msg(const tal_t *ctx,
handle_gossip_msg(pps, take(msg));
continue;
}
#if DEVELOPER
/* Handle custommsgs */
enum peer_wire type = fromwire_peektype(msg);
if (type % 2 == 1 && !peer_wire_is_defined(type)) {
@ -124,7 +123,6 @@ static u8 *closing_read_peer_msg(const tal_t *ctx,
wire_sync_write(REQ_FD, take(towire_custommsg_in(NULL, msg)));
continue;
}
#endif
if (!handle_peer_gossip_or_error(pps, channel_id, false, msg))
return msg;
}

View file

@ -20,7 +20,6 @@ MANPAGES := doc/lightning-cli.1 \
doc/lightning-delexpiredinvoice.7 \
doc/lightning-delinvoice.7 \
doc/lightning-delpay.7 \
doc/lightning-dev-sendcustommsg.7 \
doc/lightning-disableoffer.7 \
doc/lightning-disconnect.7 \
doc/lightning-feerates.7 \
@ -62,6 +61,7 @@ MANPAGES := doc/lightning-cli.1 \
doc/lightning-sendonionmessage.7 \
doc/lightning-sendpay.7 \
doc/lightning-setchannelfee.7 \
doc/lightning-sendcustommsg.7 \
doc/lightning-signmessage.7 \
doc/lightning-txprepare.7 \
doc/lightning-txdiscard.7 \

View file

@ -1462,7 +1462,7 @@ will be respected. Others will be ignored and a warning will be logged.
### `custommsg`
The `custommsg` plugin hook is the receiving counterpart to the
[`dev-sendcustommsg`][sendcustommsg] RPC method and allows plugins to handle
[`sendcustommsg`][sendcustommsg] RPC method and allows plugins to handle
messages that are not handled internally. The goal of these two components is
to allow the implementation of custom protocols or prototypes on top of a
c-lightning node, without having to change the node's implementation itself.
@ -1610,7 +1610,7 @@ The plugin must broadcast it and respond with the following fields:
[bolt4-failure-messages]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#failure-messages
[bolt4-failure-onion]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#returning-errors
[bolt2-open-channel]: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md#the-open_channel-message
[sendcustommsg]: lightning-dev-sendcustommsg.7.html
[sendcustommsg]: lightning-sendcustommsg.7.html
[oddok]: https://github.com/lightningnetwork/lightning-rfc/blob/master/00-introduction.md#its-ok-to-be-odd
[spec]: [https://github.com/lightningnetwork/lightning-rfc]
[bolt9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md

View file

@ -43,7 +43,6 @@ c-lightning Documentation
lightning-delexpiredinvoice <lightning-delexpiredinvoice.7.md>
lightning-delinvoice <lightning-delinvoice.7.md>
lightning-delpay <lightning-delpay.7.md>
lightning-dev-sendcustommsg <lightning-dev-sendcustommsg.7.md>
lightning-disableoffer <lightning-disableoffer.7.md>
lightning-disconnect <lightning-disconnect.7.md>
lightning-feerates <lightning-feerates.7.md>
@ -87,6 +86,7 @@ c-lightning Documentation
lightning-ping <lightning-ping.7.md>
lightning-plugin <lightning-plugin.7.md>
lightning-reserveinputs <lightning-reserveinputs.7.md>
lightning-sendcustommsg <lightning-sendcustommsg.7.md>
lightning-sendinvoice <lightning-sendinvoice.7.md>
lightning-sendonion <lightning-sendonion.7.md>
lightning-sendonionmessage <lightning-sendonionmessage.7.md>

View file

@ -1,13 +1,13 @@
.TH "LIGHTNING-DEV-SENDCUSTOMMSG" "7" "" "" "lightning-dev-sendcustommsg"
.TH "LIGHTNING-SENDCUSTOMMSG" "7" "" "" "lightning-sendcustommsg"
.SH NAME
lightning-dev-sendcustommsg - Low-level interface to send protocol messages to peers
lightning-sendcustommsg - Low-level interface to send protocol messages to peers
.SH SYNOPSIS
\fBdev-sendcustommsg\fR \fInode_id\fR \fImsg\fR
\fBsendcustommsg\fR \fInode_id\fR \fImsg\fR
.SH DESCRIPTION
The \fBdev-sendcustommsg\fR RPC method allows the user to inject a custom message
The \fBsendcustommsg\fR RPC method allows the user to inject a custom message
into the communication with the peer with the given \fBnode_id\fR\. This is
intended as a low-level interface to implement custom protocol extensions on
top, not for direct use by end-users\.
@ -68,4 +68,4 @@ Christian Decker \fI<decker.christian@gmail.com\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:facefdc47adcbf0342f6e359d4752b8ab1b9a7ed2d6b466c9d202939fae5019e
\" SHA256STAMP:ff2ed61f688613b74885b9cccdf58187453d012ca2f3ae149c80b68679ef0a8e

View file

@ -1,15 +1,15 @@
lightning-dev-sendcustommsg -- Low-level interface to send protocol messages to peers
lightning-sendcustommsg -- Low-level interface to send protocol messages to peers
=====================================================================================
SYNOPSIS
--------
**dev-sendcustommsg** *node_id* *msg*
**sendcustommsg** *node_id* *msg*
DESCRIPTION
-----------
The `dev-sendcustommsg` RPC method allows the user to inject a custom message
The `sendcustommsg` RPC method allows the user to inject a custom message
into the communication with the peer with the given `node_id`. This is
intended as a low-level interface to implement custom protocol extensions on
top, not for direct use by end-users.

View file

@ -464,13 +464,9 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
}
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_IN:
handle_custommsg_in(sd->ld, sd->node_id, msg);
break;
#else
case WIRE_CUSTOMMSG_IN:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_OUT:
break;

View file

@ -177,13 +177,9 @@ static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds UNUSE
}
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_IN:
handle_custommsg_in(sd->ld, sd->node_id, msg);
break;
#else
case WIRE_CUSTOMMSG_IN:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_OUT:
break;

View file

@ -2751,13 +2751,9 @@ static unsigned int dual_opend_msg(struct subd *dualopend,
}
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_IN:
handle_custommsg_in(dualopend->ld, dualopend->node_id, msg);
return 0;
#else
case WIRE_CUSTOMMSG_IN:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_OUT:
break;

View file

@ -892,13 +892,9 @@ static unsigned int openingd_msg(struct subd *openingd,
}
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_IN:
handle_custommsg_in(openingd->ld, openingd->node_id, msg);
return 0;
#else
case WIRE_CUSTOMMSG_IN:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_OUT:
break;

View file

@ -2780,6 +2780,8 @@ void peer_dev_memleak(struct command *cmd)
peer_memleak_req_next(cmd, NULL);
}
#endif /* DEVELOPER */
struct custommsg_payload {
struct node_id peer_id;
const u8 *msg;
@ -2964,6 +2966,18 @@ static struct command_result *json_sendcustommsg(struct command *cmd,
}
static const struct json_command sendcustommsg_command = {
"sendcustommsg",
"utility",
json_sendcustommsg,
"Send a custom message to the peer with the given {node_id}",
.verbose = "sendcustommsg node_id hexcustommsg",
};
AUTODATA(json_command, &sendcustommsg_command);
#ifdef COMPAT_V0100
#ifdef DEVELOPER
static const struct json_command dev_sendcustommsg_command = {
"dev-sendcustommsg",
"utility",
json_sendcustommsg,
@ -2971,7 +2985,6 @@ static const struct json_command sendcustommsg_command = {
.verbose = "dev-sendcustommsg node_id hexcustommsg",
};
AUTODATA(json_command, &sendcustommsg_command);
#endif /* DEVELOPER */
AUTODATA(json_command, &dev_sendcustommsg_command);
#endif /* DEVELOPER */
#endif /* COMPAT_V0100 */

View file

@ -100,9 +100,10 @@ struct htlc_in_map *load_channels_from_wallet(struct lightningd *ld);
#if DEVELOPER
void peer_dev_memleak(struct command *cmd);
#endif /* DEVELOPER */
void handle_custommsg_in(struct lightningd *ld, const struct node_id *peer_id,
const u8 *msg);
#endif /* DEVELOPER */
/* Triggered at each new block. */
void waitblockheight_notify_new_block(struct lightningd *ld,

View file

@ -851,6 +851,7 @@ static void handle_dev_memleak(struct state *state, const u8 *msg)
take(towire_dualopend_dev_memleak_reply(NULL,
found_leak)));
}
#endif /* DEVELOPER */
/* We were told to send a custommsg to the peer by `lightningd`. All the
* verification is done on the side of `lightningd` so we should be good to
@ -862,7 +863,6 @@ static void dualopend_send_custommsg(struct state *state, const u8 *msg)
master_badmsg(WIRE_CUSTOMMSG_OUT, msg);
sync_crypto_write(state->pps, take(inner));
}
#endif
static u8 *psbt_to_tx_sigs_msg(const tal_t *ctx,
struct state *state,
@ -3079,7 +3079,6 @@ static void try_read_gossip_store(struct state *state)
*/
static bool dualopend_handle_custommsg(const u8 *msg)
{
#if DEVELOPER
enum peer_wire type = fromwire_peektype(msg);
if (type % 2 == 1 && !peer_wire_is_defined(type)) {
/* The message is not part of the messages we know how to
@ -3090,9 +3089,6 @@ static bool dualopend_handle_custommsg(const u8 *msg)
} else {
return false;
}
#else
return false;
#endif
}
/* BOLT #2:
@ -3320,13 +3316,8 @@ static u8 *handle_master_in(struct state *state)
/* Now handle common messages. */
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_OUT:
dualopend_send_custommsg(state, msg);
#else
return NULL;
case WIRE_CUSTOMMSG_OUT:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_IN:
break;
@ -3407,7 +3398,6 @@ static u8 *handle_peer_in(struct state *state)
break;
}
#if DEVELOPER
/* Handle custommsgs */
enum peer_wire type = fromwire_peektype(msg);
if (type % 2 == 1 && !peer_wire_is_defined(type)) {
@ -3417,7 +3407,6 @@ static u8 *handle_peer_in(struct state *state)
wire_sync_write(REQ_FD, take(towire_custommsg_in(NULL, msg)));
return NULL;
}
#endif
/* Handles standard cases, and legal unknown ones. */
if (handle_peer_gossip_or_error(state->pps,

View file

@ -1154,7 +1154,6 @@ static u8 *handle_peer_in(struct state *state)
if (t == WIRE_OPEN_CHANNEL)
return fundee_channel(state, msg);
#if DEVELOPER
/* Handle custommsgs */
enum peer_wire type = fromwire_peektype(msg);
if (type % 2 == 1 && !peer_wire_is_defined(type)) {
@ -1164,7 +1163,6 @@ static u8 *handle_peer_in(struct state *state)
wire_sync_write(REQ_FD, take(towire_custommsg_in(NULL, msg)));
return NULL;
}
#endif
/* Handles standard cases, and legal unknown ones. */
if (handle_peer_gossip_or_error(state->pps,
@ -1229,6 +1227,7 @@ static void handle_dev_memleak(struct state *state, const u8 *msg)
take(towire_openingd_dev_memleak_reply(NULL,
found_leak)));
}
#endif /* DEVELOPER */
/* We were told to send a custommsg to the peer by `lightningd`. All the
* verification is done on the side of `lightningd` so we should be good to
@ -1240,7 +1239,6 @@ static void openingd_send_custommsg(struct state *state, const u8 *msg)
master_badmsg(WIRE_CUSTOMMSG_OUT, msg);
sync_crypto_write(state->pps, take(inner));
}
#endif /* DEVELOPER */
/* Standard lightningd-fd-is-ready-to-read demux code. Again, we could hang
* here, but if we can't trust our parent, who can we trust? */
@ -1302,13 +1300,9 @@ static u8 *handle_master_in(struct state *state)
/* Now handle common messages. */
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_OUT:
openingd_send_custommsg(state, msg);
return NULL;
#else
case WIRE_CUSTOMMSG_OUT:
#endif
/* We send these. */
case WIRE_CUSTOMMSG_IN:
break;

View file

@ -2237,7 +2237,6 @@ def test_waitblockheight(node_factory, executor, bitcoind):
fut2.result(5)
@pytest.mark.developer("Needs dev-sendcustommsg")
def test_sendcustommsg(node_factory):
"""Check that we can send custommsgs to peers in various states.
@ -2261,27 +2260,27 @@ def test_sendcustommsg(node_factory):
# a message to it.
node_id = '02df5ffe895c778e10f7742a6c5b8a0cefbe9465df58b92fadeb883752c8107c8f'
with pytest.raises(RpcError, match=r'No such peer'):
l1.rpc.dev_sendcustommsg(node_id, msg)
l1.rpc.sendcustommsg(node_id, msg)
# `l3` is disconnected and we can't send messages to it
assert(not l2.rpc.listpeers(l3.info['id'])['peers'][0]['connected'])
with pytest.raises(RpcError, match=r'Peer is not connected'):
l2.rpc.dev_sendcustommsg(l3.info['id'], msg)
l2.rpc.sendcustommsg(l3.info['id'], msg)
# We should not be able to send a bogus `ping` message, since it collides
# with a message defined in the spec, and could potentially mess up our
# internal state.
with pytest.raises(RpcError, match=r'Cannot send messages of type 18 .WIRE_PING.'):
l2.rpc.dev_sendcustommsg(l2.info['id'], r'0012')
l2.rpc.sendcustommsg(l2.info['id'], r'0012')
# The sendcustommsg RPC call is currently limited to odd-typed messages,
# since they will not result in disconnections or even worse channel
# failures.
with pytest.raises(RpcError, match=r'Cannot send even-typed [0-9]+ custom message'):
l2.rpc.dev_sendcustommsg(l2.info['id'], r'00FE')
l2.rpc.sendcustommsg(l2.info['id'], r'00FE')
# This should work since the peer is currently owned by `channeld`
l2.rpc.dev_sendcustommsg(l1.info['id'], msg)
l2.rpc.sendcustommsg(l1.info['id'], msg)
l2.daemon.wait_for_log(
r'{peer_id}-{owner}-chan#[0-9]: \[OUT\] {msg}'.format(
owner='channeld', msg=msg, peer_id=l1.info['id']
@ -2296,7 +2295,7 @@ def test_sendcustommsg(node_factory):
])
# This should work since the peer is currently owned by `openingd`
l2.rpc.dev_sendcustommsg(l4.info['id'], msg)
l2.rpc.sendcustommsg(l4.info['id'], msg)
l2.daemon.wait_for_log(
r'{peer_id}-{owner}-chan#[0-9]: \[OUT\] {msg}'.format(
owner='openingd', msg=msg, peer_id=l4.info['id']