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

Split polkadot parachains service file into multiple modules #4369

Closed
wants to merge 13 commits into from

Conversation

clangenb
Copy link
Contributor

@clangenb clangenb commented May 3, 2024

I have been maintaining multiple parachains for the past years, and in every team, we try to stay close to upstream for the collator implementation.

Hence, staying up-to-date with upstream when updating polkadot versions was usually done by comparing the individual files. Comparing the service file to upstream was always a pain because it contains a lot of unnecessary code for parachain teams, i.e. implementations for irrelevant nodes like glutton, contracts_rococo etc. However, at the same time there are sometimes minor adjustments necessary for the parachain teams, e.g. RPC extensions and custom types. Having more than 1000 lines of code doesn't make it easier. I know that there is the parachains template, but it is outdated too often, and I don't have enough trust in it to be honest.

This PR aims to remove friction for parachain teams trying to stay up-to-date with the polkadot-sdk by:

  • Separating the service file into modules, such that it is easier to discern parachain relevant code from irrelevant code
  • The file separation has been done in a way such that in most cases one can just accept the upstream changes as there are usually no customizations downstream.
  • Do some re-export proxying of the parachain_commons types such that down_stream implementors don't have to replace the parachain_commons import in every file. They can just update the re-export at a single place.

I thought it will take me almost as long to formulate an issue with my suggestions as already implementing it, which is why I made this draft here now. So I am happy to receive feedback and re-adjust things. Spoileralert: I am thinking about a similar change for the commands.rs

NOTE: It is hard to spot the diff as the code has been put into new files. There was absolutely no change in the functions except for some public modifiers. The service module API stayed the same except for the type exports, which reside now in the new common_types module.

Polkadot address: 16YCL3UVpVWQLGW3p3Zx4k5WAEp9W1DwdDnxAbyAaPxVxnp3

@clangenb clangenb changed the title Split polkadot-parachains service file into multiple modules Split polkadot parachains service file into multiple modules May 3, 2024
use parachains_common::{AccountId, Balance, Block, Nonce};
use crate::service::common_types::{AccountId, Balance, Block, Nonce};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, this should maybe be at the crate root now that I look at it.

Comment on lines 47 to 56
/// Module with common types.
///
/// The idea is to help downstream implementors who don't rely on `parachains_common` for types.
/// Proxying the imports paths via this module makes it possible to only adjust imports here, as
/// opposed to replacing `parachains_common` imports in every file.
pub mod common_types {
pub use parachains_common::{AuraId, AccountId, Balance, Block, Hash, Nonce, Header};
}

use common_types::Block;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the simple but efficient core changes to help parachain teams.

@kianenigma
Copy link
Contributor

I really this PR! this is very similar to the refactors that I also see necessary in #3597

That being said, I see some differences. We should break down a fully featured service.rs file into more individual components such as BuildConsensus and BuildRpc. I have used traits to standardize in the meantime how these are done although these traits are pretty ugly at the moment.

We should make sure these components are reused in polkadot-parachain and parachain-template. At the moment, almost 100% of parachain-template is copy-pasta from polkadot-parachain. It is in essence a subset of it.

Finally, we can then use these reusable components to build a nice configurable omni-node :)

@serban300 also wants to work on this. @clangenb what is your intentions? would you like to congtinue contributing?

@clangenb
Copy link
Contributor Author

I am happy to have someone else building upon my work. However, I don't understand the following:

That being said, I see some differences. We should break down a fully featured service.rs file into more individual components such as BuildConsensus and BuildRpc. I have used traits to standardize in the meantime how these are done although these traits are pretty ugly at the moment.

Isn't this exactly what I have been doing? So maybe with some detailed review this PR is mergeable?

I absolutely agree that we should actually re-use these components in the template, it is the only way that the parachain-template will not be out of sync anymore.

If the work will only consist of incorporating a PR review and using these components in the template, I am happy to continue. If the expectations are higher, I will gladly pass the torch.

