mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Make Proposer instantiation potentially async. (#4630)
* Make Proposer instantiation potentially async. * fix node-service test * fix basic-authority doc-test * only block once on futures in test * use async/await
This commit is contained in:
committed by
GitHub
parent
ab1be250bc
commit
c7069de044
@@ -34,6 +34,7 @@ use sp_transaction_pool::{TransactionPool, InPoolTransaction};
|
||||
use sc_telemetry::{telemetry, CONSENSUS_INFO};
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sp_api::{ProvideRuntimeApi, ApiExt};
|
||||
use futures::prelude::*;
|
||||
|
||||
/// Proposer factory.
|
||||
pub struct ProposerFactory<C, A> where A: TransactionPool {
|
||||
@@ -59,7 +60,7 @@ impl<B, E, Block, RA, A> ProposerFactory<SubstrateClient<B, E, Block, RA>, A>
|
||||
&mut self,
|
||||
parent_header: &<Block as BlockT>::Header,
|
||||
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
|
||||
) -> Result<Proposer<Block, SubstrateClient<B, E, Block, RA>, A>, sp_blockchain::Error> {
|
||||
) -> Proposer<Block, SubstrateClient<B, E, Block, RA>, A> {
|
||||
let parent_hash = parent_header.hash();
|
||||
|
||||
let id = BlockId::hash(parent_hash);
|
||||
@@ -77,7 +78,7 @@ impl<B, E, Block, RA, A> ProposerFactory<SubstrateClient<B, E, Block, RA>, A>
|
||||
}),
|
||||
};
|
||||
|
||||
Ok(proposer)
|
||||
proposer
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,14 +95,15 @@ impl<B, E, Block, RA, A> sp_consensus::Environment<Block> for
|
||||
BlockBuilderApi<Block, Error = sp_blockchain::Error> +
|
||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>,
|
||||
{
|
||||
type CreateProposer = future::Ready<Result<Self::Proposer, Self::Error>>;
|
||||
type Proposer = Proposer<Block, SubstrateClient<B, E, Block, RA>, A>;
|
||||
type Error = sp_blockchain::Error;
|
||||
|
||||
fn init(
|
||||
&mut self,
|
||||
parent_header: &<Block as BlockT>::Header,
|
||||
) -> Result<Self::Proposer, sp_blockchain::Error> {
|
||||
self.init_with_now(parent_header, Box::new(time::Instant::now))
|
||||
) -> Self::CreateProposer {
|
||||
future::ready(Ok(self.init_with_now(parent_header, Box::new(time::Instant::now))))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +326,7 @@ mod tests {
|
||||
*value = new;
|
||||
old
|
||||
})
|
||||
).unwrap();
|
||||
);
|
||||
|
||||
// when
|
||||
let deadline = time::Duration::from_secs(3);
|
||||
@@ -359,7 +361,7 @@ mod tests {
|
||||
let mut proposer = proposer_factory.init_with_now(
|
||||
&client.header(&block_id).unwrap().unwrap(),
|
||||
Box::new(move || time::Instant::now()),
|
||||
).unwrap();
|
||||
);
|
||||
|
||||
let deadline = time::Duration::from_secs(9);
|
||||
let proposal = futures::executor::block_on(
|
||||
|
||||
@@ -34,9 +34,12 @@
|
||||
//! };
|
||||
//!
|
||||
//! // From this factory, we create a `Proposer`.
|
||||
//! let mut proposer = proposer_factory.init(
|
||||
//! let proposer = proposer_factory.init(
|
||||
//! &client.header(&BlockId::number(0)).unwrap().unwrap(),
|
||||
//! ).unwrap();
|
||||
//! );
|
||||
//!
|
||||
//! // The proposer is created asynchronously.
|
||||
//! let mut proposer = futures::executor::block_on(proposer).unwrap();
|
||||
//!
|
||||
//! // This `Proposer` allows us to create a block proposition.
|
||||
//! // The proposer will grab transactions from the transaction pool, and put them into the block.
|
||||
|
||||
Reference in New Issue
Block a user