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

Dedicated AccountId20 type #926

Merged
merged 36 commits into from
Nov 23, 2021
Merged

Dedicated AccountId20 type #926

merged 36 commits into from
Nov 23, 2021

Conversation

JoshOrndorff
Copy link
Contributor

@JoshOrndorff JoshOrndorff commented Oct 25, 2021

What does it do?

This PR adds a dedicated type AccountId20 rather than using the general purpose hash type H160 as previously.

What important points reviewers should know?

In general, this strengthens the type system's ability to prevent us from putting inappropriate data where an account id is expected. But speaking practically, we're hoping this will allow tools that depend on type metadata (like PolkadotJs) to better infer that account-related UI components should be used.

Is there something left for follow-up PRs?

Much of this can be upstreamed to Frontier and generalized. For now this is ready for PoC work on the Polkadot JS tools.

What value does it bring to the blockchain users?

Hopefully, nicer formatting of Account Ids in UI components and easier ability to choose accounts from a list (rather than pasting bytes).

@joelamouche
Copy link
Contributor

@JoshOrndorff Please use AccountId20 type instead

@joelamouche
Copy link
Contributor

Or EthereumAddress

@JoshOrndorff JoshOrndorff added B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes C1-low Does not elevate a release containing this beyond "low priority". labels Oct 26, 2021
@JoshOrndorff
Copy link
Contributor Author

When we move this upstream into frontier, @tgmichel recommended we make a fp-ethereum crate for the AccountId20 type.

@JoshOrndorff JoshOrndorff changed the title Dedicated MoonbeamAccount type Dedicated AccountId20 type Oct 29, 2021
PartialOrd,
Ord,
)]
pub struct AccountId20(pub [u8; 20]);
Copy link
Contributor Author

@JoshOrndorff JoshOrndorff Oct 29, 2021

Choose a reason for hiding this comment

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

@joelamouche This is the type. The moonbase runtime's metadata contains this. So I guess the path is account::AccountId20 which makes sense from a Rust perspective.

          {
            id: 0
            type: {
              path: [
                account
                AccountId20
              ]
              params: []
              def: {
                Composite: {
                  fields: [
                    {
                      name: null
                      type: 1
                      typeName: [u8; 20]
                      docs: []
                    }
                  ]
                }
              }
              docs: []
            }
          }

@JoshOrndorff
Copy link
Contributor Author

Thanks a lot for your help @girazoki 🙏

This is ready for your review and experimentation @joelamouche (or @crystalin because you mentioned that having the poor account formatting is making your testing procedures take longer).

@JoshOrndorff
Copy link
Contributor Author

@joelamouche I believe I've done as you asked for the ts dependencies. Can you confirm? Feel free to revert those commits or push new commits if this is not right.

@joelamouche
Copy link
Contributor

WIP on a PR that will fix the tests

joelamouche and others added 4 commits November 9, 2021 18:54
@joelamouche
Copy link
Contributor

@JoshOrndorff pls look at the failing rust tests:

error[E0308]: mismatched types
    --> runtime/moonbeam/tests/integration_test.rs:1209:13
     |
1209 |                 source: AccountId::from(ALICE),
     |                         ^^^^^^^^^^^^^^^^^^^^^^ expected struct `H160`, found struct `account::AccountId20`

error[E0308]: mismatched types
    --> runtime/moonbeam/tests/integration_test.rs:1210:13
     |
1210 |                 target: AccountId::from(BOB),
     |                         ^^^^^^^^^^^^^^^^^^^^ expected struct `H160`, found struct `account::AccountId20`

error[E0308]: mismatched types
    --> runtime/moonbeam/tests/integration_test.rs:1237:13
     |
1237 |                 source: AccountId::from(ALICE),
     |                         ^^^^^^^^^^^^^^^^^^^^^^ expected struct `H160`, found struct `account::AccountId20`

   Compiling moonbeam-relay-encoder v0.1.0 (/Users/antoineestienne/GitHubRepo/double_repos/moonbeam/runtime/relay-encoder)
error[E0308]: mismatched types
    --> runtime/moonbeam/tests/integration_test.rs:1238:13
     |
1238 |                 target: AccountId::from(BOB),
     |                         ^^^^^^^^^^^^^^^^^^^^ expected struct `H160`, found struct `account::AccountId20`


@joelamouche
Copy link
Contributor

error: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `panic_impl`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /home/gh-actions/runner/_work/moonbeam/moonbeam/target/release/wbuild/moonbase-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-41280f87bae211df.rmeta
    = note: second definition in `sp_io` loaded from /home/gh-actions/runner/_work/moonbeam/moonbeam/target/release/wbuild/moonbase-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-e8003f60efd7156c.rmeta

  error: duplicate lang item in crate `sp_io` (which `frame_support` depends on): `oom`.
    |
    = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
    = note: first definition in `sp_io` loaded from /home/gh-actions/runner/_work/moonbeam/moonbeam/target/release/wbuild/moonbase-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-41280f87bae211df.rmeta
    = note: second definition in `sp_io` loaded from /home/gh-actions/runner/_work/moonbeam/moonbeam/target/release/wbuild/moonbase-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-e8003f60efd7156c.rmeta
    ```

@joelamouche
Copy link
Contributor

joelamouche commented Nov 16, 2021

type errors due to polkadot-js/api#4213 for latest version and this old version is not up to date

@JoshOrndorff JoshOrndorff added A8-mergeoncegreen Pull request is reviewed well. and removed A0-pleasereview Pull request needs code review. labels Nov 23, 2021
@joelamouche
Copy link
Contributor

Problem with types is now tracked here: polkadot-js/api#4241

* tried downgrading

* update types
@JoshOrndorff JoshOrndorff merged commit c555f1b into master Nov 23, 2021
@JoshOrndorff JoshOrndorff deleted the joshy-moonbeam-account branch November 23, 2021 19:56
notlesh pushed a commit that referenced this pull request Nov 24, 2021
* initial draft installed in moonbase

* fix cli-opt

* comment about better Display impl

* `Copy`, `FromStr`, and make it build

* rename to AccountId20

* Same FromStr error as AccountId32

* more comment ideas

* Do Moonriver and Moonbeam runtimes

* simplify asset_id_to_account

* start on moonbase tests

* moonbase tests pass

* river and beam

* proper blanket impl

* Be generic over the destination type too 🤷

I'll let @nanocryk tell me how generic it is really appropriate to be here.

* fix account tests

* Fix tests

* update @PolkaDot dependencies in types bundle

* update @PolkaDot dependencies in tests

* update @PolkaDot dependencies in tools

* unused imports

* update deps and fix tests (#975)

* Joshy moonbeam account : remove toLowercase (#977)

* remove tolowercase

* wip fixing tests

* fix tests

* finish fixing tests

* remove todos

* remove more todos

* update package-lock

* Fix recently-merged integration tests

* fix crossed dependencies in runtime-common

* fix package-lock

* downgrade polkadot/types because its broken

* update deps

* update deps

* Joshy moonbeam account downgrade attempt (#1019)

* tried downgrading

* update types

Co-authored-by: gorka <gorka.irazoki@gmail.com>
Co-authored-by: Antoine Estienne <antoine@purestake.com>
Co-authored-by: estienne.antoine@gmail.com <estienne.antoine@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A8-mergeoncegreen Pull request is reviewed well. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes C1-low Does not elevate a release containing this beyond "low priority".
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants