-
Notifications
You must be signed in to change notification settings - Fork 1k
Improve route randomization #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0e6aae8
5d03899
bb46f5e
f223d5e
d1a64f4
2cb6023
56203c2
3d2e910
9913e3f
d3493aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| #include <bitcoin/block.h> | ||
| #include <bitcoin/script.h> | ||
| #include <ccan/array_size/array_size.h> | ||
| #include <ccan/crypto/siphash24/siphash24.h> | ||
| #include <ccan/endian/endian.h> | ||
| #include <ccan/structeq/structeq.h> | ||
| #include <ccan/tal/str/str.h> | ||
|
|
@@ -331,10 +330,24 @@ static u64 risk_fee(u64 amount, u32 delay, double riskfactor) | |
|
|
||
| /* We track totals, rather than costs. That's because the fee depends | ||
| * on the current amount passing through. */ | ||
| static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor) | ||
| static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor, | ||
| double fuzz, const struct siphash_seed *base_seed) | ||
| { | ||
| struct node_connection *c = node->in[edgenum]; | ||
| size_t h; | ||
| double fee_scale = 1.0; | ||
|
|
||
| if (fuzz != 0.0) { | ||
| u64 scid = short_channel_id_to_uint(&c->short_channel_id); | ||
| u64 h = siphash24(base_seed, &scid, sizeof(scid)); | ||
|
|
||
| /* Scale fees for this channel */ | ||
| /* rand = (h / UINT64_MAX) random number between 0.0 -> 1.0 | ||
| * 2*fuzz*rand random number between 0.0 -> 2*fuzz | ||
| * 2*fuzz*rand - fuzz random number between -fuzz -> +fuzz | ||
| */ | ||
| fee_scale = 1.0 + (2.0 * fuzz * h / UINT64_MAX) - fuzz; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure we can just make h an s64 and divide by INT64_MAX: But it's trivial and unlikely to be any faster, so I'll just leave this as a comment.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Negative number absolute range is one higher than positive range, so getting INT64_MIN by chance would break that. Of course very unlikely but well. |
||
| } | ||
|
|
||
| assert(c->dst == node); | ||
| for (h = 0; h < ROUTING_MAX_HOPS; h++) { | ||
|
|
@@ -345,7 +358,7 @@ static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor) | |
| if (node->bfg[h].total == INFINITE) | ||
| continue; | ||
|
|
||
| fee = connection_fee(c, node->bfg[h].total); | ||
| fee = connection_fee(c, node->bfg[h].total) * fee_scale; | ||
| risk = node->bfg[h].risk + risk_fee(node->bfg[h].total + fee, | ||
| c->delay, riskfactor); | ||
|
|
||
|
|
@@ -380,7 +393,9 @@ static bool nc_is_routable(const struct node_connection *nc, time_t now) | |
| 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, u64 *fee, struct node_connection ***route) | ||
| double riskfactor, | ||
| double fuzz, const struct siphash_seed *base_seed, | ||
| u64 *fee, struct node_connection ***route) | ||
| { | ||
| struct node *n, *src, *dst; | ||
| struct node_map_iter it; | ||
|
|
@@ -440,7 +455,8 @@ find_route(const tal_t *ctx, struct routing_state *rstate, | |
| SUPERVERBOSE("...unroutable"); | ||
| continue; | ||
| } | ||
| bfg_one_edge(n, i, riskfactor); | ||
| bfg_one_edge(n, i, riskfactor, | ||
| fuzz, base_seed); | ||
| SUPERVERBOSE("...done"); | ||
| } | ||
| } | ||
|
|
@@ -1118,7 +1134,8 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate, | |
| const struct pubkey *source, | ||
| const struct pubkey *destination, | ||
| const u32 msatoshi, double riskfactor, | ||
| u32 final_cltv) | ||
| u32 final_cltv, | ||
| double fuzz, const struct siphash_seed *base_seed) | ||
| { | ||
| struct node_connection **route; | ||
| u64 total_amount; | ||
|
|
@@ -1130,6 +1147,7 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate, | |
|
|
||
| first_conn = find_route(ctx, rstate, source, destination, msatoshi, | ||
| riskfactor / BLOCKS_PER_YEAR / 10000, | ||
| fuzz, base_seed, | ||
| &fee, &route); | ||
|
|
||
| if (!first_conn) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is 75.0, or up to 75% fee distortion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops!