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

Get rid of polling in WarpSync #1265

Merged
merged 11 commits into from
Sep 5, 2023

Conversation

dmitry-markin
Copy link
Contributor

This PR is part of Sync 2.0 preparation work and a step towards ChainSync as a pure state machine.

Refs #534

@dmitry-markin dmitry-markin added R0-silent Changes should not be mentioned in any release notes T0-node This PR/Issue is related to the topic “node”. labels Aug 29, 2023
substrate/client/network/common/src/sync/warp.rs Outdated Show resolved Hide resolved
Comment on lines 248 to 250
/// A channel to get target block header if we skip over proofs downloading during warp sync.
warp_sync_target_block_header_rx: Option<oneshot::Receiver<<B as BlockT>::Header>>,

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine for now but in the future there should be some kind of syncing strategy selection like:

enum Strategy {
    Warp(WarpSync),
    Full(FullSync),
    Whatever(...)
}

enum Action {
    SendRequest(Vec<u8>),
    SendResponse(Vec<u8>),
    ImportBlock(Block),
}

enum SyncEvent {
    ResponseReceived(Vec<u8>),
}

trait Strategy {
     fn register_event(&mut self, event: SyncEvent);
     fn next_action(&mut self) -> Option<SyncAction>;
}

impl SyncingEngine {
    async fn run(mut self) {
        loop {
            tokio::select! {
                response = self.pending_responses.select_next_some() => {
                    self.strategy.register_event(SyncEvent::ResponseReceived(response));
                }
            }

            if let Some(action) = self.strategy.next_action() {
                // TODO: perform action
            }
        }
    }
}

Details of the syncing algorithm would be opaque to SyncingEngine and it would only deal with I/O and dispatch the events to the correct syncing strategy which would deal with the logic of that particular strategy and emit I/O-related events to SyncingEngine. How feasible this is to remains to be seen but worth looking into.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that is a good idea. Goes into the direction of: #532

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@altonen Thanks for the snipped provided! My idea was to gradually move all polling to the upper levels (SyncingEngine) first, otherwise it's difficult to do everything in one go. And WarpSync requiring polling was quite an annoying part, so I started from it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I agree this shouldn't be done in this PR and I think your approach of first gradually removing stuff away from ChainSync is good but I just wanted to highlight what the ultimate plan is.

substrate/client/network/sync/src/engine.rs Outdated Show resolved Hide resolved
substrate/client/network/sync/src/lib.rs Outdated Show resolved Hide resolved
substrate/client/network/sync/src/engine.rs Outdated Show resolved Hide resolved
@altonen altonen self-requested a review August 31, 2023 10:07
Copy link
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.

LGTM. Did you verify yet that both relay and parachain warp sync work?

@dmitry-markin
Copy link
Contributor Author

LGTM. Did you verify yet that both relay and parachain warp sync work?

I've only checked that warp sync tests are passing (both regular and "target block"). I'll manually check polkadot warp sync too. To be honest, I don't know how to test parachain warp sync. Do we have some "default" parachain full node in cumulus for such tests?

@dmitry-markin
Copy link
Contributor Author

@altonen both relay- and parachain warp sync works (tested with polkadot & polkadot-parachain).

@altonen
Copy link
Contributor

altonen commented Sep 4, 2023

Same here, any reason this isn't merged?

@dmitry-markin
Copy link
Contributor Author

Same here, any reason this isn't merged?

Also due to a failing zombienet test.

@dmitry-markin
Copy link
Contributor Author

bot merge

@command-bot
Copy link

command-bot bot commented Sep 5, 2023

@dmitry-markin Unknown command "merge". Refer to help docs and/or source code.

@dmitry-markin dmitry-markin enabled auto-merge (squash) September 5, 2023 08:57
@dmitry-markin dmitry-markin merged commit 1219444 into master Sep 5, 2023
91 of 101 checks passed
@dmitry-markin dmitry-markin deleted the dm-get-rid-of-polling-in-warp-sync branch September 5, 2023 09:34
ordian added a commit that referenced this pull request Sep 6, 2023
* master: (24 commits)
  GHW for building and publishing docker images (#1391)
  pallet asset-conversion additional quote tests (#1371)
  Remove deprecated `pallet_balances`'s `set_balance_deprecated` and `transfer` dispatchables (#1226)
  Fix PRdoc check (#1419)
  Fix the wasm runtime substitute caching bug (#1416)
  Bump enumn from 0.1.11 to 0.1.12 (#1412)
  RFC 14: Improve locking mechanism for parachains (#1290)
  Add PRdoc check (#1408)
  fmt fixes (#1413)
  Enforce a decoding limit in MultiAssets (#1395)
  Remove dynamic dispatch using `Ext` (#1399)
  Remove redundant calls to `borrow()` (#1393)
  Get rid of polling in `WarpSync` (#1265)
  Bump actions/checkout from 3 to 4 (#1398)
  Bump thiserror from 1.0.47 to 1.0.48 (#1396)
  Move Relay-Specific Shared Code to One Place (#1193)
  rust docs: add simple analytics (#1377)
  Contracts: Update read_sandbox (#1390)
  Extract block announce validation from `ChainSync` (#1170)
  [ci] Remove runtime-benchmarks from tests (#1335)
  ...
ordian added a commit that referenced this pull request Sep 7, 2023
* master: (28 commits)
  Adds base benchmark for do_tick in broker pallet (#1235)
  zombienet: use another collator image for the slashing test (#1386)
  Prevent a fail prdoc check to block (#1433)
  Fix nothing scheduled on session boundary (#1403)
  GHW for building and publishing docker images (#1391)
  pallet asset-conversion additional quote tests (#1371)
  Remove deprecated `pallet_balances`'s `set_balance_deprecated` and `transfer` dispatchables (#1226)
  Fix PRdoc check (#1419)
  Fix the wasm runtime substitute caching bug (#1416)
  Bump enumn from 0.1.11 to 0.1.12 (#1412)
  RFC 14: Improve locking mechanism for parachains (#1290)
  Add PRdoc check (#1408)
  fmt fixes (#1413)
  Enforce a decoding limit in MultiAssets (#1395)
  Remove dynamic dispatch using `Ext` (#1399)
  Remove redundant calls to `borrow()` (#1393)
  Get rid of polling in `WarpSync` (#1265)
  Bump actions/checkout from 3 to 4 (#1398)
  Bump thiserror from 1.0.47 to 1.0.48 (#1396)
  Move Relay-Specific Shared Code to One Place (#1193)
  ...
Ank4n pushed a commit that referenced this pull request Sep 8, 2023
Daanvdplas pushed a commit that referenced this pull request Sep 11, 2023
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
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 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