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

feat(runtime): restrict creation of non-implicit TLA #9589

Merged
merged 8 commits into from
Oct 2, 2023

Conversation

bowenwang1996
Copy link
Collaborator

Implements near/NEPs#492

Copy link
Contributor

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

LGTM

@bowenwang1996 bowenwang1996 added this pull request to the merge queue Sep 26, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 26, 2023
@bowenwang1996
Copy link
Collaborator Author

Looks like Jakob's approval expired :( @akhi3030 can I get a stamp of the PR?

Copy link
Collaborator

@akhi3030 akhi3030 left a comment

Choose a reason for hiding this comment

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

I had chatted with Jakob about this feature. Happy to approve.

Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

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

A few nits and questions but overall looks good to me.


nightly = [
"nightly_protocol",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_fix_staking_threshold",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_restrict_tla",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think tla is a widely known acronym, how about the full wording "top_level_accounts"? Same in the protocol feature enum.

Comment on lines +181 to +182
#[cfg(feature = "protocol_feature_restrict_tla")]
ProtocolFeature::RestrictTla => 139,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Out of order, probably due to some merging, can you put it after post state root?

Any reason to increase the version by 3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit: Out of order, probably due to some merging, can you put it after post state root?

Done

Any reason to increase the version by 3?

That is because there was a 138 when this feature was implemented and it is actually hard to change because of the yaml file (a bunch of things need to be regenerated). There is no harm jumping a few versions for nightly so I think it's okay.

@@ -0,0 +1,2 @@
# Implements NEP-492, disallowing all top-level accounts.
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL
Also cool that it respects protocol version.

env.clients[0].chain.get_final_transaction_result(&tx_hash).unwrap();
assert_eq!(
transaction_result.status,
FinalExecutionStatus::Failure(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused that all of the accounts failed to be created. Are the hex accounts above not implicit accounts? Can you add a comment or adjust the name of the test to reflect that it's testing this NEP specifically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

let account: AccountId = "test0".parse().unwrap();
let mut genesis = Genesis::test(vec![account.clone()], 1);
genesis.config.epoch_length = epoch_length;
genesis.config.protocol_version = PROTOCOL_VERSION;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm shouldn't that be nightly or the exact protocol version for this NEP, at least until this feature is stabilized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test is only enabled for nightly. This is done in feature.rs with conditional compilation

FinalExecutionStatus::Failure(
ActionError {
index: Some(0),
kind: ActionErrorKind::CreateAccountOnlyByRegistrar {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can you add a dedicated error type for the restricted TLAs? OnlyByRegistrar seems to be about something else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No it is the same thing. The purpose of registrar is to create top level accounts

Comment on lines 126 to 127
#[allow(unused)]
pub(crate) fn create_account(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this function? I think it's better to only add it when needed to reduce code bloat.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to conditional compilation. Hopefully that is more clear

@bowenwang1996 bowenwang1996 added this pull request to the merge queue Oct 2, 2023
Merged via the queue into master with commit 85e3bd2 Oct 2, 2023
@bowenwang1996 bowenwang1996 deleted the restrict-tla branch October 2, 2023 18:39
github-merge-queue bot pushed a commit that referenced this pull request Oct 10, 2023
Stabilize near/NEPs#492. Restrict the creation
of non-implicit top-level account that are longer than 32 bytes. Only
the registrar account can create them. More context on the proposal:

- The NEP has been officially approved in September
(near/NEPs#492 (comment)).
- #9589 implements the feature and includes tests checking that TLA can
no longer be created in the new protocol version.
nikurt pushed a commit that referenced this pull request Oct 11, 2023
Stabilize near/NEPs#492. Restrict the creation
of non-implicit top-level account that are longer than 32 bytes. Only
the registrar account can create them. More context on the proposal:

- The NEP has been officially approved in September
(near/NEPs#492 (comment)).
- #9589 implements the feature and includes tests checking that TLA can
no longer be created in the new protocol version.
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.

4 participants