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

Syncing strategy refactoring (part 2) #5666

Merged

Conversation

nazar-pc
Copy link
Contributor

@nazar-pc nazar-pc commented Sep 10, 2024

Description

Follow-up to #5469 and mostly covering #5333.

The primary change here is that syncing strategy is no longer created inside of syncing engine, instead syncing strategy is an argument of syncing engine, more specifically it is an argument to build_network that most downstream users will use. This also extracts addition of request-response protocols outside of network construction, making sure they are physically not present when they don't need to be (imagine syncing strategy that uses none of Substrate's protocols in its implementation for example).

This technically allows to completely replace syncing strategy with whatever strategy chain might need.

There will be at least one follow-up PR that will simplify SyncingStrategy trait and other public interfaces to remove mentions of block/state/warp sync requests, replacing them with generic APIs, such that strategies where warp sync is not applicable don't have to provide dummy method implementations, etc.

Integration

Downstream projects will have to write a bit of boilerplate calling build_polkadot_syncing_strategy function to create previously default syncing strategy.

Review Notes

Please review PR through individual commits rather than the final diff, it will be easier that way. The changes are mostly just moving code around one step at a time.

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T required)
    • External contributors: ask maintainers to put the right label on your PR.
  • I have made corresponding changes to the documentation (if applicable)

@nazar-pc
Copy link
Contributor Author

@dmitry-markin @lexnv another one for you folks

@dmitry-markin dmitry-markin added the T0-node This PR/Issue is related to the topic “node”. label Sep 10, 2024
@dmitry-markin
Copy link
Contributor

Impeccable! Once again thanks for excellent work!

…refactoring-part-2

# Conflicts:
#	polkadot/node/service/src/lib.rs
let request = WarpProofRequest { begin };

let Some(protocol_name) = self.protocol_name.clone() else {
warn!(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Wouldn't this generate too much noise?

Copy link
Contributor Author

@nazar-pc nazar-pc Sep 13, 2024

Choose a reason for hiding this comment

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

It will not, this method is not supposed to be called when there is no need for warp requests, that would basically be an implementation bug. This code effectively migrated from substrate/client/network/sync/src/engine.rs (see the change at the bottom of the file). Should be clear if looking at individual commits.

It is just that the invariants for warp sync are a bit strange, which causes this property to be optional (I only did mechanical refactoring, I didn't change the algorithm).

Copy link
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for contributing! 🙏

@nazar-pc
Copy link
Contributor Author

What else is left here? I have another set of changes that depend on this for review already 🙂

@dmitry-markin dmitry-markin added this pull request to the merge queue Sep 17, 2024
Merged via the queue into paritytech:master with commit 43cd6fd Sep 17, 2024
206 of 208 checks passed
@nazar-pc nazar-pc deleted the syncing-strategy-refactoring-part-2 branch September 17, 2024 12:25
/// Metrics.
pub metrics: NotificationMetrics,
}

/// Build the network service, the network status sinks and an RPC sender.
pub fn build_network<TBl, TNet, TExPool, TImpQu, TCl>(
params: BuildNetworkParams<TBl, TNet, TExPool, TImpQu, TCl>,
pub fn build_network<Block, Net, TxPool, IQ, Client>(
Copy link
Member

Choose a reason for hiding this comment

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

While I'm late to the party (sorry).

Before this goes into any stable release or whatever, can we please revert this?

Basically we should not expose build_polkadot_syncing_strategy . Instead we should do this internally in this build_network function and then expose some build_network_advanced or whatever for @nazar-pc that takes then the syncing strategy. This way there is no breaking change to the outside for developers. (that only have a node and not any custom syncing stuff)

The end goal should be that all the node/service changes to all the nodes in this repo are reverted.

@lexnv or @dmitry-markin can you please take care of 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.

#5737 actually extracted the whole syncing strategy out of build_network and exposed build_default_syncing_engine function to construct the typical setup.

The fact that build_network was not just building the network, but also syncing engine, syncing strategies and hardcoding all the protocol was a long standing problem IMO. It was also taking (and still does) the whole sc_service::config::Configuration, most of which it doesn't use, which is also a problem (though I didn't address it in any of my changes). It makes using Substrate as a library quite painful for those who need to customize it the way we do at Subspace.

My goal would be for build_network to be simplified to little more than Net::new() call. The fact that it unconditionally adds a whole bunch of the protocols is annoying and undesirable.

Having build_network_advanced is an option, but not a long-term solution the way I imagine it. Happy to push it into #5737 if that is something you feel strongly about.

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 guess the gist of it is that build_network should build the network, not syncing engines and other stuff it is coupled with right now.

Copy link
Member

Choose a reason for hiding this comment

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

I guess the gist of it is that build_network should build the network, not syncing engines and other stuff it is coupled with right now.

I mean I'm not against this and I support this. Just about how it is done. I mean just keep the function do what it was doing all the time and then provide some extended way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted build_network's API to before this PR and added build_network_advanced instead in #5737

nazar-pc added a commit to nazar-pc/polkadot-sdk that referenced this pull request Sep 20, 2024
nazar-pc added a commit to autonomys/polkadot-sdk that referenced this pull request Sep 27, 2024
# Description

Follow-up to paritytech#5469 and
mostly covering paritytech#5333.

The primary change here is that syncing strategy is no longer created
inside of syncing engine, instead syncing strategy is an argument of
syncing engine, more specifically it is an argument to `build_network`
that most downstream users will use. This also extracts addition of
request-response protocols outside of network construction, making sure
they are physically not present when they don't need to be (imagine
syncing strategy that uses none of Substrate's protocols in its
implementation for example).

This technically allows to completely replace syncing strategy with
whatever strategy chain might need.

There will be at least one follow-up PR that will simplify
`SyncingStrategy` trait and other public interfaces to remove mentions
of block/state/warp sync requests, replacing them with generic APIs,
such that strategies where warp sync is not applicable don't have to
provide dummy method implementations, etc.

## Integration

Downstream projects will have to write a bit of boilerplate calling
`build_polkadot_syncing_strategy` function to create previously default
syncing strategy.

## Review Notes

Please review PR through individual commits rather than the final diff,
it will be easier that way. The changes are mostly just moving code
around one step at a time.

# Checklist

* [x] My PR includes a detailed description as outlined in the
"Description" and its two subsections above.
* [x] My PR follows the [labeling requirements](

https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
) of this project (at minimum one label for `T` required)
* External contributors: ask maintainers to put the right label on your
PR.
* [x] I have made corresponding changes to the documentation (if
applicable)

(cherry picked from commit 43cd6fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants