mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 11:15:47 +00:00
Consensus data added with generic use in service/src/consensus.rs. Th… (#1274)
* Consensus data added with generic use in service/src/consensus.rs. This may need to change. * refactor consensus service a bit
This commit is contained in:
committed by
Robert Habermeier
parent
c1b08cd9b0
commit
1c104e0568
@@ -31,6 +31,7 @@ use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as Heade
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::BasicInherentData;
|
||||
use transaction_pool::txpool::{self, Pool as TransactionPool};
|
||||
use aura_primitives::AuraConsensusData;
|
||||
|
||||
type Timestamp = u64;
|
||||
|
||||
@@ -111,11 +112,12 @@ pub struct ProposerFactory<C, A> where A: txpool::ChainApi {
|
||||
pub transaction_pool: Arc<TransactionPool<A>>,
|
||||
}
|
||||
|
||||
impl<C, A> consensus_common::Environment<<C as AuthoringApi>::Block> for ProposerFactory<C, A> where
|
||||
impl<C, A, ConsensusData> consensus_common::Environment<<C as AuthoringApi>::Block, ConsensusData> for ProposerFactory<C, A> where
|
||||
C: AuthoringApi,
|
||||
<C as ProvideRuntimeApi>::Api: BlockBuilderApi<<C as AuthoringApi>::Block, BasicInherentData>,
|
||||
A: txpool::ChainApi<Block=<C as AuthoringApi>::Block>,
|
||||
client::error::Error: From<<C as AuthoringApi>::Error>
|
||||
client::error::Error: From<<C as AuthoringApi>::Error>,
|
||||
Proposer<<C as AuthoringApi>::Block, C, A>: consensus_common::Proposer<<C as AuthoringApi>::Block, ConsensusData>,
|
||||
{
|
||||
type Proposer = Proposer<<C as AuthoringApi>::Block, C, A>;
|
||||
type Error = error::Error;
|
||||
@@ -144,6 +146,10 @@ impl<C, A> consensus_common::Environment<<C as AuthoringApi>::Block> for Propose
|
||||
}
|
||||
}
|
||||
|
||||
struct ConsensusData {
|
||||
timestamp: Option<u64>,
|
||||
}
|
||||
|
||||
/// The proposer logic.
|
||||
pub struct Proposer<Block: BlockT, C, A: txpool::ChainApi> {
|
||||
client: Arc<C>,
|
||||
@@ -153,7 +159,7 @@ pub struct Proposer<Block: BlockT, C, A: txpool::ChainApi> {
|
||||
transaction_pool: Arc<TransactionPool<A>>,
|
||||
}
|
||||
|
||||
impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block> for Proposer<Block, C, A> where
|
||||
impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block, AuraConsensusData> for Proposer<Block, C, A> where
|
||||
Block: BlockT,
|
||||
C: AuthoringApi<Block=Block>,
|
||||
<C as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, BasicInherentData>,
|
||||
@@ -163,10 +169,41 @@ impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block> for Pro
|
||||
type Create = Result<<C as AuthoringApi>::Block, error::Error>;
|
||||
type Error = error::Error;
|
||||
|
||||
fn propose(&self) -> Result<<C as AuthoringApi>::Block, error::Error> {
|
||||
fn propose(&self, consensus_data: AuraConsensusData)
|
||||
-> Result<<C as AuthoringApi>::Block, error::Error>
|
||||
{
|
||||
self.propose_with(ConsensusData { timestamp: Some(consensus_data.timestamp) })
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block, ()> for Proposer<Block, C, A> where
|
||||
Block: BlockT,
|
||||
C: AuthoringApi<Block=Block>,
|
||||
<C as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, BasicInherentData>,
|
||||
A: txpool::ChainApi<Block=Block>,
|
||||
client::error::Error: From<<C as AuthoringApi>::Error>
|
||||
{
|
||||
type Create = Result<<C as AuthoringApi>::Block, error::Error>;
|
||||
type Error = error::Error;
|
||||
|
||||
fn propose(&self, _consensus_data: ()) -> Result<<C as AuthoringApi>::Block, error::Error> {
|
||||
self.propose_with(ConsensusData { timestamp: None })
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, C, A> Proposer<Block, C, A> where
|
||||
Block: BlockT,
|
||||
C: AuthoringApi<Block=Block>,
|
||||
<C as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, BasicInherentData>,
|
||||
A: txpool::ChainApi<Block=Block>,
|
||||
client::error::Error: From<<C as AuthoringApi>::Error>,
|
||||
{
|
||||
fn propose_with(&self, consensus_data: ConsensusData)
|
||||
-> Result<<C as AuthoringApi>::Block, error::Error>
|
||||
{
|
||||
use runtime_primitives::traits::BlakeTwo256;
|
||||
|
||||
let timestamp = current_timestamp();
|
||||
let timestamp = consensus_data.timestamp.unwrap_or_else(current_timestamp);
|
||||
let inherent_data = BasicInherentData::new(timestamp, 0);
|
||||
|
||||
let block = self.client.build_block(
|
||||
|
||||
@@ -34,6 +34,7 @@ extern crate substrate_client as client;
|
||||
extern crate substrate_client_db as client_db;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate substrate_transaction_pool as transaction_pool;
|
||||
extern crate substrate_consensus_aura_primitives as aura_primitives;
|
||||
extern crate substrate_rpc_servers as rpc;
|
||||
extern crate target_info;
|
||||
extern crate tokio;
|
||||
|
||||
Reference in New Issue
Block a user