-
Notifications
You must be signed in to change notification settings - Fork 769
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
[parachain-template] runtime API Implementations into mod apis
#3817
Conversation
mod apis
mod apis
mod apis
There was a problem hiding this 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 ),* ]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@bkchr This PR has a minor change for the Runtime macro. Could you help to review this? |
Head branch was pushed to by a user without write access
Hi @bkchr, I think label T* is missing |
60846a0
…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.
This PR significantly refactors the runtime API implementations to improve project structure, maintainability, and readability. Key changes include:
RUNTIME_API_VERSIONS
inimpl_runtime_apis.rs
topub
, making it accessible throughout the runtime module.apis.rs
, within the parachain template's runtime directory.lib.rs
: Updates the main runtime library file to reflect these structural changes. It removes redundant API implementations and pointsVERSION
to the newly exposedRUNTIME_API_VERSIONS
fromapis.rs
, simplifying the overall runtime configuration.Motivations Behind the Refactoring:
apis.rs
offers a clearer, more navigable project structure.lib.rs
and reducing clutter enhance readability, making it easier for new contributors to understand the project layout and logic.Summary of Changes:
RUNTIME_API_VERSIONS
public inimpl_runtime_apis.rs
.apis.rs
to centralize runtime API implementations.lib.rs
to adjust to the refactored project structure.