Extrinsics root is calculated as part of block-building (#120)

* extrinsics root is calculated as part of block-building.

* Fix build.

* Fix xt root.

* Couple of fixes.

* Logging and more useful APIs.

* Fix test.

* Update log version.

* Switch back to correct version of log.
This commit is contained in:
Gav Wood
2018-04-12 12:18:43 +02:00
committed by Robert Habermeier
parent 9b0ef06cf8
commit 65489f1b19
9 changed files with 24 additions and 17 deletions
+1
View File
@@ -5,6 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies] [dependencies]
error-chain = "0.11" error-chain = "0.11"
log = "0.3"
polkadot-executor = { path = "../executor" } polkadot-executor = { path = "../executor" }
polkadot-runtime = { path = "../runtime" } polkadot-runtime = { path = "../runtime" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
+5 -6
View File
@@ -31,6 +31,9 @@ extern crate substrate_state_machine as state_machine;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate error_chain;
#[macro_use]
extern crate log;
#[cfg(test)] #[cfg(test)]
extern crate substrate_keyring as keyring; extern crate substrate_keyring as keyring;
@@ -174,7 +177,7 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
fn check_id(&self, id: BlockId) -> Result<CheckedId> { fn check_id(&self, id: BlockId) -> Result<CheckedId> {
// bail if the code is not the same as the natively linked. // bail if the code is not the same as the natively linked.
if self.code_at(&id)? != LocalDispatch::native_equivalent() { if self.code_at(&id)? != LocalDispatch::native_equivalent() {
bail!(ErrorKind::UnknownRuntime); warn!("This node is out of date. Block authoring may not work correctly.")
} }
Ok(CheckedId(id)) Ok(CheckedId(id))
@@ -324,19 +327,15 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
} }
fn bake(mut self) -> Block { fn bake(mut self) -> Block {
use substrate_runtime_executive::extrinsics_root;
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,
}; };
let mut final_header = ::substrate_executor::with_native_environment( let final_header = ::substrate_executor::with_native_environment(
&mut ext, &mut ext,
move || runtime::Executive::finalise_block() move || runtime::Executive::finalise_block()
).expect("all inherent extrinsics pushed; all other extrinsics executed correctly; qed"); ).expect("all inherent extrinsics pushed; all other extrinsics executed correctly; qed");
final_header.extrinsics_root = extrinsics_root::<runtime_io::BlakeTwo256, _>(&self.extrinsics);
Block { Block {
header: final_header, header: final_header,
extrinsics: self.extrinsics, extrinsics: self.extrinsics,
+1 -1
View File
@@ -9,7 +9,7 @@ parking_lot = "0.4"
tokio-core = "0.1.12" tokio-core = "0.1.12"
ed25519 = { path = "../../substrate/ed25519" } ed25519 = { path = "../../substrate/ed25519" }
error-chain = "0.11" error-chain = "0.11"
log = "0.4" log = "0.3"
polkadot-api = { path = "../api" } polkadot-api = { path = "../api" }
polkadot-collator = { path = "../collator" } polkadot-collator = { path = "../collator" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
Binary file not shown.
+1 -1
View File
@@ -8,7 +8,7 @@ futures = "0.1.17"
parking_lot = "0.4" parking_lot = "0.4"
tokio-timer = "0.1.2" tokio-timer = "0.1.2"
error-chain = "0.11" error-chain = "0.11"
log = "0.4" log = "0.3"
tokio-core = "0.1.12" tokio-core = "0.1.12"
ed25519 = { path = "../../substrate/ed25519" } ed25519 = { path = "../../substrate/ed25519" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
+1
View File
@@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
[dependencies] [dependencies]
log = "0.4.0"
transaction-pool = "1.9.0" transaction-pool = "1.9.0"
error-chain = "0.11" error-chain = "0.11"
polkadot-api = { path = "../api" } polkadot-api = { path = "../api" }
+15 -9
View File
@@ -28,6 +28,9 @@ extern crate transaction_pool;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate error_chain;
#[macro_use]
extern crate log;
use std::collections::HashMap; use std::collections::HashMap;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::sync::Arc; use std::sync::Arc;
@@ -296,12 +299,10 @@ impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready<VerifiedTransaction> for R
let next_index = self.known_indices.entry(sender) let next_index = self.known_indices.entry(sender)
.or_insert_with(|| api_handle.index(at_block, sender).ok().unwrap_or_else(u64::max_value)); .or_insert_with(|| api_handle.index(at_block, sender).ok().unwrap_or_else(u64::max_value));
*next_index += 1;
match xt.inner.index.cmp(&next_index) { match xt.inner.index.cmp(&next_index) {
Ordering::Greater => Readiness::Future, Ordering::Greater => Readiness::Future,
Ordering::Equal => Readiness::Ready, Ordering::Equal => Readiness::Ready,
Ordering::Less => Readiness::Stalled, Ordering::Less => Readiness::Stalled, // TODO: this is not "stalled" but rather stale and can be discarded.
} }
} }
} }
@@ -330,12 +331,14 @@ impl TransactionPool {
let verified = VerifiedTransaction::create(xt, insertion_index)?; let verified = VerifiedTransaction::create(xt, insertion_index)?;
info!("Extrinsic verified {:?}. Importing...", verified);
// TODO: just use a foreign link when the error type is made public. // TODO: just use a foreign link when the error type is made public.
let hash = verified.hash.clone(); let hash = verified.hash.clone();
self.inner.import(verified) self.inner.import(verified)
.map_err(|e| .map_err(|e|
match e { match e {
// TODO: make error types public in transaction_pool. For now just treat all errors as AlradyImported // TODO: make error types public in transaction_pool. For now just treat all errors as AlreadyImported
_ => ErrorKind::AlreadyImported(hash), _ => ErrorKind::AlreadyImported(hash),
// transaction_pool::error::AlreadyImported(h) => ErrorKind::AlreadyImported(h), // transaction_pool::error::AlreadyImported(h) => ErrorKind::AlreadyImported(h),
// e => ErrorKind::Import(Box::new(e)), // e => ErrorKind::Import(Box::new(e)),
@@ -376,11 +379,14 @@ impl TransactionPool {
impl substrate_rpc::author::AsyncAuthorApi for TransactionPool { impl substrate_rpc::author::AsyncAuthorApi for TransactionPool {
fn submit_extrinsic(&mut self, xt: Extrinsic) -> substrate_rpc::author::error::Result<()> { fn submit_extrinsic(&mut self, xt: Extrinsic) -> substrate_rpc::author::error::Result<()> {
self.import(xt use substrate_primitives::hexdisplay::HexDisplay;
.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s)) info!("Extrinsic submitted: {}", HexDisplay::from(&xt.0));
.ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?) let xt = xt.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s))
.map(|_| ()) .ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?;
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError.into()) info!("Correctly formatted: {:?}", xt);
self.import(xt)
.map(|_| ())
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError.into())
} }
} }