decred / dcrdex

The Decred Decentralized Exchange (DEX), powered by atomic-swaps.
Other
184 stars 91 forks source link

zec: Incorrect available/locked amounts. #1768

Closed JoeGruffins closed 1 year ago

JoeGruffins commented 2 years ago

Testing on testnet zec_btc because dcr testnet is down. Here trying to make a market sell (limit gives same error) and the error message is confusing. It looks like I should have 1.0119302 zec available, but the error message will tell me I only have 0.0019302 so exactly 1.01 less.

image

image

Also, I have about 0.006 zec in sell orders already, so I think that should be showing up in locked but it is not.

JoeGruffins commented 2 years ago

It would make sense that that the 1.01 is two utxo. One from the testnet faucet and the other from my other node. I guess it should be showing 1.01 locked is the real problem.

$ zcash-cli listtransactions
[
  {
    "address": "tmYVXVYEbFSWMfsjYM9UD4MgJTT22rqqSBk",
    "category": "receive",
    "amount": 1.00000000,
    "amountZat": 100000000,
    "vout": 1,
    "confirmations": 141,
    "blockhash": "0036bcdfc2657b8dea0ba5b260ba43271f3187b971ae5b1bcad3170474e91d6c",
    "blockindex": 1,
    "blocktime": 1660026546,
    "expiryheight": 1991190,
    "status": "mined",
    "txid": "f76c3ac4e4d7e9a0c082488004cffa83300b93607a11bac6d30dfd2444424257",
    "walletconflicts": [
    ],
    "time": 1660026412,
    "timereceived": 1660026412,
    "vjoinsplit": [
    ],
    "size": 244
  },
  {
    "address": "tmYVXVYEbFSWMfsjYM9UD4MgJTT22rqqSBk",
    "category": "receive",
    "amount": 0.01000000,
    "amountZat": 1000000,
    "vout": 1,
    "confirmations": 84,
    "blockhash": "005eb6d155fc0bf3eb5302f34b6158dc4153c1cc9c039ec4d0550d2f29e74eec",
    "blockindex": 1,
    "blocktime": 1660031903,
    "expiryheight": 1991247,
    "status": "mined",
    "txid": "7cccb31925a9f563cb75bf0acd38894ccf98337d4b970b46bf4673967498d0af",
    "walletconflicts": [
    ],
    "time": 1660031796,
    "timereceived": 1660031796,
    "vjoinsplit": [
    ],
    "size": 240
  },
  {
    "address": "tmTvqYpFu5iU64w3hiNpemoC5rco3xvR6NY",
    "category": "receive",
    "amount": 0.00096510,
    "amountZat": 96510,
    "vout": 0,
    "confirmations": 58,
    "blockhash": "00102dab41a8c30a9fd90cd1c6ad5a5cdf50f949326cd38eaaba21177c6b7332",
    "blockindex": 2,
    "blocktime": 1660033282,
    "expiryheight": 499999999,
    "status": "mined",
    "txid": "2aab3e2bce184aca986a6df2069ff94d42fe1d185d10016a55a49bf98880fc19",
    "walletconflicts": [
    ],
    "time": 1660033205,
    "timereceived": 1660033205,
    "vjoinsplit": [
    ],
    "size": 339
  },
  {
    "address": "tmHBVaM4cxpe3AqcFJSJcCiUhWvuiHDUc3s",
    "category": "receive",
    "amount": 0.00096510,
    "amountZat": 96510,
    "vout": 0,
    "confirmations": 25,
    "blockhash": "00474915257a9f18ecd8c82721764b9c8f755c642e2f487fbe71c287c1d0d4f1",
    "blockindex": 2,
    "blocktime": 1660035654,
    "expiryheight": 499999999,
    "status": "mined",
    "txid": "0c9fc2c33dff37b46b3e0d69e9ab24f7fe594520f7eccfd997fee76c605bdd19",
    "walletconflicts": [
    ],
    "time": 1660035524,
    "timereceived": 1660035524,
    "vjoinsplit": [
    ],
    "size": 340
  },
  {
    "address": "t2JGPCQEH1GpbPQJQPLGQf4pJxH6jrv4qUB",
    "category": "send",
    "amount": -0.00100000,
    "amountZat": -100000,
    "vout": 0,
    "fee": -0.00002460,
    "confirmations": 3,
    "blockhash": "0051572a3408ffd053ad00aa7f4a9b68d75e6493bcadacc188a85c3de531660e",
    "blockindex": 2,
    "blocktime": 1660037092,
    "expiryheight": 499999999,
    "status": "mined",
    "txid": "98147b5ae5e1d28fcea75c2033f0a0b1eabf7ffc8d29237b291043b8386d3e40",
    "walletconflicts": [
    ],
    "time": 1660036900,
    "timereceived": 1660036900,
    "vjoinsplit": [
    ],
    "size": 238
  }
]
chappjc commented 1 year ago

https://github.com/decred/dcrdex/blob/50cf04fcf09919d96c801cae5c03ef4430eb1923/client/asset/btc/btc.go#L1393-L1416

For ZEC, it looks like we just don't set the Locked field at all. @buck54321 Do you recall a reason why we don't also use btc.lockedSats() in this zecStyleBalance path? Seems like a bug. I just checked that the getbalance result is not affected by any locked utxos.

Also, I think we should look again at (*baseWallet).lockedSats and how it takes the result of gettransaction and does uint64(txOut.Value). If it is negative (like it can be with listtransactions), we'll have an underflow. nvm, this is a value of a wire.TxOut, so won't be negative.