Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offers: Update to include sciddir_or_pubkey, for introduction point in blinded path. #7212

Merged
18 changes: 18 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@
"DecodeOffer_paths": {
"Decode.offer_paths[].blinding": 2,
"Decode.offer_paths[].first_node_id": 1,
"Decode.offer_paths[].first_scid": 5,
"Decode.offer_paths[].first_scid_dir": 4,
"Decode.offer_paths[].path[]": 3
},
"DecodeOffer_recurrencePaywindow": {
Expand Down Expand Up @@ -3410,6 +3412,14 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"Decode.invoice_paths[].first_scid": {
"added": "v23.05",
"deprecated": false
},
"Decode.invoice_paths[].first_scid_dir": {
"added": "v23.05",
"deprecated": false
},
"Decode.invoice_paths[].path[]": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down Expand Up @@ -3550,6 +3560,14 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"Decode.offer_paths[].first_scid": {
"added": "v23.05",
"deprecated": false
},
"Decode.offer_paths[].first_scid_dir": {
"added": "v23.05",
"deprecated": false
},
"Decode.offer_paths[].path[]": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down
3 changes: 3 additions & 0 deletions channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
/* Generated stub for fromwire_node_id */
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,
Expand Down
3 changes: 3 additions & 0 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ void memleak_add_helper_(const tal_t *p UNNEEDED, void (*cb)(struct htable *memt
/* Generated stub for memleak_scan_htable */
void memleak_scan_htable(struct htable *memtable UNNEEDED, const struct htable *ht UNNEEDED)
{ fprintf(stderr, "memleak_scan_htable called!\n"); abort(); }
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)
Expand Down
3 changes: 3 additions & 0 deletions cli/test/run-human-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const char *log_level_name(enum log_level level UNNEEDED)
bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED,
enum log_level *level UNNEEDED)
{ fprintf(stderr, "log_level_parse called!\n"); abort(); }
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }
Expand Down
3 changes: 3 additions & 0 deletions cli/test/run-large-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const char *log_level_name(enum log_level level UNNEEDED)
bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED,
enum log_level *level UNNEEDED)
{ fprintf(stderr, "log_level_parse called!\n"); abort(); }
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }
Expand Down
3 changes: 3 additions & 0 deletions cli/test/run-remove-hint.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const char *log_level_name(enum log_level level UNNEEDED)
bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED,
enum log_level *level UNNEEDED)
{ fprintf(stderr, "log_level_parse called!\n"); abort(); }
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }
Expand Down
4 changes: 3 additions & 1 deletion cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ COMMON_SRC_NOGEN := \
common/initial_commit_tx.c \
common/invoice_path_id.c \
common/iso4217.c \
common/json_blinded_path.c \
common/json_channel_type.c \
common/json_filter.c \
common/json_param.c \
Expand Down Expand Up @@ -84,6 +85,7 @@ COMMON_SRC_NOGEN := \
common/random_select.c \
common/read_peer_msg.c \
common/route.c \
common/sciddir_or_pubkey.c \
common/setup.c \
common/shutdown_scriptpubkey.c \
common/sphinx.c \
Expand Down
57 changes: 57 additions & 0 deletions common/json_blinded_path.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "config.h"
#include <common/json_blinded_path.h>
#include <common/json_parse.h>
#include <wire/onion_wire.h>

struct blinded_path *
json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
{
struct blinded_path *rpath;
const jsmntok_t *hops, *t;
size_t i;
const char *err;
struct pubkey first_node_id;
struct short_channel_id_dir first_scidd;

rpath = tal(ctx, struct blinded_path);

/* It will give us either scid or node_id */
memset(&first_scidd, 0, sizeof(first_scidd));
err = json_scan(tmpctx, buffer, tok,
"{blinding:%,"
"first_node_id?:%,"
"first_scid?:%,"
"first_scid_dir?:%}",
JSON_SCAN(json_to_pubkey, &rpath->blinding),
JSON_SCAN(json_to_pubkey, &first_node_id),
JSON_SCAN(json_to_short_channel_id, &first_scidd.scid),
JSON_SCAN(json_to_int, &first_scidd.dir),
NULL);
if (err)
return tal_free(rpath);

if (first_scidd.scid.u64 != 0)
sciddir_or_pubkey_from_scidd(&rpath->first_node_id, &first_scidd);
else
sciddir_or_pubkey_from_pubkey(&rpath->first_node_id, &first_node_id);

hops = json_get_member(buffer, tok, "hops");
if (!hops || hops->size < 1)
return tal_free(rpath);

rpath->path = tal_arr(rpath, struct onionmsg_hop *, hops->size);
json_for_each_arr(i, t, hops) {
rpath->path[i] = tal(rpath->path, struct onionmsg_hop);
err = json_scan(tmpctx, buffer, t, "{blinded_node_id:%,encrypted_recipient_data:%}",
JSON_SCAN(json_to_pubkey,
&rpath->path[i]->blinded_node_id),
JSON_SCAN_TAL(rpath->path[i],
json_tok_bin_from_hex,
&rpath->path[i]->encrypted_recipient_data));
if (err)
return tal_free(rpath);
}

return rpath;
}

10 changes: 10 additions & 0 deletions common/json_blinded_path.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef LIGHTNING_COMMON_JSON_BLINDED_PATH_H
#define LIGHTNING_COMMON_JSON_BLINDED_PATH_H
#include "config.h"
#include <common/json_parse_simple.h>

/* Extract reply path from this JSON */
struct blinded_path *
json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);

#endif /* LIGHTNING_COMMON_JSON_BLINDED_PATH_H */
36 changes: 0 additions & 36 deletions common/json_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,42 +649,6 @@ struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
return psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start);
}

struct blinded_path *
json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
{
struct blinded_path *rpath;
const jsmntok_t *hops, *t;
size_t i;
const char *err;

rpath = tal(ctx, struct blinded_path);
err = json_scan(tmpctx, buffer, tok, "{blinding:%,first_node_id:%}",
JSON_SCAN(json_to_pubkey, &rpath->blinding),
JSON_SCAN(json_to_pubkey, &rpath->first_node_id),
NULL);
if (err)
return tal_free(rpath);

hops = json_get_member(buffer, tok, "hops");
if (!hops || hops->size < 1)
return tal_free(rpath);

rpath->path = tal_arr(rpath, struct onionmsg_hop *, hops->size);
json_for_each_arr(i, t, hops) {
rpath->path[i] = tal(rpath->path, struct onionmsg_hop);
err = json_scan(tmpctx, buffer, t, "{blinded_node_id:%,encrypted_recipient_data:%}",
JSON_SCAN(json_to_pubkey,
&rpath->path[i]->blinded_node_id),
JSON_SCAN_TAL(rpath->path[i],
json_tok_bin_from_hex,
&rpath->path[i]->encrypted_recipient_data));
if (err)
return tal_free(rpath);
}

return rpath;
}

bool
json_tok_channel_id(const char *buffer, const jsmntok_t *tok,
struct channel_id *cid)
Expand Down
4 changes: 0 additions & 4 deletions common/json_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
bool json_to_coin_mvt_tag(const char *buffer, const jsmntok_t *tok,
enum mvt_tag *tag);

/* Extract reply path from this JSON */
struct blinded_path *
json_to_blinded_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);

bool json_tok_channel_id(const char *buffer, const jsmntok_t *tok,
struct channel_id *cid);

Expand Down
71 changes: 71 additions & 0 deletions common/sciddir_or_pubkey.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "config.h"
#include <assert.h>
#include <common/node_id.h>
#include <common/sciddir_or_pubkey.h>
#include <wire/wire.h>

/* BOLT-sciddir_or_pubkey #1:
* * `sciddir_or_pubkey`: either 9 or 33 bytes referencing or identifying a node, respectively
* * if the first byte is 0 or 1, then an 8-byte `short_channel_id` follows for a total of 9 bytes
* * 0 for the first byte indicates this refers to `node_id_1` in the `channel_announcement` for `short_channel_id` (see [BOLT #7](07-routing-gossip.md#the-channel_announcement-message))
* * 1 for the first byte indicates this refers to `node_id_2` in the `channel_announcement` for `short_channel_id` (see [BOLT #7](07-routing-gossip.md#the-channel_announcement-message))
* * if the first byte is 2 or 3, then the value is a 33-byte `point`
*/
void towire_sciddir_or_pubkey(u8 **pptr,
const struct sciddir_or_pubkey *sciddpk)
{
if (sciddpk->is_pubkey)
towire_pubkey(pptr, &sciddpk->pubkey);
else {
assert(sciddpk->scidd.dir == 0 || sciddpk->scidd.dir == 1);
towire_u8(pptr, sciddpk->scidd.dir);
towire_short_channel_id(pptr, sciddpk->scidd.scid);
}
}

