mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
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:
committed by
Robert Habermeier
parent
9b0ef06cf8
commit
65489f1b19
@@ -5,6 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
error-chain = "0.11"
|
||||
log = "0.3"
|
||||
polkadot-executor = { path = "../executor" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
|
||||
@@ -31,6 +31,9 @@ extern crate substrate_state_machine as state_machine;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(test)]
|
||||
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> {
|
||||
// bail if the code is not the same as the natively linked.
|
||||
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))
|
||||
@@ -324,19 +327,15 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
|
||||
}
|
||||
|
||||
fn bake(mut self) -> Block {
|
||||
use substrate_runtime_executive::extrinsics_root;
|
||||
|
||||
let mut ext = state_machine::Ext {
|
||||
overlay: &mut self.changes,
|
||||
backend: &self.state,
|
||||
};
|
||||
|
||||
let mut final_header = ::substrate_executor::with_native_environment(
|
||||
let final_header = ::substrate_executor::with_native_environment(
|
||||
&mut ext,
|
||||
move || runtime::Executive::finalise_block()
|
||||
).expect("all inherent extrinsics pushed; all other extrinsics executed correctly; qed");
|
||||
|
||||
final_header.extrinsics_root = extrinsics_root::<runtime_io::BlakeTwo256, _>(&self.extrinsics);
|
||||
Block {
|
||||
header: final_header,
|
||||
extrinsics: self.extrinsics,
|
||||
|
||||
@@ -9,7 +9,7 @@ parking_lot = "0.4"
|
||||
tokio-core = "0.1.12"
|
||||
ed25519 = { path = "../../substrate/ed25519" }
|
||||
error-chain = "0.11"
|
||||
log = "0.4"
|
||||
log = "0.3"
|
||||
polkadot-api = { path = "../api" }
|
||||
polkadot-collator = { path = "../collator" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,7 @@ futures = "0.1.17"
|
||||
parking_lot = "0.4"
|
||||
tokio-timer = "0.1.2"
|
||||
error-chain = "0.11"
|
||||
log = "0.4"
|
||||
log = "0.3"
|
||||
tokio-core = "0.1.12"
|
||||
ed25519 = { path = "../../substrate/ed25519" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
|
||||
@@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.0"
|
||||
transaction-pool = "1.9.0"
|
||||
error-chain = "0.11"
|
||||
polkadot-api = { path = "../api" }
|
||||
|
||||
@@ -28,6 +28,9 @@ extern crate transaction_pool;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::cmp::Ordering;
|
||||
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)
|
||||
.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) {
|
||||
Ordering::Greater => Readiness::Future,
|
||||
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)?;
|
||||
|
||||
info!("Extrinsic verified {:?}. Importing...", verified);
|
||||
|
||||
// TODO: just use a foreign link when the error type is made public.
|
||||
let hash = verified.hash.clone();
|
||||
self.inner.import(verified)
|
||||
.map_err(|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),
|
||||
// transaction_pool::error::AlreadyImported(h) => ErrorKind::AlreadyImported(h),
|
||||
// e => ErrorKind::Import(Box::new(e)),
|
||||
@@ -376,11 +379,14 @@ impl TransactionPool {
|
||||
|
||||
impl substrate_rpc::author::AsyncAuthorApi for TransactionPool {
|
||||
fn submit_extrinsic(&mut self, xt: Extrinsic) -> substrate_rpc::author::error::Result<()> {
|
||||
self.import(xt
|
||||
.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s))
|
||||
.ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?)
|
||||
.map(|_| ())
|
||||
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError.into())
|
||||
use substrate_primitives::hexdisplay::HexDisplay;
|
||||
info!("Extrinsic submitted: {}", HexDisplay::from(&xt.0));
|
||||
let xt = xt.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s))
|
||||
.ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?;
|
||||
info!("Correctly formatted: {:?}", xt);
|
||||
self.import(xt)
|
||||
.map(|_| ())
|
||||
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user