Skip to content

fix: prevent decimal precision error in extendLease amount calculation#244

Open
rippleitinnz wants to merge 1 commit into
mainfrom
fix/extend-lease-decimal-precision
Open

fix: prevent decimal precision error in extendLease amount calculation#244
rippleitinnz wants to merge 1 commit into
mainfrom
fix/extend-lease-decimal-precision

Conversation

@rippleitinnz

Copy link
Copy Markdown

Problem

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 with TRANSACTION_FAILURE for
any number of moments > 1 on affected hosts. Single-moment extensions work
because 1 * leaseAmount stays 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.00007 fail at 23 moments,
succeed at 1 moment. Fix resolves the precision error.

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)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant