Skip to content

Move syncing code from sc-network-common to sc-network-sync#1912

Merged
dmitry-markin merged 13 commits intomasterfrom
dm-get-rid-common-sync
Nov 1, 2023
Merged

Move syncing code from sc-network-common to sc-network-sync#1912
dmitry-markin merged 13 commits intomasterfrom
dm-get-rid-common-sync

Conversation

@dmitry-markin
Copy link
Copy Markdown
Contributor

@dmitry-markin dmitry-markin commented Oct 17, 2023

This PR moves syncing-related code from sc-network-common to sc-network-sync.

Unfortunately, some parts are tightly integrated with networking, so they were left in sc-network-common for now:

  1. SyncMode in common/src/sync.rs (used in NetworkConfiguration).
  2. BlockAnnouncesHandshake, BlockRequest, BlockResponse, etc. in common/src/sync/message.rs (used in src/protocol.rs and src/protocol/message.rs).

More substantial refactoring is needed to decouple syncing and networking completely, including getting rid of the hardcoded sync protocol.

Release notes

Move syncing-related code from sc-network-common to sc-network-sync. Delete ChainSync trait as it's never used (the only implementation is accessed directly from SyncingEngine and exposes a lot of public methods that are not part of the trait). Some new trait(s) for syncing will likely be introduced as part of Sync 2.0 refactoring to represent syncing strategies.

Builds upon #1736.

@dmitry-markin dmitry-markin added R0-no-crate-publish-required The change does not require any crates to be re-published. T0-node This PR/Issue is related to the topic “node”. labels Oct 17, 2023
@dmitry-markin dmitry-markin requested a review from altonen October 17, 2023 12:46
@dmitry-markin dmitry-markin changed the title [draft] Move syncing code from sc-network-common to sc-network-sync Move syncing code from sc-network-common to sc-network-sync Oct 18, 2023
@dmitry-markin dmitry-markin marked this pull request as ready for review October 18, 2023 14:26
Copy link
Copy Markdown
Contributor

@altonen altonen left a comment

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 should be silent. There are at least two external teams that are working on their own syncing implementations so this will likely affect them. At least the removal of ChainSync is something that should be mentioned, with a note that there will be some kind of new ChainSync trait in the near future.

@dmitry-markin dmitry-markin removed the R0-no-crate-publish-required The change does not require any crates to be re-published. label Oct 20, 2023
@dmitry-markin dmitry-markin requested a review from bkchr October 23, 2023 14:29
Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Looking good. Just a little bit confused why some types are being made public?

/// Action that [`engine::SyncingEngine`] should perform after reporting imported blocks with
/// [`ChainSync::on_blocks_processed`].
enum BlockRequestAction<B: BlockT> {
pub enum BlockRequestAction<B: BlockT> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to make this public?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's consumed by SyncingEngine, that owns ChainSync.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But isn't this in the same crate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Technically, SyncingEngine is in the same root module as ChainSync, because ChainSync is defined in lib.rs. So pub is not needed at all (even as pub(crate)). Semantically, these types are public for SyncingEngine, so I feel inclined to highlight this with either pub or pub(crate).

pub(crate) is probably a better option, but may be it's also worth moving ChainSync to a separate chain_sync.rs file.

@bkchr would it be better to move ChainSync and its types to a separate file and use pub(crate) for types consumed by SyncingEngine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bkchr would it be better to move ChainSync and its types to a separate file and use pub(crate) for types consumed by SyncingEngine?

Done. PR looks scary now due to moved code, but overall situation with ChainSync should have improved.

Copy link
Copy Markdown
Contributor Author

@dmitry-markin dmitry-markin Oct 30, 2023

Choose a reason for hiding this comment

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

@bkchr @altonen Could you have a look if moving ChainSync to a separate file worth it: 2511cfc?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pub(crate) is probably a better option, but may be it's also worth moving ChainSync to a separate chain_sync.rs file.

Yeah sorry for these dumb questions :P I should have realized that the module is private to the crate. Pub is fine by me here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking this reordering could've been done in another PR but whatever. SyncingEngine should be moved to sync/src/lib.rs but that can be done in another PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why SyncingEngine should be moved to the root module and not kept in it's own module, may be reexporting it in the root module?

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Oct 29, 2023

with a note that there will be some kind of new ChainSync trait in the near future.

What is the status of completely getting rid off sync in the networking crate? Because ideally there should not exist a chain sync trait at all.

@dmitry-markin
Copy link
Copy Markdown
Contributor Author

with a note that there will be some kind of new ChainSync trait in the near future.

What is the status of completely getting rid off sync in the networking crate? Because ideally there should not exist a chain sync trait at all.

There won't be ChainSync trait in networking for sure. There may be some new traits for syncing in sc-network-sync though.

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Oct 30, 2023

There may be some new traits for syncing in sc-network-sync though.

Do we really need to make sync itself generic? I don't think so? As this is some self contained implementation.

@altonen
Copy link
Copy Markdown
Contributor

altonen commented Oct 30, 2023

There may be some new traits for syncing in sc-network-sync though.

Do we really need to make sync itself generic? I don't think so? As this is some self contained implementation.

That is not the current plan at least. We are most likely going to introduce some traits for the strategies that we discussed earlier, simply to make the code easier to maintain and plug additional syncing implementations without major headache.

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Oct 30, 2023

Okay :)

Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Moving to its own file sounds reasonable!

}

#[cfg(test)]
mod test {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you are at it, why not also move them into their own file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@dmitry-markin dmitry-markin merged commit 1cd6acd into master Nov 1, 2023
@dmitry-markin dmitry-markin deleted the dm-get-rid-common-sync branch November 1, 2023 13:10
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
…tytech#1912)

This PR moves syncing-related code from `sc-network-common` to
`sc-network-sync`.

Unfortunately, some parts are tightly integrated with networking, so
they were left in `sc-network-common` for now:

1. `SyncMode` in `common/src/sync.rs` (used in `NetworkConfiguration`).
2. `BlockAnnouncesHandshake`, `BlockRequest`, `BlockResponse`, etc. in
`common/src/sync/message.rs` (used in `src/protocol.rs` and
`src/protocol/message.rs`).

More substantial refactoring is needed to decouple syncing and
networking completely, including getting rid of the hardcoded sync
protocol.

## Release notes

Move syncing-related code from `sc-network-common` to `sc-network-sync`.
Delete `ChainSync` trait as it's never used (the only implementation is
accessed directly from `SyncingEngine` and exposes a lot of public
methods that are not part of the trait). Some new trait(s) for syncing
will likely be introduced as part of Sync 2.0 refactoring to represent
syncing strategies.
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

Status: Done ✅

Development

Successfully merging this pull request may close these issues.

4 participants