Skip to content

Commit

Permalink
References to transaction pool are now Unsized
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkucharczyk committed May 23, 2024
1 parent 4965180 commit e6ca18e
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 41 deletions.
4 changes: 2 additions & 2 deletions substrate/bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct BeefyDeps {
}

/// Full client dependencies.
pub struct FullDeps<C, P, SC, B> {
pub struct FullDeps<C, P: ?Sized, SC, B> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand Down Expand Up @@ -141,7 +141,7 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
P: TransactionPool + 'static + ?Sized,
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashingFor<Block>>,
Expand Down
20 changes: 10 additions & 10 deletions substrate/client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const DEFAULT_SOFT_DEADLINE_PERCENT: Percent = Percent::from_percent(50);
const LOG_TARGET: &'static str = "basic-authorship";

/// [`Proposer`] factory.
pub struct ProposerFactory<A, C, PR> {
pub struct ProposerFactory<A: ?Sized, C, PR> {
spawn_handle: Box<dyn SpawnNamed>,
/// The client instance.
client: Arc<C>,
Expand Down Expand Up @@ -87,7 +87,7 @@ pub struct ProposerFactory<A, C, PR> {
_phantom: PhantomData<PR>,
}

impl<A, C, PR> Clone for ProposerFactory<A, C, PR> {
impl<A: ?Sized, C, PR> Clone for ProposerFactory<A, C, PR> {
fn clone(&self) -> Self {
Self {
spawn_handle: self.spawn_handle.clone(),
Expand All @@ -103,7 +103,7 @@ impl<A, C, PR> Clone for ProposerFactory<A, C, PR> {
}
}

impl<A, C> ProposerFactory<A, C, DisableProofRecording> {
impl<A: ?Sized, C> ProposerFactory<A, C, DisableProofRecording> {
/// Create a new proposer factory.
///
/// Proof recording will be disabled when using proposers built by this instance to build
Expand All @@ -129,7 +129,7 @@ impl<A, C> ProposerFactory<A, C, DisableProofRecording> {
}
}

impl<A, C> ProposerFactory<A, C, EnableProofRecording> {
impl<A: ?Sized, C> ProposerFactory<A, C, EnableProofRecording> {
/// Create a new proposer factory with proof recording enabled.
///
/// Each proposer created by this instance will record a proof while building a block.
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<A, C> ProposerFactory<A, C, EnableProofRecording> {
}
}

impl<A, C, PR> ProposerFactory<A, C, PR> {
impl<A: ?Sized, C, PR> ProposerFactory<A, C, PR> {
/// Set the default block size limit in bytes.
///
/// The default value for the block size limit is:
Expand Down Expand Up @@ -193,7 +193,7 @@ impl<A, C, PR> ProposerFactory<A, C, PR> {

impl<Block, C, A, PR> ProposerFactory<A, C, PR>
where
A: TransactionPool<Block = Block> + 'static,
A: TransactionPool<Block = Block> + 'static + ?Sized,
Block: BlockT,
C: HeaderBackend<Block> + ProvideRuntimeApi<Block> + Send + Sync + 'static,
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
Expand Down Expand Up @@ -228,7 +228,7 @@ where

impl<A, Block, C, PR> sp_consensus::Environment<Block> for ProposerFactory<A, C, PR>
where
A: TransactionPool<Block = Block> + 'static,
A: TransactionPool<Block = Block> + 'static + ?Sized,
Block: BlockT,
C: HeaderBackend<Block> + ProvideRuntimeApi<Block> + CallApiAt<Block> + Send + Sync + 'static,
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
Expand All @@ -244,7 +244,7 @@ where
}

/// The proposer logic.
pub struct Proposer<Block: BlockT, C, A: TransactionPool, PR> {
pub struct Proposer<Block: BlockT, C, A: TransactionPool + ?Sized, PR> {
spawn_handle: Box<dyn SpawnNamed>,
client: Arc<C>,
parent_hash: Block::Hash,
Expand All @@ -261,7 +261,7 @@ pub struct Proposer<Block: BlockT, C, A: TransactionPool, PR> {

impl<A, Block, C, PR> sp_consensus::Proposer<Block> for Proposer<Block, C, A, PR>
where
A: TransactionPool<Block = Block> + 'static,
A: TransactionPool<Block = Block> + 'static + ?Sized,
Block: BlockT,
C: HeaderBackend<Block> + ProvideRuntimeApi<Block> + CallApiAt<Block> + Send + Sync + 'static,
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
Expand Down Expand Up @@ -312,7 +312,7 @@ const MAX_SKIPPED_TRANSACTIONS: usize = 8;

impl<A, Block, C, PR> Proposer<Block, C, A, PR>
where
A: TransactionPool<Block = Block>,
A: TransactionPool<Block = Block> + ?Sized,
Block: BlockT,
C: HeaderBackend<Block> + ProvideRuntimeApi<Block> + CallApiAt<Block> + Send + Sync + 'static,
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/mixnet/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub async fn run<B, C, S, P>(
C: BlockchainEvents<B> + ProvideRuntimeApi<B> + HeaderBackend<B>,
C::Api: MixnetApi<B>,
S: SyncOracle,
P: TransactionPool<Block = B> + LocalTransactionPool<Block = B> + 'static,
P: TransactionPool<Block = B> + LocalTransactionPool<Block = B> + 'static + ?Sized,
{
let local_peer_id = network.local_peer_id();
let Some(local_peer_id) = to_core_peer_id(&local_peer_id) else {
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/rpc-spec-v2/src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::sync::Arc;
pub(crate) const LOG_TARGET: &str = "rpc-spec-v2";

/// An API for transaction RPC calls.
pub struct Transaction<Pool, Client> {
pub struct Transaction<Pool: ?Sized, Client> {
/// Substrate client.
client: Arc<Client>,
/// Transactions pool.
Expand All @@ -52,7 +52,7 @@ pub struct Transaction<Pool, Client> {
executor: SubscriptionTaskExecutor,
}

impl<Pool, Client> Transaction<Pool, Client> {
impl<Pool: ?Sized, Client> Transaction<Pool, Client> {
/// Creates a new [`Transaction`].
pub fn new(client: Arc<Client>, pool: Arc<Pool>, executor: SubscriptionTaskExecutor) -> Self {
Transaction { client, pool, executor }
Expand All @@ -67,7 +67,7 @@ impl<Pool, Client> Transaction<Pool, Client> {
const TX_SOURCE: TransactionSource = TransactionSource::External;

#[async_trait]
impl<Pool, Client> TransactionApiServer<BlockHash<Pool>> for Transaction<Pool, Client>
impl<Pool: ?Sized, Client> TransactionApiServer<BlockHash<Pool>> for Transaction<Pool, Client>
where
Pool: TransactionPool + Sync + Send + 'static,
Pool::Hash: Unpin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::{collections::HashMap, sync::Arc};
use super::error::ErrorBroadcast;

/// An API for transaction RPC calls.
pub struct TransactionBroadcast<Pool: TransactionPool, Client> {
pub struct TransactionBroadcast<Pool: TransactionPool + ?Sized, Client> {
/// Substrate client.
client: Arc<Client>,
/// Transactions pool.
Expand All @@ -57,14 +57,14 @@ pub struct TransactionBroadcast<Pool: TransactionPool, Client> {
}

/// The state of a broadcast operation.
struct BroadcastState<Pool: TransactionPool> {
struct BroadcastState<Pool: TransactionPool + ?Sized> {
/// Handle to abort the running future that broadcasts the transaction.
handle: AbortHandle,
/// Associated tx hash.
tx_hash: <Pool as TransactionPool>::Hash,
}

impl<Pool: TransactionPool, Client> TransactionBroadcast<Pool, Client> {
impl<Pool: TransactionPool + ?Sized, Client> TransactionBroadcast<Pool, Client> {
/// Creates a new [`TransactionBroadcast`].
pub fn new(
client: Arc<Client>,
Expand Down Expand Up @@ -116,7 +116,7 @@ const TX_SOURCE: TransactionSource = TransactionSource::External;
#[async_trait]
impl<Pool, Client> TransactionBroadcastApiServer for TransactionBroadcast<Pool, Client>
where
Pool: TransactionPool + Sync + Send + 'static,
Pool: TransactionPool + Sync + Send + 'static + ?Sized,
Pool::Error: IntoPoolError,
<Pool::Block as BlockT>::Hash: Unpin,
Client: HeaderBackend<Pool::Block> + BlockchainEvents<Pool::Block> + Send + Sync + 'static,
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/rpc/src/author/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use self::error::{Error, Result};
pub use sc_rpc_api::author::*;

/// Authoring API
pub struct Author<P, Client> {
pub struct Author<P: ?Sized, Client> {
/// Substrate client
client: Arc<Client>,
/// Transactions pool
Expand All @@ -61,7 +61,7 @@ pub struct Author<P, Client> {
executor: SubscriptionTaskExecutor,
}

impl<P, Client> Author<P, Client> {
impl<P: ?Sized, Client> Author<P, Client> {
/// Create new instance of Authoring API.
pub fn new(
client: Arc<Client>,
Expand All @@ -82,7 +82,7 @@ impl<P, Client> Author<P, Client> {
const TX_SOURCE: TransactionSource = TransactionSource::External;

#[async_trait]
impl<P, Client> AuthorApiServer<TxHash<P>, BlockHash<P>> for Author<P, Client>
impl<P: ?Sized, Client> AuthorApiServer<TxHash<P>, BlockHash<P>> for Author<P, Client>
where
P: TransactionPool + Sync + Send + 'static,
Client: HeaderBackend<P::Block> + ProvideRuntimeApi<P::Block> + Send + Sync + 'static,
Expand Down
14 changes: 8 additions & 6 deletions substrate/client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ where
}

/// Parameters to pass into `build`.
pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool, TRpc, Backend> {
pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool: ?Sized, TRpc, Backend> {
/// The service configuration.
pub config: Configuration,
/// A shared client returned by `new_full_parts`.
Expand Down Expand Up @@ -405,7 +405,8 @@ where
TBl::Hash: Unpin,
TBl::Header: Unpin,
TBackend: 'static + sc_client_api::backend::Backend<TBl> + Send,
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static,
TExPool:
MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static + ?Sized,
{
let SpawnTasksParams {
mut config,
Expand Down Expand Up @@ -536,7 +537,7 @@ pub async fn propagate_transaction_notifications<Block, ExPool>(
telemetry: Option<TelemetryHandle>,
) where
Block: BlockT,
ExPool: MaintainedTransactionPool<Block = Block, Hash = <Block as BlockT>::Hash>,
ExPool: MaintainedTransactionPool<Block = Block, Hash = <Block as BlockT>::Hash> + ?Sized,
{
// transaction notifications
transaction_pool
Expand Down Expand Up @@ -623,7 +624,8 @@ where
+ 'static,
TBackend: sc_client_api::backend::Backend<TBl> + 'static,
<TCl as ProvideRuntimeApi<TBl>>::Api: sp_session::SessionKeys<TBl> + sp_api::Metadata<TBl>,
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static,
TExPool:
MaintainedTransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static + ?Sized,
TBl::Hash: Unpin,
TBl::Header: Unpin,
{
Expand Down Expand Up @@ -736,7 +738,7 @@ pub struct BuildNetworkParams<
'a,
TBl: BlockT,
TNet: NetworkBackend<TBl, <TBl as BlockT>::Hash>,
TExPool,
TExPool: ?Sized,
TImpQu,
TCl,
> {
Expand Down Expand Up @@ -788,7 +790,7 @@ where
+ HeaderBackend<TBl>
+ BlockchainEvents<TBl>
+ 'static,
TExPool: TransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static,
TExPool: TransactionPool<Block = TBl, Hash = <TBl as BlockT>::Hash> + 'static + ?Sized,
TImpQu: ImportQueue<TBl> + 'static,
TNet: NetworkBackend<TBl, <TBl as BlockT>::Hash>,
{
Expand Down
17 changes: 12 additions & 5 deletions substrate/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ impl RpcHandlers {
}

/// An incomplete set of chain components, but enough to run the chain ops subcommands.
pub struct PartialComponents<Client, Backend, SelectChain, ImportQueue, TransactionPool, Other> {
pub struct PartialComponents<
Client,
Backend,
SelectChain,
ImportQueue,
TransactionPool: ?Sized,
Other,
> {
/// A shared client instance.
pub client: Arc<Client>,
/// A shared backend instance.
Expand Down Expand Up @@ -425,12 +432,12 @@ where
}

/// Transaction pool adapter.
pub struct TransactionPoolAdapter<C, P> {
pub struct TransactionPoolAdapter<C, P: ?Sized> {
pool: Arc<P>,
client: Arc<C>,
}

impl<C, P> TransactionPoolAdapter<C, P> {
impl<C, P: ?Sized> TransactionPoolAdapter<C, P> {
/// Constructs a new instance of [`TransactionPoolAdapter`].
pub fn new(pool: Arc<P>, client: Arc<C>) -> Self {
Self { pool, client }
Expand All @@ -442,7 +449,7 @@ impl<C, P> TransactionPoolAdapter<C, P> {
/// Function extracted to simplify the test and prevent creating `ServiceFactory`.
fn transactions_to_propagate<Pool, B, H, E>(pool: &Pool) -> Vec<(H, B::Extrinsic)>
where
Pool: TransactionPool<Block = B, Hash = H, Error = E>,
Pool: TransactionPool<Block = B, Hash = H, Error = E> + ?Sized,
B: BlockT,
H: std::hash::Hash + Eq + sp_runtime::traits::Member + sp_runtime::traits::MaybeSerialize,
E: IntoPoolError + From<sc_transaction_pool_api::error::Error>,
Expand All @@ -467,7 +474,7 @@ where
+ Send
+ Sync
+ 'static,
Pool: 'static + TransactionPool<Block = B, Hash = H, Error = E>,
Pool: 'static + TransactionPool<Block = B, Hash = H, Error = E> + ?Sized,
B: BlockT,
H: std::hash::Hash + Eq + sp_runtime::traits::Member + sp_runtime::traits::MaybeSerialize,
E: 'static + IntoPoolError + From<sc_transaction_pool_api::error::Error>,
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/service/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl MetricsService {
) where
TBl: Block,
TCl: ProvideRuntimeApi<TBl> + UsageProvider<TBl>,
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as Block>::Hash>,
TExPool: MaintainedTransactionPool<Block = TBl, Hash = <TBl as Block>::Hash> + ?Sized,
TNet: NetworkStatusProvider,
TSync: SyncStatusProvider<TBl>,
{
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/transaction-pool/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub trait LocalTransactionPool: Send + Sync {
) -> Result<Self::Hash, Self::Error>;
}

impl<T: LocalTransactionPool> LocalTransactionPool for Arc<T> {
impl<T: LocalTransactionPool + ?Sized> LocalTransactionPool for Arc<T> {
type Block = T::Block;

type Hash = T::Hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ pub async fn notification_future<Client, Pool, Block>(client: Arc<Client>, txpoo
where
Block: BlockT,
Client: sc_client_api::BlockchainEvents<Block>,
Pool: MaintainedTransactionPool<Block = Block>,
Pool: MaintainedTransactionPool<Block = Block> + ?Sized,
{
let import_stream = client
.import_notification_stream()
Expand Down
8 changes: 4 additions & 4 deletions substrate/utils/frame/rpc/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ impl From<Error> for i32 {
}

/// An implementation of System-specific RPC methods on full client.
pub struct System<P: TransactionPool, C, B> {
pub struct System<P: TransactionPool + ?Sized, C, B> {
client: Arc<C>,
pool: Arc<P>,
deny_unsafe: DenyUnsafe,
_marker: std::marker::PhantomData<B>,
}

impl<P: TransactionPool, C, B> System<P, C, B> {
impl<P: TransactionPool + ?Sized, C, B> System<P, C, B> {
/// Create new `FullSystem` given client and transaction pool.
pub fn new(client: Arc<C>, pool: Arc<P>, deny_unsafe: DenyUnsafe) -> Self {
Self { client, pool, deny_unsafe, _marker: Default::default() }
Expand All @@ -93,7 +93,7 @@ where
C: Send + Sync + 'static,
C::Api: AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
P: TransactionPool + 'static + ?Sized,
Block: traits::Block,
AccountId: Clone + Display + Codec + Send + 'static,
Nonce: Clone + Display + Codec + Send + traits::AtLeast32Bit + 'static,
Expand Down Expand Up @@ -178,7 +178,7 @@ where
/// placed after all ready txpool transactions.
fn adjust_nonce<P, AccountId, Nonce>(pool: &P, account: AccountId, nonce: Nonce) -> Nonce
where
P: TransactionPool,
P: TransactionPool + ?Sized,
AccountId: Clone + std::fmt::Display + Encode,
Nonce: Clone + std::fmt::Display + Encode + traits::AtLeast32Bit + 'static,
{
Expand Down

0 comments on commit e6ca18e

Please sign in to comment.