Skip to content
Snippets Groups Projects

Bugfix: correctly compute transfer amount

Closed Carles Barrobés requested to merge transfer-fee-bug into develop
1 unresolved thread

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):

image

However, the blockchain ATM also refunds the fees as a follow-up system event, as part of the blockchain rules:

image

Edited by Carles Barrobés

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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);
  • Carles Barrobés added 5 commits

    added 5 commits

    Compare with previous version

  • Carles Barrobés marked this merge request as ready

    marked this merge request as ready

  • Carles Barrobés changed title from Draft: fix: correctly compute transfer amount to Bugfix: correctly compute transfer amount

    changed title from Draft: fix: correctly compute transfer amount to Bugfix: correctly compute transfer amount

  • Carles Barrobés changed the description

    changed the description

  • added 1 commit

    • f15d7101 - Check for enough credit should use totalAmount

    Compare with previous version

  • Carles Barrobés changed the description

    changed the description

  • closed

  • Carles Barrobés mentioned in merge request !9 (closed)

    mentioned in merge request !9 (closed)

  • Please register or sign in to reply
    Loading