void fromwire_sciddir_or_pubkey(const u8 **cursor, size_t *max,
struct sciddir_or_pubkey *sciddpk)
{
const u8 *peek = *cursor;
size_t peek_max = *max;
u8 firstbyte = fromwire_u8(&peek, &peek_max);

if (firstbyte == 0 || firstbyte == 1) {
sciddpk->is_pubkey = false;
sciddpk->scidd.dir = fromwire_u8(cursor, max);
sciddpk->scidd.scid = fromwire_short_channel_id(cursor, max);
} else {
sciddpk->is_pubkey = true;
fromwire_pubkey(cursor, max, &sciddpk->pubkey);
}
}

void sciddir_or_pubkey_from_pubkey(struct sciddir_or_pubkey *sciddpk,
const struct pubkey *pubkey)
{
sciddpk->is_pubkey = true;
sciddpk->pubkey = *pubkey;
}

bool sciddir_or_pubkey_from_node_id(struct sciddir_or_pubkey *sciddpk,
const struct node_id *node_id)
{
sciddpk->is_pubkey = true;
return pubkey_from_node_id(&sciddpk->pubkey, node_id);
}

void sciddir_or_pubkey_from_scidd(struct sciddir_or_pubkey *sciddpk,
const struct short_channel_id_dir *scidd)
{
sciddpk->is_pubkey = false;
sciddpk->scidd = *scidd;
assert(sciddpk->scidd.dir == 0 || sciddpk->scidd.dir == 1);
}

const char *fmt_sciddir_or_pubkey(const tal_t *ctx,
const struct sciddir_or_pubkey *sciddpk)
{
if (sciddpk->is_pubkey)
return fmt_pubkey(ctx, &sciddpk->pubkey);
return fmt_short_channel_id_dir(ctx, &sciddpk->scidd);
}
30 changes: 30 additions & 0 deletions common/sciddir_or_pubkey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef LIGHTNING_COMMON_SCIDDIR_OR_PUBKEY_H
#define LIGHTNING_COMMON_SCIDDIR_OR_PUBKEY_H
#include "config.h"
#include <bitcoin/pubkey.h>
#include <bitcoin/short_channel_id.h>

struct node_id;

struct sciddir_or_pubkey {
bool is_pubkey;
/* Only valid if is_pubkey is true */
struct pubkey pubkey;
/* Only valid if is_pubkey is false */
struct short_channel_id_dir scidd;
};
void towire_sciddir_or_pubkey(u8 **pptr,
const struct sciddir_or_pubkey *sciddpk);
void fromwire_sciddir_or_pubkey(const u8 **cursor, size_t *max,
struct sciddir_or_pubkey *sciddpk);

void sciddir_or_pubkey_from_pubkey(struct sciddir_or_pubkey *sciddpk,
const struct pubkey *pubkey);
WARN_UNUSED_RESULT
bool sciddir_or_pubkey_from_node_id(struct sciddir_or_pubkey *sciddpk,
const struct node_id *node_id);
void sciddir_or_pubkey_from_scidd(struct sciddir_or_pubkey *sciddpk,
const struct short_channel_id_dir *scidd);
const char *fmt_sciddir_or_pubkey(const tal_t *ctx,
const struct sciddir_or_pubkey *sciddpk);
#endif /* LIGHTNING_COMMON_SCIDDIR_OR_PUBKEY_H */
8 changes: 8 additions & 0 deletions common/test/run-blindedpath_enctlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
/* Generated stub for fromwire_node_id */
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
/* Generated stub for fromwire_sciddir_or_pubkey */
void fromwire_sciddir_or_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct sciddir_or_pubkey *sciddpk UNNEEDED)
{ fprintf(stderr, "fromwire_sciddir_or_pubkey called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }
Expand All @@ -70,6 +74,10 @@ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id U
/* Generated stub for towire_node_id */
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
/* Generated stub for towire_sciddir_or_pubkey */
void towire_sciddir_or_pubkey(u8 **pptr UNNEEDED,
const struct sciddir_or_pubkey *sciddpk UNNEEDED)
{ fprintf(stderr, "towire_sciddir_or_pubkey called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

static void json_strfield(const char *name, const char *val)
Expand Down
Loading
Loading