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

Add Registrar proxy type #358

Merged
merged 22 commits into from
Dec 19, 2023
Merged

Add Registrar proxy type #358

merged 22 commits into from
Dec 19, 2023

Conversation

nanocryk
Copy link
Contributor

@nanocryk nanocryk commented Dec 4, 2023

Adds new Registrar and SudoRegistrar proxy types.

@nanocryk nanocryk added a0-pleasereview Pull request needs code review. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes not-breaking Does not need to be mentioned in breaking changes labels Dec 4, 2023
Copy link
Contributor

github-actions bot commented Dec 4, 2023

Coverage Report

(master)

@@                      Coverage Diff                       @@
##           master   jeremy-registar-proxy-type      +/-   ##
==============================================================
+ Coverage   73.94%                       74.06%   +0.12%     
  Files          91                           91              
+ Lines       20536                        20637     +101     
==============================================================
+ Hits        15184                        15283      +99     
+ Misses       5352                         5354       +2     
Files Changed Coverage
/container-chains/templates/frontier/runtime/src/lib.rs 42.72% (-0.42%) 🔽
/container-chains/templates/simple/runtime/src/lib.rs 57.43% (-0.88%) 🔽
/pallets/registrar/src/lib.rs 92.18% (+0.25%) 🔼
/runtime/dancebox/src/lib.rs 81.00% (+1.27%) 🔼
/runtime/dancebox/tests/integration_test.rs 99.70% (+0.01%) 🔼

Coverage generated Tue Dec 19 15:14:25 UTC 2023

@tmpolaczyk
Copy link
Contributor

Let's add a typescript test, I guess it will be a combination of these 2:

test/suites/common/proxy/test-proxy-balances.ts
test/suites/dev-tanssi/registrar/test_registrar_register.ts

null,
polkadotJs.tx.registrar.register(2002, containerChainGenesisData)
);
const tx3 = polkadotJs.tx.registrar.markValidForCollating(2002);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt it sufficient for the test that we test only that the genesis data gets set? the rest is made with sudo

@@ -940,6 +942,9 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::Balances => {
matches!(c, RuntimeCall::Balances(..) | RuntimeCall::Utility(..))
}
ProxyType::Registrar => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a proxy type called SUdoRegistrar that is sable to call with sudo any of the registrar calls? similar to https://github.com/paritytech/polkadot-sdk/blob/e7651cf41b2d775dedcc897e17ead16e200a4fff/polkadot/runtime/westend/src/lib.rs#L1064

const onChainBootnodes = await polkadotJs.query.registrar.bootNodes(2002);
// TODO: fix once we have types
expect(onChainBootnodes.toHuman()).to.deep.equal(["dummy"]);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test could also check that the registrar deposit is set to alice when charlie registers the chain using proxy. And also add a test for sudoRegistrar, it should be easy, try calling sudo(markValidForCollating) through the proxy.

Comment on lines 953 to 954
RuntimeCall::Sudo(pallet_sudo::Call::sudo {call: ref x})
if matches!(x.as_ref(), RuntimeCall::Registrar(..))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to SudoBalances this is missing RuntimeCall::Utility, but I guess that's good, we don't want the proxy to be able to call sudo(utility.dispatchAs)... But what about allowing utility.batch*, that should be ok?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not entirely sure what would happen if we enable utility here, but I see that parity has it enabled in a similar proxy type: https://github.com/paritytech/polkadot-sdk/blob/4c4407a8930267e139db93019c01444acf49e1ce/polkadot/runtime/westend/src/lib.rs#L1066

@nanocryk can you try it out?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong, it depends on how you define the proxy:

Sudo(Registrar) || Utility this is fine
Sudo(Registrar || Utility) this is bad

The current way of always allowing utility should be ok as well

Cargo.lock Outdated
@@ -853,7 +853,7 @@ dependencies = [
[[package]]
name = "binary-merkle-tree"
version = "4.0.0-dev"
source = "git+https://github.com/moondance-labs/polkadot-sdk?branch=tanssi-polkadot-v1.3.0#c3d18c8c2f4c5462b752b98eb2908dc32b5ec985"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge master? It should remove the changes in Cargo.lock

ProxyType::Balances,
ProxyType::Registrar,
ProxyType::SudoRegistrar,
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some external crates that allow iterating over enums, not sure if we already have one, but as a nice hack we could use the Decode trait (not tested but should work):

for x in 0u8.. {
    if let Ok(x) = x.decode::<ProxyType>() {
        proxy_types.push(x);
    } else {
        break;
    }
}

const tx3 = polkadotJs.tx.proxy.proxy(
bob.address,
null,
polkadotJs.tx.registrar.setBootNodes(2002, ["dummy"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, in #341 we moved the setBootNodes to a different pallet, pallet_data_preservers. I guess we want that to be included in the SudoRegistrar proxy as well. So this should work:

Suggested change
polkadotJs.tx.registrar.setBootNodes(2002, ["dummy"])
polkadotJs.tx.dataPreservers.setBootNodes(2002, ["dummy"])

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly

@girazoki
Copy link
Collaborator

Please put a description in the PR and let's merge master back in

nanocryk and others added 3 commits December 18, 2023 14:52
Co-authored-by: tmpolaczyk <44604217+tmpolaczyk@users.noreply.github.com>
nanocryk and others added 3 commits December 18, 2023 17:45
Co-authored-by: tmpolaczyk <44604217+tmpolaczyk@users.noreply.github.com>
None,
Box::new(
pallet_utility::Call::batch {
calls: vec![pallet_balances::Call::force_set_balance {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force_set_balance will always fail because it needs root origin, maybe this test is missing a call to sudo first?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the test needs to be batch->sudo.>force_set_balacne

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But ProxyType::Any should allow this, right? Then why doesn't the test fail?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that's a good question

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its probably becaues we are still not going through the sudo pallet right?

@nanocryk nanocryk merged commit aad62b8 into master Dec 19, 2023
26 checks passed
@nanocryk nanocryk deleted the jeremy-registar-proxy-type branch December 19, 2023 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a0-pleasereview Pull request needs code review. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes not-breaking Does not need to be mentioned in breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants