gossip_store: mark private updates separately from normal ones.

They're really gossipd-internal, and we don't want per-peer daemons
to confuse them with normal updates.

I don't bump the gossip_store version; that's coming with another update
anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-06-04 03:35:25 +09:30
parent a57fdf2033
commit 180a552fba
8 changed files with 75 additions and 4 deletions

View file

@ -491,6 +491,14 @@ u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg,
return off; return off;
} }
u64 gossip_store_add_private_update(struct gossip_store *gs, const u8 *update)
{
/* A local update for an unannounced channel: not broadcastable, but
* otherwise the same as a normal channel_update */
const u8 *pupdate = towire_gossip_store_private_update(tmpctx, update);
return gossip_store_add(gs, pupdate, NULL);
}
void gossip_store_add_channel_delete(struct gossip_store *gs, void gossip_store_add_channel_delete(struct gossip_store *gs,
const struct short_channel_id *scid) const struct short_channel_id *scid)
{ {
@ -513,6 +521,20 @@ const u8 *gossip_store_get(const tal_t *ctx,
return gossip_store_read(ctx, gs->fd, offset); return gossip_store_read(ctx, gs->fd, offset);
} }
const u8 *gossip_store_get_private_update(const tal_t *ctx,
struct gossip_store *gs,
u64 offset)
{
const u8 *pmsg = gossip_store_get(tmpctx, gs, offset);
u8 *msg;
if (!fromwire_gossip_store_private_update(ctx, pmsg, &msg))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Failed to decode private update @%"PRIu64": %s",
offset, tal_hex(tmpctx, pmsg));
return msg;
}
int gossip_store_readonly_fd(struct gossip_store *gs) int gossip_store_readonly_fd(struct gossip_store *gs)
{ {
return open(GOSSIP_STORE_FILENAME, O_RDONLY); return open(GOSSIP_STORE_FILENAME, O_RDONLY);
@ -579,6 +601,12 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
chan_ann = tal_steal(gs, msg); chan_ann = tal_steal(gs, msg);
chan_ann_off = gs->len; chan_ann_off = gs->len;
break; break;
case WIRE_GOSSIP_STORE_PRIVATE_UPDATE:
if (!fromwire_gossip_store_private_update(tmpctx, msg, &msg)) {
bad = "invalid gossip_store_private_update";
goto truncate;
}
/* fall thru */
case WIRE_CHANNEL_UPDATE: case WIRE_CHANNEL_UPDATE:
if (!routing_add_channel_update(rstate, if (!routing_add_channel_update(rstate,
take(msg), gs->len)) { take(msg), gs->len)) {

View file

@ -9,6 +9,10 @@ gossip_store_channel_amount,,satoshis,struct amount_sat
gossip_store_channel_delete,4099 gossip_store_channel_delete,4099
gossip_store_channel_delete,,short_channel_id,struct short_channel_id gossip_store_channel_delete,,short_channel_id,struct short_channel_id
gossip_store_private_update,4102
gossip_store_private_update,,len,u16
gossip_store_private_update,,update,len*u8
### Older v3 messages ### Older v3 messages
gossip_store_v3_channel_announcement,4096 gossip_store_v3_channel_announcement,4096
gossip_store_v3_channel_announcement,,len,u16 gossip_store_v3_channel_announcement,,len,u16

1 # gossip_store messages: messages persisted in the gossip_store
9 ### Older v3 messages gossip_store_private_update,4102
10 gossip_store_v3_channel_announcement,4096 gossip_store_private_update,,len,u16
11 gossip_store_v3_channel_announcement,,len,u16 gossip_store_private_update,,update,len*u8
12 ### Older v3 messages
13 gossip_store_v3_channel_announcement,4096
14 gossip_store_v3_channel_announcement,,len,u16
15 gossip_store_v3_channel_announcement,,announcement,len*u8
16 gossip_store_v3_channel_announcement,,announcement,len*u8 gossip_store_v3_channel_announcement,,satoshis,struct amount_sat
17 gossip_store_v3_channel_announcement,,satoshis,struct amount_sat gossip_store_v3_channel_update,4097
18 gossip_store_v3_channel_update,4097 gossip_store_v3_channel_update,,len,u16

View file

@ -26,6 +26,11 @@ struct gossip_store *gossip_store_new(struct routing_state *rstate);
*/ */
void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs); void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs);
/**
* Add a private channel_update message to the gossip_store
*/
u64 gossip_store_add_private_update(struct gossip_store *gs, const u8 *update);
/** /**
* Add a gossip message to the gossip_store (and optional addendum) * Add a gossip message to the gossip_store (and optional addendum)
*/ */
@ -48,6 +53,15 @@ const u8 *gossip_store_get(const tal_t *ctx,
struct gossip_store *gs, struct gossip_store *gs,
u64 offset); u64 offset);
/**
* Direct store accessor: loads private gossip msg back from store.
*
* Caller must ensure offset != 0. Never returns NULL.
*/
const u8 *gossip_store_get_private_update(const tal_t *ctx,
struct gossip_store *gs,
u64 offset);
/** /**
* If we need to compact the gossip store, do so. * If we need to compact the gossip store, do so.
* @gs: the gossip store. * @gs: the gossip store.

View file

@ -1403,12 +1403,12 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
/* Reload any private updates */ /* Reload any private updates */
if (chan->half[0].bcast.index) if (chan->half[0].bcast.index)
private_updates[0] private_updates[0]
= gossip_store_get(NULL, = gossip_store_get_private_update(NULL,
rstate->broadcasts->gs, rstate->broadcasts->gs,
chan->half[0].bcast.index); chan->half[0].bcast.index);
if (chan->half[1].bcast.index) if (chan->half[1].bcast.index)
private_updates[1] private_updates[1]
= gossip_store_get(NULL, = gossip_store_get_private_update(NULL,
rstate->broadcasts->gs, rstate->broadcasts->gs,
chan->half[1].bcast.index); chan->half[1].bcast.index);
} }
@ -1855,8 +1855,9 @@ bool routing_add_channel_update(struct routing_state *rstate,
/* Don't save if we're loading from store */ /* Don't save if we're loading from store */
assert(is_local_channel(rstate, chan)); assert(is_local_channel(rstate, chan));
if (!index) { if (!index) {
hc->bcast.index = gossip_store_add(rstate->broadcasts->gs, hc->bcast.index
update, NULL); = gossip_store_add_private_update(rstate->broadcasts->gs,
update);
} else } else
hc->bcast.index = index; hc->bcast.index = index;
return true; return true;

View file

@ -45,6 +45,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
/* Generated stub for fromwire_gossip_store_channel_delete */ /* Generated stub for fromwire_gossip_store_channel_delete */
bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_private_update */
bool fromwire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_v3_channel_announcement */ /* Generated stub for fromwire_gossip_store_v3_channel_announcement */
bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); }
@ -97,6 +100,9 @@ u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_
/* Generated stub for towire_gossip_store_channel_delete */ /* Generated stub for towire_gossip_store_channel_delete */
u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for towire_gossip_store_private_update */
u8 *towire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */ /* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } { fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }

View file

@ -34,6 +34,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
/* Generated stub for fromwire_gossip_store_channel_delete */ /* Generated stub for fromwire_gossip_store_channel_delete */
bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_private_update */
bool fromwire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_v3_channel_announcement */ /* Generated stub for fromwire_gossip_store_v3_channel_announcement */
bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); }
@ -86,6 +89,9 @@ u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_
/* Generated stub for towire_gossip_store_channel_delete */ /* Generated stub for towire_gossip_store_channel_delete */
u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for towire_gossip_store_private_update */
u8 *towire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */ /* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } { fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }

View file

@ -32,6 +32,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
/* Generated stub for fromwire_gossip_store_channel_delete */ /* Generated stub for fromwire_gossip_store_channel_delete */
bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_private_update */
bool fromwire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_v3_channel_announcement */ /* Generated stub for fromwire_gossip_store_v3_channel_announcement */
bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); }
@ -84,6 +87,9 @@ u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_
/* Generated stub for towire_gossip_store_channel_delete */ /* Generated stub for towire_gossip_store_channel_delete */
u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for towire_gossip_store_private_update */
u8 *towire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */ /* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } { fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }

View file

@ -32,6 +32,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
/* Generated stub for fromwire_gossip_store_channel_delete */ /* Generated stub for fromwire_gossip_store_channel_delete */
bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED) bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_private_update */
bool fromwire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_v3_channel_announcement */ /* Generated stub for fromwire_gossip_store_v3_channel_announcement */
bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED) bool fromwire_gossip_store_v3_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, struct amount_sat *satoshis UNNEEDED)
{ fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_store_v3_channel_announcement called!\n"); abort(); }
@ -84,6 +87,9 @@ u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_
/* Generated stub for towire_gossip_store_channel_delete */ /* Generated stub for towire_gossip_store_channel_delete */
u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED) u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); } { fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); }
/* Generated stub for towire_gossip_store_private_update */
u8 *towire_gossip_store_private_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED)
{ fprintf(stderr, "towire_gossip_store_private_update called!\n"); abort(); }
/* Generated stub for update_peers_broadcast_index */ /* Generated stub for update_peers_broadcast_index */
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED) void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); } { fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }