gossip: Have gossip_store annotate gossip messages
This makes the exposed interface much smaller, cleaner and will allow us to just replay gossip messages from the broadcast. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
0546ca446d
commit
e6ab594904
|
@ -1782,8 +1782,7 @@ static struct io_plan *owner_msg_in(struct io_conn *conn,
|
|||
} else if (type == WIRE_GOSSIP_GET_UPDATE) {
|
||||
handle_get_update(peer, dc->msg_in);
|
||||
} else if (type == WIRE_GOSSIP_LOCAL_ADD_CHANNEL) {
|
||||
gossip_store_local_add_channel(peer->daemon->rstate->store,
|
||||
dc->msg_in);
|
||||
gossip_store_add(peer->daemon->rstate->store, dc->msg_in);
|
||||
handle_local_add_channel(peer->daemon->rstate, dc->msg_in);
|
||||
} else if (type == WIRE_GOSSIP_LOCAL_CHANNEL_UPDATE) {
|
||||
handle_local_channel_update(peer, dc->msg_in);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <gossipd/gen_gossip_store.h>
|
||||
#include <gossipd/gen_gossip_wire.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <wire/gen_peer_wire.h>
|
||||
#include <wire/wire.h>
|
||||
|
@ -107,23 +109,46 @@ static void gossip_store_append(struct gossip_store *gs, const u8 *msg)
|
|||
}
|
||||
}
|
||||
|
||||
void gossip_store_add_channel_announcement(struct gossip_store *gs,
|
||||
const u8 *gossip_msg, u64 satoshis)
|
||||
static void gossip_store_add_channel_announcement(struct gossip_store *gs,
|
||||
const u8 *gossip_msg)
|
||||
{
|
||||
u8 *msg = towire_gossip_store_channel_announcement(NULL, gossip_msg, satoshis);
|
||||
secp256k1_ecdsa_signature node_signature_1, node_signature_2;
|
||||
secp256k1_ecdsa_signature bitcoin_signature_1, bitcoin_signature_2;
|
||||
u8 *features;
|
||||
struct bitcoin_blkid chain_hash;
|
||||
struct short_channel_id scid;
|
||||
struct pubkey node_id_1;
|
||||
struct pubkey node_id_2;
|
||||
struct pubkey bitcoin_key_1;
|
||||
struct pubkey bitcoin_key_2;
|
||||
|
||||
/* Which channel are we talking about here? */
|
||||
if (!fromwire_channel_announcement(
|
||||
tmpctx, gossip_msg, &node_signature_1, &node_signature_2,
|
||||
&bitcoin_signature_1, &bitcoin_signature_2, &features,
|
||||
&chain_hash, &scid, &node_id_1, &node_id_2, &bitcoin_key_1,
|
||||
&bitcoin_key_2))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Error parsing channel_announcement");
|
||||
|
||||
struct chan *chan = get_channel(gs->rstate, &scid);
|
||||
assert(chan && chan->satoshis > 0);
|
||||
|
||||
u8 *msg = towire_gossip_store_channel_announcement(NULL, gossip_msg,
|
||||
chan->satoshis);
|
||||
gossip_store_append(gs, msg);
|
||||
tal_free(msg);
|
||||
}
|
||||
|
||||
void gossip_store_add_channel_update(struct gossip_store *gs,
|
||||
const u8 *gossip_msg)
|
||||
static void gossip_store_add_channel_update(struct gossip_store *gs,
|
||||
const u8 *gossip_msg)
|
||||
{
|
||||
u8 *msg = towire_gossip_store_channel_update(NULL, gossip_msg);
|
||||
gossip_store_append(gs, msg);
|
||||
tal_free(msg);
|
||||
}
|
||||
|
||||
void gossip_store_add_node_announcement(struct gossip_store *gs,
|
||||
static void gossip_store_add_node_announcement(struct gossip_store *gs,
|
||||
const u8 *gossip_msg)
|
||||
{
|
||||
u8 *msg = towire_gossip_store_node_announcement(NULL, gossip_msg);
|
||||
|
@ -139,14 +164,31 @@ void gossip_store_add_channel_delete(struct gossip_store *gs,
|
|||
tal_free(msg);
|
||||
}
|
||||
|
||||
void gossip_store_local_add_channel(struct gossip_store *gs,
|
||||
const u8 *add_msg)
|
||||
static void gossip_store_local_add_channel(struct gossip_store *gs,
|
||||
const u8 *add_msg)
|
||||
{
|
||||
u8 *msg = towire_gossip_store_local_add_channel(NULL, add_msg);
|
||||
gossip_store_append(gs, msg);
|
||||
tal_free(msg);
|
||||
}
|
||||
|
||||
void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg)
|
||||
{
|
||||
int t = fromwire_peektype(gossip_msg);
|
||||
|
||||
if (t == WIRE_CHANNEL_ANNOUNCEMENT)
|
||||
gossip_store_add_channel_announcement(gs, gossip_msg);
|
||||
else if(t == WIRE_CHANNEL_UPDATE)
|
||||
gossip_store_add_channel_update(gs, gossip_msg);
|
||||
else if(t == WIRE_NODE_ANNOUNCEMENT)
|
||||
gossip_store_add_node_announcement(gs, gossip_msg);
|
||||
else if(t == WIRE_GOSSIP_LOCAL_ADD_CHANNEL)
|
||||
gossip_store_local_add_channel(gs, gossip_msg);
|
||||
else
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Unexpected message passed to gossip_store: %s",
|
||||
wire_type_name(t));
|
||||
}
|
||||
|
||||
void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
|
||||
{
|
||||
|
|
|
@ -27,28 +27,9 @@ struct gossip_store *gossip_store_new(const tal_t *ctx,
|
|||
void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs);
|
||||
|
||||
/**
|
||||
* Store a channel_announcement with all its extra data
|
||||
* Add a gossip message to the gossip_store
|
||||
*/
|
||||
void gossip_store_add_channel_announcement(struct gossip_store *gs,
|
||||
const u8 *gossip_msg, u64 satoshis);
|
||||
|
||||
/**
|
||||
* Store a local_add_channel so we remember it when restarting
|
||||
*/
|
||||
void gossip_store_local_add_channel(struct gossip_store *gs,
|
||||
const u8 *add_msg);
|
||||
|
||||
/**
|
||||
* Store a channel_update with its associated data in the gossip_store
|
||||
*/
|
||||
void gossip_store_add_channel_update(struct gossip_store *gs,
|
||||
const u8 *gossip_msg);
|
||||
|
||||
/**
|
||||
* Store a node_announcement with its associated data in the gossip_store
|
||||
*/
|
||||
void gossip_store_add_node_announcement(struct gossip_store *gs,
|
||||
const u8 *gossip_msg);
|
||||
void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg);
|
||||
|
||||
/**
|
||||
* Remember that we deleted a channel as a result of its outpoint being spent
|
||||
|
|
|
@ -942,7 +942,7 @@ void handle_pending_cannouncement(struct routing_state *rstate,
|
|||
if (!routing_add_channel_announcement(rstate, pending->announce, satoshis))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Could not add channel_announcement");
|
||||
gossip_store_add_channel_announcement(rstate->store, pending->announce, satoshis);
|
||||
gossip_store_add(rstate->store, pending->announce);
|
||||
|
||||
/* Did we have an update waiting? If so, apply now. */
|
||||
process_pending_channel_update(rstate, scid, pending->updates[0]);
|
||||
|
@ -1207,7 +1207,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
|
|||
/* Store the channel_update for both public and non-public channels
|
||||
* (non-public ones may just be the incoming direction). We'd have
|
||||
* dropped invalid ones earlier. */
|
||||
gossip_store_add_channel_update(rstate->store, serialized);
|
||||
gossip_store_add(rstate->store, serialized);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1420,7 +1420,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||
|
||||
applied = routing_add_node_announcement(rstate, serialized);
|
||||
assert(applied);
|
||||
gossip_store_add_node_announcement(rstate->store, serialized);
|
||||
gossip_store_add(rstate->store, serialized);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue