mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-06 06:34:22 +01:00
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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)];
|
||||
}
|
||||
|
||||
|
||||
@@ -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). */
|
||||
|
||||
Reference in New Issue
Block a user