polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
240 stars 114 forks source link

host doesn't provide such function: env:ext_trie_blake2_256_ordered_root_version_2 #201

Closed khssnv closed 2 years ago

khssnv commented 2 years ago

Hi,

I'm trying to make a remark call on Kusama and I'm getting an error. Please find more details below.

Error

>>> call = substrate.compose_call(call_module="System", call_function="remark", call_params={"remark": "myremark"})
>>> substrate.create_signed_extrinsic(call, keypair, {"period": 64})
Traceback (most recent call last):
...
SubstrateRequestException({'code': 1, 'message': 'Unable to query nonce.', 'data': 'Application(VersionInvalid("RuntimeConstruction(Other(\\"host doesn\'t provide such function: env:ext_trie_blake2_256_ordered_root_version_2\\"))"))'})

Environment

# uname -a
Linux myhost 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 GNU/Linux
# python -V
Python 3.9.7
# cat poetry.lock | grep substrate-interface
name = "substrate-interface"
substrate-interface = [
    {file = "substrate-interface-1.2.2.tar.gz", hash = "sha256:27bba2518837c4c2b1510ee012ed269ce3513ecd5c436a582dc1d6a55780cbe7"}
# cat poetry.lock | grep scalecodec
name = "scalecodec"
scalecodec = ">=1.0.34,<2"
scalecodec = [
    {file = "scalecodec-1.0.34-py3-none-any.whl", hash = "sha256:e19400ef3fdc6e8938f97f2d8a5cb9c0dbf1dfaa5ef4e900af770571a79ccd0c"},
    {file = "scalecodec-1.0.34.tar.gz", hash = "sha256:30d3e6d0687671fdd823e9a3968a8656f1414bfda5150bcc01240d47a6ab8c9a"},
khssnv commented 2 years ago

By the way, this guy works.

>>> substrate.query(module='System', storage_function='Account', params=['Gecm9tRWX5sFzttHLB2j6PurJBeNM3oLHABvztnqXCnmHwZ'])
<scale_info::3(value={'nonce': 553, 'consumers': 0, 'providers': 1, 'sufficients': 0, 'data': {'free': 929871682926, 'reserved': 0, 'misc_frozen': 0, 'fee_frozen': 0}})>
khssnv commented 2 years ago

Also, there is a workaround if you provide nonce to create_signed_extrinsic explicitly.

>>> call = substrate.compose_call(call_module="System", call_function="remark", call_params={"remark": "12"})
>>> nonce = substrate.query(module='System', storage_function='Account', params=['Gecm9tRWX5sFzttHLB2j6PurJBeNM3oLHABvztnqXCnmHwZ']).value["nonce"]
>>> extrinsic = substrate.create_signed_extrinsic(call, keypair, {"period": 64}, nonce=nonce)
extrinsic
<GenericExtrinsic(value={'account_id': '0xb437f703710d52aed228ae7f941f8e08b32edde56e683dcc94664c3dc8622e02', 'signature': {'Sr25519': '0x8212abbf4c45dbdf89e9b408fe9c994f8da82a17ff6ff4043c875aedbf1c215b6d333d9e26b228536dd5a4c28e388ea79a83d829b6300fdbf68b9fe6f7d86188'}, 'call_function': 'remark', 'call_module': 'System', 'call_args': {'remark': '12'}, 'nonce': 553, 'era': {'period': 64, 'current': 11601803}, 'tip': 0, 'asset_id': {'tip': 0, 'asset_id': None}, 'signature_version': 1, 'address': '0xb437f703710d52aed228ae7f941f8e08b32edde56e683dcc94664c3dc8622e02', 'call': {'call_function': 'remark', 'call_module': 'System', 'call_args': {'remark': '12'}}})>
khssnv commented 2 years ago

By the way, this workaround does not help to submit the extrinsic.

>>> receipt = substrate.submit_extrinsic(extrinsic)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/substrateinterface/base.py", line 1838, in submit_extrinsic
    response = self.rpc_request("author_submitExtrinsic", [str(extrinsic.data)])
  File "/usr/local/lib/python3.9/site-packages/substrateinterface/base.py", line 575, in rpc_request
    raise SubstrateRequestException(message['error'])
substrateinterface.exceptions.SubstrateRequestException: {'code': 1002, 'message': 'Verification Error: Runtime error: Failed to get runtime version: RuntimeConstruction(Other("host doesn\'t provide such function: env:ext_trie_blake2_256_ordered_root_version_2"))', 'data': 'RuntimeApi("Failed to get runtime version: RuntimeConstruction(Other(\\"host doesn\'t provide such function: env:ext_trie_blake2_256_ordered_root_version_2\\"))")'}

If you try to get runtime version to provided it explicitly, you will get this.

block = substrate.get_block()
>>> runtime_version = substrate.get_block_runtime_version(block_hash=block["header"]["hash"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/substrateinterface/base.py", line 887, in get_block_runtime_version
    response = self.rpc_request("chain_getRuntimeVersion", [block_hash])
  File "/usr/local/lib/python3.9/site-packages/substrateinterface/base.py", line 575, in rpc_request
    raise SubstrateRequestException(message['error'])
substrateinterface.exceptions.SubstrateRequestException: {'code': -32603, 'message': 'Unknown error occurred', 'data': 'Client(Application(VersionInvalid("RuntimeConstruction(Other(\\"host doesn\'t provide such function: env:ext_trie_blake2_256_ordered_root_version_2\\"))")))'}
maayank commented 2 years ago

We're experiencing the same issue

maayank commented 2 years ago

For us upgrading the node to 0.9.17 solved the issue.

arjanz commented 2 years ago

For us upgrading the node to 0.9.17 solved the issue.

I haven't had the chance to look into it yet, but it looks indeed like a Substrate runtime related issue; maybe a change in storage structure that can't be handled by the automatically upgraded WASM version of the runtime but only the native version (in use after physically upgrading the node).

khssnv commented 2 years ago

Yes, sorry guys, the source of the issue was an outdated PRC node. Thanks!