mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
plugin: Fix the custommsg hook not to include the internal prefix
We were always prefixing the `message` field with the internal type prefix 0x0407, followed by the length prefix. Neither is needed since the type being constant is of no interest to the plugin and the length being implicit due to the JSON-encoding. Reported-by: Ilya Evdokimov Changelog-Fixed: plugin: The `custommsg` hook no longer includes the internal type prefix and length prefix in its `payload` Changelog-Deprecated: plugin: The `message` field on the `custommsg` hook is deprecated in favor of the `payload` field, which skips the internal prefix.
This commit is contained in:
parent
804c2c2c20
commit
ebb1b19c65
@ -1212,7 +1212,7 @@ The payload for a call follows this format:
|
||||
```json
|
||||
{
|
||||
"peer_id": "02df5ffe895c778e10f7742a6c5b8a0cefbe9465df58b92fadeb883752c8107c8f",
|
||||
"message": "1337ffffffff"
|
||||
"payload": "1337ffffffff"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -2454,7 +2454,16 @@ static void custommsg_final(struct custommsg_payload *payload STEALS)
|
||||
static void custommsg_payload_serialize(struct custommsg_payload *payload,
|
||||
struct json_stream *stream)
|
||||
{
|
||||
json_add_hex_talarr(stream, "message", payload->msg);
|
||||
if (deprecated_apis) {
|
||||
json_add_hex_talarr(stream, "message", payload->msg);
|
||||
json_add_string(
|
||||
stream, "warning",
|
||||
"The `message` field is deprecated and has been replaced "
|
||||
"with the payload` field which skips the internal type and "
|
||||
"the length prefix. Please update to use that instead.");
|
||||
}
|
||||
json_add_hex(stream, "payload", payload->msg + 4,
|
||||
tal_bytelen(payload->msg) - 4);
|
||||
json_add_node_id(stream, "peer_id", &payload->peer_id);
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,9 @@ plugin = Plugin()
|
||||
|
||||
|
||||
@plugin.hook('custommsg')
|
||||
def on_custommsg(peer_id, message, plugin, **kwargs):
|
||||
def on_custommsg(peer_id, payload, plugin, message=None, **kwargs):
|
||||
plugin.log("Got custommessage_a {msg} from peer {peer_id}".format(
|
||||
msg=message,
|
||||
msg=payload,
|
||||
peer_id=peer_id
|
||||
))
|
||||
return {'result': 'continue'}
|
||||
|
@ -5,9 +5,9 @@ plugin = Plugin()
|
||||
|
||||
|
||||
@plugin.hook('custommsg')
|
||||
def on_custommsg(peer_id, message, plugin, **kwargs):
|
||||
def on_custommsg(peer_id, payload, plugin, message=None, **kwargs):
|
||||
plugin.log("Got custommessage_b {msg} from peer {peer_id}".format(
|
||||
msg=message,
|
||||
msg=payload,
|
||||
peer_id=peer_id
|
||||
))
|
||||
return {'result': 'continue'}
|
||||
|
@ -2284,10 +2284,10 @@ def test_sendcustommsg(node_factory):
|
||||
)
|
||||
l1.daemon.wait_for_log(r'\[IN\] {}'.format(serialized))
|
||||
l1.daemon.wait_for_logs([
|
||||
r'Got custommessage_a {serialized} from peer {peer_id}'.format(
|
||||
serialized=serialized, peer_id=l2.info['id']),
|
||||
r'Got custommessage_b {serialized} from peer {peer_id}'.format(
|
||||
serialized=serialized, peer_id=l2.info['id'])
|
||||
r'Got custommessage_a {msg} from peer {peer_id}'.format(
|
||||
msg=msg, peer_id=l2.info['id']),
|
||||
r'Got custommessage_b {msg} from peer {peer_id}'.format(
|
||||
msg=msg, peer_id=l2.info['id'])
|
||||
])
|
||||
|
||||
# This should work since the peer is currently owned by `openingd`
|
||||
@ -2299,10 +2299,10 @@ def test_sendcustommsg(node_factory):
|
||||
)
|
||||
l4.daemon.wait_for_log(r'\[IN\] {}'.format(serialized))
|
||||
l4.daemon.wait_for_logs([
|
||||
r'Got custommessage_a {serialized} from peer {peer_id}'.format(
|
||||
serialized=serialized, peer_id=l2.info['id']),
|
||||
r'Got custommessage_b {serialized} from peer {peer_id}'.format(
|
||||
serialized=serialized, peer_id=l2.info['id']),
|
||||
r'Got custommessage_a {msg} from peer {peer_id}'.format(
|
||||
msg=msg, peer_id=l2.info['id']),
|
||||
r'Got custommessage_b {msg} from peer {peer_id}'.format(
|
||||
msg=msg, peer_id=l2.info['id']),
|
||||
])
|
||||
|
||||
|
||||
|
2
wallet/db_postgres_sqlgen.c
generated
2
wallet/db_postgres_sqlgen.c
generated
@ -1792,4 +1792,4 @@ struct db_query db_postgres_queries[] = {
|
||||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
||||
|
||||
// SHA256STAMP:d5554774287ded802c96fc975565e5557e5f7e174fea04ad7ec080400a15992b
|
||||
// SHA256STAMP:759b19435d68328d597f6540e1f4f8c42ce22ef91dbf66c1098de0434462546c
|
||||
|
2
wallet/db_sqlite3_sqlgen.c
generated
2
wallet/db_sqlite3_sqlgen.c
generated
@ -1792,4 +1792,4 @@ struct db_query db_sqlite3_queries[] = {
|
||||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
||||
|
||||
// SHA256STAMP:d5554774287ded802c96fc975565e5557e5f7e174fea04ad7ec080400a15992b
|
||||
// SHA256STAMP:759b19435d68328d597f6540e1f4f8c42ce22ef91dbf66c1098de0434462546c
|
||||
|
4
wallet/statements_gettextgen.po
generated
4
wallet/statements_gettextgen.po
generated
@ -1178,7 +1178,7 @@ msgstr ""
|
||||
msgid "not a valid SQL statement"
|
||||
msgstr ""
|
||||
|
||||
#: wallet/test/run-wallet.c:1395
|
||||
#: wallet/test/run-wallet.c:1399
|
||||
msgid "INSERT INTO channels (id) VALUES (1);"
|
||||
msgstr ""
|
||||
# SHA256STAMP:6aef0052df3b7141edbb7af83a1242a31af18b55aed8e14ca5ede7d783f86309
|
||||
# SHA256STAMP:c51857ae4385dd151d6a60f5ce99a5227a9a0cd01a66e0507bb81c04db07c39e
|
||||
|
@ -272,6 +272,10 @@ void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
|
||||
void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
|
||||
bool value UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
|
||||
/* Generated stub for json_add_hex */
|
||||
void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
|
||||
const void *data UNNEEDED, size_t len UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_hex called!\n"); abort(); }
|
||||
/* Generated stub for json_add_hex_talarr */
|
||||
void json_add_hex_talarr(struct json_stream *result UNNEEDED,
|
||||
const char *fieldname UNNEEDED,
|
||||
|
Loading…
Reference in New Issue
Block a user