mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
gossmap: fix gossmap_chan_get_announce() and gossmap_node_get_announce().
These were never used, nor tested. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
d54abd0e36
commit
167681c709
@ -1087,9 +1087,18 @@ u8 *gossmap_chan_get_announce(const tal_t *ctx,
|
|||||||
const struct gossmap *map,
|
const struct gossmap *map,
|
||||||
const struct gossmap_chan *c)
|
const struct gossmap_chan *c)
|
||||||
{
|
{
|
||||||
u16 len = map_be16(map, c->cann_off);
|
u32 len;
|
||||||
u8 *msg = tal_arr(ctx, u8, len);
|
u8 *msg;
|
||||||
|
u32 pre_off;
|
||||||
|
|
||||||
|
/* We need to go back to struct gossip_hdr to get len */
|
||||||
|
if (c->private)
|
||||||
|
pre_off = 2 + 8 + 2 + sizeof(struct gossip_hdr);
|
||||||
|
else
|
||||||
|
pre_off = sizeof(struct gossip_hdr);
|
||||||
|
len = (map_be32(map, c->cann_off - pre_off) & GOSSIP_STORE_LEN_MASK);
|
||||||
|
|
||||||
|
msg = tal_arr(ctx, u8, len);
|
||||||
map_copy(map, c->cann_off, msg, len);
|
map_copy(map, c->cann_off, msg, len);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@ -1099,13 +1108,14 @@ u8 *gossmap_node_get_announce(const tal_t *ctx,
|
|||||||
const struct gossmap *map,
|
const struct gossmap *map,
|
||||||
const struct gossmap_node *n)
|
const struct gossmap_node *n)
|
||||||
{
|
{
|
||||||
u16 len;
|
u32 len;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
|
||||||
if (n->nann_off == 0)
|
if (n->nann_off == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
len = map_be16(map, n->nann_off);
|
len = (map_be32(map, n->nann_off - sizeof(struct gossip_hdr))
|
||||||
|
& GOSSIP_STORE_LEN_MASK);
|
||||||
msg = tal_arr(ctx, u8, len);
|
msg = tal_arr(ctx, u8, len);
|
||||||
|
|
||||||
map_copy(map, n->nann_off, msg, len);
|
map_copy(map, n->nann_off, msg, len);
|
||||||
|
@ -45,5 +45,9 @@ common/test/run-route common/test/run-route-specific: \
|
|||||||
wire/peer$(EXP)_wiregen.o \
|
wire/peer$(EXP)_wiregen.o \
|
||||||
wire/towire.o
|
wire/towire.o
|
||||||
|
|
||||||
|
common/test/run-gossmap_local: \
|
||||||
|
wire/fromwire.o \
|
||||||
|
wire/peer$(EXP)_wiregen.o \
|
||||||
|
wire/towire.o
|
||||||
|
|
||||||
check-units: $(COMMON_TEST_PROGRAMS:%=unittest/%)
|
check-units: $(COMMON_TEST_PROGRAMS:%=unittest/%)
|
||||||
|
@ -11,69 +11,32 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* AUTOGENERATED MOCKS START */
|
/* AUTOGENERATED MOCKS START */
|
||||||
/* Generated stub for fromwire */
|
/* Generated stub for fromwire_bigsize */
|
||||||
const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED)
|
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_bool */
|
/* Generated stub for fromwire_channel_id */
|
||||||
bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
||||||
{ fprintf(stderr, "fromwire_bool called!\n"); abort(); }
|
struct channel_id *channel_id UNNEEDED)
|
||||||
/* Generated stub for fromwire_fail */
|
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
|
||||||
void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
/* Generated stub for fromwire_tlv */
|
||||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
||||||
/* Generated stub for fromwire_secp256k1_ecdsa_signature */
|
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
|
||||||
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
void *record UNNEEDED, struct tlv_field **fields UNNEEDED)
|
||||||
secp256k1_ecdsa_signature *signature UNNEEDED)
|
{ fprintf(stderr, "fromwire_tlv called!\n"); abort(); }
|
||||||
{ fprintf(stderr, "fromwire_secp256k1_ecdsa_signature called!\n"); abort(); }
|
/* Generated stub for tlv_fields_valid */
|
||||||
/* Generated stub for fromwire_sha256 */
|
bool tlv_fields_valid(const struct tlv_field *fields UNNEEDED, size_t *err_index UNNEEDED)
|
||||||
void fromwire_sha256(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sha256 *sha256 UNNEEDED)
|
{ fprintf(stderr, "tlv_fields_valid called!\n"); abort(); }
|
||||||
{ fprintf(stderr, "fromwire_sha256 called!\n"); abort(); }
|
/* Generated stub for towire_bigsize */
|
||||||
/* Generated stub for fromwire_tal_arrn */
|
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
|
||||||
u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
|
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }
|
||||||
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
|
/* Generated stub for towire_channel_id */
|
||||||
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
|
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
|
||||||
/* Generated stub for fromwire_u16 */
|
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
|
||||||
u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
/* Generated stub for towire_tlv */
|
||||||
{ fprintf(stderr, "fromwire_u16 called!\n"); abort(); }
|
void towire_tlv(u8 **pptr UNNEEDED,
|
||||||
/* Generated stub for fromwire_u32 */
|
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
|
||||||
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
const void *record UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
|
{ fprintf(stderr, "towire_tlv called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_u64 */
|
|
||||||
u64 fromwire_u64(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
|
||||||
{ fprintf(stderr, "fromwire_u64 called!\n"); abort(); }
|
|
||||||
/* Generated stub for fromwire_u8 */
|
|
||||||
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
|
||||||
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
|
|
||||||
/* Generated stub for fromwire_u8_array */
|
|
||||||
void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED)
|
|
||||||
{ fprintf(stderr, "fromwire_u8_array called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire */
|
|
||||||
void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_bool */
|
|
||||||
void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_bool called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_secp256k1_ecdsa_signature */
|
|
||||||
void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
|
|
||||||
const secp256k1_ecdsa_signature *signature UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_secp256k1_ecdsa_signature called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_sha256 */
|
|
||||||
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_sha256 called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_u16 */
|
|
||||||
void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_u16 called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_u32 */
|
|
||||||
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_u32 called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_u64 */
|
|
||||||
void towire_u64(u8 **pptr UNNEEDED, u64 v UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_u64 called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_u8 */
|
|
||||||
void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_u8 called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_u8_array */
|
|
||||||
void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_u8_array called!\n"); abort(); }
|
|
||||||
/* Generated stub for type_to_string_ */
|
/* Generated stub for type_to_string_ */
|
||||||
const char *type_to_string_(const tal_t *ctx UNNEEDED, const char *typename UNNEEDED,
|
const char *type_to_string_(const tal_t *ctx UNNEEDED, const char *typename UNNEEDED,
|
||||||
union printable_types u UNNEEDED)
|
union printable_types u UNNEEDED)
|
||||||
@ -290,6 +253,53 @@ static u8 canned_map[] = {
|
|||||||
, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x02, 0x33, 0x80
|
, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x02, 0x33, 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void check_cannounce(const u8 *cannounce,
|
||||||
|
const struct short_channel_id *scid,
|
||||||
|
const struct node_id *n1,
|
||||||
|
const struct node_id *n2)
|
||||||
|
{
|
||||||
|
secp256k1_ecdsa_signature sig;
|
||||||
|
u8 *features;
|
||||||
|
struct bitcoin_blkid chain_hash;
|
||||||
|
struct short_channel_id actual_scid;
|
||||||
|
struct node_id actual_n1, actual_n2;
|
||||||
|
struct pubkey k;
|
||||||
|
|
||||||
|
assert(fromwire_channel_announcement(cannounce, cannounce,
|
||||||
|
&sig, &sig, &sig, &sig,
|
||||||
|
&features, &chain_hash,
|
||||||
|
&actual_scid,
|
||||||
|
&actual_n1,
|
||||||
|
&actual_n2,
|
||||||
|
&k, &k));
|
||||||
|
assert(short_channel_id_eq(&actual_scid, scid));
|
||||||
|
if (node_id_cmp(n1, n2) < 0) {
|
||||||
|
assert(node_id_eq(&actual_n1, n1));
|
||||||
|
assert(node_id_eq(&actual_n2, n2));
|
||||||
|
} else {
|
||||||
|
assert(node_id_eq(&actual_n1, n2));
|
||||||
|
assert(node_id_eq(&actual_n2, n1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void check_nannounce(const u8 *nannounce,
|
||||||
|
const struct node_id *n)
|
||||||
|
{
|
||||||
|
secp256k1_ecdsa_signature sig;
|
||||||
|
u8 *features, *addresses;
|
||||||
|
u32 timestamp;
|
||||||
|
u8 rgb_color[3], alias[32];
|
||||||
|
struct node_id node_id;
|
||||||
|
assert(fromwire_node_announcement(nannounce, nannounce,
|
||||||
|
&sig, &features,
|
||||||
|
×tamp,
|
||||||
|
&node_id,
|
||||||
|
rgb_color,
|
||||||
|
alias,
|
||||||
|
&addresses));
|
||||||
|
assert(node_id_eq(&node_id, n));
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -303,6 +313,7 @@ int main(int argc, char *argv[])
|
|||||||
u32 timestamp, fee_base_msat, fee_proportional_millionths;
|
u32 timestamp, fee_base_msat, fee_proportional_millionths;
|
||||||
u8 message_flags, channel_flags;
|
u8 message_flags, channel_flags;
|
||||||
struct amount_msat htlc_minimum_msat, htlc_maximum_msat;
|
struct amount_msat htlc_minimum_msat, htlc_maximum_msat;
|
||||||
|
u8 *cann, *nann;
|
||||||
|
|
||||||
common_setup(argv[0]);
|
common_setup(argv[0]);
|
||||||
|
|
||||||
@ -407,6 +418,23 @@ int main(int argc, char *argv[])
|
|||||||
assert(tal_bytelen(gossmap_chan_get_features(tmpctx, map,
|
assert(tal_bytelen(gossmap_chan_get_features(tmpctx, map,
|
||||||
gossmap_find_chan(map, &scid23))) == 0);
|
gossmap_find_chan(map, &scid23))) == 0);
|
||||||
|
|
||||||
|
cann = gossmap_chan_get_announce(tmpctx, map,
|
||||||
|
gossmap_find_chan(map, &scid12));
|
||||||
|
check_cannounce(cann, &scid12, &l1, &l2);
|
||||||
|
cann = gossmap_chan_get_announce(tmpctx, map,
|
||||||
|
gossmap_find_chan(map, &scid23));
|
||||||
|
check_cannounce(cann, &scid23, &l2, &l3);
|
||||||
|
|
||||||
|
nann = gossmap_node_get_announce(tmpctx, map,
|
||||||
|
gossmap_find_node(map, &l1));
|
||||||
|
assert(!nann);
|
||||||
|
nann = gossmap_node_get_announce(tmpctx, map,
|
||||||
|
gossmap_find_node(map, &l2));
|
||||||
|
check_nannounce(nann, &l2);
|
||||||
|
nann = gossmap_node_get_announce(tmpctx, map,
|
||||||
|
gossmap_find_node(map, &l3));
|
||||||
|
check_nannounce(nann, &l3);
|
||||||
|
|
||||||
/* Now, let's add a new channel l1 -> l4. */
|
/* Now, let's add a new channel l1 -> l4. */
|
||||||
mods = gossmap_localmods_new(tmpctx);
|
mods = gossmap_localmods_new(tmpctx);
|
||||||
assert(node_id_from_hexstr("0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199", 66, &l4));
|
assert(node_id_from_hexstr("0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199", 66, &l4));
|
||||||
|
Loading…
Reference in New Issue
Block a user