Rewrite the BasiQueue using channels#1327
Conversation
|
It looks like @gterzian signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
|
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 |
c1b8903 to
6095ffb
Compare
|
This is, I think, currently blocked on #1326 the locks in the Protocol and ChainSync code) |
b6d3dac to
979ce9d
Compare
33e94d6 to
34ae605
Compare
81e058f to
6f897a9
Compare
6f897a9 to
b4c4f56
Compare
c05df23 to
17d10a5
Compare
|
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
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
| 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> { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| return true | |
| return true; |
| let mut imported = 0; | ||
|
|
||
| let blocks_range = match ( | ||
| blocks |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
| imported = imported + 1; | |
| imported += 1; |
| /// 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), |
There was a problem hiding this comment.
| 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. |
There was a problem hiding this comment.
Why were these removed? (I'm not familiar with this test in particular)
There was a problem hiding this comment.
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...
| 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); |
There was a problem hiding this comment.
Can we move this to inside the map above so we can log the error itself?
eefe1ee to
dfd2e22
Compare
* 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
networking: Pause piece provider when not connected to DSN.
Fix #1325
Fix #1482