Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Rewrite the BasiQueue using channels#1327

Merged
gavofyork merged 14 commits into
paritytech:masterfrom
gterzian:try_using_channels_2
Feb 17, 2019
Merged

Rewrite the BasiQueue using channels#1327
gavofyork merged 14 commits into
paritytech:masterfrom
gterzian:try_using_channels_2

Conversation

@gterzian

@gterzian gterzian commented Dec 24, 2018

Copy link
Copy Markdown
Contributor

Fix #1325
Fix #1482

@parity-cla-bot

Copy link
Copy Markdown

It looks like @gterzian signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@gterzian gterzian added the A3-in_progress Pull request is in progress. No review needed at this stage. label Dec 24, 2018
@gterzian

gterzian commented Dec 24, 2018

Copy link
Copy Markdown
Contributor Author

This is currently written on top of #1282, which makes this PR look bigger than it is...

The main change is https://github.com/paritytech/substrate/pull/1327/files#diff-fdedd07ae8ae881a0907be42dd80a840

@gterzian gterzian force-pushed the try_using_channels_2 branch 5 times, most recently from c1b8903 to 6095ffb Compare December 26, 2018 10:50
@gterzian

Copy link
Copy Markdown
Contributor Author

This is, I think, currently blocked on #1326 the locks in the Protocol and ChainSync code)

@gterzian gterzian force-pushed the try_using_channels_2 branch 2 times, most recently from b6d3dac to 979ce9d Compare January 2, 2019 11:47
@gterzian gterzian force-pushed the try_using_channels_2 branch 6 times, most recently from 33e94d6 to 34ae605 Compare January 12, 2019 14:25
@gterzian gterzian force-pushed the try_using_channels_2 branch 7 times, most recently from 81e058f to 6f897a9 Compare January 24, 2019 12:14
@gterzian gterzian changed the title [WIP] Rewrite the BasiQueue using channels Rewrite the BasiQueue using channels Jan 24, 2019
@gterzian gterzian force-pushed the try_using_channels_2 branch from 6f897a9 to b4c4f56 Compare January 24, 2019 12:35
@gterzian gterzian force-pushed the try_using_channels_2 branch 2 times, most recently from c05df23 to 17d10a5 Compare February 6, 2019 14:10
@gterzian

Copy link
Copy Markdown
Contributor Author

Ok I fixed an error introduced in the rebase, and tested on charred-cherry(which seems to work on master again), which seemed to work fine...

@andresilva andresilva left a comment

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.

Just some minor grumbles.


fn handle_import_justification(&self, who: Origin, hash: B::Hash, number: NumberFor<B>, justification: Justification) {
let success = self.justification_import.as_ref().map(|justification_import| {
justification_import.import_justification(hash, number, justification).is_ok()

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.

Let's log this error here under debug.


/// The Aura import queue type.
pub type AuraImportQueue<B, C, E> = BasicQueue<B, AuraVerifier<C, E>>;
pub type AuraImportQueue<B> = BasicQueue<B>;

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.

Maybe we can remove this type, since the BasicQueue type is now an opaque interface that will be used by everyone (regardless of underlying verifier).

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.

The problem with this is that the AuraImportQueue is exported and used outside of the crate, while BasicQueue is private(and probably should be). Perhaps AuraImportQueue can be replaced by a ImportQueue, however I think that's going to require boxing it 😄 , and will also require some additional work since I would be very surprised if it didn't require changing some of the code using it. Perhaps we can look into this as a follow-up?

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.

Didn't think about that. Sure that's reasonable. 👍

let _ = self
.sender
.send(BlockImportMsg::Start(link))
.expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around");

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.

We usually write these proofs in the form:
"self is holding a sender to the Importer; Importer should handle messages while there are senders around; qed"

ImportBlocks(BlockOrigin, Vec<IncomingBlock<B>>),
Imported(
Vec<(
Result<BlockImportResult<<<B as BlockT>::Header as HeaderT>::Number>, BlockImportError>,

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.

Suggested change
Result<BlockImportResult<<<B as BlockT>::Header as HeaderT>::Number>, BlockImportError>,
Result<BlockImportResult<NumberFor<Block>>, BlockImportError>,

impl<B: BlockT> AsyncImportQueueData<B> {
/// Instantiate a new async import queue data.
pub fn new() -> Self {
impl<B: BlockT> BasicQueue<B> {

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.

Can you add a general description here about how the queue works? e.g. how messages are dispatched to a worker, and blocks are imported on a different worker.

Some(link) => link,
None => {
trace!(target:"sync", "Received import result for {} while import-queue has no link", hash);
return true

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.

Suggested change
return true
return true;

let mut imported = 0;

let blocks_range = match (
blocks

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.

This formatting is weird, it should be fine the keep the expression on one line like:
blocks.first().and_then(|b| b.header.as_ref().map(|h| h.number())),

let was_ok = import_result.is_ok();
results.push((import_result, block.hash));
if was_ok {
imported = imported + 1;

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.

Suggested change
imported = imported + 1;
imported += 1;

Comment thread core/network/src/protocol.rs Outdated
/// Tell protocol to request justification for a block.
RequestJustification(B::Hash, NumberFor<B>),
/// Inform protocol whether a justification was successfully imported.
JustificationImportResut(B::Hash, NumberFor<B>, bool),

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.

Suggested change
JustificationImportResut(B::Hash, NumberFor<B>, bool),
JustificationImportResult(B::Hash, NumberFor<B>, bool),

let mut net = TestNet::new(2);
net.peer(1).push_blocks(500, false);
net.sync();
// Wait for peer 0 to import blocks received over the network.

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.

Why were these removed? (I'm not familiar with this test in particular)

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.

I think it's a result of this change: https://github.com/paritytech/substrate/pull/1327/files/8113ac554afb9ed430b565e4569d9bc695c06a55#diff-d19df74b5b495aae3892f8f92a5f174aR213

It appears unnecessary to have the extra wait in the test...

@gavofyork gavofyork added A5-grumble and removed A0-please_review Pull request needs code review. labels Feb 15, 2019
justification_import.import_justification(hash, number, justification).is_ok()
}).unwrap_or(false);
if !success {
debug!("Justification import failed for hash: {:?} number: {:?} coming from node: {:?}", hash, number, who);

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.

Can we move this to inside the map above so we can log the error itself?

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.

yes indeed

@gterzian gterzian force-pushed the try_using_channels_2 branch from eefe1ee to dfd2e22 Compare February 15, 2019 16:38
@gavofyork gavofyork merged commit ed2faf4 into paritytech:master Feb 17, 2019
@gterzian gterzian deleted the try_using_channels_2 branch February 18, 2019 04:15
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* use channels to implement basic import queue

* async justification import

* better conditional for is_done in tests

* reword the test for presence of link

* fix conditional

* trace instead of panic when no link present

* reword expectations when sending to importers

* fix

* debug justification import error

* update expectations

* use NumberFor

* nits

* add general description

* move error handling into closure
liuchengxu pushed a commit to liuchengxu/substrate that referenced this pull request May 31, 2023
networking: Pause piece provider when not connected to DSN.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants