Commit b3f026f1 authored by Gav Wood's avatar Gav Wood Committed by asynchronous rob
Browse files

Make Polkadot use the Substrate traity libraries (#105)

* Initial stuff.

* Various fixes.

* Fix tests.

* Fix another test

* Fix another test.

* Docs in polkadot runtime.

* Fix up ser/de tests.

* Update god keys

* Syntax

* Fix

* Merge remote-tracking branch 'origin/master' into gav-merge-runtime

* Permissions on init.sh

* Port-over the whitespace from @rphmeier

* Rename

* Merge branch 'master' into gav-merge-runtime

* Fix typo.

* Fix grumbles.

* Make more idiomatic.

* Move `Ed25519Signature` out of traits.
parent 7d65a0ed
...@@ -8,7 +8,10 @@ error-chain = "0.11" ...@@ -8,7 +8,10 @@ error-chain = "0.11"
polkadot-executor = { path = "../executor" } polkadot-executor = { path = "../executor" }
polkadot-runtime = { path = "../runtime" } polkadot-runtime = { path = "../runtime" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
substrate-codec = { path = "../../substrate/codec" }
substrate-runtime-io = { path = "../../substrate/runtime-io" }
substrate-client = { path = "../../substrate/client" } substrate-client = { path = "../../substrate/client" }
substrate-primitives = { path = "../../substrate/primitives" }
substrate-executor = { path = "../../substrate/executor" } substrate-executor = { path = "../../substrate/executor" }
substrate-state-machine = { path = "../../substrate/state-machine" } substrate-state-machine = { path = "../../substrate/state-machine" }
......
...@@ -18,10 +18,13 @@ ...@@ -18,10 +18,13 @@
//! runtime. //! runtime.
extern crate polkadot_executor; extern crate polkadot_executor;
extern crate polkadot_runtime; extern crate polkadot_runtime as runtime;
extern crate polkadot_primitives as primitives; extern crate polkadot_primitives as primitives;
extern crate substrate_codec as codec;
extern crate substrate_runtime_io as runtime_io;
extern crate substrate_client as client; extern crate substrate_client as client;
extern crate substrate_executor as substrate_executor; extern crate substrate_executor as substrate_executor;
extern crate substrate_primitives;
extern crate substrate_state_machine as state_machine; extern crate substrate_state_machine as state_machine;
#[macro_use] #[macro_use]
...@@ -32,14 +35,12 @@ extern crate substrate_keyring as keyring; ...@@ -32,14 +35,12 @@ extern crate substrate_keyring as keyring;
use client::backend::Backend; use client::backend::Backend;
use client::Client; use client::Client;
use polkadot_runtime::runtime;
use polkadot_executor::Executor as LocalDispatch; use polkadot_executor::Executor as LocalDispatch;
use substrate_executor::{NativeExecutionDispatch, NativeExecutor}; use substrate_executor::{NativeExecutionDispatch, NativeExecutor};
use state_machine::OverlayedChanges; use state_machine::OverlayedChanges;
use primitives::{AccountId, SessionKey, Timestamp, TxOrder}; use primitives::{AccountId, BlockId, Index, SessionKey, Timestamp};
use primitives::block::{Id as BlockId, Block, Header, Body};
use primitives::transaction::UncheckedTransaction;
use primitives::parachain::DutyRoster; use primitives::parachain::DutyRoster;
use runtime::{Block, Header, UncheckedExtrinsic, Extrinsic, Call, TimestampCall};
error_chain! { error_chain! {
errors { errors {
...@@ -53,15 +54,15 @@ error_chain! { ...@@ -53,15 +54,15 @@ error_chain! {
description("Unknown block") description("Unknown block")
display("Unknown block") display("Unknown block")
} }
/// Attempted to push an inherent transaction manually. /// Attempted to push an inherent extrinsic manually.
PushedInherentTransaction(tx: UncheckedTransaction) { PushedInherentTransaction(xt: UncheckedExtrinsic) {
description("Attempted to push an inherent transaction to a block."), description("Attempted to push an inherent extrinsic to a block."),
display("Pushed inherent transaction to a block: {:?}", tx), display("Pushed inherent extrinsic to a block: {:?}", xt),
} }
/// Badly-formed transaction. /// Badly-formed extrinsic.
BadlyFormedTransaction(tx: UncheckedTransaction) { BadlyFormedTransaction(xt: UncheckedExtrinsic) {
description("Attempted to push a badly-formed transaction to a block."), description("Attempted to push a badly-formed extrinsic to a block."),
display("Pushed badly-formed transaction to a block: {:?}", tx), display("Pushed badly-formed extrinsic to a block: {:?}", xt),
} }
/// Some other error. /// Some other error.
// TODO: allow to be specified as associated type of PolkadotApi // TODO: allow to be specified as associated type of PolkadotApi
...@@ -87,8 +88,8 @@ impl From<client::error::Error> for Error { ...@@ -87,8 +88,8 @@ impl From<client::error::Error> for Error {
/// A builder for blocks. /// A builder for blocks.
pub trait BlockBuilder: Sized { pub trait BlockBuilder: Sized {
/// Push a non-inherent transaction. /// Push a non-inherent extrinsic.
fn push_transaction(&mut self, transaction: UncheckedTransaction) -> Result<()>; fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()>;
/// Finalise the block. /// Finalise the block.
fn bake(self) -> Block; fn bake(self) -> Block;
...@@ -127,8 +128,8 @@ pub trait PolkadotApi { ...@@ -127,8 +128,8 @@ pub trait PolkadotApi {
/// Get the timestamp registered at a block. /// Get the timestamp registered at a block.
fn timestamp(&self, at: &Self::CheckedBlockId) -> Result<Timestamp>; fn timestamp(&self, at: &Self::CheckedBlockId) -> Result<Timestamp>;
/// Get the nonce of an account at a block. /// Get the index of an account at a block.
fn nonce(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<TxOrder>; fn index(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<Index>;
/// Evaluate a block and see if it gives an error. /// Evaluate a block and see if it gives an error.
...@@ -179,27 +180,27 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>> ...@@ -179,27 +180,27 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
} }
fn session_keys(&self, at: &CheckedId) -> Result<Vec<SessionKey>> { fn session_keys(&self, at: &CheckedId) -> Result<Vec<SessionKey>> {
with_runtime!(self, at, ::runtime::consensus::authorities) with_runtime!(self, at, ::runtime::Consensus::authorities)
} }
fn validators(&self, at: &CheckedId) -> Result<Vec<AccountId>> { fn validators(&self, at: &CheckedId) -> Result<Vec<AccountId>> {
with_runtime!(self, at, ::runtime::session::validators) with_runtime!(self, at, ::runtime::Session::validators)
} }
fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> { fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> {
with_runtime!(self, at, ::runtime::parachains::calculate_duty_roster) with_runtime!(self, at, ::runtime::Parachains::calculate_duty_roster)
} }
fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> { fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
with_runtime!(self, at, ::runtime::timestamp::get) with_runtime!(self, at, ::runtime::Timestamp::now)
} }
fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<()> { fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<()> {
with_runtime!(self, at, || ::runtime::system::internal::execute_block(block)) with_runtime!(self, at, || ::runtime::Executive::execute_block(block))
} }
fn nonce(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<TxOrder> { fn index(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<Index> {
with_runtime!(self, at, || ::runtime::system::nonce(account)) with_runtime!(self, at, || ::runtime::System::account_index(account))
} }
fn build_block(&self, parent: &CheckedId, timestamp: Timestamp) -> Result<Self::BlockBuilder> { fn build_block(&self, parent: &CheckedId, timestamp: Timestamp) -> Result<Self::BlockBuilder> {
...@@ -208,14 +209,20 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>> ...@@ -208,14 +209,20 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
parent_hash: self.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?, parent_hash: self.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?,
number: self.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1, number: self.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1,
state_root: Default::default(), state_root: Default::default(),
transaction_root: Default::default(), extrinsics_root: Default::default(),
digest: Default::default(), digest: Default::default(),
}; };
let body = Body { let extrinsics = vec![
timestamp: timestamp, UncheckedExtrinsic {
transactions: Vec::new(), extrinsic: Extrinsic {
}; signed: Default::default(),
index: Default::default(),
function: Call::Timestamp(TimestampCall::set(timestamp)),
},
signature: Default::default(),
}
];
let mut builder = ClientBlockBuilder { let mut builder = ClientBlockBuilder {
parent: *parent, parent: *parent,
...@@ -223,11 +230,13 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>> ...@@ -223,11 +230,13 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
state: self.state_at(parent)?, state: self.state_at(parent)?,
header, header,
timestamp, timestamp,
transactions: Vec::new(), extrinsics: extrinsics.clone(),
}; };
for inherent in body.inherent_transactions() { builder.initialise_block()?;
builder.execute_transaction(inherent)?;
for inherent in extrinsics {
builder.apply_extrinsic(inherent)?;
} }
Ok(builder) Ok(builder)
...@@ -242,34 +251,53 @@ pub struct ClientBlockBuilder<S> { ...@@ -242,34 +251,53 @@ pub struct ClientBlockBuilder<S> {
state: S, state: S,
header: Header, header: Header,
timestamp: Timestamp, timestamp: Timestamp,
transactions: Vec<UncheckedTransaction>, extrinsics: Vec<UncheckedExtrinsic>,
} }
impl<S: state_machine::Backend> ClientBlockBuilder<S> impl<S: state_machine::Backend> ClientBlockBuilder<S>
where S::Error: Into<client::error::Error> where S::Error: Into<client::error::Error>
{ {
// executes a transaction, inherent or otherwise, without appending to the list // executes a extrinsic, inherent or otherwise, without appending to the list
fn execute_transaction(&mut self, transaction: UncheckedTransaction) -> Result<()> { fn initialise_block(&mut self) -> Result<()> {
if !transaction.is_well_formed() { let mut ext = state_machine::Ext {
bail!(ErrorKind::BadlyFormedTransaction(transaction)); overlay: &mut self.changes,
backend: &self.state,
};
let h = self.header.clone();
let result = ::substrate_executor::with_native_environment(
&mut ext,
|| runtime::Executive::initialise_block(&h),
).map_err(Into::into);
match result {
Ok(_) => {
ext.overlay.commit_prospective();
Ok(())
}
Err(e) => {
ext.overlay.discard_prospective();
Err(e)
}
}
} }
// executes a extrinsic, inherent or otherwise, without appending to the list
fn apply_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
let mut ext = state_machine::Ext { let mut ext = state_machine::Ext {
overlay: &mut self.changes, overlay: &mut self.changes,
backend: &self.state, backend: &self.state,
}; };
// TODO: avoid clone
let header = self.header.clone();
let result = ::substrate_executor::with_native_environment( let result = ::substrate_executor::with_native_environment(
&mut ext, &mut ext,
move || runtime::system::internal::execute_transaction(transaction, header), move || runtime::Executive::apply_extrinsic(extrinsic),
).map_err(Into::into); ).map_err(Into::into);
match result { match result {
Ok(header) => { Ok(_) => {
ext.overlay.commit_prospective(); ext.overlay.commit_prospective();
self.header = header;
Ok(()) Ok(())
} }
Err(e) => { Err(e) => {
...@@ -283,12 +311,13 @@ impl<S: state_machine::Backend> ClientBlockBuilder<S> ...@@ -283,12 +311,13 @@ impl<S: state_machine::Backend> ClientBlockBuilder<S>
impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S> impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
where S::Error: Into<client::error::Error> where S::Error: Into<client::error::Error>
{ {
fn push_transaction(&mut self, transaction: UncheckedTransaction) -> Result<()> { fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
if transaction.transaction.function.is_inherent() { // Check that this is not an "inherent" extrinsic.
bail!(ErrorKind::PushedInherentTransaction(transaction)); if extrinsic.signature == Default::default() {
bail!(ErrorKind::PushedInherentTransaction(extrinsic));
} else { } else {
self.execute_transaction(transaction.clone())?; self.apply_extrinsic(extrinsic.clone())?;
self.transactions.push(transaction); self.extrinsics.push(extrinsic);
Ok(()) Ok(())
} }
} }
...@@ -299,18 +328,14 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S> ...@@ -299,18 +328,14 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
backend: &self.state, backend: &self.state,
}; };
let old_header = self.header;
let final_header = ::substrate_executor::with_native_environment( let final_header = ::substrate_executor::with_native_environment(
&mut ext, &mut ext,
move || runtime::system::internal::finalise_block(old_header) move || runtime::Executive::finalise_block()
).expect("all inherent transactions pushed; all other transactions executed correctly; qed"); ).expect("all inherent extrinsics pushed; all other extrinsics executed correctly; qed");
Block { Block {
header: final_header, header: final_header,
body: Body { extrinsics: self.extrinsics,
timestamp: self.timestamp,
transactions: self.transactions,
}
} }
} }
} }
...@@ -318,10 +343,12 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S> ...@@ -318,10 +343,12 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use runtime_io::with_externalities;
use keyring::Keyring;
use codec::Slicable;
use client::in_mem::Backend as InMemory; use client::in_mem::Backend as InMemory;
use polkadot_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
use substrate_executor::NativeExecutionDispatch; use substrate_executor::NativeExecutionDispatch;
use keyring::Keyring; use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildExternalities};
fn validators() -> Vec<AccountId> { fn validators() -> Vec<AccountId> {
vec![ vec![
...@@ -331,20 +358,31 @@ mod tests { ...@@ -331,20 +358,31 @@ mod tests {
} }
fn client() -> Client<InMemory, NativeExecutor<LocalDispatch>> { fn client() -> Client<InMemory, NativeExecutor<LocalDispatch>> {
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: LocalDispatch::native_equivalent().to_vec(),
authorities: validators(),
}),
system: None,
session: Some(SessionConfig {
validators: validators(),
session_length: 100,
}),
council: Some(Default::default()),
democracy: Some(Default::default()),
parachains: Some(Default::default()),
staking: Some(Default::default()),
};
::client::new_in_mem( ::client::new_in_mem(
LocalDispatch::new(), LocalDispatch::new(),
|| { || {
let config = GenesisConfig::new_simple(validators(), 100); let mut storage = genesis_config.build_externalities();
let block = ::client::genesis::construct_genesis_block(&storage);
// override code entry. with_externalities(&mut storage, ||
let mut storage = config.genesis_map(); // TODO: use api.rs to dispatch instead
storage.insert(b":code".to_vec(), LocalDispatch::native_equivalent().to_vec()); runtime::System::initialise_genesis_state(&block.header)
let block = ::client::genesis::construct_genesis_block(
&config.genesis_map()
); );
storage.extend(additional_storage_with_genesis(&block)); (substrate_primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
(block.header, storage.into_iter().collect())
} }
).unwrap() ).unwrap()
} }
......
...@@ -13,6 +13,7 @@ log = "0.4" ...@@ -13,6 +13,7 @@ log = "0.4"
polkadot-api = { path = "../api" } polkadot-api = { path = "../api" }
polkadot-collator = { path = "../collator" } polkadot-collator = { path = "../collator" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" }
polkadot-statement-table = { path = "../statement-table" } polkadot-statement-table = { path = "../statement-table" }
polkadot-transaction-pool = { path = "../transaction-pool" } polkadot-transaction-pool = { path = "../transaction-pool" }
substrate-bft = { path = "../../substrate/bft" } substrate-bft = { path = "../../substrate/bft" }
......
...@@ -38,6 +38,7 @@ extern crate polkadot_collator as collator; ...@@ -38,6 +38,7 @@ extern crate polkadot_collator as collator;
extern crate polkadot_statement_table as table; extern crate polkadot_statement_table as table;
extern crate polkadot_primitives; extern crate polkadot_primitives;
extern crate polkadot_transaction_pool as transaction_pool; extern crate polkadot_transaction_pool as transaction_pool;
extern crate polkadot_runtime;
extern crate substrate_bft as bft; extern crate substrate_bft as bft;
extern crate substrate_codec as codec; extern crate substrate_codec as codec;
extern crate substrate_primitives as primitives; extern crate substrate_primitives as primitives;
...@@ -62,11 +63,11 @@ use table::generic::Statement as GenericStatement; ...@@ -62,11 +63,11 @@ use table::generic::Statement as GenericStatement;
use runtime_support::Hashable; use runtime_support::Hashable;
use polkadot_api::{PolkadotApi, BlockBuilder}; use polkadot_api::{PolkadotApi, BlockBuilder};
use polkadot_primitives::{Hash, Timestamp}; use polkadot_primitives::{Hash, Timestamp};
use polkadot_primitives::block::Block as PolkadotBlock;
use polkadot_primitives::parachain::{Id as ParaId, DutyRoster, BlockData, Extrinsic, CandidateReceipt}; use polkadot_primitives::parachain::{Id as ParaId, DutyRoster, BlockData, Extrinsic, CandidateReceipt};
use polkadot_runtime::Block as PolkadotGenericBlock;
use primitives::block::{Block as SubstrateBlock, Header as SubstrateHeader, HeaderHash, Id as BlockId, Number as BlockNumber}; use primitives::block::{Block as SubstrateBlock, Header as SubstrateHeader, HeaderHash, Id as BlockId, Number as BlockNumber};
use primitives::AuthorityId; use primitives::AuthorityId;
use transaction_pool::{Ready, TransactionPool}; use transaction_pool::{Ready, TransactionPool, PolkadotBlock};
use futures::prelude::*; use futures::prelude::*;
use futures::future; use futures::future;
...@@ -152,7 +153,7 @@ impl TableContext { ...@@ -152,7 +153,7 @@ impl TableContext {
} }
fn sign_statement(&self, statement: table::Statement) -> table::SignedStatement { fn sign_statement(&self, statement: table::Statement) -> table::SignedStatement {
let signature = sign_table_statement(&statement, &self.key, &self.parent_hash); let signature = sign_table_statement(&statement, &self.key, &self.parent_hash).into();
let local_id = self.key.public().0; let local_id = self.key.public().0;
table::SignedStatement { table::SignedStatement {
...@@ -552,7 +553,7 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> { ...@@ -552,7 +553,7 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
if pending_size + pending.encoded_size() >= MAX_TRANSACTIONS_SIZE { break } if pending_size + pending.encoded_size() >= MAX_TRANSACTIONS_SIZE { break }
match block_builder.push_transaction(pending.as_transaction().clone()) { match block_builder.push_extrinsic(pending.as_transaction().clone()) {
Ok(()) => { Ok(()) => {
pending_size += pending.encoded_size(); pending_size += pending.encoded_size();
} }
...@@ -582,23 +583,23 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> { ...@@ -582,23 +583,23 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, bft::Misbehavior)>) { fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, bft::Misbehavior)>) {
use bft::generic::Misbehavior as GenericMisbehavior; use bft::generic::Misbehavior as GenericMisbehavior;
use primitives::bft::{MisbehaviorKind, MisbehaviorReport}; use primitives::bft::{MisbehaviorKind, MisbehaviorReport};
use polkadot_primitives::transaction::{Function, Transaction, UncheckedTransaction}; use polkadot_runtime::{Call, Extrinsic, UncheckedExtrinsic, ConsensusCall};
let local_id = self.local_key.public().0; let local_id = self.local_key.public().0;
let mut pool = self.transaction_pool.lock(); let mut pool = self.transaction_pool.lock();
let mut next_nonce = { let mut next_index = {
let readiness_evaluator = Ready::create(self.parent_id.clone(), &*self.client); let readiness_evaluator = Ready::create(self.parent_id.clone(), &*self.client);
let cur_nonce = pool.pending(readiness_evaluator) let cur_index = pool.pending(readiness_evaluator)
.filter(|tx| tx.as_transaction().transaction.signed == local_id) .filter(|tx| tx.as_ref().as_ref().signed == local_id)
.last() .last()
.map(|tx| Ok(tx.as_transaction().transaction.nonce)) .map(|tx| Ok(tx.as_ref().as_ref().index))
.unwrap_or_else(|| self.client.nonce(&self.parent_id, local_id)); .unwrap_or_else(|| self.client.index(&self.parent_id, local_id));
match cur_nonce { match cur_index {
Ok(cur_nonce) => cur_nonce + 1, Ok(cur_index) => cur_index + 1,
Err(e) => { Err(e) => {
warn!(target: "consensus", "Error computing next transaction nonce: {}", e); warn!(target: "consensus", "Error computing next transaction index: {}", e);
return; return;
} }
} }
...@@ -618,23 +619,18 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> { ...@@ -618,23 +619,18 @@ impl<C: PolkadotApi, R: TableRouter> bft::Proposer for Proposer<C, R> {
=> MisbehaviorKind::BftDoubleCommit(round as u32, (h1, s1.signature), (h2, s2.signature)), => MisbehaviorKind::BftDoubleCommit(round as u32, (h1, s1.signature), (h2, s2.signature)),
} }
}; };
let extrinsic = Extrinsic {
let tx = Transaction {
signed: local_id, signed: local_id,
nonce: next_nonce, index: next_index,
function: Function::ReportMisbehavior(report), function: Call::Consensus(ConsensusCall::report_misbehavior(report)),
}; };
next_nonce += 1; next_index += 1;
let message = tx.encode(); let signature = self.local_key.sign(&extrinsic.encode()).into();
let signature = self.local_key.sign(&message); let uxt = UncheckedExtrinsic { extrinsic, signature };
let tx = UncheckedTransaction {
transaction: tx,
signature,
};
pool.import(tx).expect("locally signed transaction is valid; qed"); pool.import(uxt).expect("locally signed extrinsic is valid; qed");
} }
} }
} }
...@@ -649,10 +645,11 @@ fn evaluate_proposal<C: PolkadotApi>( ...@@ -649,10 +645,11 @@ fn evaluate_proposal<C: PolkadotApi>(
const MAX_TIMESTAMP_DRIFT: Timestamp = 4; const MAX_TIMESTAMP_DRIFT: Timestamp = 4;
let encoded = Slicable::encode(proposal); let encoded = Slicable::encode(proposal);
let proposal = PolkadotBlock::decode(&mut &encoded[..]) let proposal = PolkadotGenericBlock::decode(&mut &encoded[..])
.and_then(|b| PolkadotBlock::from(b).ok())
.ok_or_else(|| ErrorKind::ProposalNotForPolkadot)?; .ok_or_else(|| ErrorKind::ProposalNotForPolkadot)?;
let transactions_size = proposal.body.transactions.iter().fold(0, |a, tx| { let transactions_size = proposal.extrinsics.iter().fold(0, |a, tx| {
a + Slicable::encode(tx).len() a + Slicable::encode(tx).len()
}); });
...@@ -668,7 +665,7 @@ fn evaluate_proposal<C: PolkadotApi>( ...@@ -668,7 +665,7 @@ fn evaluate_proposal<C: PolkadotApi>(
// a) we assume the parent is valid.