mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Move proof generation to the type system level (#8185)
* Start * Finish!!!! * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Review comments Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -52,8 +52,7 @@ use sp_consensus_pow::{Seal, TotalDifficulty, POW_ENGINE_ID};
|
||||
use sp_inherents::{InherentDataProviders, InherentData};
|
||||
use sp_consensus::{
|
||||
BlockImportParams, BlockOrigin, ForkChoiceStrategy, SyncOracle, Environment, Proposer,
|
||||
SelectChain, Error as ConsensusError, CanAuthorWith, RecordProof, BlockImport,
|
||||
BlockCheckParams, ImportResult,
|
||||
SelectChain, Error as ConsensusError, CanAuthorWith, BlockImport, BlockCheckParams, ImportResult,
|
||||
};
|
||||
use sp_consensus::import_queue::{
|
||||
BoxBlockImport, BasicQueue, Verifier, BoxJustificationImport,
|
||||
@@ -549,7 +548,10 @@ pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, CAW>(
|
||||
timeout: Duration,
|
||||
build_time: Duration,
|
||||
can_author_with: CAW,
|
||||
) -> (Arc<Mutex<MiningWorker<Block, Algorithm, C>>>, impl Future<Output = ()>) where
|
||||
) -> (
|
||||
Arc<Mutex<MiningWorker<Block, Algorithm, C, <E::Proposer as Proposer<Block>>::Proof>>>,
|
||||
impl Future<Output = ()>,
|
||||
) where
|
||||
Block: BlockT,
|
||||
C: ProvideRuntimeApi<Block> + BlockchainEvents<Block> + 'static,
|
||||
S: SelectChain<Block> + 'static,
|
||||
@@ -566,7 +568,7 @@ pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, CAW>(
|
||||
}
|
||||
|
||||
let timer = UntilImportedOrTimeout::new(client.import_notification_stream(), timeout);
|
||||
let worker = Arc::new(Mutex::new(MiningWorker::<Block, Algorithm, C> {
|
||||
let worker = Arc::new(Mutex::new(MiningWorker::<Block, Algorithm, C, _> {
|
||||
build: None,
|
||||
algorithm: algorithm.clone(),
|
||||
block_import,
|
||||
@@ -664,7 +666,6 @@ pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, CAW>(
|
||||
inherent_data,
|
||||
inherent_digest,
|
||||
build_time.clone(),
|
||||
RecordProof::No,
|
||||
).await {
|
||||
Ok(x) => x,
|
||||
Err(err) => {
|
||||
@@ -678,7 +679,7 @@ pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, CAW>(
|
||||
},
|
||||
};
|
||||
|
||||
let build = MiningBuild::<Block, Algorithm, C> {
|
||||
let build = MiningBuild::<Block, Algorithm, C, _> {
|
||||
metadata: MiningMetadata {
|
||||
best_hash,
|
||||
pre_hash: proposal.block.header().hash(),
|
||||
|
||||
@@ -40,21 +40,31 @@ pub struct MiningMetadata<H, D> {
|
||||
}
|
||||
|
||||
/// A build of mining, containing the metadata and the block proposal.
|
||||
pub struct MiningBuild<Block: BlockT, Algorithm: PowAlgorithm<Block>, C: sp_api::ProvideRuntimeApi<Block>> {
|
||||
pub struct MiningBuild<
|
||||
Block: BlockT,
|
||||
Algorithm: PowAlgorithm<Block>,
|
||||
C: sp_api::ProvideRuntimeApi<Block>,
|
||||
Proof
|
||||
> {
|
||||
/// Mining metadata.
|
||||
pub metadata: MiningMetadata<Block::Hash, Algorithm::Difficulty>,
|
||||
/// Mining proposal.
|
||||
pub proposal: Proposal<Block, sp_api::TransactionFor<C, Block>>,
|
||||
pub proposal: Proposal<Block, sp_api::TransactionFor<C, Block>, Proof>,
|
||||
}
|
||||
|
||||
/// Mining worker that exposes structs to query the current mining build and submit mined blocks.
|
||||
pub struct MiningWorker<Block: BlockT, Algorithm: PowAlgorithm<Block>, C: sp_api::ProvideRuntimeApi<Block>> {
|
||||
pub(crate) build: Option<MiningBuild<Block, Algorithm, C>>,
|
||||
pub struct MiningWorker<
|
||||
Block: BlockT,
|
||||
Algorithm: PowAlgorithm<Block>,
|
||||
C: sp_api::ProvideRuntimeApi<Block>,
|
||||
Proof
|
||||
> {
|
||||
pub(crate) build: Option<MiningBuild<Block, Algorithm, C, Proof>>,
|
||||
pub(crate) algorithm: Algorithm,
|
||||
pub(crate) block_import: BoxBlockImport<Block, sp_api::TransactionFor<C, Block>>,
|
||||
}
|
||||
|
||||
impl<Block, Algorithm, C> MiningWorker<Block, Algorithm, C> where
|
||||
impl<Block, Algorithm, C, Proof> MiningWorker<Block, Algorithm, C, Proof> where
|
||||
Block: BlockT,
|
||||
C: sp_api::ProvideRuntimeApi<Block>,
|
||||
Algorithm: PowAlgorithm<Block>,
|
||||
@@ -72,7 +82,7 @@ impl<Block, Algorithm, C> MiningWorker<Block, Algorithm, C> where
|
||||
|
||||
pub(crate) fn on_build(
|
||||
&mut self,
|
||||
build: MiningBuild<Block, Algorithm, C>,
|
||||
build: MiningBuild<Block, Algorithm, C, Proof>,
|
||||
) {
|
||||
self.build = Some(build);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user