-
Notifications
You must be signed in to change notification settings - Fork 901
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
paymod: Scale presplit amounts to support larger payments while maintaining size buckets for privacy #3986
Merged
Merged
paymod: Scale presplit amounts to support larger payments while maintaining size buckets for privacy #3986
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2796,6 +2796,12 @@ REGISTER_PAYMENT_MODIFIER(waitblockheight, void *, NULL, waitblockheight_cb); | |
#define MPP_TARGET_SIZE (10 * 1000 * 1000) | ||
#define PRESPLIT_MAX_HTLC_SHARE 3 | ||
|
||
/* How many parts do we split into before we increase the bucket size. This is | ||
* a tradeoff between the number of payments whose parts are identical and the | ||
* number of concurrent HTLCs. The larger this amount the more HTLCs we may | ||
* end up starting, but the more payments result in the same part sizes.*/ | ||
#define PRESPLIT_MAX_SPLITS 16 | ||
|
||
static struct presplit_mod_data *presplit_mod_data_init(struct payment *p) | ||
{ | ||
struct presplit_mod_data *d; | ||
|
@@ -2871,6 +2877,15 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) | |
u32 htlcs = payment_max_htlcs(p) / PRESPLIT_MAX_HTLC_SHARE; | ||
struct amount_msat target, amt = p->amount; | ||
char *partids = tal_strdup(tmpctx, ""); | ||
u64 target_amount = MPP_TARGET_SIZE; | ||
|
||
/* We aim for at most PRESPLIT_MAX_SPLITS parts, even for | ||
* large values. To achieve this we take the base amount and | ||
* multiply it by the number of targetted parts until the | ||
* total amount divided by part amount gives us at most that | ||
* number of parts. */ | ||
while (target_amount * PRESPLIT_MAX_SPLITS < p->amount.millisatoshis) /* Raw: Multiplication comparison */ | ||
target_amount *= PRESPLIT_MAX_SPLITS; | ||
|
||
/* We need to opt-in to the MPP sending facility no matter | ||
* what we do. That means setting all partids to a non-zero | ||
|
@@ -2888,10 +2903,10 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) | |
return payment_fail( | ||
p, "Cannot attempt payment, we have no channel to " | ||
"which we can add an HTLC"); | ||
} else if (p->amount.millisatoshis / MPP_TARGET_SIZE > htlcs) /* Raw: division */ | ||
} else if (p->amount.millisatoshis / target_amount > htlcs) /* Raw: division */ | ||
target.millisatoshis = p->amount.millisatoshis / htlcs; /* Raw: division */ | ||
else | ||
target = AMOUNT_MSAT(MPP_TARGET_SIZE); | ||
target.millisatoshis = target_amount; /* Raw: init */ | ||
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. Simpler as |
||
|
||
/* If we are already below the target size don't split it | ||
* either. */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
target = amount_msat_div(p->amount, htlcs);