Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions common/fee_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ u32 marginal_feerate(u32 current_feerate)
/* This could happen in future if we celebrate sub-sat summer! */
if (current_feerate < minfeerate)
current_feerate = minfeerate;
if (current_feerate > maxfeerate)
return current_feerate * 1.1;
if (current_feerate > maxfeerate) {
u64 marginal = ((u64)current_feerate * 11) / 10;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that the fixed version rounds down ((current_feerate * 11) / 10 truncates), while the old double version also truncated on conversion to u32? I confirmed both truncate the same way for in-range values, so behavior should be unchanged for normal feerates - just confirming this was checked, since it affects the exact fee charged to peers, not just an internal-only value :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was simply trying to preserve the existing behavior. However, I don't think it really matters whether we use floor, round, or ceil here, since this function only influences the "fee spike buffer", whose size is a fuzzy concept to begin with.

if (marginal > UINT32_MAX)
return UINT32_MAX;
return marginal;
}

/* min gives 1, max gives 0.1 */
double proportion = 1.0 - ((double)current_feerate - minfeerate) / (maxfeerate - minfeerate) * 0.9;
Expand Down
7 changes: 7 additions & 0 deletions common/test/run-marginal_feerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,12 @@ int main(int argc, char *argv[])
u32 half = (45000 + 253)/2;
assert(marginal_feerate(half) == (u32)(half * 1.55));

/* These values straddle the case where adding 10% exceeds UINT32_MAX.
* No overflow should occur. */
assert(marginal_feerate(3904515722) == UINT32_MAX - 1);
assert(marginal_feerate(3904515723) == UINT32_MAX);
assert(marginal_feerate(3904515724) == UINT32_MAX);
assert(marginal_feerate(UINT32_MAX) == UINT32_MAX);

common_shutdown();
}
Loading