Browse Source

gossipd/routing: remove/static unused functions.

I missed these when I removed the legacy daemon.  We also remove the
min_blocks field which was always 0.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
6933db04b5
  1. 116
      gossipd/routing.c
  2. 41
      gossipd/routing.h
  3. 33
      gossipd/test/run-find_route.c

116
gossipd/routing.c

@ -16,6 +16,14 @@
/* 365.25 * 24 * 60 / 10 */
#define BLOCKS_PER_YEAR 52596
static struct node_map *empty_node_map(const tal_t *ctx)
{
struct node_map *map = tal(ctx, struct node_map);
node_map_init(map);
tal_add_destructor(map, node_map_clear);
return map;
}
struct routing_state *new_routing_state(const tal_t *ctx,
const struct sha256_double *chain_hash)
{
@ -42,20 +50,6 @@ bool node_map_node_eq(const struct node *n, const secp256k1_pubkey *key)
return structeq(&n->id.pubkey, key);
}
struct node_map *empty_node_map(const tal_t *ctx)
{
struct node_map *map = tal(ctx, struct node_map);
node_map_init(map);
tal_add_destructor(map, node_map_clear);
return map;
}
struct node *get_node(struct routing_state *rstate,
const struct pubkey *id)
{
return node_map_get(rstate->nodes, &id->pubkey);
}
static void destroy_node(struct node *node)
{
/* These remove themselves from the array. */
@ -65,8 +59,14 @@ static void destroy_node(struct node *node)
tal_free(node->out[0]);
}
struct node *new_node(struct routing_state *rstate,
static struct node *get_node(struct routing_state *rstate,
const struct pubkey *id)
{
return node_map_get(rstate->nodes, &id->pubkey);
}
static struct node *new_node(struct routing_state *rstate,
const struct pubkey *id)
{
struct node *n;
@ -86,22 +86,6 @@ struct node *new_node(struct routing_state *rstate,
return n;
}
struct node *add_node(
struct routing_state *rstate,
const struct pubkey *pk)
{
struct node *n = get_node(rstate, pk);
if (!n) {
n = new_node(rstate, pk);
status_trace("Creating new node %s",
type_to_string(trc, struct pubkey, pk));
} else {
status_trace("Update existing node %s",
type_to_string(trc, struct pubkey, pk));
}
return n;
}
static bool remove_conn_from_array(struct node_connection ***conns,
struct node_connection *nc)
{
@ -127,9 +111,9 @@ static void destroy_connection(struct node_connection *nc)
abort();
}
struct node_connection * get_connection(struct routing_state *rstate,
const struct pubkey *from_id,
const struct pubkey *to_id)
static struct node_connection * get_connection(struct routing_state *rstate,
const struct pubkey *from_id,
const struct pubkey *to_id)
{
int i, n;
struct node *from, *to;
@ -232,61 +216,11 @@ struct node_connection *half_add_connection(struct routing_state *rstate,
nc->active = false;
nc->flags = flags;
nc->last_timestamp = -1;
nc->min_blocks = 0;
return nc;
}
/* Updates existing route if required. */
struct node_connection *add_connection(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to,
u32 base_fee, s32 proportional_fee,
u32 delay, u32 min_blocks)
{
struct node_connection *c = get_or_make_connection(rstate, from, to);
c->base_fee = base_fee;
c->proportional_fee = proportional_fee;
c->delay = delay;
c->min_blocks = min_blocks;
c->active = true;
memset(&c->short_channel_id, 0, sizeof(c->short_channel_id));
c->flags = get_channel_direction(from, to);
return c;
}
void remove_connection(struct routing_state *rstate,
const struct pubkey *src, const struct pubkey *dst)
{
struct node *from, *to;
size_t i, num_edges;
status_trace("Removing route from %s to %s",
type_to_string(trc, struct pubkey, src),
type_to_string(trc, struct pubkey, dst));
from = get_node(rstate, src);
to = get_node(rstate, dst);
if (!from || !to) {
status_trace("Not found: src=%p dst=%p", from, to);
return;
}
num_edges = tal_count(from->out);
for (i = 0; i < num_edges; i++) {
if (from->out[i]->dst != to)
continue;
status_trace("Matched route %zu of %zu", i, num_edges);
/* Destructor makes it delete itself */
tal_free(from->out[i]);
return;
}
status_trace(" None of %zu routes matched", num_edges);
}
/* Too big to reach, but don't overflow if added. */
#define INFINITE 0x3FFFFFFFFFFFFFFFULL
@ -358,7 +292,7 @@ static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor)
}
}
struct node_connection *
static struct node_connection *
find_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *from, const struct pubkey *to, u64 msatoshi,
double riskfactor, s64 *fee, struct node_connection ***route)
@ -466,11 +400,11 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
return first_conn;
}
bool add_channel_direction(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to,
const struct short_channel_id *short_channel_id,
const u8 *announcement)
static bool add_channel_direction(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to,
const struct short_channel_id *short_channel_id,
const u8 *announcement)
{
struct node_connection *c = get_connection(rstate, from, to);
u16 direction = get_channel_direction(from, to);
@ -917,8 +851,6 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
total_amount += connection_fee(route[i], total_amount);
total_delay += route[i]->delay;
if (total_delay < route[i]->min_blocks)
total_delay = route[i]->min_blocks;
hops[i + 1].delay = total_delay;
}
/* Backfill the first hop manually */

