diff --git a/Makefile b/Makefile index 311541fdf..f0b72dd3d 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/channeld/channeld.c b/channeld/channeld.c index 362de09a3..dc614af9d 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -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; diff --git a/closingd/closingd.c b/closingd/closingd.c index 106b7caa5..792749f21 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -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; } diff --git a/doc/Makefile b/doc/Makefile index db8267983..1af44a323 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -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 \ diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index fc0102452..4f204cb88 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -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 diff --git a/doc/index.rst b/doc/index.rst index d89b01aed..8371e18fc 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -43,7 +43,6 @@ c-lightning Documentation lightning-delexpiredinvoice lightning-delinvoice lightning-delpay - lightning-dev-sendcustommsg lightning-disableoffer lightning-disconnect lightning-feerates @@ -87,6 +86,7 @@ c-lightning Documentation lightning-ping lightning-plugin lightning-reserveinputs + lightning-sendcustommsg lightning-sendinvoice lightning-sendonion lightning-sendonionmessage diff --git a/doc/lightning-dev-sendcustommsg.7 b/doc/lightning-sendcustommsg.7 similarity index 86% rename from doc/lightning-dev-sendcustommsg.7 rename to doc/lightning-sendcustommsg.7 index 654640226..9c13bb6b8 100644 --- a/doc/lightning-dev-sendcustommsg.7 +++ b/doc/lightning-sendcustommsg.7 @@ -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 is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:facefdc47adcbf0342f6e359d4752b8ab1b9a7ed2d6b466c9d202939fae5019e +\" SHA256STAMP:ff2ed61f688613b74885b9cccdf58187453d012ca2f3ae149c80b68679ef0a8e diff --git a/doc/lightning-dev-sendcustommsg.7.md b/doc/lightning-sendcustommsg.7.md similarity index 92% rename from doc/lightning-dev-sendcustommsg.7.md rename to doc/lightning-sendcustommsg.7.md index 1b78a156c..ee2b2a11d 100644 --- a/doc/lightning-dev-sendcustommsg.7.md +++ b/doc/lightning-sendcustommsg.7.md @@ -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. diff --git a/doc/schemas/dev-sendcustommsg.schema.json b/doc/schemas/sendcustommsg.schema.json similarity index 100% rename from doc/schemas/dev-sendcustommsg.schema.json rename to doc/schemas/sendcustommsg.schema.json diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index e1585e0d7..1df8e749f 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -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; diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 42d9909bf..4574c5580 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -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; diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 167074eea..b8dc8de51 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -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; diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index ef23e6480..6add3f9e4 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -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; diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 77a235a6c..48412597e 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -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 */ diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 281538ea9..419ddfbeb 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -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, diff --git a/openingd/dualopend.c b/openingd/dualopend.c index ed5f58300..704449142 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -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, diff --git a/openingd/openingd.c b/openingd/openingd.c index 051b153ea..8ebb3da94 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -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; diff --git a/tests/test_misc.py b/tests/test_misc.py index 486d2b37b..1b24d5e7e 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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']