Repository navigation
fix(fees): avoid floating point error when converting sats/vbyte to sats/kvbyte - #1587
Merged
theborakompanioni merged 1 commit intoOct 31, 2026
Conversation
…ats/kvbyte `Math.ceil(value * 1_000)` rounds up floating point noise, e.g. 4.03 * 1_000 === 4030.0000000000005, so 4.03 sat/vB became 4031 sat/kvB. This hit 2936 of the valid values (1.001-350 sat/vB), both for the fee sent with a transaction and for `tx_fees` saved from the fee settings, which then reopened showing 4.031 instead of 4.03. Round the product to 3 decimals before rounding up, in one shared helper. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
theborakompanioni
approved these changes
Oct 31, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Mining fees entered in sats/vbyte are converted to sats/kvbyte with
Math.ceil(value * 1_000). Because of floating point error,4.03 * 1_000 === 4030.0000000000005, so the result is rounded up to4031. This affects 2936 of the valid values (1.001–350 sat/vB), in two places:tx_feesis saved as4031, and the dialog shows4.031the next time it's opened4.03sat/vB is requested astxfee = 4031Changes:
add
satsPerVbyteToSatsPerKvbyteinsrc/lib/feeConfig.ts, which rounds the product to 3 decimals beforeMath.ceil, so real fractions still round up (4.0301→4031,1 + 1/3→1334)use it in
FeeConfigDialogandcollaborativeSendinstead of the two inline copiestests: helper cases, a check that every
tx_feesvalue from 1001 to 350000 converts back to itself, plus one test each for the send request and the saved fee settingFixes Fees: sats/vbyte values like 4.03 are saved as 4031 sats/kvbyte (floating point rounding) #1586
Visual Demo (For contributors especially)
Image Demo (if applicable):
The new tests run against the old code (
Math.ceil(value * 1_000)) and against the fix:Before
After