Browse Source

routing: remove negative fee support.

We can't get them; channel_update doesn't support it.

# 1M nodes:
$ /gossipd/test/run-bench-find_route 1000000 1 > /tmp/out
=> 47677 msec

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
589cb673ce
  1. 22
      gossipd/routing.c
  2. 4
      gossipd/routing.h
  3. 2
      gossipd/test/run-bench-find_route.c
  4. 2
      gossipd/test/run-find_route-specific.c
  5. 2
      gossipd/test/run-find_route.c

22
gossipd/routing.c

@ -246,11 +246,11 @@ static void clear_bfg(struct node_map *nodes)
} }
} }
static s64 connection_fee(const struct node_connection *c, u64 msatoshi) static u64 connection_fee(const struct node_connection *c, u64 msatoshi)
{ {
s64 fee; u64 fee;
if (mul_overflows_s64(c->proportional_fee, msatoshi)) if (mul_overflows_u64(c->proportional_fee, msatoshi))
return INFINITE; return INFINITE;
fee = (c->proportional_fee * msatoshi) / 1000000; fee = (c->proportional_fee * msatoshi) / 1000000;
/* This can't overflow: c->base_fee is a u32 */ /* This can't overflow: c->base_fee is a u32 */
@ -259,12 +259,8 @@ static s64 connection_fee(const struct node_connection *c, u64 msatoshi)
/* Risk of passing through this channel. We insert a tiny constant here /* Risk of passing through this channel. We insert a tiny constant here
* in order to prefer shorter routes, all things equal. */ * in order to prefer shorter routes, all things equal. */
static u64 risk_fee(s64 amount, u32 delay, double riskfactor) static u64 risk_fee(u64 amount, u32 delay, double riskfactor)
{ {
/* If fees are so negative we're making money, ignore risk. */
if (amount < 0)
return 1;
return 1 + amount * delay * riskfactor / BLOCKS_PER_YEAR / 10000; return 1 + amount * delay * riskfactor / BLOCKS_PER_YEAR / 10000;
} }
@ -278,7 +274,7 @@ static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor)
assert(c->dst == node); assert(c->dst == node);
for (h = 0; h < ROUTING_MAX_HOPS; h++) { for (h = 0; h < ROUTING_MAX_HOPS; h++) {
/* FIXME: Bias against smaller channels. */ /* FIXME: Bias against smaller channels. */
s64 fee; u64 fee;
u64 risk; u64 risk;
if (node->bfg[h].total == INFINITE) if (node->bfg[h].total == INFINITE)
@ -287,8 +283,8 @@ static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor)
fee = connection_fee(c, node->bfg[h].total); fee = connection_fee(c, node->bfg[h].total);
risk = node->bfg[h].risk + risk_fee(node->bfg[h].total + fee, risk = node->bfg[h].risk + risk_fee(node->bfg[h].total + fee,
c->delay, riskfactor); c->delay, riskfactor);
if (node->bfg[h].total + (s64)fee + (s64)risk if (node->bfg[h].total + fee + risk
< c->src->bfg[h+1].total + (s64)c->src->bfg[h+1].risk) { < c->src->bfg[h+1].total + c->src->bfg[h+1].risk) {
SUPERVERBOSE("...%s can reach here in hoplen %zu total %"PRIu64, SUPERVERBOSE("...%s can reach here in hoplen %zu total %"PRIu64,
type_to_string(trc, struct pubkey, type_to_string(trc, struct pubkey,
&c->src->id), &c->src->id),
@ -303,7 +299,7 @@ static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor)
static struct node_connection * static struct node_connection *
find_route(const tal_t *ctx, struct routing_state *rstate, find_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *from, const struct pubkey *to, u64 msatoshi, const struct pubkey *from, const struct pubkey *to, u64 msatoshi,
double riskfactor, s64 *fee, struct node_connection ***route) double riskfactor, u64 *fee, struct node_connection ***route)
{ {
struct node *n, *src, *dst; struct node *n, *src, *dst;
struct node_map_iter it; struct node_map_iter it;
@ -770,7 +766,7 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
struct node_connection **route; struct node_connection **route;
u64 total_amount; u64 total_amount;
unsigned int total_delay; unsigned int total_delay;
s64 fee; u64 fee;
struct route_hop *hops; struct route_hop *hops;
int i; int i;
struct node_connection *first_conn; struct node_connection *first_conn;

4
gossipd/routing.h

@ -14,7 +14,7 @@ struct node_connection {
/* millisatoshi. */ /* millisatoshi. */
u32 base_fee; u32 base_fee;
/* millionths */ /* millionths */
s32 proportional_fee; u32 proportional_fee;
/* Delay for HTLC in blocks.*/ /* Delay for HTLC in blocks.*/
u32 delay; u32 delay;
@ -54,7 +54,7 @@ struct node {
/* Temporary data for routefinding. */ /* Temporary data for routefinding. */
struct { struct {
/* Total to get to here from target. */ /* Total to get to here from target. */
s64 total; u64 total;
/* Total risk premium of this route. */ /* Total risk premium of this route. */
u64 risk; u64 risk;
/* Where that came from. */ /* Where that came from. */

2
gossipd/test/run-bench-find_route.c

@ -187,7 +187,7 @@ int main(int argc, char *argv[])
for (size_t i = 0; i < num_runs; i++) { for (size_t i = 0; i < num_runs; i++) {
struct pubkey from = nodeid(pseudorand(num_nodes)); struct pubkey from = nodeid(pseudorand(num_nodes));
struct pubkey to = nodeid(pseudorand(num_nodes)); struct pubkey to = nodeid(pseudorand(num_nodes));
s64 fee; u64 fee;
struct node_connection **route, *nc; struct node_connection **route, *nc;
nc = find_route(ctx, rstate, &from, &to, nc = find_route(ctx, rstate, &from, &to,

2
gossipd/test/run-find_route-specific.c

@ -61,7 +61,7 @@ int main(void)
struct node_connection *nc; struct node_connection *nc;
struct routing_state *rstate; struct routing_state *rstate;
struct pubkey a, b, c; struct pubkey a, b, c;
s64 fee; u64 fee;
struct node_connection **route; struct node_connection **route;
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY

2
gossipd/test/run-find_route.c

@ -72,7 +72,7 @@ int main(void)
struct routing_state *rstate; struct routing_state *rstate;
struct pubkey a, b, c, d; struct pubkey a, b, c, d;
struct privkey tmp; struct privkey tmp;
s64 fee; u64 fee;
struct node_connection **route; struct node_connection **route;
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY

Loading…
Cancel
Save