Copy link
Contributor

@skunert skunert left a comment

Choose a reason for hiding this comment

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

I agree with @kianenigma , this is a nice step.

+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
{
let deps = crate::rpc::FullDeps { client, pool, deny_unsafe };
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we could further simplify this. The FullDeps struct only has three members and this method here does nothing except create the struct and forward it to the rpc module.

My suggestion is to remove FullDeps alltogether and just pass the arguments to the rpc module methods. Then delete this file.

Copy link
Contributor Author

@clangenb clangenb May 22, 2024

Choose a reason for hiding this comment

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

Yes, I agree. I just thought that this PR should maybe consist of file-splitting only, so that we have a better understandable diff when we want to change the code afterward. But I agree that this would be kind of a minor change.

/// The idea is to help downstream implementors who don't rely on `parachains_common` for types.
/// Proxying the imports paths via this module makes it possible to only adjust imports here, as
/// opposed to replacing `parachains_common` imports in every file.
pub mod common_types {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this makes sense. polkadot-parachain crate is just code that is necessary to build the polkadot-parachain binary. It has no external facing API, so there are no downstream implementors using this. We should continue using parachains_common here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I badly formulated here. The reasoning here was that if a parachain team updates the polkadot version, and they want to integrate the changes by comparing the source files, they need to change the files in more places instead of just here.

Moonbeam for example would have to change the parachains_common::AccountId import in about four places now if I remember correctly, but I don't really like this re-export thing either, but I think it is better than the status quo.

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/2024-05-21-technical-fellowship-opendev-call/8264/1

@serban300
Copy link
Contributor

I am happy to have someone else building upon my work.

If the work will only consist of incorporating a PR review and using these components in the template, I am happy to continue. If the expectations are higher, I will gladly pass the torch.

Awesome and thanks for the contribution so far ! I would like to also take a look on the PR probably next week and let's discuss the way forward after that.

@kianenigma
Copy link
Contributor

That being said, I see some differences. We should break down a fully featured service.rs file into more individual components such as BuildConsensus and BuildRpc. I have used traits to standardize in the meantime how these are done although these traits are pretty ugly at the moment.

Isn't this exactly what I have been doing? So maybe with some detailed review this PR is mergeable?

The main reason I said that, and the only disagreement I have with this PR is that these reusable-components should live outside of polkadot-parachain. I proposed cumulus/service, it could also be in a new omni-node/service or omni-node/common as in #2457.

@clangenb
Copy link
Contributor Author

That being said, I see some differences. We should break down a fully featured service.rs file into more individual components such as BuildConsensus and BuildRpc. I have used traits to standardize in the meantime how these are done although these traits are pretty ugly at the moment.

Isn't this exactly what I have been doing? So maybe with some detailed review this PR is mergeable?

The main reason I said that, and the only disagreement I have with this PR is that these reusable-components should live outside of polkadot-parachain. I proposed cumulus/service, it could also be in a new omni-node/service or omni-node/common as in #2457.

ohhhh, got it! This makes absolute sense. I would probably go for an omni-node/service, but I will await @serban300's review before I continue doing anything.

@serban300
Copy link
Contributor

I looked on the PR. Thank you again for the contribution !

For more context, our intention is to make the entire node code more reusable and the end goal is indeed to remove friction for the parachain teams trying to stay up-to-date with the polkadot-sdk. There are some details here: #5 . Probably one of the steps would be to split the service.rs into multiple files, but we will also have to do bigger refactorings, for example:

  • move common logic to a separate crate
  • move some logic to reusable components
  • add some traits maybe
  • probably have some builder

The entire project is quite big and ambiguous, and there are some unknowns at this point.

The idea of splitting the service.rs file is good and aligned with our vision, but the problem is that at this point I'm not sure how the split should look like exactly, and I would leave it as a future step after some refactoring. Probably at some point, a particular split will become natural. So I would like to continue the work from here, do some refactoring and we can sync at that point about the split if that's ok with you.

Spoileralert: I am thinking about a similar change for the commands.rs

Please let's sync again at a later time about this as well since we'll probably touch the command.rs file in our refactorings.

@kianenigma
Copy link
Contributor

@clangenb given the outcome above, please provide your DOT address in the PR description and I will submit an onchain DOT tip for your contributions. I do agree that this particular refactor might be best done by a full time contributor. Nonetheless, the exploration you have done here is super valuable.

@clangenb
Copy link
Contributor Author

clangenb commented Jun 4, 2024

@clangenb given the outcome above, please provide your DOT address in the PR description and I will submit an onchain DOT tip for your contributions. I do agree that this particular refactor might be best done by a full time contributor. Nonetheless, the exploration you have done here is super valuable.

Thanks a lot, it is highly appreciated. However, I am a fairly new Rank 1 member of the fellowship and just became active. Hence, I would have assumed this to be part of the fellowship. Regardless, as a Rank 1 salary is not really that high, I will gladly accept the tip, I just don't know if this considered to be ok. Just in case, I will leave my address here: :)

My polkadot address would be: 16YCL3UVpVWQLGW3p3Zx4k5WAEp9W1DwdDnxAbyAaPxVxnp3

@clangenb
Copy link
Contributor Author

clangenb commented Jun 4, 2024

I looked on the PR. Thank you again for the contribution !

For more context, our intention is to make the entire node code more reusable and the end goal is indeed to remove friction for the parachain teams trying to stay up-to-date with the polkadot-sdk. There are some details here: #5 . Probably one of the steps would be to split the service.rs into multiple files, but we will also have to do bigger refactorings, for example:

* move common logic to a separate crate

* move some logic to reusable components

* add some traits maybe

* probably have some builder

The entire project is quite big and ambiguous, and there are some unknowns at this point.

The idea of splitting the service.rs file is good and aligned with our vision, but the problem is that at this point I'm not sure how the split should look like exactly, and I would leave it as a future step after some refactoring. Probably at some point, a particular split will become natural. So I would like to continue the work from here, do some refactoring and we can sync at that point about the split if that's ok with you.

Spoileralert: I am thinking about a similar change for the commands.rs

Please let's sync again at a later time about this as well since we'll probably touch the command.rs file in our refactorings.

I absolutely align with what you have intended here. My idea was to have the PR as a first step to that refactoring. And merging this PR would immediately simplify the maintenance process for parachain teams. However, I also agree that we don't want to have too many refactoring PRs as every refactoring is an extra overhead for the parachain maintainers. I guess the decision of merging this PR more or less as-is should mainly depend on the timeline you have in mind for the overall project.

I am simply stating my thoughts here, if you think you want to build take it from here without merging the PR I am completely fine with it. 👍

@serban300
Copy link
Contributor

serban300 commented Jun 12, 2024

My idea was to have the PR as a first step to that refactoring. And merging this PR would immediately simplify the maintenance process for parachain teams. However, I also agree that we don't want to have too many refactoring PRs as every refactoring is an extra overhead for the parachain maintainers.

Yes, I also thought of that and I have the same concern about changing this too many times. And because of this to me it seems safer to postpone the split a bit.

I am simply stating my thoughts here, if you think you want to build take it from here without merging the PR I am completely fine with it. 👍

Thanks ! I'm not sure how the final split will look like, but I will use the split from this PR as a template while moving forward with the refactoring.

@kianenigma
Copy link
Contributor

/tip medium

Copy link

@kianenigma A referendum for a medium (80 DOT) tip was successfully submitted for @clangenb (16YCL3UVpVWQLGW3p3Zx4k5WAEp9W1DwdDnxAbyAaPxVxnp3 on polkadot).

Referendum number: 865.
tip

@kianenigma kianenigma closed this Jun 13, 2024
Copy link

The referendum has appeared on Polkassembly.

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.

5 participants