mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-05 23:47:25 +00:00
Update futures and tokio for browser light client (#673)
* Make availability-store compile for WASM * Use --manifest-path instead * Make validation work on wasm! * Switch to Spawn trait * Migrate validation to std futures * Migrate network to std futures * Final changes to validation * Tidy up network * Tidy up validation * Switch branch * Migrate service * Get polkadot to compile via wasm! * Add browser-demo * Add initial browser file * Add browser-demo * Tidy * Temp switch back to substrate/master * tidy * Fix wasm build * Re-add release flag * Switch to polkadot-master * Revert cli tokio version to avoid libp2p panic * Update tokio version * Fix availability store tests * Fix validation tests * Remove futures01 from availability-store * Fix network tests * Small changes * Fix collator * Fix typo * Revert removal of tokio_executor that causes tokio version mismatch panic * Fix adder test parachain * Revert "Revert removal of tokio_executor that causes tokio version mismatch panic" This reverts commit cfeb50c01d8df5e209483406a711e64761b44ae9. * Update availability-store/src/worker.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Update network/src/lib.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Update network/src/lib.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Box pin changes * Asyncify network functions * Clean up browser validation worker error * Fix av store test * Nits * Fix validation test * Switch favicon * Fix validation test again * Revert "Asyncify network functions" This reverts commit f20ae6548dc482cb1e75bc80641cfe55c6131a53. * Add async blocks back in
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use futures::prelude::*;
|
||||
use futures::sync::oneshot;
|
||||
use futures::channel::oneshot;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Poll, Context};
|
||||
|
||||
use polkadot_primitives::Hash;
|
||||
|
||||
@@ -95,17 +97,17 @@ impl IncludabilitySender {
|
||||
pub struct Includable(oneshot::Receiver<()>);
|
||||
|
||||
impl Future for Includable {
|
||||
type Item = ();
|
||||
type Error = oneshot::Canceled;
|
||||
type Output = Result<(), oneshot::Canceled>;
|
||||
|
||||
fn poll(&mut self) -> Poll<(), oneshot::Canceled> {
|
||||
self.0.poll()
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
Pin::new(&mut Pin::into_inner(self).0).poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use futures::executor::block_on;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
@@ -132,6 +134,6 @@ mod tests {
|
||||
sender.update_candidate(hash1, true);
|
||||
assert!(sender.is_complete());
|
||||
|
||||
recv.wait().unwrap();
|
||||
block_on(recv).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ impl SharedTableInner {
|
||||
statement: table::SignedStatement,
|
||||
max_block_data_size: Option<u64>,
|
||||
) -> Option<ParachainWork<
|
||||
<R::FetchValidationProof as IntoFuture>::Future,
|
||||
R::FetchValidationProof
|
||||
>> {
|
||||
let summary = self.table.import_statement(context, statement)?;
|
||||
self.update_trackers(&summary.candidate, context);
|
||||
@@ -172,7 +172,7 @@ impl SharedTableInner {
|
||||
None
|
||||
}
|
||||
Some(candidate) => {
|
||||
let fetch = router.fetch_pov_block(candidate).into_future();
|
||||
let fetch = router.fetch_pov_block(candidate);
|
||||
|
||||
Some(Work {
|
||||
candidate_receipt: candidate.clone(),
|
||||
@@ -267,13 +267,13 @@ pub struct ParachainWork<Fetch> {
|
||||
max_block_data_size: Option<u64>,
|
||||
}
|
||||
|
||||
impl<Fetch: Future> ParachainWork<Fetch> {
|
||||
impl<Fetch: Future + Unpin> ParachainWork<Fetch> {
|
||||
/// Prime the parachain work with an API reference for extracting
|
||||
/// chain information.
|
||||
pub fn prime<P: ProvideRuntimeApi>(self, api: Arc<P>)
|
||||
-> PrimedParachainWork<
|
||||
Fetch,
|
||||
impl Send + FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()>,
|
||||
impl Send + FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()> + Unpin,
|
||||
>
|
||||
where
|
||||
P: Send + Sync + 'static,
|
||||
@@ -326,14 +326,13 @@ pub struct PrimedParachainWork<Fetch, F> {
|
||||
|
||||
impl<Fetch, F, Err> PrimedParachainWork<Fetch, F>
|
||||
where
|
||||
Fetch: Future<Item=PoVBlock,Error=Err>,
|
||||
F: FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()>,
|
||||
Fetch: Future<Output=Result<PoVBlock,Err>> + Unpin,
|
||||
F: FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<(OutgoingMessages, ErasureChunk), ()> + Unpin,
|
||||
Err: From<::std::io::Error>,
|
||||
{
|
||||
pub async fn validate(mut self) -> Result<(Validated, Option<ErasureChunk>), Err> {
|
||||
use futures03::compat::Future01CompatExt;
|
||||
let candidate = &self.inner.work.candidate_receipt;
|
||||
let pov_block = self.inner.work.fetch.compat().await?;
|
||||
let pov_block = self.inner.work.fetch.await?;
|
||||
|
||||
let validation_res = (self.validate)(
|
||||
&BlockId::hash(self.inner.relay_parent),
|
||||
@@ -439,7 +438,7 @@ impl SharedTable {
|
||||
router: &R,
|
||||
statement: table::SignedStatement,
|
||||
) -> Option<ParachainWork<
|
||||
<R::FetchValidationProof as IntoFuture>::Future,
|
||||
R::FetchValidationProof,
|
||||
>> {
|
||||
self.inner.lock().import_remote_statement(&*self.context, router, statement, self.max_block_data_size)
|
||||
}
|
||||
@@ -455,7 +454,7 @@ impl SharedTable {
|
||||
R: TableRouter,
|
||||
I: IntoIterator<Item=table::SignedStatement>,
|
||||
U: ::std::iter::FromIterator<Option<ParachainWork<
|
||||
<R::FetchValidationProof as IntoFuture>::Future,
|
||||
R::FetchValidationProof,
|
||||
>>>,
|
||||
{
|
||||
let mut inner = self.inner.lock();
|
||||
@@ -575,8 +574,9 @@ mod tests {
|
||||
use polkadot_primitives::parachain::{AvailableMessages, BlockData, ConsolidatedIngress, Collation};
|
||||
use polkadot_erasure_coding::{self as erasure};
|
||||
use availability_store::ProvideGossipMessages;
|
||||
|
||||
use futures::{future};
|
||||
use futures::future;
|
||||
use futures::executor::block_on;
|
||||
use std::pin::Pin;
|
||||
|
||||
fn pov_block_with_data(data: Vec<u8>) -> PoVBlock {
|
||||
PoVBlock {
|
||||
@@ -592,8 +592,8 @@ mod tests {
|
||||
fn gossip_messages_for(
|
||||
&self,
|
||||
_topic: Hash
|
||||
) -> Box<dyn futures03::Stream<Item = (Hash, Hash, ErasureChunk)> + Unpin + Send> {
|
||||
Box::new(futures03::stream::empty())
|
||||
) -> Pin<Box<dyn futures::Stream<Item = (Hash, Hash, ErasureChunk)> + Send>> {
|
||||
futures::stream::empty().boxed()
|
||||
}
|
||||
|
||||
fn gossip_erasure_chunk(
|
||||
@@ -609,7 +609,7 @@ mod tests {
|
||||
struct DummyRouter;
|
||||
impl TableRouter for DummyRouter {
|
||||
type Error = ::std::io::Error;
|
||||
type FetchValidationProof = future::FutureResult<PoVBlock,Self::Error>;
|
||||
type FetchValidationProof = future::Ready<Result<PoVBlock,Self::Error>>;
|
||||
|
||||
fn local_collation(
|
||||
&self,
|
||||
@@ -766,7 +766,7 @@ mod tests {
|
||||
n_validators as u32,
|
||||
).unwrap();
|
||||
|
||||
let producer: ParachainWork<future::FutureResult<_, ::std::io::Error>> = ParachainWork {
|
||||
let producer: ParachainWork<future::Ready<Result<_, ::std::io::Error>>> = ParachainWork {
|
||||
work: Work {
|
||||
candidate_receipt: candidate,
|
||||
fetch: future::ok(pov_block.clone()),
|
||||
@@ -777,7 +777,7 @@ mod tests {
|
||||
max_block_data_size: None,
|
||||
};
|
||||
|
||||
let validated = futures03::executor::block_on(producer.prime_with(|_, _, _| Ok((
|
||||
let validated = block_on(producer.prime_with(|_, _, _| Ok((
|
||||
OutgoingMessages { outgoing_messages: Vec::new() },
|
||||
ErasureChunk {
|
||||
chunk: vec![1, 2, 3],
|
||||
@@ -841,7 +841,7 @@ mod tests {
|
||||
max_block_data_size: None,
|
||||
};
|
||||
|
||||
let validated = futures03::executor::block_on(producer.prime_with(|_, _, _| Ok((
|
||||
let validated = block_on(producer.prime_with(|_, _, _| Ok((
|
||||
OutgoingMessages { outgoing_messages: Vec::new() },
|
||||
ErasureChunk {
|
||||
chunk: chunks[local_index].clone(),
|
||||
|
||||
Reference in New Issue
Block a user