Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow sudo for polkadot indexed proxy enum #3286

Merged
merged 2 commits into from
Mar 8, 2021
Merged

fix: Allow sudo for polkadot indexed proxy enum #3286

merged 2 commits into from
Mar 8, 2021

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Mar 8, 2021

rel: paritytech/substrate-api-sidecar#461

Starting with @polkadot/api v3.11.1 decoding of old blocks with the sudo proxy no longer works. I think the issue may have been introduced with pull #3194, which commented out the SudoBalances variant.

Here is an example that breaks with api versions >= 3.11.1:

async function main() {
	const api = await ApiPromise.create({
		provider: new WsProvider('wss://rpc.polkadot.io'),
	});

	// Block from runtime 7 when sudo proxy was enabled
	const hashBlock214576 = await api.rpc.chain.getBlockHash(214576);
	const { block: block214576 } = await api.rpc.chain.getBlock( 
		hashBlock214576
	);
        // Errors with: "Unable to create Enum via index 4, in Any, NonTransfer, Governance, Staking, IdentityJudgement, CancelProxy"
 
	console.log(block214576.toHuman());

	// Block from runtime 28 when sudo proxy is disabled
	const hashBlock4101428 = await api.rpc.chain.getBlockHash(4101428);
	const { block: block4101428 } = await api.rpc.chain.getBlock(
		hashBlock4101428
	);

	console.log(block4101428.toHuman());
}

I was not actually able to figure out how to test this PR directly (I was trying to import the package from my local branch but couldn't figure out how to get it to cooperate with the workspaces), but I did find that adding

		types:  {
			ProxyType: {
				_enum: {
					Any: 0,
					NonTransfer: 1,
					Governance: 2,
					Staking: 3,
					SudoBalances: 4,
					IdentityJudgement: 5,
					CancelProxy: 6
				}
			}
		}

to the api initialization fixed the issue and had the above example working properly, so I assumed doing the same in types-known would have an identical effect. From my understanding of the SCALE codec it should be fine to have the SudoBalances variant defined for all the runtime versions so I did not think there needed to be a historical version of the type defined, (but I maybe I am missing some edge cases?)

Feel free to push to this branch or close if it's not the appropriate fix.

@jacogr
Copy link
Member

jacogr commented Mar 8, 2021

It needs a historical version, applied to the correct versions for types-known to cater for older.

The issue is that anybody using the definition will assume there is an entry where there is not, unless there is a gap. An example - any UI that allows entry will inspect the type and assume the entry is still valid while it is not.

As a stopgap can re-introduce as „Unused“ (which is how it previously filled the entry). But really based on what you are saying it needs the historical solution to be clear In all cases.

@jacogr jacogr merged commit 3f0457e into polkadot-js:master Mar 8, 2021
@emostov emostov deleted the zeke-allow-sudo-proxy branch March 8, 2021 21:23
emostov added a commit to paritytech/substrate-api-sidecar that referenced this pull request Mar 10, 2021
BREAKING CHANGE
Enums in responses serialize with [camelCase variants](polkadot-js/api#3024). Check spec diffs for details

Other changes
- Reverses regressions in decoding blocks with [sudo proxy variants](polkadot-js/api#3286)
- Updates jest.config to treat `.js` files as ESM - transforming @polkadot/* packages from ESM to CJS.
- Bump deps
emostov added a commit to paritytech/substrate-api-sidecar that referenced this pull request Mar 10, 2021
…SM (#467)

BREAKING CHANGE
Enums in responses serialize with [camelCase variants](polkadot-js/api#3024). Check spec diffs for details

Other changes
- Reverses regressions in decoding blocks with [sudo proxy variants](polkadot-js/api#3286)
- Updates jest.config to treat `.js` files as ESM - transforming @polkadot/* packages from ESM to CJS.
- Bump deps
woss pushed a commit to woss/api that referenced this pull request Apr 23, 2021
* fix: Allow sudo for polkadot indexed proxy enum

* Update packages/types-known/src/spec/polkadot.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants