Bugfix: correctly compute transfer amount
How to reproduce the error:
- on a local Duniter-v2 test node transfer e.g. 1GD from Alice to Bob
- outcome: 2GD are being transferred, rather than the expected 1GD
This error was compounded by 3 factors:
- Transaction fees are already applied by the network/blockchain, so clients don't need to do anything special
- Transaction fees were being added to the transfer amount (Alice to Bob) so they went to Bob and not the treasury
- Fees were multiplied by 100, so rather than the expected 0.01GD, we were appyling 1GD
Solution:
- Simply just not add transfer fees to the transaction
Additionally, there was an issue where the check for available balance was done using the wrong amount units (cents rather than GD), and the fees in configuration data were incorrect for GDev. These issues have also been addressed in this MR.
This is the proof of the blockchain logic already adding fees (which incidentally are 2GD cents and not 1 as stated by Cesium):
However, the blockchain ATM also refunds the fees as a follow-up system event, as part of the blockchain rules:
Merge request reports
Activity
requested review from @blavenie
assigned to @txels
463 463 464 464 // Compute total amount (with fee) and remove decimals 465 465 const powBase = Math.pow(10, currency.decimals || 0); 466 const totalAmount = Math.floor((amount + fee) * powBase); 466 const totalAmount = Math.floor(amount * powBase + fee); changed this line in version 2 of the diff
added 5 commits
-
c165ec62...06def537 - 4 commits from branch
develop
- bd5e9fcb - bugfix: transfer fees shouldn't be added to transfer
-
c165ec62...06def537 - 4 commits from branch
added 1 commit
- f15d7101 - Check for enough credit should use totalAmount
Thank you for your analysis !
But i cannot use your changes: Yes, fees should NOT be added to the TX amount, BUT we need to check if the account has enought money to paid it.
I fix the original issue base on your analysis. in the
develop
branch. Thank you again !Edited by Benoit LavenierAh cool. Please note that this MR did already check that the account had enough money to check for amount and fees, and did this using the right units (!5 (diffs))
Looking at the code in develop right now I think it still suffers from one of the issues I mentioned, which is that the fees are multiplied by
powBase
(https://git.duniter.org/clients/cesium-grp/cesium2s/-/blob/develop/src/app/account/accounts.service.ts?ref_type=heads#L483) when in fact they souldn't, as they are in GDcents and not GD (see https://git.duniter.org/clients/cesium-grp/cesium2s/-/blob/develop/src/app/network/network.service.ts?ref_type=heads#L25).So the current code in
develop
still has a unit mismatch.
mentioned in merge request !9 (closed)