Skip to content

Commit

Permalink
Make the custom pool work
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored and valentinfernandez1 committed Apr 25, 2024
1 parent 3509007 commit 2374830
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ hex-literal = { workspace = true }
testnet-runtime = { workspace = true }
mainnet-runtime = { workspace = true }
runtime-common = { workspace = true }
custom-pool = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ where
}

#[allow(clippy::too_many_arguments)]

fn start_consensus<RuntimeApi, Executor>(
client: Arc<ParachainClient<RuntimeApi, Executor>>,
backend: Arc<ParachainBackend>,
Expand Down Expand Up @@ -516,7 +515,7 @@ where
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
Arc::new(custom_pool::CustomPool::new(transaction_pool)),
prometheus_registry,
telemetry.clone(),
);
Expand Down
3 changes: 0 additions & 3 deletions primitives/custom-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ sc-transaction-pool-api = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-runtime = {workspace = true}
sp-transaction-pool = { workspace = true }
sp-core = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }



[features]
default = ["std"]
std = []
80 changes: 19 additions & 61 deletions primitives/custom-pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
use sc_transaction_pool::{BasicPool, RevalidationType};
use sc_transaction_pool::{ChainApi,FullChainApi, Options};
use futures::Future;
use sc_transaction_pool_api::{
ImportNotificationStream, PoolFuture, PoolStatus, ReadyTransactions, TransactionFor,
TransactionPool, TransactionSource, TransactionStatusStreamFor, TxHash,
};
use sp_core::traits::SpawnEssentialNamed;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use futures::Future;
use substrate_prometheus_endpoint::Registry as PrometheusRegistry;
use std::{collections::HashMap, pin::Pin, sync::Arc};

pub type FullPool<Block, Client> = CustomPool<FullChainApi<Client, Block>, Block>;
pub struct CustomPool<I> {
inner_pool: Arc<I>,
}

pub struct CustomPool<PoolApi, Block>
where
Block: BlockT,
PoolApi: ChainApi<Block = Block>,
{
inner_pool: BasicPool<PoolApi, Block>,
impl<I> CustomPool<I> {
pub fn new(inner_pool: Arc<I>) -> Self {
Self { inner_pool }
}
}

impl<PoolApi: ChainApi<Block = Block> + 'static, Block: BlockT> TransactionPool
for CustomPool<PoolApi, Block>
impl<I> TransactionPool for CustomPool<I>
where
I: TransactionPool,
{
type Block = <BasicPool<PoolApi, Block> as TransactionPool>::Block;
type Hash = <BasicPool<PoolApi, Block> as TransactionPool>::Hash;
type InPoolTransaction = <BasicPool<PoolApi, Block> as TransactionPool>::InPoolTransaction;
type Error = <BasicPool<PoolApi, Block> as TransactionPool>::Error;
type Block = I::Block;
type Hash = I::Hash;
type InPoolTransaction = I::InPoolTransaction;
type Error = I::Error;

fn submit_at(
&self,
Expand All @@ -52,11 +49,12 @@ impl<PoolApi: ChainApi<Block = Block> + 'static, Block: BlockT> TransactionPool
source: TransactionSource,
xt: TransactionFor<Self>,
) -> PoolFuture<Pin<Box<TransactionStatusStreamFor<Self>>>, Self::Error> {
self.inner_pool.submit_and_watch(at, source, xt)
self.inner_pool.submit_and_watch(at, source, xt)
}

fn remove_invalid(&self, hashes: &[TxHash<Self>]) -> Vec<Arc<Self::InPoolTransaction>> {
self.inner_pool.remove_invalid(hashes)
fn remove_invalid(&self, _: &[TxHash<Self>]) -> Vec<Arc<Self::InPoolTransaction>> {
// Don't do anything on purpose.
Vec::new()
}

fn status(&self) -> PoolStatus {
Expand Down Expand Up @@ -100,43 +98,3 @@ impl<PoolApi: ChainApi<Block = Block> + 'static, Block: BlockT> TransactionPool
self.inner_pool.futures()
}
}

impl<Block, Client> FullPool<Block, Client>
where
Block: BlockT,
Client: sp_api::ProvideRuntimeApi<Block>
+ sc_client_api::BlockBackend<Block>
+ sc_client_api::blockchain::HeaderBackend<Block>
+ sp_runtime::traits::BlockIdTo<Block>
+ sc_client_api::ExecutorProvider<Block>
+ sc_client_api::UsageProvider<Block>
+ sp_blockchain::HeaderMetadata<Block, Error = sp_blockchain::Error>
+ Send
+ Sync
+ 'static,
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
{
/// Create new basic transaction pool for a full node with the provided api.
pub fn new_full(
options: Options,
is_validator: IsValidator,
prometheus: Option<&PrometheusRegistry>,
spawner: impl SpawnEssentialNamed,
client: Arc<Client>,
) -> Arc<BasicPool<FullChainApi<Client, Block>, Block>> {
let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus, &spawner));
let pool = Arc::new(BasicPool::with_revalidation_type(
options,
is_validator,
pool_api,
prometheus,
RevalidationType::Full,
spawner,
client.usage_info().chain.best_number,
client.usage_info().chain.best_hash,
client.usage_info().chain.finalized_hash,
));

pool
}
}

0 comments on commit 2374830

Please sign in to comment.