projectpai / paicoin

Official repo of PAI Coin
https://projectpai.com
MIT License
63 stars 35 forks source link

Additional issue with balance calls when involving only stake transactions #374

Open pgerzani opened 3 years ago

pgerzani commented 3 years ago

Mark and I both have wallets that only do staking and voting transactions. In both cases, they are showing odd values for the balance that don't seem to sum up to what was sent to the wallet.

Mark's wallet:

  1. Starting balance was 1.73M PAI
  2. Maintain set at 200,000 PAI
  3. getbalance returns 204,074
  4. staked_balance from getwalletinfo shows 520,054
  5. getstakeinfo shows that the wallet owns 41 immature tickets. At an average cost of 12,684, that is 520,044 so that makes sense with fees
  6. getstakeinfo shows ownmempooltix as 0 which we assume means that there are no mempool transactions hanging out there? So, 1,730,000 - (204,074 + 520,054) results in a discrepancy of ~1M PAI Another odd thing is paicoin-cli getbalance "*" 6 returns a value of 1.73M PAI. Is this due to the tickets being immature?

Staker's wallet:

  1. Total sent to wallet of around 3.3M PAI
  2. Maintain set at 0
  3. getbalance returns 12,250
  4. staked_balance from getwalletinfo shows: 1,391,398
  5. getstakeinfo shows 0 for ownmempooltix and 4956 for unspent with 55007 for totalsubsidy So, again we have a substantial disparity: 3,300,000 - (1,391,398 + 12,250) = 1.896M PAI paicoin-cli getbalance "*" 6 returns 3,291,638 PAI which makes sense for the full total and matches the value from paicoin-cli listaccounts

In order to identify the source of these discrepancies, I was thinking we should first update the functional tests to ensure they are covered. The following balances I would expect to all match:

and likewise:

sebastianrusu commented 3 years ago

@pgerzani

The latest changes are implemented in https://github.com/projectpai/paicoin/tree/feature/develop/balance-inconsistencies.

I removed the vote and revocation inputs from the debit calculations, since they should not in principle affect the wallet balance. In case of stake transactions, it is the tickets that spend funds and the vote and revocations that bring funds, from the wallet perspective. However, if this logic is not correct, please let me know.

These changes also contain some new values in the getwalletinfo response, for available_balance and legacy_balance.

The balance in getbalance (without any parameter) and getwalletinfo->balance should be the same. listaccounts uses a different calculation method and may diverge from the values above.

totalsubsidy in getstakeinfo should be the sum of all ticket stake outputs that have been used for voting. This is not the sum of funds being staked by all the tickets. Maybe this is a misnomer, something like totalvotedstake would be better. Please advise.

I also created this document to detail the various balance calculations as they are currently implemented in the code: https://docs.google.com/document/d/18dUzqxmKDA2th5HUgOJuQUCKQyBbUKBuelpdHx9UlvQ.

pgerzani commented 3 years ago

@sebastianrusu It does not appear that this resolved the issue, at least not the bulk of what we were seeing. @mharvilla has agreed to provide you with the Lanier AI wallet which has ~1.5M funds that appear to be missing. I will connect with you to provide it.