diff --git a/gossipd/routing.c b/gossipd/routing.c index 2bf5a12ad..18b09c3cd 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -282,7 +282,8 @@ static void bad_gossip_order(const u8 *msg, const char *source, struct chan *new_chan(struct routing_state *rstate, const struct short_channel_id *scid, const struct pubkey *id1, - const struct pubkey *id2) + const struct pubkey *id2, + u64 satoshis) { struct chan *chan = tal(rstate, struct chan); int n1idx = pubkey_idx(id1, id2); @@ -306,7 +307,7 @@ struct chan *new_chan(struct routing_state *rstate, chan->txout_script = NULL; chan->channel_announce = NULL; chan->channel_announcement_index = 0; - chan->satoshis = 0; + chan->satoshis = satoshis; chan->local_disabled = false; n = tal_count(n2->chans); @@ -740,9 +741,8 @@ bool routing_add_channel_announcement(struct routing_state *rstate, * channel_announcements. See handle_channel_announcement. */ chan = get_channel(rstate, &scid); if (!chan) - chan = new_chan(rstate, &scid, &node_id_1, &node_id_2); + chan = new_chan(rstate, &scid, &node_id_1, &node_id_2, satoshis); - chan->satoshis = satoshis; /* Channel is now public. */ chan->channel_announce = tal_dup_arr(chan, u8, msg, tal_count(msg), 0); @@ -1682,7 +1682,6 @@ void handle_local_add_channel(struct routing_state *rstate, const u8 *msg) { struct short_channel_id scid; struct pubkey remote_node_id; - struct chan *chan; u64 satoshis; if (!fromwire_gossip_local_add_channel(msg, &scid, &remote_node_id, @@ -1702,6 +1701,5 @@ void handle_local_add_channel(struct routing_state *rstate, const u8 *msg) type_to_string(tmpctx, struct short_channel_id, &scid)); /* Create new (unannounced) channel */ - chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); - chan->satoshis = satoshis; + new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, satoshis); } diff --git a/gossipd/routing.h b/gossipd/routing.h index 10df1a023..999b23571 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -206,10 +206,17 @@ struct routing_state *new_routing_state(const tal_t *ctx, const struct pubkey *local_id, u32 prune_timeout); +/** + * Add a new bidirectional channel from id1 to id2 with the given + * short_channel_id and capacity to the local network view. The channel may not + * already exist, and might create the node entries for the two endpoints, if + * they do not exist yet. + */ struct chan *new_chan(struct routing_state *rstate, const struct short_channel_id *scid, const struct pubkey *id1, - const struct pubkey *id2); + const struct pubkey *id2, + u64 satoshis); /* Handlers for incoming messages */ diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 9c7d70a98..9984bce8b 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -154,7 +154,7 @@ static void add_connection(struct routing_state *rstate, memset(&scid, 0, sizeof(scid)); chan = get_channel(rstate, &scid); if (!chan) - chan = new_chan(rstate, &scid, from, to); + chan = new_chan(rstate, &scid, from, to, 1000000); c = &chan->half[pubkey_idx(from, to)]; c->base_fee = base_fee; diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 424c29496..79d25b5b3 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -121,14 +121,12 @@ get_or_make_connection(struct routing_state *rstate, abort(); chan = get_channel(rstate, &scid); if (!chan) - chan = new_chan(rstate, &scid, from_id, to_id); + chan = new_chan(rstate, &scid, from_id, to_id, satoshis); /* Make sure it's seen as initialized (update non-NULL). */ chan->half[idx].channel_update = (void *)chan; chan->half[idx].htlc_minimum_msat = 0; - chan->satoshis = satoshis; - return &chan->half[pubkey_idx(from_id, to_id)]; } diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 1863f6b7e..372106fab 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -119,9 +119,7 @@ static void add_connection(struct routing_state *rstate, chan = get_channel(rstate, &scid); if (!chan) - chan = new_chan(rstate, &scid, from, to); - - chan->satoshis = 100000; + chan = new_chan(rstate, &scid, from, to, 100000); c = &chan->half[pubkey_idx(from, to)]; /* Make sure it's seen as initialized (update non-NULL). */