Skip to content

RemainingScaleBytesNotEmptyException for Kilt Spiritnet #412

Open

Description

@Maharacha

Reproduce:

substrate-interface==1.7.11
scalecodec==1.2.11

    substrate = SubstrateInterface(url=server_address_ws)
    call = substrate.compose_call(
        'Session', 'set_keys', {
            'keys': keys,
            'proof': '0x00',
        }
    )

    keypair = Keypair.create_from_mnemonic(mnemonic)
    extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)

Error:

scalecodec.exceptions.RemainingScaleBytesNotEmptyException: Decoding <U32> - Current offset: 4 / length: 8

Some trace in my application:

substrateinterface/base.py", line 1593, in create_signed_extrinsic
    nonce = self.get_account_nonce(keypair.ss58_address) or 0
substrateinterface/base.py", line 1428, in get_account_nonce
    nonce_obj = self.runtime_call("AccountNonceApi", "account_nonce", [account_address])
substrateinterface/base.py", line 1283, in runtime_call
    result_obj.decode(ScaleBytes(result_data['result']), check_remaining=self.config.get('strict_scale_decode'))
scalecodec/base.py", line 888, in decode
    raise RemainingScaleBytesNotEmptyException(
scalecodec.exceptions.RemainingScaleBytesNotEmptyException: Decoding <U32> - Current offset: 4 / length: 8

Activity

  1. Maharacha commented on Apr 1, 2025

    @Maharacha
    Author

    Is this repo still maintained? @arjanz ?

  2. emielsebastiaan commented on Apr 2, 2025

    @emielsebastiaan
    Contributor

    Hello @Maharacha
    This week JAMdotTechnologies has announced to take up stewardship of Polkascan's Python libraries for the Polkadot ecosystem.
    Our current focus is on delivering our Python implementation of JAM Protocol. However as we expect major delivery milestones for JAM later this year, we will be shifting our attention more towards user/developer facing libraries, such as this library (PyPolkadotSDK).

    We will schedule some timeboxed resources this week to check if we can help you with this issue. Thank you for understanding.

  3. arjanz commented on Apr 7, 2025

    @arjanz
    Contributor

    @Maharacha It seems it is a type registry related issue. To determine the account nonce, the Runtime API AccountNonceApi.account_nonce() is being called. Runtime API calls are still manually administered in the library atm, type definition updates are not automatically applied (yet).

    After some debugging I found out Index is not a u32 but a u64 for Kilt.

    As a workaround until runtime APIs are included in the metadata (It was under development in Substrate but didn't check progress of this for a while to be honest), you can add the following:

    substrate = SubstrateInterface(url=server_address_ws)
    # Manually update type definition
    substrate.runtime_config.update_type_registry_types({'Index': 'U64'})
    
     call = substrate.compose_call(
        'Session', 'set_keys', {
            'keys': {
                'aura': '0x0000000000000000000000000000000000000000000000000000000000000000'
            },
            'proof': '0x00'
        }
    )
    
    keypair = Keypair.create_from_mnemonic(mnemonic)
    extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
    
  4. Maharacha commented on Apr 9, 2025

    @Maharacha
    Author

    @Maharacha It seems it is a type registry related issue. To determine the account nonce, the Runtime API AccountNonceApi.account_nonce() is being called. Runtime API calls are still manually administered in the library atm, type definition updates are not automatically applied (yet).

    After some debugging I found out Index is not a u32 but a u64 for Kilt.

    As a workaround until runtime APIs are included in the metadata (It was under development in Substrate but didn't check progress of this for a while to be honest), you can add the following:

    substrate = SubstrateInterface(url=server_address_ws)
    # Manually update type definition
    substrate.runtime_config.update_type_registry_types({'Index': 'U64'})
    
     call = substrate.compose_call(
        'Session', 'set_keys', {
            'keys': {
                'aura': '0x0000000000000000000000000000000000000000000000000000000000000000'
            },
            'proof': '0x00'
        }
    )
    
    keypair = Keypair.create_from_mnemonic(mnemonic)
    extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
    

    Thanks, I will try this!

  5. Maharacha commented on Apr 14, 2025

    @Maharacha
    Author

    @arjanz I just tried the work around and it works well! You want to keep the issue open for the actual fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions