mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Make Proposer consume its reference on propose (#6190)
* Make `Proposer` consume its reference on `propose` A proposer must be created per new round, so it makes sense to have the proposer consume its own reference. * Remove `ProposerInner`
This commit is contained in:
@@ -91,16 +91,14 @@ impl<B, Block, C, A> ProposerFactory<A, B, C>
|
||||
info!("🙌 Starting consensus session on top of parent {:?}", parent_hash);
|
||||
|
||||
let proposer = Proposer {
|
||||
inner: Arc::new(ProposerInner {
|
||||
client: self.client.clone(),
|
||||
parent_hash,
|
||||
parent_id: id,
|
||||
parent_number: *parent_header.number(),
|
||||
transaction_pool: self.transaction_pool.clone(),
|
||||
now,
|
||||
metrics: self.metrics.clone(),
|
||||
_phantom: PhantomData,
|
||||
}),
|
||||
client: self.client.clone(),
|
||||
parent_hash,
|
||||
parent_id: id,
|
||||
parent_number: *parent_header.number(),
|
||||
transaction_pool: self.transaction_pool.clone(),
|
||||
now,
|
||||
metrics: self.metrics.clone(),
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
|
||||
proposer
|
||||
@@ -132,11 +130,6 @@ impl<A, B, Block, C> sp_consensus::Environment<Block> for
|
||||
|
||||
/// The proposer logic.
|
||||
pub struct Proposer<B, Block: BlockT, C, A: TransactionPool> {
|
||||
inner: Arc<ProposerInner<B, Block, C, A>>,
|
||||
}
|
||||
|
||||
/// Proposer inner, to wrap parameters under Arc.
|
||||
struct ProposerInner<B, Block: BlockT, C, A: TransactionPool> {
|
||||
client: Arc<C>,
|
||||
parent_hash: <Block as BlockT>::Hash,
|
||||
parent_id: BlockId<Block>,
|
||||
@@ -165,22 +158,21 @@ impl<A, B, Block, C> sp_consensus::Proposer<Block> for
|
||||
type Error = sp_blockchain::Error;
|
||||
|
||||
fn propose(
|
||||
&mut self,
|
||||
self,
|
||||
inherent_data: InherentData,
|
||||
inherent_digests: DigestFor<Block>,
|
||||
max_duration: time::Duration,
|
||||
record_proof: RecordProof,
|
||||
) -> Self::Proposal {
|
||||
let inner = self.inner.clone();
|
||||
tokio_executor::blocking::run(move || {
|
||||
// leave some time for evaluation and block finalization (33%)
|
||||
let deadline = (inner.now)() + max_duration - max_duration / 3;
|
||||
inner.propose_with(inherent_data, inherent_digests, deadline, record_proof)
|
||||
let deadline = (self.now)() + max_duration - max_duration / 3;
|
||||
self.propose_with(inherent_data, inherent_digests, deadline, record_proof)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B, Block, C> ProposerInner<B, Block, C, A>
|
||||
impl<A, B, Block, C> Proposer<B, Block, C, A>
|
||||
where
|
||||
A: TransactionPool<Block = Block>,
|
||||
B: backend::Backend<Block> + Send + Sync + 'static,
|
||||
@@ -191,7 +183,7 @@ impl<A, B, Block, C> ProposerInner<B, Block, C, A>
|
||||
+ BlockBuilderApi<Block, Error = sp_blockchain::Error>,
|
||||
{
|
||||
fn propose_with(
|
||||
&self,
|
||||
self,
|
||||
inherent_data: InherentData,
|
||||
inherent_digests: DigestFor<Block>,
|
||||
deadline: time::Instant,
|
||||
@@ -399,7 +391,7 @@ mod tests {
|
||||
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
||||
|
||||
let cell = Mutex::new((false, time::Instant::now()));
|
||||
let mut proposer = proposer_factory.init_with_now(
|
||||
let proposer = proposer_factory.init_with_now(
|
||||
&client.header(&BlockId::number(0)).unwrap().unwrap(),
|
||||
Box::new(move || {
|
||||
let mut value = cell.lock();
|
||||
@@ -440,7 +432,7 @@ mod tests {
|
||||
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
||||
|
||||
let cell = Mutex::new((false, time::Instant::now()));
|
||||
let mut proposer = proposer_factory.init_with_now(
|
||||
let proposer = proposer_factory.init_with_now(
|
||||
&client.header(&BlockId::number(0)).unwrap().unwrap(),
|
||||
Box::new(move || {
|
||||
let mut value = cell.lock();
|
||||
@@ -489,7 +481,7 @@ mod tests {
|
||||
|
||||
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
||||
|
||||
let mut proposer = proposer_factory.init_with_now(
|
||||
let proposer = proposer_factory.init_with_now(
|
||||
&client.header(&block_id).unwrap().unwrap(),
|
||||
Box::new(move || time::Instant::now()),
|
||||
);
|
||||
@@ -560,7 +552,7 @@ mod tests {
|
||||
expected_block_extrinsics,
|
||||
expected_pool_transactions,
|
||||
| {
|
||||
let mut proposer = proposer_factory.init_with_now(
|
||||
let proposer = proposer_factory.init_with_now(
|
||||
&client.header(&BlockId::number(number)).unwrap().unwrap(),
|
||||
Box::new(move || time::Instant::now()),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user