41
gossipd/routing.h

@ -18,8 +18,6 @@ struct node_connection {
/* Delay for HTLC in blocks.*/
u32 delay;
/* Minimum allowable HTLC expiry in blocks. */
u32 min_blocks;
/* Is this connection active? */
bool active;
@ -97,27 +95,10 @@ struct route_hop {
struct routing_state *new_routing_state(const tal_t *ctx,
const struct sha256_double *chain_hash);
struct node *new_node(struct routing_state *rstate,
const struct pubkey *id);
struct node *get_node(struct routing_state *rstate,
const struct pubkey *id);
/* msatoshi must be possible (< 21 million BTC), ie < 2^60.
* If it returns more than msatoshi, it overflowed. */
s64 connection_fee(const struct node_connection *c, u64 msatoshi);
/* Updates existing node, or creates a new one as required. */
struct node *add_node(struct routing_state *rstate,
const struct pubkey *pk);
/* Updates existing connection, or creates new one as required. */
struct node_connection *add_connection(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to,
u32 base_fee, s32 proportional_fee,
u32 delay, u32 min_blocks);
/* Add a connection to the routing table, but do not mark it as usable
* yet. Used by channel_announcements before the channel_update comes
* in. */
@ -128,34 +109,12 @@ struct node_connection *half_add_connection(struct routing_state *rstate,
const struct short_channel_id *schanid,
const u16 flags);
/* Get an existing connection between `from` and `to`, NULL if no such
* connection exists. */
struct node_connection *get_connection(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to);
/* Given a short_channel_id, retrieve the matching connection, or NULL if it is
* unknown. */
struct node_connection *get_connection_by_scid(const struct routing_state *rstate,
const struct short_channel_id *schanid,
const u8 direction);
void remove_connection(struct routing_state *rstate,
const struct pubkey *src, const struct pubkey *dst);
struct node_connection *
find_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *from, const struct pubkey *to, u64 msatoshi,
double riskfactor, s64 *fee, struct node_connection ***route);
struct node_map *empty_node_map(const tal_t *ctx);
bool add_channel_direction(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to,
const struct short_channel_id *short_channel_id,
const u8 *announcement);
bool read_ip(const tal_t *ctx, const u8 *addresses, char **hostname, int *port);
u8 *write_ip(const tal_t *ctx, const char *srcip, int port);

33
gossipd/test/run-find_route.c

@ -44,6 +44,23 @@ void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
const void *trc;
/* Updates existing route if required. */
static struct node_connection *add_connection(struct routing_state *rstate,
const struct pubkey *from,
const struct pubkey *to,
u32 base_fee, s32 proportional_fee,
u32 delay)
{
struct node_connection *c = get_or_make_connection(rstate, from, to);
c->base_fee = base_fee;
c->proportional_fee = proportional_fee;
c->delay = delay;
c->active = true;
memset(&c->short_channel_id, 0, sizeof(c->short_channel_id));
c->flags = get_channel_direction(from, to);
return c;
}
int main(void)
{
static const struct sha256_double zerohash;
@ -62,14 +79,14 @@ int main(void)
memset(&tmp, 'a', sizeof(tmp));
pubkey_from_privkey(&tmp, &a);
add_node(rstate, &a);
new_node(rstate, &a);
memset(&tmp, 'b', sizeof(tmp));
pubkey_from_privkey(&tmp, &b);
add_node(rstate, &b);
new_node(rstate, &b);
/* A<->B */
add_connection(rstate, &a, &b, 1, 1, 1, 1);
add_connection(rstate, &a, &b, 1, 1, 1);
nc = find_route(ctx, rstate, &a, &b, 1000, 1.0, &fee, &route);
assert(nc);
@ -79,12 +96,12 @@ int main(void)
/* A<->B<->C */
memset(&tmp, 'c', sizeof(tmp));
pubkey_from_privkey(&tmp, &c);
add_node(rstate, &c);
new_node(rstate, &c);
status_trace("A = %s", type_to_string(trc, struct pubkey, &a));
status_trace("B = %s", type_to_string(trc, struct pubkey, &b));
status_trace("C = %s", type_to_string(trc, struct pubkey, &c));
add_connection(rstate, &b, &c, 1, 1, 1, 1);
add_connection(rstate, &b, &c, 1, 1, 1);
nc = find_route(ctx, rstate, &a, &c, 1000, 1.0, &fee, &route);
assert(nc);
@ -94,11 +111,11 @@ int main(void)
/* A<->D<->C: Lower base, higher percentage. */
memset(&tmp, 'd', sizeof(tmp));
pubkey_from_privkey(&tmp, &d);
add_node(rstate, &d);
new_node(rstate, &d);
status_trace("D = %s", type_to_string(trc, struct pubkey, &d));
add_connection(rstate, &a, &d, 0, 2, 1, 1);
add_connection(rstate, &d, &c, 0, 2, 1, 1);
add_connection(rstate, &a, &d, 0, 2, 1);
add_connection(rstate, &d, &c, 0, 2, 1);
/* Will go via D for small amounts. */
nc = find_route(ctx, rstate, &a, &c, 1000, 1.0, &fee, &route);

Loading…
Cancel
Save