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

Test P<>K bridge-init calls using chopsticks #3522

Closed
serban300 opened this issue Feb 29, 2024 · 8 comments
Closed

Test P<>K bridge-init calls using chopsticks #3522

serban300 opened this issue Feb 29, 2024 · 8 comments
Assignees
Labels
T10-tests This PR/Issue is related to tests. T15-bridges This PR/Issue is related to bridges.

Comments

@serban300
Copy link
Contributor

We should test the bridge-init calls using chopsticks before actually executing them

Submitting the calls and checking the effects on the storage would be a first step.

With chopsticks we won't be able to run the relayer, since chopsticks doesn't come with the grandpa subscriptions and many RPCs. So as a second step it would be nice if we could take the forked chains and run them in zombienet somehow.

@serban300 serban300 added T10-tests This PR/Issue is related to tests. T15-bridges This PR/Issue is related to bridges. labels Feb 29, 2024
@serban300 serban300 self-assigned this Feb 29, 2024
@serban300
Copy link
Contributor Author

We can simulate an approved preimage in chopsticks with something like this:

const number = (await api.rpc.chain.getHeader()).number.toNumber()
// TODO: fill in
const extrinsic: HexString = "0x...";
const data = hexToU8a(extrinsic)
const hash = blake2AsHex(data, 256)

await api.rpc('dev_setStorage', {
    Preimage: {
      PreimageFor: [
        [
          [[hash, data.byteLength]],
          u8aToHex(compactAddLength(data))
        ]
      ],
      StatusFor: [
        [
          [hash],
          {
            Requested: {
              count: 1,
              len: data.byteLength,
            },
          },
        ],
      ],
    },
    Scheduler: {
      Agenda: [
        [
          [number + 1],
          [
            {
              call: {
                Lookup: {
                  hash: hash,
                  len: data.byteLength,
                },
              },
              origin: {
                system: 'Root'
              },
            },
          ],
        ],
      ]
    },
  });

await api.rpc('dev_newBlock', {count: 1});

@serban300
Copy link
Contributor Author

Looks like there is this tool that can be used for forking-off chains: https://github.com/hack-ink/subalfred
And here is an example on how to use it: https://github.com/hack-ink/subalfred/blob/main/example/cmd/state/src/main.rs

Trying to experiment with it a bit. The plan would be to:

  • fork the chains with chopsticks
  • execute the preimages
  • fork-off the chopsticks chains with subalfred
  • start the forked-off chains in zombienet

@xlc
Copy link
Contributor

xlc commented Mar 2, 2024

If you can list all the RPCs used by relayer, we maybe able to provide a mock implementation in Chopsticks

@serban300
Copy link
Contributor Author

@xlc thank you, it would be great if you could provide mock implementations in chopsticks. As far as I can tell there are only 2 additional RPCs that we would need apart from what is already available (@svyatonik please correct me if I'm wrong):

  • grandpa_subscribeJustifications
  • state_getReadProof

Do you think this would be doable ?

@svyatonik
Copy link
Contributor

The full set of RPC calls we use is quite large: https://github.com/paritytech/parity-bridges-common/blob/polkadot-staging/relays/client-substrate/src/rpc.rs#L37-L170 (everything except BEEFY).

@xlc
Copy link
Contributor

xlc commented Mar 5, 2024

I think it is doable. However, Chopsticks is only a mocking client that doesn't actually finalize blocks using grandpa/beefy protocol so that it cannot provide real justifications.

There are two possible solutions:

  1. Add a new feature to specify signing keys to Chopsticks so it can generate valid justifications.
  2. Modify relayer to accept mock justifications. This will be useful to fork mainnet and run tests with it. As it is not possible to get real justifications from mainnet fork.

Let me know what do you think.

Also opened a tracking issue at Chopsticks AcalaNetwork/chopsticks#681

@serban300
Copy link
Contributor Author

I think it is doable. However, Chopsticks is only a mocking client that doesn't actually finalize blocks using grandpa/beefy protocol so that it cannot provide real justifications.

There are two possible solutions:

1. Add a new feature to specify signing keys to Chopsticks so it can generate valid justifications.

2. Modify relayer to accept mock justifications. This will be useful to fork mainnet and run tests with it. As it is not possible to get real justifications from mainnet fork.

Let me know what do you think.

Also opened a tracking issue at Chopsticks AcalaNetwork/chopsticks#681

Thanks for the answer ! Moved the discussion to AcalaNetwork/chopsticks#681

@serban300
Copy link
Contributor Author

Closing this issue since the Polkadot <> Kusama bridge has been initialized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T10-tests This PR/Issue is related to tests. T15-bridges This PR/Issue is related to bridges.
Projects
None yet
Development

No branches or pull requests

3 participants