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

[authority] Refactor AuthorityState creation to have a single creation point #504

Merged
merged 3 commits into from
Feb 22, 2022

Conversation

awelc
Copy link
Contributor

@awelc awelc commented Feb 21, 2022

This is ideally the first step towards running module initializers when creating genesis state.

The main point of this refactoring is to have a single AuthorityState constructor with a clearly defined set of modules that are created as part of the genesis state, so that we can run module initializers at the point of AuthorityState construction.

@awelc awelc self-assigned this Feb 21, 2022
@lxfind
Copy link
Contributor

lxfind commented Feb 21, 2022

I wonder if we still need the constructors that create AuthorityState without genesis.
We had those in the past because we didn't have genesis modules at first.
Now that we have them, I think they should always be included in all cases.

@awelc
Copy link
Contributor Author

awelc commented Feb 21, 2022

I wonder if we still need the constructors that create AuthorityState without genesis.

That's part of the refactoring. I got rid of the new_with_genesis_modules constructor so that we simply always use new - I left the new_without_genesis_for_testing as it's testing only so I did not bother.

@awelc
Copy link
Contributor Author

awelc commented Feb 21, 2022

I wonder if we still need the constructors that create AuthorityState without genesis.

That's part of the refactoring. I got rid of the new_with_genesis_modules constructor so that we simply always use new - I left the new_without_genesis_for_testing as it's testing only so I did not bother.

I removed the test-only constructor. Are we good with this refactoring otherwise?

@lxfind
Copy link
Contributor

lxfind commented Feb 21, 2022

Do we still need two constructors? I was wondering if we could just always init it with genesis, and then we could just handle the module init logic in authority state constructor.

@awelc
Copy link
Contributor Author

awelc commented Feb 21, 2022

Do we still need two constructors? I was wondering if we could just always init it with genesis, and then we could just handle the module init logic in authority state constructor.

This is the intent I expressed in this PR's description, and my previous commit removed the test-only constructor (that would not have any genesis modules anyway), but even previously we only had one constructor for non-test cases. Am I missing something here?

@lxfind
Copy link
Contributor

lxfind commented Feb 22, 2022

Ah sorry I misunderstood somehow!
In that case, why do we prefer passing the genesis module as parameter instead of getting it inside the constructor?

@awelc
Copy link
Contributor Author

awelc commented Feb 22, 2022

Ah sorry I misunderstood somehow! In that case, why do we prefer passing the genesis module as parameter instead of getting it inside the constructor?

This is because the genesis state is constructed slightly differently in genesir.rs and in sui_commands.rs and I did not intend it as too general of a refactoring, but rather just good enough to get me a single constructor for injecting module initializer execution.

@awelc
Copy link
Contributor Author

awelc commented Feb 22, 2022

Could I please get additional revision feedback or get it it stamped?

Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

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

Approving to unblock you.
But I don't quite understand why we have a path to create the state without genesis modules in sui_command. Maybe @patrickkuo or @oxade could clarify that.

@awelc
Copy link
Contributor Author

awelc commented Feb 22, 2022

Approving to unblock you. But I don't quite understand why we have a path to create the state without genesis modules in sui_command. Maybe @patrickkuo or @oxade could clarify that

Thank you! And I don't think we do a no-genesis part in sui_command. The separate genesis_modules parameter is there more because sui_command.rs creates a list of modules differently than adapter's genesis.rs (and none of this code was written by me) - the former creates them on-the-fly including user-defined modules whereas the latter stores them in a global so that it can be easily retrieved. And again, this refactoring was not meant to clean all this up but rather do enough to serve as the first step for module initialization code injection.

@awelc awelc merged commit 4e7c20f into main Feb 22, 2022
@awelc awelc deleted the aw/authority-state-construct-refactor branch February 22, 2022 18:07
store: Arc<AuthorityStore>,
) -> Self {
let (genesis_modules, native_functions) = genesis::clone_genesis_data();
// let (genesis_modules, native_functions) = genesis::clone_genesis_data();
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, forgot to delete this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I certainly did... Thanks for noticing! Fixed in #518.

@awelc awelc linked an issue Feb 22, 2022 that may be closed by this pull request
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.

[sui adapter] Run module initializers during genesis
2 participants