Browse Source

gossipd: hand (any) timestamps through to callback for query_channel_range.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
1f2a03f019
  1. 35
      common/decode_array.c
  2. 4
      common/decode_array.h
  3. 3
      gossipd/gossipd.h
  4. 27
      gossipd/queries.c
  5. 2
      gossipd/queries.h
  6. 1
      gossipd/seeker.c
  7. 4
      gossipd/test/run-crc32_of_update.c
  8. 4
      gossipd/test/run-extended-info.c
  9. 1
      gossipd/test/run-next_block_range.c

35
common/decode_array.c

@ -103,3 +103,38 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx,
} }
return NULL; return NULL;
} }
struct channel_update_timestamps *
decode_channel_update_timestamps(const tal_t *ctx,
const struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv)
{
/* Note that our parser will set this to NULL if there are no elements */
u8 *encoded = timestamps_tlv->encoded_timestamps;
size_t max = tal_count(encoded);
struct channel_update_timestamps *ts;
/* FIXME: BOLT #7 should have a requirements like it does for
* query_short_channel_ids_tlvs! */
switch (timestamps_tlv->encoding_type) {
case ARR_ZLIB:
encoded = unzlib(tmpctx, encoded, max);
if (!encoded)
return NULL;
max = tal_count(encoded);
/* fall thru */
case ARR_UNCOMPRESSED:
ts = tal_arr(ctx, struct channel_update_timestamps, 0);
while (max) {
struct channel_update_timestamps t;
fromwire_channel_update_timestamps
(cast_const2(const u8 **, &encoded),
&max, &t);
/* Sets this to NULL if it fails */
if (!encoded)
return tal_free(ts);
tal_arr_expand(&ts, t);
}
return ts;
}
return NULL;
}

4
common/decode_array.h

@ -6,6 +6,7 @@
#include <common/bigsize.h> #include <common/bigsize.h>
struct tlv_query_short_channel_ids_tlvs_query_flags; struct tlv_query_short_channel_ids_tlvs_query_flags;
struct tlv_reply_channel_range_tlvs_timestamps_tlv;
/* BOLT #7: /* BOLT #7:
* *
@ -44,4 +45,7 @@ enum scid_query_flag {
bigsize_t *decode_scid_query_flags(const tal_t *ctx, bigsize_t *decode_scid_query_flags(const tal_t *ctx,
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf); const struct tlv_query_short_channel_ids_tlvs_query_flags *qf);
struct channel_update_timestamps *decode_channel_update_timestamps(const tal_t *ctx,
const struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv);
#endif /* LIGHTNING_COMMON_DECODE_ARRAY_H */ #endif /* LIGHTNING_COMMON_DECODE_ARRAY_H */

3
gossipd/gossipd.h

@ -15,6 +15,7 @@
#define CONNECTD_FD 4 #define CONNECTD_FD 4
struct chan; struct chan;
struct channel_update_timestamps;
struct broadcastable; struct broadcastable;
struct seeker; struct seeker;
@ -103,9 +104,11 @@ struct peer {
u32 range_first_blocknum, range_end_blocknum; u32 range_first_blocknum, range_end_blocknum;
u32 range_blocks_remaining; u32 range_blocks_remaining;
struct short_channel_id *query_channel_scids; struct short_channel_id *query_channel_scids;
struct channel_update_timestamps *query_channel_timestamps;
void (*query_channel_range_cb)(struct peer *peer, void (*query_channel_range_cb)(struct peer *peer,
u32 first_blocknum, u32 number_of_blocks, u32 first_blocknum, u32 number_of_blocks,
const struct short_channel_id *scids, const struct short_channel_id *scids,
const struct channel_update_timestamps *,
bool complete); bool complete);
/* Are we asking this peer to give us gossip? */ /* Are we asking this peer to give us gossip? */

27
gossipd/queries.c

@ -637,11 +637,13 @@ const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)
u32 first_blocknum, number_of_blocks, start, end; u32 first_blocknum, number_of_blocks, start, end;
u8 *encoded; u8 *encoded;
struct short_channel_id *scids; struct short_channel_id *scids;
struct channel_update_timestamps *ts;
size_t n; size_t n;
unsigned long b; unsigned long b;
void (*cb)(struct peer *peer, void (*cb)(struct peer *peer,
u32 first_blocknum, u32 number_of_blocks, u32 first_blocknum, u32 number_of_blocks,
const struct short_channel_id *scids, const struct short_channel_id *scids,
const struct channel_update_timestamps *ts,
bool complete); bool complete);
struct tlv_reply_channel_range_tlvs *tlvs struct tlv_reply_channel_range_tlvs *tlvs
= tlv_reply_channel_range_tlvs_new(tmpctx); = tlv_reply_channel_range_tlvs_new(tmpctx);
@ -741,20 +743,40 @@ const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)
tal_resize(&peer->query_channel_scids, n + tal_count(scids)); tal_resize(&peer->query_channel_scids, n + tal_count(scids));
memcpy(peer->query_channel_scids + n, scids, tal_bytelen(scids)); memcpy(peer->query_channel_scids + n, scids, tal_bytelen(scids));
/* Add timestamps (if any), or zeroes */
if (tlvs->timestamps_tlv) {
ts = decode_channel_update_timestamps(tlvs,
tlvs->timestamps_tlv);
if (!ts || tal_count(ts) != tal_count(scids)) {
return towire_errorfmt(peer, NULL,
"reply_channel_range %zu timestamps when %zu scids?",
tal_count(ts),
tal_count(scids));
}
} else {
ts = tal_arrz(tlvs, struct channel_update_timestamps,
tal_count(scids));
}
n = tal_count(peer->query_channel_timestamps);
tal_resize(&peer->query_channel_timestamps, n + tal_count(ts));
memcpy(peer->query_channel_timestamps + n, ts, tal_bytelen(ts));
/* Still more to go? */ /* Still more to go? */
if (peer->range_blocks_remaining) if (peer->range_blocks_remaining)
return NULL; return NULL;
/* Clear these immediately in case cb want to queue more */ /* Clear these immediately in case cb want to queue more */
scids = tal_steal(tmpctx, peer->query_channel_scids); scids = tal_steal(tmpctx, peer->query_channel_scids);
ts = tal_steal(tmpctx, peer->query_channel_timestamps);
cb = peer->query_channel_range_cb; cb = peer->query_channel_range_cb;
tal_steal(tmpctx, peer->query_channel_blocks); tal_steal(tmpctx, peer->query_channel_blocks);
peer->query_channel_scids = NULL; peer->query_channel_scids = NULL;
peer->query_channel_timestamps = NULL;
peer->query_channel_blocks = NULL; peer->query_channel_blocks = NULL;
peer->query_channel_range_cb = NULL; peer->query_channel_range_cb = NULL;
cb(peer, first_blocknum, number_of_blocks, scids, complete); cb(peer, first_blocknum, number_of_blocks, scids, ts, complete);
return NULL; return NULL;
} }
@ -983,6 +1005,7 @@ bool query_channel_range(struct daemon *daemon,
void (*cb)(struct peer *peer, void (*cb)(struct peer *peer,
u32 first_blocknum, u32 number_of_blocks, u32 first_blocknum, u32 number_of_blocks,
const struct short_channel_id *scids, const struct short_channel_id *scids,
const struct channel_update_timestamps *,
bool complete)) bool complete))
{ {
u8 *msg; u8 *msg;
@ -1020,6 +1043,8 @@ bool query_channel_range(struct daemon *daemon,
peer->query_channel_blocks = tal_arrz(peer, bitmap, peer->query_channel_blocks = tal_arrz(peer, bitmap,
BITMAP_NWORDS(number_of_blocks)); BITMAP_NWORDS(number_of_blocks));
peer->query_channel_scids = tal_arr(peer, struct short_channel_id, 0); peer->query_channel_scids = tal_arr(peer, struct short_channel_id, 0);
peer->query_channel_timestamps
= tal_arr(peer, struct channel_update_timestamps, 0);
peer->query_channel_range_cb = cb; peer->query_channel_range_cb = cb;
return true; return true;

2
gossipd/queries.h

@ -3,6 +3,7 @@
#include "config.h" #include "config.h"
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
struct channel_update_timestamps;
struct daemon; struct daemon;
struct io_conn; struct io_conn;
struct peer; struct peer;
@ -42,6 +43,7 @@ bool query_channel_range(struct daemon *daemon,
void (*cb)(struct peer *peer, void (*cb)(struct peer *peer,
u32 first_blocknum, u32 number_of_blocks, u32 first_blocknum, u32 number_of_blocks,
const struct short_channel_id *scids, const struct short_channel_id *scids,
const struct channel_update_timestamps *,
bool complete)); bool complete));
/* Ask this peer for info about an array of scids, with optional query_flags */ /* Ask this peer for info about an array of scids, with optional query_flags */

1
gossipd/seeker.c

@ -472,6 +472,7 @@ static void peer_gossip_probe_nannounces(struct seeker *seeker)
static void process_scid_probe(struct peer *peer, static void process_scid_probe(struct peer *peer,
u32 first_blocknum, u32 number_of_blocks, u32 first_blocknum, u32 number_of_blocks,
const struct short_channel_id *scids, const struct short_channel_id *scids,
const struct channel_update_timestamps *ts,
bool complete) bool complete)
{ {
struct seeker *seeker = peer->daemon->seeker; struct seeker *seeker = peer->daemon->seeker;

4
gossipd/test/run-crc32_of_update.c

@ -13,6 +13,10 @@ struct io_plan *daemon_conn_read_next(struct io_conn *conn UNNEEDED,
/* Generated stub for daemon_conn_wake */ /* Generated stub for daemon_conn_wake */
void daemon_conn_wake(struct daemon_conn *dc UNNEEDED) void daemon_conn_wake(struct daemon_conn *dc UNNEEDED)
{ fprintf(stderr, "daemon_conn_wake called!\n"); abort(); } { fprintf(stderr, "daemon_conn_wake called!\n"); abort(); }
/* Generated stub for decode_channel_update_timestamps */
struct channel_update_timestamps *decode_channel_update_timestamps(const tal_t *ctx UNNEEDED,
const struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv UNNEEDED)
{ fprintf(stderr, "decode_channel_update_timestamps called!\n"); abort(); }
/* Generated stub for decode_scid_query_flags */ /* Generated stub for decode_scid_query_flags */
bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED, bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED,
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf UNNEEDED) const struct tlv_query_short_channel_ids_tlvs_query_flags *qf UNNEEDED)

4
gossipd/test/run-extended-info.c

@ -20,6 +20,10 @@ struct io_plan *daemon_conn_read_next(struct io_conn *conn UNNEEDED,
/* Generated stub for daemon_conn_wake */ /* Generated stub for daemon_conn_wake */
void daemon_conn_wake(struct daemon_conn *dc UNNEEDED) void daemon_conn_wake(struct daemon_conn *dc UNNEEDED)
{ fprintf(stderr, "daemon_conn_wake called!\n"); abort(); } { fprintf(stderr, "daemon_conn_wake called!\n"); abort(); }
/* Generated stub for decode_channel_update_timestamps */
struct channel_update_timestamps *decode_channel_update_timestamps(const tal_t *ctx UNNEEDED,
const struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv UNNEEDED)
{ fprintf(stderr, "decode_channel_update_timestamps called!\n"); abort(); }
/* Generated stub for decode_scid_query_flags */ /* Generated stub for decode_scid_query_flags */
bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED, bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED,
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf UNNEEDED) const struct tlv_query_short_channel_ids_tlvs_query_flags *qf UNNEEDED)

1
gossipd/test/run-next_block_range.c

@ -27,6 +27,7 @@ bool query_channel_range(struct daemon *daemon UNNEEDED,
void (*cb)(struct peer *peer UNNEEDED, void (*cb)(struct peer *peer UNNEEDED,
u32 first_blocknum UNNEEDED, u32 number_of_blocks UNNEEDED, u32 first_blocknum UNNEEDED, u32 number_of_blocks UNNEEDED,
const struct short_channel_id *scids UNNEEDED, const struct short_channel_id *scids UNNEEDED,
const struct channel_update_timestamps * UNNEEDED,
bool complete)) bool complete))
{ fprintf(stderr, "query_channel_range called!\n"); abort(); } { fprintf(stderr, "query_channel_range called!\n"); abort(); }
/* Generated stub for query_short_channel_ids */ /* Generated stub for query_short_channel_ids */

Loading…
Cancel
Save