remove float from the core shares calculation for LP + use shopsring decimal #3451
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.
This is a fix for the state issue on testnet.
problem
The core calculate for each liquidity provider their share of the fees being paid. Using this share (a number between 0 and 1) we then multiply it against the total amount of fee to be paid per LP.
We then math.Floor the result of all these (share * fee to be paid) calculation, and give the rest (1 at most) to the last LP for which we paid the fee. Doing this ensure that we do not loose any pennies in the calculation.
This is very fine until we get a scenario where a float on some run / nodes fives a result in between 2 numbers (e.g sometimes: 127855.99999999999 and sometimes 127856) which would impact the actual flooring, and the rest to be distributed.
Amount of fee to be paid - 799100
Run 1
Run 2
Adding all amount floored, give us for the run 1 a rest of 1, which is then distributed as part of the last party (dd2154a...7ba0a9). Adding all amount floored of the run 2 gives us the exact amoubt distributed, which do not requred to give the rest of 1 to the last party.
fix
We implemented all floating point calculation using a abitrary precision fixed point decimal number library for go (github.com/shopspring/decimal).
This will impact slighlty the performance, but will keep all calculation of fees correct over all the different nodes.