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

[parachain-template] runtime API Implementations into mod apis #3817

Merged
merged 7 commits into from
Mar 28, 2024

Conversation

asiniscalchi
Copy link
Contributor

@asiniscalchi asiniscalchi commented Mar 25, 2024

This PR significantly refactors the runtime API implementations to improve project structure, maintainability, and readability. Key changes include:

  1. Enhancing Visibility: Adjusts the visibility of RUNTIME_API_VERSIONS in impl_runtime_apis.rs to pub, making it accessible throughout the runtime module.
  2. Centralizing API Implementations: Introduces a new file, apis.rs, within the parachain template's runtime directory.
  3. Streamlining lib.rs: Updates the main runtime library file to reflect these structural changes. It removes redundant API implementations and points VERSION to the newly exposed RUNTIME_API_VERSIONS from apis.rs, simplifying the overall runtime configuration.

Motivations Behind the Refactoring:

  • Improved Project Structure: Centralizing API implementations in apis.rs offers a clearer, more navigable project structure.
  • Better Readability: Streamlining lib.rs and reducing clutter enhance readability, making it easier for new contributors to understand the project layout and logic.

Summary of Changes:

  • Made RUNTIME_API_VERSIONS public in impl_runtime_apis.rs.
  • Added apis.rs to centralize runtime API implementations.
  • Streamlined lib.rs to adjust to the refactored project structure.

@asiniscalchi asiniscalchi changed the title fix compilation for all targets [parachain-template] Streamline Runtime API Implementations Mar 25, 2024
@asiniscalchi asiniscalchi changed the title [parachain-template] Streamline Runtime API Implementations [parachain-template] Centralizing Runtime API Implementations for Improved Maintainability Mar 25, 2024
@asiniscalchi asiniscalchi marked this pull request as ready for review March 25, 2024 07:46
@asiniscalchi asiniscalchi changed the title [parachain-template] Centralizing Runtime API Implementations for Improved Maintainability [parachain-template] centralizing Runtime API Implementations for Improved Maintainability Mar 25, 2024
@asiniscalchi asiniscalchi changed the title [parachain-template] centralizing Runtime API Implementations for Improved Maintainability [parachain-template] centralizing Runtime API Implementations into mod apis Mar 25, 2024
@asiniscalchi asiniscalchi changed the title [parachain-template] centralizing Runtime API Implementations into mod apis [parachain-template] runtime API Implementations into mod apis Mar 25, 2024
@asiniscalchi asiniscalchi marked this pull request as draft March 25, 2024 10:12
@asiniscalchi asiniscalchi marked this pull request as ready for review March 25, 2024 10:35
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

I dont see an issue with the current code.

Just refactoring for the sake of it is not useful. There are enough actual issues in this repo that need fixing. Some are listed here https://mentor.tasty.limo/

@@ -797,7 +797,7 @@ fn generate_runtime_api_versions(impls: &[ItemImpl]) -> Result<TokenStream> {
}

Ok(quote!(
const RUNTIME_API_VERSIONS: #c::ApisVec = #c::create_apis_vec!([ #( #result ),* ]);
pub const RUNTIME_API_VERSIONS: #c::ApisVec = #c::create_apis_vec!([ #( #result ),* ]);
Copy link
Contributor Author

@asiniscalchi asiniscalchi Mar 25, 2024

Choose a reason for hiding this comment

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

This refactoring also reveals a potential issue with the visibility of the RUNTIME_API_VERSIONS constant. It necessitates placing the VERSION: RuntimeVersion definition on the same level as the impl_runtime_apis macro call.

Copy link
Member

Choose a reason for hiding this comment

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

Okay I guess making that thing pub is valid. But that is a one-line change...

Copy link
Contributor

Choose a reason for hiding this comment

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

This line change looks useful. I'm also wondering how to separate api! from lib.rs. because I don't like a single file too big (we have more than 2k lines...)

Copy link
Contributor Author

@asiniscalchi asiniscalchi Mar 25, 2024

Choose a reason for hiding this comment

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

Indeed, while the change to make the RUNTIME_API_VERSIONS constant public might seem minor, it aligns with a broader goal.
The presence of a "god file" exceeding 700 lines in Substrate's parachain template node, leading to runtimes spanning over 2000 lines throughout the ecosystem, highlights a structural inefficiency.
My proposed refactoring, although not functionally essential, is designed with the parachain template node's users in mind, especially considering the template's role as both an example and a starting point for new parachains.

Copy link
Contributor Author

@asiniscalchi asiniscalchi Mar 25, 2024

Choose a reason for hiding this comment

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

The proposed refactor beneficially exposes SDK challenges that obstruct the creation of organized runtimes.

@ggwpez ggwpez self-requested a review March 25, 2024 19:08
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Okay then i guess its fine.

@asiniscalchi asiniscalchi requested a review from jasl March 26, 2024 17:03
@jasl
Copy link
Contributor

jasl commented Mar 27, 2024

@bkchr This PR has a minor change for the Runtime macro. Could you help to review this?

@bkchr bkchr enabled auto-merge March 27, 2024 21:03
auto-merge was automatically disabled March 28, 2024 07:03

Head branch was pushed to by a user without write access

@asiniscalchi asiniscalchi requested a review from bkchr March 28, 2024 07:04
@asiniscalchi
Copy link
Contributor Author

Hi @bkchr, I think label T* is missing

@bkchr bkchr added the R0-silent Changes should not be mentioned in any release notes label Mar 28, 2024
@bkchr bkchr enabled auto-merge March 28, 2024 08:50
@bkchr bkchr added this pull request to the merge queue Mar 28, 2024
Merged via the queue into paritytech:master with commit 60846a0 Mar 28, 2024
125 of 135 checks passed
@asiniscalchi asiniscalchi deleted the refactor/parachain-runtime-apis branch March 31, 2024 07:21
@Morganamilo Morganamilo mentioned this pull request Apr 4, 2024
12 tasks
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this pull request Apr 9, 2024
…itytech#3817)

This PR significantly refactors the runtime API implementations to
improve project structure, maintainability, and readability. Key changes
include:

1. **Enhancing Visibility**: Adjusts the visibility of
`RUNTIME_API_VERSIONS` in `impl_runtime_apis.rs` to `pub`, making it
accessible throughout the runtime module.
2. **Centralizing API Implementations**: Introduces a new file,
`apis.rs`, within the parachain template's runtime directory.
3. **Streamlining `lib.rs`**: Updates the main runtime library file to
reflect these structural changes. It removes redundant API
implementations and points `VERSION` to the newly exposed
`RUNTIME_API_VERSIONS` from `apis.rs`, simplifying the overall runtime
configuration.

### Motivations Behind the Refactoring:
- **Improved Project Structure**: Centralizing API implementations in
`apis.rs` offers a clearer, more navigable project structure.
- **Better Readability**: Streamlining `lib.rs` and reducing clutter
enhance readability, making it easier for new contributors to understand
the project layout and logic.

### Summary of Changes:
- Made `RUNTIME_API_VERSIONS` public in `impl_runtime_apis.rs`.
- Added `apis.rs` to centralize runtime API implementations.
- Streamlined `lib.rs` to adjust to the refactored project structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants