Recover transaction pool on light client (#3833)

* recover tx pool on light client

* revert local tests fix

* removed import renamings

* futures03::Future -> std::future::Future

* Update core/transaction-pool/graph/src/error.rs

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* replace remove_from_ready with remove_invalid

* avoid excess hashing

* debug -> warn

* TransactionPool + BasicTransactionPool

* pause future tx reject when resubmitting

* bump impl_version to make CI happy

* and revert back local test fixes

* alter doc to restart CI

* Transaction::clone() -> Transaction::duplicate()

* transactions -> updated_tranasctions

* remove explicit consensus-common ref

* ::std:: -> std::

* manual set/unset flag -> calling clusore with given flag value

* removed comments

* removed force argument

* BestIterator -> Box<Iterator>

* separate crate for TxPool + Maintainer trait

* long line fix

* pos-merge fix

* fix benches compilation

* Rename txpoolapi to txpool_api

* Clean up.

* Finalize merge.

* post-merge fix

* Move transaction pool api to primitives directly.

* Consistent naming for txpool-runtime-api

* Warn about missing docs.

* Move  abstraction for offchain calls to tx-pool-api.

* Merge RPC instantiation.

* Update cargo.lock

* Post merge fixes.

* Avoid depending on client.

* Fix build
This commit is contained in:
Svyatoslav Nikolsky
2019-11-28 03:00:54 +03:00
committed by Gavin Wood
parent 3e26fceda4
commit a782021ee8
64 changed files with 2370 additions and 667 deletions
+2 -1
View File
@@ -49,7 +49,8 @@ runtime-io = { package = "sr-io", path = "../../../primitives/sr-io" }
client-api = { package = "substrate-client-api", path = "../../../client/api" }
client = { package = "substrate-client", path = "../../../client/" }
chain-spec = { package = "substrate-chain-spec", path = "../../../client/chain-spec" }
transaction_pool = { package = "sc-transaction-pool", path = "../../../client/transaction-pool" }
txpool = { package = "sc-transaction-pool", path = "../../../client/transaction-pool" }
txpool-api = { package = "sp-transaction-pool-api", path = "../../../primitives/transaction-pool" }
network = { package = "substrate-network", path = "../../../client/network" }
babe = { package = "substrate-consensus-babe", path = "../../../client/consensus/babe" }
grandpa = { package = "substrate-finality-grandpa", path = "../../../client/finality-grandpa" }
+38 -12
View File
@@ -29,7 +29,6 @@ use node_runtime::{GenesisConfig, RuntimeApi};
use substrate_service::{
AbstractService, ServiceBuilder, config::Configuration, error::{Error as ServiceError},
};
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
use inherents::InherentDataProviders;
use network::construct_simple_protocol;
@@ -63,9 +62,13 @@ macro_rules! new_full_start {
.with_select_chain(|_config, backend| {
Ok(client::LongestChain::new(backend.clone()))
})?
.with_transaction_pool(|config, client|
Ok(transaction_pool::txpool::Pool::new(config, transaction_pool::FullChainApi::new(client)))
)?
.with_transaction_pool(|config, client, _fetcher| {
let pool_api = txpool::FullChainApi::new(client.clone());
let pool = txpool::BasicPool::new(config, pool_api);
let maintainer = txpool::FullBasicPoolMaintainer::new(pool.pool().clone(), client);
let maintainable_pool = txpool_api::MaintainableTransactionPool::new(pool, maintainer);
Ok(maintainable_pool)
})?
.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {
let select_chain = select_chain.take()
.ok_or_else(|| substrate_service::Error::SelectChainRequired)?;
@@ -96,8 +99,8 @@ macro_rules! new_full_start {
import_setup = Some((block_import, grandpa_link, babe_link));
Ok(import_queue)
})?
.with_rpc_extensions(|client, pool, _backend| -> RpcExtension {
node_rpc::create(client, pool)
.with_rpc_extensions(|client, pool, _backend, fetcher, _remote_blockchain| -> Result<RpcExtension, _> {
Ok(node_rpc::create(client, pool, node_rpc::LightDeps::none(fetcher)))
})?;
(builder, import_setup, inherent_data_providers)
@@ -267,6 +270,17 @@ type ConcreteClient =
>;
#[allow(dead_code)]
type ConcreteBackend = Backend<ConcreteBlock>;
#[allow(dead_code)]
type ConcreteTransactionPool = txpool_api::MaintainableTransactionPool<
txpool::BasicPool<
txpool::FullChainApi<ConcreteClient, ConcreteBlock>,
ConcreteBlock
>,
txpool::FullBasicPoolMaintainer<
ConcreteClient,
txpool::FullChainApi<ConcreteClient, Block>
>
>;
/// A specialized configuration object for setting up the node..
pub type NodeConfiguration<C> = Configuration<C, GenesisConfig, crate::chain_spec::Extensions>;
@@ -280,7 +294,7 @@ pub fn new_full<C: Send + Default + 'static>(config: NodeConfiguration<C>)
LongestChain<ConcreteBackend, ConcreteBlock>,
NetworkStatus<ConcreteBlock>,
NetworkService<ConcreteBlock, crate::service::NodeProtocol, <ConcreteBlock as BlockT>::Hash>,
TransactionPool<transaction_pool::FullChainApi<ConcreteClient, ConcreteBlock>>,
ConcreteTransactionPool,
OffchainWorkers<
ConcreteClient,
<ConcreteBackend as client_api::backend::Backend<Block, Blake2Hasher>>::OffchainStorage,
@@ -303,9 +317,15 @@ pub fn new_light<C: Send + Default + 'static>(config: NodeConfiguration<C>)
.with_select_chain(|_config, backend| {
Ok(LongestChain::new(backend.clone()))
})?
.with_transaction_pool(|config, client|
Ok(TransactionPool::new(config, transaction_pool::FullChainApi::new(client)))
)?
.with_transaction_pool(|config, client, fetcher| {
let fetcher = fetcher
.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
let pool_api = txpool::LightChainApi::new(client.clone(), fetcher.clone());
let pool = txpool::BasicPool::new(config, pool_api);
let maintainer = txpool::LightBasicPoolMaintainer::with_defaults(pool.pool().clone(), client, fetcher);
let maintainable_pool = txpool_api::MaintainableTransactionPool::new(pool, maintainer);
Ok(maintainable_pool)
})?
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool| {
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
@@ -344,8 +364,14 @@ pub fn new_light<C: Send + Default + 'static>(config: NodeConfiguration<C>)
.with_finality_proof_provider(|client, backend|
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
)?
.with_rpc_extensions(|client, pool, _backend| -> RpcExtension {
node_rpc::create(client, pool)
.with_rpc_extensions(|client, pool, _backend, fetcher, remote_blockchain| -> Result<RpcExtension, _> {
let fetcher = fetcher
.ok_or_else(|| "Trying to start node RPC without active fetcher")?;
let remote_blockchain = remote_blockchain
.ok_or_else(|| "Trying to start node RPC without active remote blockchain")?;
let light_deps = node_rpc::LightDeps { remote_blockchain, fetcher };
Ok(node_rpc::create(client, pool, Some(light_deps)))
})?
.build()?;
+1 -1
View File
@@ -13,4 +13,4 @@ sr-primitives = { path = "../../../primitives/sr-primitives" }
pallet-contracts-rpc = { path = "../../../frame/contracts/rpc/" }
pallet-transaction-payment-rpc = { path = "../../../frame/transaction-payment/rpc/" }
substrate-frame-rpc-system = { path = "../../../utils/frame/rpc/system" }
transaction_pool = { package = "sc-transaction-pool", path = "../../../client/transaction-pool" }
txpool-api = { package = "sp-transaction-pool-api", path = "../../../primitives/transaction-pool" }
+49 -13
View File
@@ -34,32 +34,68 @@ use std::sync::Arc;
use node_primitives::{Block, AccountId, Index, Balance};
use node_runtime::UncheckedExtrinsic;
use sr_primitives::traits::ProvideRuntimeApi;
use transaction_pool::txpool::{ChainApi, Pool};
use txpool_api::TransactionPool;
/// Light client extra dependencies.
pub struct LightDeps<F> {
/// Remote access to the blockchain (async).
pub remote_blockchain: Arc<dyn client::light::blockchain::RemoteBlockchain<Block>>,
/// Fetcher instance.
pub fetcher: Arc<F>,
}
impl<F> LightDeps<F> {
/// Create empty `LightDeps` with given `F` type.
///
/// This is a convenience method to be used in the service builder,
/// to make sure the type of the `LightDeps<F>` is matching.
pub fn none(_: Option<Arc<F>>) -> Option<Self> {
None
}
}
/// Instantiate all RPC extensions.
pub fn create<C, P, M>(client: Arc<C>, pool: Arc<Pool<P>>) -> jsonrpc_core::IoHandler<M> where
///
/// If you provide `LightDeps`, the system is configured for light client.
pub fn create<C, P, M, F>(
client: Arc<C>,
pool: Arc<P>,
light_deps: Option<LightDeps<F>>,
) -> jsonrpc_core::IoHandler<M> where
C: ProvideRuntimeApi,
C: client::blockchain::HeaderBackend<Block>,
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UncheckedExtrinsic>,
P: ChainApi + Sync + Send + 'static,
F: client::light::fetcher::Fetcher<Block> + 'static,
P: TransactionPool + 'static,
M: jsonrpc_core::Metadata + Default,
{
use substrate_frame_rpc_system::{System, SystemApi};
use substrate_frame_rpc_system::{FullSystem, LightSystem, SystemApi};
use pallet_contracts_rpc::{Contracts, ContractsApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(
SystemApi::to_delegate(System::new(client.clone(), pool))
);
io.extend_with(
ContractsApi::to_delegate(Contracts::new(client.clone()))
);
io.extend_with(
TransactionPaymentApi::to_delegate(TransactionPayment::new(client))
);
if let Some(LightDeps { remote_blockchain, fetcher }) = light_deps {
io.extend_with(
SystemApi::<AccountId, Index>::to_delegate(LightSystem::new(client, remote_blockchain, fetcher, pool))
);
} else {
io.extend_with(
SystemApi::to_delegate(FullSystem::new(client.clone(), pool))
);
// Making synchronous calls in light client freezes the browser currently,
// more context: https://github.com/paritytech/substrate/pull/3480
// These RPCs should use an asynchronous caller instead.
io.extend_with(
ContractsApi::to_delegate(Contracts::new(client.clone()))
);
io.extend_with(
TransactionPaymentApi::to_delegate(TransactionPayment::new(client))
);
}
io
}
+2 -2
View File
@@ -27,7 +27,7 @@ sr-primitives = { path = "../../../primitives/sr-primitives", default-features =
sr-staking-primitives = { path = "../../../primitives/sr-staking-primitives", default-features = false }
substrate-keyring = { path = "../../../primitives/keyring", optional = true }
substrate-session = { path = "../../../primitives/session", default-features = false }
tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../../../primitives/transaction-pool/runtime-api", default-features = false }
txpool-runtime-api = { package = "sp-transaction-pool-runtime-api", path = "../../../primitives/transaction-pool/runtime-api", default-features = false }
version = { package = "sr-version", path = "../../../primitives/sr-version", default-features = false }
# frame dependencies
@@ -116,7 +116,7 @@ std = [
"transaction-payment-rpc-runtime-api/std",
"transaction-payment/std",
"treasury/std",
"tx-pool-api/std",
"txpool-runtime-api/std",
"utility/std",
"version/std",
]
+1 -1
View File
@@ -609,7 +609,7 @@ impl_runtime_apis! {
}
}
impl tx_pool_api::TaggedTransactionQueue<Block> for Runtime {
impl txpool_runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
Executive::validate_transaction(tx)
}