Browse Source

routing: Make the capacity a parameter to new_chan

As pointed out by @rustyrussell the capacity is now always defined, so we can
fold that into the construction of the channel itself.

Reported-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <@cdecker>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
84905eac2b
  1. 12
      gossipd/routing.c
  2. 9
      gossipd/routing.h
  3. 2
      gossipd/test/run-bench-find_route.c
  4. 4
      gossipd/test/run-find_route-specific.c
  5. 4
      gossipd/test/run-find_route.c

12
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);
}

9
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 */

2
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;

4
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)];
}

4
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). */

Loading…
Cancel
Save