mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
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:
parent
a57fdf2033
commit
180a552fba
8 changed files with 75 additions and 4 deletions
|
@ -491,6 +491,14 @@ u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg,
|
|||
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,
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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_off = gs->len;
|
||||
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:
|
||||
if (!routing_add_channel_update(rstate,
|
||||
take(msg), gs->len)) {
|
||||
|
|
|
@ -9,6 +9,10 @@ gossip_store_channel_amount,,satoshis,struct amount_sat
|
|||
gossip_store_channel_delete,4099
|
||||
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
|
||||
gossip_store_v3_channel_announcement,4096
|
||||
gossip_store_v3_channel_announcement,,len,u16
|
||||
|
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
@ -48,6 +53,15 @@ const u8 *gossip_store_get(const tal_t *ctx,
|
|||
struct gossip_store *gs,
|
||||
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.
|
||||
* @gs: the gossip store.
|
||||
|
|
|
@ -1403,12 +1403,12 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
|
|||
/* Reload any private updates */
|
||||
if (chan->half[0].bcast.index)
|
||||
private_updates[0]
|
||||
= gossip_store_get(NULL,
|
||||
= gossip_store_get_private_update(NULL,
|
||||
rstate->broadcasts->gs,
|
||||
chan->half[0].bcast.index);
|
||||
if (chan->half[1].bcast.index)
|
||||
private_updates[1]
|
||||
= gossip_store_get(NULL,
|
||||
= gossip_store_get_private_update(NULL,
|
||||
rstate->broadcasts->gs,
|
||||
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 */
|
||||
assert(is_local_channel(rstate, chan));
|
||||
if (!index) {
|
||||
hc->bcast.index = gossip_store_add(rstate->broadcasts->gs,
|
||||
update, NULL);
|
||||
hc->bcast.index
|
||||
= gossip_store_add_private_update(rstate->broadcasts->gs,
|
||||
update);
|
||||
} else
|
||||
hc->bcast.index = index;
|
||||
return true;
|
||||
|
|
|
@ -45,6 +45,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
|
|||
/* 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)
|
||||
{ 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 */
|
||||
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(); }
|
||||
|
@ -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 */
|
||||
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(); }
|
||||
/* 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 */
|
||||
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
|
||||
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
|
||||
|
|
|
@ -34,6 +34,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
|
|||
/* 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)
|
||||
{ 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 */
|
||||
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(); }
|
||||
|
@ -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 */
|
||||
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(); }
|
||||
/* 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 */
|
||||
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
|
||||
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
|
||||
|
|
|
@ -32,6 +32,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
|
|||
/* 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)
|
||||
{ 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 */
|
||||
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(); }
|
||||
|
@ -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 */
|
||||
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(); }
|
||||
/* 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 */
|
||||
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
|
||||
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
|
||||
|
|
|
@ -32,6 +32,9 @@ bool fromwire_gossip_store_channel_amount(const void *p UNNEEDED, struct amount_
|
|||
/* 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)
|
||||
{ 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 */
|
||||
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(); }
|
||||
|
@ -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 */
|
||||
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(); }
|
||||
/* 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 */
|
||||
void update_peers_broadcast_index(struct list_head *peers UNNEEDED, u32 offset UNNEEDED)
|
||||
{ fprintf(stderr, "update_peers_broadcast_index called!\n"); abort(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue