Skip to content

Commit

Permalink
Merge pull request #201 from paritytech/custom-pool-inclusion
Browse files Browse the repository at this point in the history
Custom pool reinclusion
  • Loading branch information
valentinfernandez1 authored Aug 14, 2024
2 parents b62b01a + 267b889 commit 4884f3e
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ panic = "unwind"

[workspace]
members = [
"node",
"primitives/xcm",
"runtime/mainnet",
"runtime/testnet",
"node",
"primitives/xcm",
"runtime/mainnet",
"runtime/testnet",
"primitives/custom-pool",
]

resolver = "2"
Expand Down Expand Up @@ -157,3 +158,4 @@ xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/par
# Primitives
account = { path = "./primitives/account", default-features = false }
fp-self-contained = { path = "./primitives/self-contained", default-features = false }
custom-pool = { path = "./primitives/custom-pool", default-features = false }
3 changes: 2 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ homepage = { workspace = true }
license = { workspace = true }
name = "mythos-node"
repository = { workspace = true }
version = "1.13.0"
version = "1.13.8"

[dependencies]
clap = { workspace = true }
Expand All @@ -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
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,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
19 changes: 19 additions & 0 deletions primitives/custom-pool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "custom-pool"
version = "0.1.0"
edition = "2021"

[dependencies]
futures = { workspace = true }
sc-client-api = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-runtime = {workspace = true}
sp-core = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }

[features]
default = ["std"]
std = []
100 changes: 100 additions & 0 deletions primitives/custom-pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use futures::Future;
use sc_transaction_pool_api::{
ImportNotificationStream, PoolFuture, PoolStatus, ReadyTransactions, TransactionFor,
TransactionPool, TransactionSource, TransactionStatusStreamFor, TxHash,
};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{collections::HashMap, pin::Pin, sync::Arc};

pub struct CustomPool<I> {
inner_pool: Arc<I>,
}

impl<I> CustomPool<I> {
pub fn new(inner_pool: Arc<I>) -> Self {
Self { inner_pool }
}
}

impl<I> TransactionPool for CustomPool<I>
where
I: TransactionPool,
{
type Block = I::Block;
type Hash = I::Hash;
type InPoolTransaction = I::InPoolTransaction;
type Error = I::Error;

fn submit_at(
&self,
at: <Self::Block as BlockT>::Hash,
source: TransactionSource,
xts: Vec<TransactionFor<Self>>,
) -> PoolFuture<Vec<Result<TxHash<Self>, Self::Error>>, Self::Error> {
self.inner_pool.submit_at(at, source, xts)
}

fn submit_one(
&self,
at: <Self::Block as BlockT>::Hash,
source: TransactionSource,
xt: TransactionFor<Self>,
) -> PoolFuture<TxHash<Self>, Self::Error> {
self.inner_pool.submit_one(at, source, xt)
}

fn submit_and_watch(
&self,
at: <Self::Block as BlockT>::Hash,
source: TransactionSource,
xt: TransactionFor<Self>,
) -> PoolFuture<Pin<Box<TransactionStatusStreamFor<Self>>>, Self::Error> {
self.inner_pool.submit_and_watch(at, source, xt)
}

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

fn status(&self) -> PoolStatus {
self.inner_pool.status()
}

fn import_notification_stream(&self) -> ImportNotificationStream<TxHash<Self>> {
self.inner_pool.import_notification_stream()
}

fn hash_of(&self, xt: &TransactionFor<Self>) -> TxHash<Self> {
self.inner_pool.hash_of(xt)
}

fn on_broadcasted(&self, propagations: HashMap<TxHash<Self>, Vec<String>>) {
self.inner_pool.on_broadcasted(propagations)
}

fn ready_transaction(&self, hash: &TxHash<Self>) -> Option<Arc<Self::InPoolTransaction>> {
self.inner_pool.ready_transaction(hash)
}

fn ready_at(
&self,
at: NumberFor<Self::Block>,
) -> Pin<
Box<
dyn Future<
Output = Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send>,
> + Send,
>,
> {
self.inner_pool.ready_at(at)
}

fn ready(&self) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
self.inner_pool.ready()
}

fn futures(&self) -> Vec<Self::InPoolTransaction> {
self.inner_pool.futures()
}
}

0 comments on commit 4884f3e

Please sign in to comment.