make block builder and construct_runtime! generic over inherent-data (#1191)

* make block builder generic over inherent-data

* construct_runtime has you specify inherent data type

* get all tests to compile
This commit is contained in:
Robert Habermeier
2018-12-03 11:49:30 +01:00
committed by GitHub
parent 69a288e586
commit 63980e3770
17 changed files with 96 additions and 109 deletions
+12 -10
View File
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! provide consensus service to substrate.
//! A consensus proposer for "basic" chains which use the primitive inherent-data.
// FIXME: move this into substrate-consensus-common - https://github.com/paritytech/substrate/issues/1021
@@ -29,7 +29,7 @@ use consensus_common::{self, evaluation, offline_tracker::OfflineTracker};
use primitives::{H256, AuthorityId, ed25519, Blake2Hasher};
use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi};
use runtime_primitives::generic::BlockId;
use runtime_primitives::InherentData;
use runtime_primitives::BasicInherentData;
use transaction_pool::txpool::{self, Pool as TransactionPool};
use parking_lot::RwLock;
@@ -60,16 +60,18 @@ pub trait AuthoringApi: Send + Sync + ProvideRuntimeApi where
fn build_block<F: FnMut(&mut BlockBuilder<Self::Block>) -> ()>(
&self,
at: &BlockId<Self::Block>,
inherent_data: InherentData,
inherent_data: BasicInherentData,
build_ctx: F,
) -> Result<Self::Block, error::Error>;
}
impl<'a, B, E, Block, RA> BlockBuilder<Block> for client::block_builder::BlockBuilder<'a, Block, SubstrateClient<B, E, Block, RA>> where
impl<'a, B, E, Block, RA> BlockBuilder<Block>
for client::block_builder::BlockBuilder<'a, Block, BasicInherentData, SubstrateClient<B, E, Block, RA>>
where
B: client::backend::Backend<Block, Blake2Hasher> + 'static,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone + 'static,
Block: BlockT<Hash=H256>,
RA: BlockBuilderApi<Block>,
RA: BlockBuilderApi<Block, BasicInherentData>,
{
fn push_extrinsic(&mut self, extrinsic: <Block as BlockT>::Extrinsic) -> Result<(), error::Error> {
client::block_builder::BlockBuilder::push(self, extrinsic).map_err(Into::into)
@@ -80,7 +82,7 @@ impl<B, E, Block, RA> AuthoringApi for SubstrateClient<B, E, Block, RA> where
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone + 'static,
Block: BlockT<Hash=H256>,
RA: BlockBuilderApi<Block>,
RA: BlockBuilderApi<Block, BasicInherentData>,
{
type Block = Block;
type Error = client::error::Error;
@@ -88,7 +90,7 @@ impl<B, E, Block, RA> AuthoringApi for SubstrateClient<B, E, Block, RA> where
fn build_block<F: FnMut(&mut BlockBuilder<Self::Block>) -> ()>(
&self,
at: &BlockId<Self::Block>,
inherent_data: InherentData,
inherent_data: BasicInherentData,
mut build_ctx: F,
) -> Result<Self::Block, error::Error> {
let runtime_version = self.runtime_version_at(at)?;
@@ -119,7 +121,7 @@ pub struct ProposerFactory<C, A> where A: txpool::ChainApi {
impl<C, A> consensus_common::Environment<<C as AuthoringApi>::Block> for ProposerFactory<C, A> where
C: AuthoringApi,
<C as ProvideRuntimeApi>::Api: BlockBuilderApi<<C as AuthoringApi>::Block>,
<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>
{
@@ -174,7 +176,7 @@ pub struct Proposer<Block: BlockT, C, A: txpool::ChainApi> {
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>,
<C as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, BasicInherentData>,
A: txpool::ChainApi<Block=Block>,
client::error::Error: From<<C as AuthoringApi>::Error>
{
@@ -201,7 +203,7 @@ impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block> for Pro
)
}
let inherent_data = InherentData::new(timestamp, offline_indices);
let inherent_data = BasicInherentData::new(timestamp, offline_indices);
let block = self.client.build_block(
&self.parent_id,