mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Tagged transaction queue integration (#893)
* Make the graph generic. * Adapting pool API for the graph. * Merge pool & graph. * Restructure. * Fix test of transaction pool. * Get rid of node/transaction-pool. * Compilation fixes. * Test7 * Fix compilation of tests. * Revert runtime changes. * Add validate_transaction to test-runtime. * Fix RPC tests. * Add clearing of the old transactions. * Trigger pool events. * Use new queue API. * Fix wasm build, re-export Hasher. * No warning if validate transaction fails. * Get rid of Into<u64> and use As
This commit is contained in:
@@ -28,7 +28,7 @@ use client::{self, Client};
|
||||
use {error, Service};
|
||||
use network::{self, OnDemand};
|
||||
use substrate_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use transaction_pool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
|
||||
use transaction_pool::txpool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
|
||||
use runtime_primitives::{traits::Block as BlockT, traits::Header as HeaderT, BuildStorage};
|
||||
use config::Configuration;
|
||||
use primitives::{Blake2Hasher};
|
||||
@@ -105,7 +105,7 @@ pub type ComponentClient<C> = Client<
|
||||
pub type ComponentBlock<C> = <<C as Components>::Factory as ServiceFactory>::Block;
|
||||
|
||||
/// Extrinsic hash type for `Components`
|
||||
pub type ComponentExHash<C> = <<C as Components>::TransactionPoolApi as transaction_pool::ChainApi>::Hash;
|
||||
pub type ComponentExHash<C> = <<C as Components>::TransactionPoolApi as txpool::ChainApi>::Hash;
|
||||
|
||||
/// Extrinsic type.
|
||||
pub type ComponentExtrinsic<C> = <ComponentBlock<C> as BlockT>::Extrinsic;
|
||||
@@ -128,9 +128,9 @@ pub trait ServiceFactory: 'static + Sized {
|
||||
/// Chain runtime.
|
||||
type RuntimeDispatch: NativeExecutionDispatch + Send + Sync + 'static;
|
||||
/// Extrinsic pool backend type for the full client.
|
||||
type FullTransactionPoolApi: transaction_pool::ChainApi<Hash = Self::ExtrinsicHash, Block = Self::Block> + Send + 'static;
|
||||
type FullTransactionPoolApi: txpool::ChainApi<Hash = Self::ExtrinsicHash, Block = Self::Block> + Send + 'static;
|
||||
/// Extrinsic pool backend type for the light client.
|
||||
type LightTransactionPoolApi: transaction_pool::ChainApi<Hash = Self::ExtrinsicHash, Block = Self::Block> + 'static;
|
||||
type LightTransactionPoolApi: txpool::ChainApi<Hash = Self::ExtrinsicHash, Block = Self::Block> + 'static;
|
||||
/// Genesis configuration for the runtime.
|
||||
type Genesis: RuntimeGenesis;
|
||||
/// Other configuration for service members.
|
||||
@@ -169,7 +169,7 @@ pub trait Components: 'static {
|
||||
/// Client executor.
|
||||
type Executor: 'static + client::CallExecutor<FactoryBlock<Self::Factory>, Blake2Hasher> + Send + Sync;
|
||||
/// Extrinsic pool type.
|
||||
type TransactionPoolApi: 'static + transaction_pool::ChainApi<
|
||||
type TransactionPoolApi: 'static + txpool::ChainApi<
|
||||
Hash = <Self::Factory as ServiceFactory>::ExtrinsicHash,
|
||||
Block = FactoryBlock<Self::Factory>
|
||||
>;
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct Configuration<C, G: Serialize + DeserializeOwned + BuildStorage> {
|
||||
/// Node roles.
|
||||
pub roles: Roles,
|
||||
/// Extrinsic pool configuration.
|
||||
pub transaction_pool: transaction_pool::Options,
|
||||
pub transaction_pool: transaction_pool::txpool::Options,
|
||||
/// Network configuration.
|
||||
pub network: NetworkConfiguration,
|
||||
/// Path to key files.
|
||||
@@ -113,7 +113,7 @@ pub fn platform() -> String {
|
||||
let env_dash = if env.is_empty() { "" } else { "-" };
|
||||
format!("{}-{}{}{}", Target::arch(), Target::os(), env_dash, env)
|
||||
}
|
||||
|
||||
|
||||
/// Returns full version string, using supplied version and commit.
|
||||
pub fn full_version_from_strs(impl_version: &str, impl_commit: &str) -> String {
|
||||
let commit_dash = if impl_commit.is_empty() { "" } else { "-" };
|
||||
|
||||
@@ -75,7 +75,7 @@ use codec::{Encode, Decode};
|
||||
pub use self::error::{ErrorKind, Error};
|
||||
pub use config::{Configuration, Roles, PruningMode};
|
||||
pub use chain_spec::ChainSpec;
|
||||
pub use transaction_pool::{Pool as TransactionPool, Options as TransactionPoolOptions, ChainApi, VerifiedTransaction, IntoPoolError};
|
||||
pub use transaction_pool::txpool::{self, Pool as TransactionPool, Options as TransactionPoolOptions, ChainApi, IntoPoolError};
|
||||
pub use client::ExecutionStrategy;
|
||||
|
||||
pub use components::{ServiceFactory, FullBackend, FullExecutor, LightBackend,
|
||||
@@ -116,6 +116,8 @@ pub fn new_client<Factory: components::ServiceFactory>(config: FactoryFullConfig
|
||||
impl<Components> Service<Components>
|
||||
where
|
||||
Components: components::Components,
|
||||
txpool::ExHash<Components::TransactionPoolApi>: serde::de::DeserializeOwned + serde::Serialize,
|
||||
txpool::ExtrinsicFor<Components::TransactionPoolApi>: serde::de::DeserializeOwned + serde::Serialize,
|
||||
{
|
||||
/// Creates a new service.
|
||||
pub fn new(
|
||||
@@ -196,7 +198,7 @@ impl<Components> Service<Components>
|
||||
if let Some(network) = network.upgrade() {
|
||||
network.on_block_imported(notification.hash, ¬ification.header);
|
||||
}
|
||||
txpool.cull(&BlockId::hash(notification.hash))
|
||||
txpool.prune_tags(&BlockId::hash(notification.hash), notification.tags)
|
||||
.map_err(|e| warn!("Error removing extrinsics: {:?}", e))?;
|
||||
Ok(())
|
||||
})
|
||||
@@ -288,7 +290,11 @@ impl<Components> Service<Components>
|
||||
_telemetry: telemetry,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<Components> Service<Components> where
|
||||
Components: components::Components,
|
||||
{
|
||||
/// Get shared client instance.
|
||||
pub fn client(&self) -> Arc<ComponentClient<Components>> {
|
||||
self.client.clone()
|
||||
@@ -386,21 +392,13 @@ impl<C: Components> TransactionPoolAdapter<C> {
|
||||
|
||||
impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<C>> for TransactionPoolAdapter<C> {
|
||||
fn transactions(&self) -> Vec<(ComponentExHash<C>, ComponentExtrinsic<C>)> {
|
||||
let best_block_id = match self.best_block_id() {
|
||||
Some(id) => id,
|
||||
None => return vec![],
|
||||
};
|
||||
self.pool.cull_and_get_pending(&best_block_id, |pending| pending
|
||||
self.pool.ready(|pending| pending
|
||||
.map(|t| {
|
||||
let hash = t.hash().clone();
|
||||
let ex: ComponentExtrinsic<C> = t.original.clone();
|
||||
let hash = t.hash.clone();
|
||||
let ex: ComponentExtrinsic<C> = t.data.raw.clone();
|
||||
(hash, ex)
|
||||
})
|
||||
.collect()
|
||||
).unwrap_or_else(|e| {
|
||||
warn!("Error retrieving pending set: {}", e);
|
||||
vec![]
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn import(&self, transaction: &ComponentExtrinsic<C>) -> Option<ComponentExHash<C>> {
|
||||
@@ -412,13 +410,12 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
|
||||
let encoded = transaction.encode();
|
||||
if let Some(uxt) = Decode::decode(&mut &encoded[..]) {
|
||||
let best_block_id = self.best_block_id()?;
|
||||
let hash = self.pool.hash_of(&uxt);
|
||||
match self.pool.submit_one(&best_block_id, uxt) {
|
||||
Ok(xt) => Some(*xt.hash()),
|
||||
Ok(hash) => Some(hash),
|
||||
Err(e) => match e.into_pool_error() {
|
||||
Ok(e) => match e.kind() {
|
||||
transaction_pool::ErrorKind::AlreadyImported(hash) =>
|
||||
Some(::std::str::FromStr::from_str(&hash[2..]).map_err(|_| {})
|
||||
.expect("Hash string is always valid")),
|
||||
txpool::error::ErrorKind::AlreadyImported => Some(hash),
|
||||
_ => {
|
||||
debug!("Error adding transaction to the pool: {:?}", e);
|
||||
None
|
||||
@@ -427,7 +424,7 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
|
||||
Err(e) => {
|
||||
debug!("Error converting pool error: {:?}", e);
|
||||
None
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user