Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

getaccountstate returns the wrong balance of NEO #578

Closed
jseagrave21 opened this issue Aug 26, 2018 · 13 comments
Closed

getaccountstate returns the wrong balance of NEO #578

jseagrave21 opened this issue Aug 26, 2018 · 13 comments

Comments

@jseagrave21
Copy link
Contributor

jseagrave21 commented Aug 26, 2018

Current behavior

getaccounstate returns the wrong balance of NEO. NEO-cli returns the correct balance.
GAS balance seems to be correct

PM me on Discord if you want a specific address to query (I only figured this out because I queried one of my addresses)

Expected behavior

getaccountstate should return the correct balance of both NEO and GAS

How to reproduce

You can use this script in Python to test if the balances match:

import requests

url = "http://108.252.121.18:10332"
body = {"jsonrpc": "2.0","method": "getaccountstate","params": ["<address>"],"id": 2}

req = requests.post(url, json=body)
req = req.json()
data = req['result']

print('Python Data: ', data)

url = "http://18.197.197.10:10332"
body = {"jsonrpc": "2.0","method": "getaccountstate","params": ["<address>"],"id": 2}

req = requests.post(url, json=body)
req = req.json()
data = req['result']

print('NEO-cli: ', data)

Your environment

This is based on live RPC calls

@localhuman
Copy link
Collaborator

You'll need to specify an address with a mismatch.

@jseagrave21
Copy link
Contributor Author

@localhuman I PM'd you.

@wy
Copy link

wy commented Aug 28, 2018

NEO and GAS are based on UTXO so only problem I can think of is the 'dead fork' incident.

@jseagrave21 if you know the block number when the transfer happened, then you can use getblockhash to compare. They should mismatch for faulty vs correct nodes.

@jseagrave21
Copy link
Contributor Author

jseagrave21 commented Aug 28, 2018

@wy I spoke with @localhuman and am going to try to import the address as watch only so I can compare transaction history that way. I check the most recent transactions and it is not that.

Additionally, I still don't understand how the calc of NEO could be incorrect and GAS is correct.

@jseagrave21
Copy link
Contributor Author

jseagrave21 commented Aug 29, 2018

Although I haven't confirmed completely, I think this issue is caused by missing block information for some RPC nodes. For example, block 2669088 is corrupted on http://108.252.121.18:10332.

I queried 3 different RPC nodes running NEO-Python and got 2 similar responses and 1 different and none of them were correct.

I queried 2 different RPC nodes running NEO-Cli and got 2 similar responses and both were correct.

@jseagrave21
Copy link
Contributor Author

jseagrave21 commented Aug 29, 2018

When querying http://108.252.121.18:10332 about block 2669088, I get the following:

for getblockhash, I receive: {'jsonrpc': '2.0', 'id': 2, 'error': {'code': -32603, 'message': "'>=' not supported between instances of 'str' and 'int'"}}

for getblock (non-verbose), I receive: {'jsonrpc': '2.0', 'id': 2, 'result': '00000000408668e83c9fedfa9417483b27438082ee5d3342114441ba6e427972ea3d1a03e2023c0dad8def3855e267071b95eca9cf5df56fa2d58a976c03eaa828ce3aaf0bf6855b20ba28007ef7b9da40e5d79f83f5011bdaaccee8c4d2555c829fa51e31551ef201fd4501405658f2a61de8dd909dbe4e67291324302d027c6da4860bd35ef7d8de52ebc48fcc381c0390efc935835062fef8d5277821a3de7d526ff1b301de8178a59e5732404315ab76f8e4d62b2743cc4f52e690467e47564aa32655ae4323e390ef4238d1e951956f16167c4485932a214c02841df1a11eada5459dcc58338ce844b110d1401b8e7a1c7da59018c73cdb158c69cca95bce39313638a20a35b657e8d32d52299bcb76275444b2bddf57b878ddf839f6d2bb98a05f9411dfc41a9f91f918c5164002c395972f1da2dc29475ba4958b7ad0ca3283339dd76a1372872aee72b883c5038613d02950b173aea93a7528c295293bce49702a767d2e174ae47cd82818554008dfd6028313ef6a9e20b57f2e402332a1f5df32104c243d5fc6a492d62c63832f306cb14efdd8488124c453cca6a014238184c40519f401c17898d970aaa871f15521024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d21025bdf3f181f53e9696227843950deb72dcd374ded17c057159513c3d0abe20b642102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae00'}

and for getblock (verbose), I get: {'jsonrpc': '2.0', 'id': 2, 'error': {'code': -32603, 'message': 'list index out of range'}}

@jseagrave21
Copy link
Contributor Author

jseagrave21 commented Aug 29, 2018

Here are the results of my findings after querying each listed neo-python RPC node on HappyNodes:
BLUF: Every neo-python RPC node seems to have a getaccountstate issue and many have the same issue

# correct response based on NEO-Cli is: `balances': [{'asset': '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7', 'value': '14.37532376'}, {'asset': '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b', 'value': '264'}
# http://node2.nyc3.bridgeprotocol.io:10332 < -- gives balances': {'0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7': '14.37532376', '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b': '163.0'}
# http://node2.sgp1.bridgeprotocol.io:10332 - same
# https://pyrpc1.redpulse.com:10331 - same
# https://pyrpc2.redpulse.com:10331 - same
# http://pyrpc1.redpulse.com:10332 - same
# http://pyrpc2.redpulse.com:10332 - same
# https://pyrpc1.narrative.org:443 - same
# https://pyrpc2.narrative.org:443 - same
# https://pyrpc3.narrative.org:443 - same
# https://pyrpc4.narrative.org:443 - same
# http://108.252.121.18:10332 - same
# http://101.100.174.24:10332 <-- gives a different accountstate: 'balances': {'0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7': '13.77532376', '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b': '627.0'}
# http://52.204.61.212:10332 same as 101

cc @wy

@jseagrave21
Copy link
Contributor Author

This issue seems to be separate from the block corruption issue. After testing with @hal0x2328 , we were able to call every tx associated with the subject address. However, getaccountstate still returns the wrong value as shown above. I have found several bad blocks in http://108.252.121.18:10332 and have searched other NEO-PYTHON nodes to see if they also have similar issues. Some do. I recorded my findings here:
alienworks/Happynodes#113

Should I create a separate issue for the corrupted blocks?

@jseagrave21
Copy link
Contributor Author

@localhuman @hal0x2328 After further testing, I think the issue is in the chain db, not in the getaccountstate method.

Using a fresh pull of the master branch, I created a wallet and imported the wif of my suspect address. Running wallet yields the same results as getaccountstate. What do you guys think?

@localhuman
Copy link
Collaborator

I've got a theory about what may be causing this, but a fix is waiting on my np-import to finish.

@jseagrave21
Copy link
Contributor Author

I will close this issue as soon as I can personally verify #611 has fixed the issue. Right now, I am waiting for an updated bootstrap.

@jseagrave21
Copy link
Contributor Author

jseagrave21 commented Sep 23, 2018

@localhuman I performed np-bootstrap with the new chain located here: https://s3.us-east-2.amazonaws.com/cityofzion/bootstrap_main/Main2758xxx.tar.gz
My local node used to display this balance (see #578 (comment)):

{'0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7': '14.37532376', '0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b': '163.0'}

Now, the balance is:

{
            "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "13.77532376",
            "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "627.0"
        }

This is wrong and similar to the last two IPs listed in the previously mentioned comment.
So, evidently the fix from #611 did not completely solve the issue. Let me know if I can help out.

@jseagrave21
Copy link
Contributor Author

jseagrave21 commented Sep 26, 2018

@localhuman with the most recent bootstrap file you posted
https://s3.us-east-2.amazonaws.com/cityofzion/bootstrap_main/Main276xxxx.tar.gz, the issue appears resolved

"balances": {
        "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "14.37532376",
        "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "264.0"

I think it would be good to include this bootstrap file in the next neo-python release.

Good work! 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants