fix: prevent decimal precision error in extendLease amount calculation#244
Open
rippleitinnz wants to merge 1 commit into
Open
fix: prevent decimal precision error in extendLease amount calculation#244rippleitinnz wants to merge 1 commit into
rippleitinnz wants to merge 1 commit into
Conversation
Multiplying moments * uriInfo.leaseAmount using JavaScript floating point produces imprecise results for certain leaseAmount values (e.g. 0.00007). Example: 23 * 0.00007 = 0.0016099999999999999 instead of 0.00161. This causes a 'Decimal precision out of range' error in the Xahau payment transaction, causing extendLease to fail silently with TRANSACTION_FAILURE for any number of moments > 1 on affected hosts. Fix: round the result to 8 decimal places before submission using parseFloat((moments * leaseAmount).toFixed(8)).
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.
Problem
Multiplying
moments * uriInfo.leaseAmountusing JavaScript floating pointproduces imprecise results for certain leaseAmount values (e.g. 0.00007).
Example:
23 * 0.00007 = 0.0016099999999999999instead of0.00161This causes a "Decimal precision out of range" error in the Xahau payment
transaction, causing
extendLeaseto fail withTRANSACTION_FAILUREforany number of moments > 1 on affected hosts. Single-moment extensions work
because
1 * leaseAmountstays clean.Fix
Round the result to 8 decimal places before submission:
parseFloat((moments * uriInfo.leaseAmount).toFixed(8))Tested
Confirmed on mainnet — hosts with leaseAmount
0.00007fail at 23 moments,succeed at 1 moment. Fix resolves the precision error.