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

refactor: Reintroduce strictly typed AccountId #4621

Merged
merged 3 commits into from
Aug 5, 2021

Conversation

miraclx
Copy link
Contributor

@miraclx miraclx commented Aug 2, 2021

Resolves #4600

Nayduck

http://nayduck.eastus.cloudapp.azure.com:3000/#/run/1943

Testing Plan

  • Manually booted a testnet node to ensure genesis loads properly and that no further AccountId-related issues occur.
  • Ensured unit tests pass with no further updates
  • Nayduck tests pass without modifications

…ear#4440)

This PR introduces a strictly typed structure - `AccountId` that enforces account ID validation.
This way, we can ensure validity and thereby fail fast before an invalid account name is used.

This also, optionally, ensures validation on {,de}serialization so, yeah..

The structure is defined within its own self-contained crate `near-account-id` to allow for easy publishing.
The extra dependencies - `borsh`, `serde` are made optional to allow the crate to be lightweight enough to be depended upon.

Within `nearcore`, the structure is reexported via `near_primitives::AccountId` and the crate via `near_primitives{,_core}::account::id` with default features (`borsh`, `serde`) but you can opt-out of those by depending on it directly.

Resolves near#2074, supersedes near#2831.

* [x] Existing unit tests pass with minor updates
* [x] Nayduck tests pass without modifications
* [x] Manually ensured that the protocol is not changed
Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

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

@miraclx the PR is very large. Could you point to where exactly the fix is?

@frol
Copy link
Collaborator

frol commented Aug 3, 2021

@miraclx Please, provide more context about the issue with the Access Keys in the genesis file (it is even better if you provide the specific examples with the invalid account ids we have there)

@bowenwang1996 I asked @miraclx to prepare the PR in such a way that the first commit is a squash-commit from the previous PR, and the second commit is the patch on top of that, so see the second commit.

@miraclx
Copy link
Contributor Author

miraclx commented Aug 3, 2021

We have invalid AccountId-s in .records[].AccessKey occurring several times in the genesis config. Here's two of those cases..

  • Case 1: Empty String (ErrorKind::TooShort)

    {
      "AccessKey": {
        "account_id": "bentiancai629",
        "public_key": "ed25519:FSgxX7YwuCveCeYqsSAB3sD8dgdy3XBWztCQcEjimpaN",
        "access_key": {
          "nonce": 0,
          "permission": {
            "FunctionCall": {
              "allowance": "100000000",
              "receiver_id": "", <--
              "method_names": []
            }
          }
        }
      }
    },
  • Case 2: Caps characters (ErrorKind::Invalid)

    {
      "AccessKey": {
        "account_id": "jfaulkner",
        "public_key": "ed25519:HBonxN3DJpnTSiy5DF4NN7eAfcm7mV26PNhHW42Lb5k6",
        "access_key": {
          "nonce": 0,
          "permission": {
            "FunctionCall": {
              "allowance": "10000000000000000000000",
              "receiver_id": "NEAR_wallet_app", <--
              "method_names": []
            }
          }
        }
      }
    }, 

With the previous behavior not doing any validation, this is an impediment to our initiative of using strictly typed AccountId's everywhere. To remedy this, we retain the previous behavior and strictly define this field as a String.

@frol frol merged commit 2d7b3c0 into near:master Aug 5, 2021
@miraclx miraclx deleted the strict-account-id-validity branch August 5, 2021 15:42
nikurt pushed a commit that referenced this pull request Aug 9, 2021
This PR introduces a strictly typed structure - `AccountId` that enforces account ID validation.
This way, we can ensure validity and thereby fail fast before an invalid account name is used.

This also, optionally, ensures validation on {,de}serialization so, yeah..

The structure is defined within its own self-contained crate `near-account-id` to allow for easy publishing.
The extra dependencies - `borsh`, `serde` are made optional to allow the crate to be lightweight enough to be depended upon.

Within `nearcore`, the structure is reexported via `near_primitives::AccountId` and the crate via `near_primitives{,_core}::account::id` with default features (`borsh`, `serde`) but you can opt-out of those by depending on it directly.

Resolves #2074, supersedes #2831.

* [x] Existing unit tests pass with minor updates
* [x] Nayduck tests pass without modifications
* [x] Manually ensured that the protocol is not changed

* [x] Manually booted a testnet node to ensure genesis loads properly and that no further AccountId-related issues occur.
* [x] Ensured unit tests pass with no further updates
* [x] Nayduck tests pass without modifications
near-bulldozer bot pushed a commit that referenced this pull request Sep 6, 2021
…_id != AccountId (#4773)

Resolves #4739: documents why the `receiver_id` field in `FunctionCallPermission` isn't an `AccountId` despite recently refactoring the whole workspace to using strict `AccountId`-s.

See #4621 (comment) for more context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Account Id change caused neard to break on testnet Define AccountId to hold a contract of being valid
4 participants