Skip to content

Commit c59a6c1

Browse files
feat: add support for fork-aware txpool (#1653)
* feat: replace basic pool impl with txpool wrapper * feat: update integration tests * feat: add comments in tests * format: make clippy happy * deps: pin to stable2412-4 tag * Revert "deps: pin to stable2412-4 tag" This reverts commit 997260b.
1 parent e5ce844 commit c59a6c1

23 files changed

+147
-139
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/rpc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ sc-network = { workspace = true }
3636
sc-network-sync = { workspace = true }
3737
sc-rpc = { workspace = true }
3838
sc-service = { workspace = true }
39-
sc-transaction-pool = { workspace = true }
4039
sc-transaction-pool-api = { workspace = true }
4140
sc-utils = { workspace = true }
4241
sp-api = { workspace = true, features = ["default"] }

client/rpc/src/eth/block.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use ethereum_types::{H256, U256};
2222
use jsonrpsee::core::RpcResult;
2323
// Substrate
2424
use sc_client_api::backend::{Backend, StorageProvider};
25-
use sc_transaction_pool::ChainApi;
26-
use sc_transaction_pool_api::InPoolTransaction;
25+
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
2726
use sp_api::ProvideRuntimeApi;
2827
use sp_blockchain::HeaderBackend;
2928
use sp_core::hashing::keccak_256;
@@ -37,14 +36,14 @@ use crate::{
3736
frontier_backend_client, internal_err,
3837
};
3938

40-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
39+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
4140
where
4241
B: BlockT,
4342
C: ProvideRuntimeApi<B>,
4443
C::Api: EthereumRuntimeRPCApi<B>,
4544
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
4645
BE: Backend<B> + 'static,
47-
A: ChainApi<Block = B>,
46+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
4847
{
4948
pub async fn block_by_hash(&self, hash: H256, full: bool) -> RpcResult<Option<RichBlock>> {
5049
let BlockInfo {
@@ -145,7 +144,6 @@ where
145144
// ready validated pool
146145
xts.extend(
147146
graph
148-
.validated_pool()
149147
.ready()
150148
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
151149
.collect::<Vec<<B as BlockT>::Extrinsic>>(),
@@ -154,10 +152,9 @@ where
154152
// future validated pool
155153
xts.extend(
156154
graph
157-
.validated_pool()
158155
.futures()
159156
.iter()
160-
.map(|(_hash, extrinsic)| extrinsic.as_ref().clone())
157+
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
161158
.collect::<Vec<<B as BlockT>::Extrinsic>>(),
162159
);
163160

@@ -197,9 +194,7 @@ where
197194
) -> RpcResult<Option<U256>> {
198195
if let BlockNumberOrHash::Pending = number_or_hash {
199196
// get the pending transactions count
200-
return Ok(Some(U256::from(
201-
self.graph.validated_pool().ready().count(),
202-
)));
197+
return Ok(Some(U256::from(self.graph.ready().count())));
203198
}
204199

205200
let block_info = self.block_info_by_number(number_or_hash).await?;

client/rpc/src/eth/client.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use ethereum_types::{H160, U256, U64};
2020
use jsonrpsee::core::RpcResult;
2121
// Substrate
2222
use sc_client_api::backend::{Backend, StorageProvider};
23-
use sc_transaction_pool::ChainApi;
2423
use sp_api::ProvideRuntimeApi;
2524
use sp_blockchain::HeaderBackend;
2625
use sp_consensus::SyncOracle;
@@ -31,14 +30,13 @@ use fp_rpc::EthereumRuntimeRPCApi;
3130

3231
use crate::{eth::Eth, internal_err};
3332

34-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
33+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
3534
where
3635
B: BlockT,
3736
C: ProvideRuntimeApi<B>,
3837
C::Api: EthereumRuntimeRPCApi<B>,
3938
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
4039
BE: Backend<B>,
41-
A: ChainApi<Block = B>,
4240
{
4341
pub fn protocol_version(&self) -> RpcResult<u64> {
4442
Ok(1)

client/rpc/src/eth/execute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use jsonrpsee::{core::RpcResult, types::error::CALL_EXECUTION_FAILED_CODE};
2424
use scale_codec::{Decode, Encode};
2525
// Substrate
2626
use sc_client_api::backend::{Backend, StorageProvider};
27-
use sc_transaction_pool::ChainApi;
27+
use sc_transaction_pool_api::TransactionPool;
2828
use sp_api::{ApiExt, CallApiAt, CallApiAtParams, CallContext, ProvideRuntimeApi};
2929
use sp_block_builder::BlockBuilder as BlockBuilderApi;
3030
use sp_blockchain::HeaderBackend;
@@ -65,16 +65,16 @@ impl EstimateGasAdapter for () {
6565
}
6666
}
6767

68-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
68+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
6969
where
7070
B: BlockT,
7171
C: CallApiAt<B> + ProvideRuntimeApi<B>,
7272
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
7373
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
7474
BE: Backend<B> + 'static,
75-
A: ChainApi<Block = B>,
7675
CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
7776
EC: EthConfig<B, C>,
77+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
7878
{
7979
pub async fn call(
8080
&self,

client/rpc/src/eth/fee.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use ethereum_types::U256;
2020
use jsonrpsee::core::RpcResult;
2121
// Substrate
2222
use sc_client_api::backend::{Backend, StorageProvider};
23-
use sc_transaction_pool::ChainApi;
2423
use sp_api::ProvideRuntimeApi;
2524
use sp_blockchain::HeaderBackend;
2625
use sp_runtime::{
@@ -33,14 +32,13 @@ use fp_rpc::EthereumRuntimeRPCApi;
3332

3433
use crate::{eth::Eth, frontier_backend_client, internal_err};
3534

36-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
35+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
3736
where
3837
B: BlockT,
3938
C: ProvideRuntimeApi<B>,
4039
C::Api: EthereumRuntimeRPCApi<B>,
4140
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
4241
BE: Backend<B> + 'static,
43-
A: ChainApi<Block = B>,
4442
{
4543
pub fn gas_price(&self) -> RpcResult<U256> {
4644
let block_hash = self.client.info().best_hash;

client/rpc/src/eth/filter.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use ethereum_types::{H256, U256};
2828
use jsonrpsee::core::{async_trait, RpcResult};
2929
// Substrate
3030
use sc_client_api::backend::{Backend, StorageProvider};
31-
use sc_transaction_pool::{ChainApi, Pool};
32-
use sc_transaction_pool_api::InPoolTransaction;
31+
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
3332
use sp_api::ProvideRuntimeApi;
3433
use sp_blockchain::HeaderBackend;
3534
use sp_core::hashing::keccak_256;
@@ -43,22 +42,22 @@ use fp_rpc::{EthereumRuntimeRPCApi, TransactionStatus};
4342

4443
use crate::{cache::EthBlockDataCacheTask, frontier_backend_client, internal_err};
4544

46-
pub struct EthFilter<B: BlockT, C, BE, A: ChainApi> {
45+
pub struct EthFilter<B: BlockT, C, BE, P> {
4746
client: Arc<C>,
4847
backend: Arc<dyn fc_api::Backend<B>>,
49-
graph: Arc<Pool<A>>,
48+
graph: Arc<P>,
5049
filter_pool: FilterPool,
5150
max_stored_filters: usize,
5251
max_past_logs: u32,
5352
block_data_cache: Arc<EthBlockDataCacheTask<B>>,
5453
_marker: PhantomData<BE>,
5554
}
5655

57-
impl<B: BlockT, C, BE, A: ChainApi> EthFilter<B, C, BE, A> {
56+
impl<B: BlockT, C, BE, P: TransactionPool> EthFilter<B, C, BE, P> {
5857
pub fn new(
5958
client: Arc<C>,
6059
backend: Arc<dyn fc_api::Backend<B>>,
61-
graph: Arc<Pool<A>>,
60+
graph: Arc<P>,
6261
filter_pool: FilterPool,
6362
max_stored_filters: usize,
6463
max_past_logs: u32,
@@ -77,13 +76,13 @@ impl<B: BlockT, C, BE, A: ChainApi> EthFilter<B, C, BE, A> {
7776
}
7877
}
7978

80-
impl<B, C, BE, A> EthFilter<B, C, BE, A>
79+
impl<B, C, BE, P> EthFilter<B, C, BE, P>
8180
where
8281
B: BlockT,
8382
C: ProvideRuntimeApi<B>,
8483
C::Api: EthereumRuntimeRPCApi<B>,
8584
C: HeaderBackend<B> + 'static,
86-
A: ChainApi<Block = B> + 'static,
85+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
8786
{
8887
fn create_filter(&self, filter_type: FilterType) -> RpcResult<U256> {
8988
let info = self.client.info();
@@ -109,7 +108,6 @@ where
109108
let pending_transaction_hashes = if let FilterType::PendingTransaction = filter_type {
110109
let txs_ready = self
111110
.graph
112-
.validated_pool()
113111
.ready()
114112
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
115113
.collect();
@@ -146,14 +144,14 @@ where
146144
}
147145

148146
#[async_trait]
149-
impl<B, C, BE, A> EthFilterApiServer for EthFilter<B, C, BE, A>
147+
impl<B, C, BE, P> EthFilterApiServer for EthFilter<B, C, BE, P>
150148
where
151149
B: BlockT,
152150
C: ProvideRuntimeApi<B>,
153151
C::Api: EthereumRuntimeRPCApi<B>,
154152
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
155153
BE: Backend<B> + 'static,
156-
A: ChainApi<Block = B> + 'static,
154+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
157155
{
158156
fn new_filter(&self, filter: Filter) -> RpcResult<U256> {
159157
self.create_filter(FilterType::Log(filter))
@@ -223,7 +221,6 @@ where
223221
let previous_hashes = pool_item.pending_transaction_hashes;
224222
let txs_ready = self
225223
.graph
226-
.validated_pool()
227224
.ready()
228225
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
229226
.collect();

client/rpc/src/eth/mining.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
use ethereum_types::{H256, H64, U256};
2020
use jsonrpsee::core::RpcResult;
2121
// Substrate
22-
use sc_transaction_pool::ChainApi;
2322
use sp_runtime::traits::Block as BlockT;
2423
// Frontier
2524
use fc_rpc_core::types::*;
2625

2726
use crate::eth::Eth;
2827

29-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
28+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
3029
where
3130
B: BlockT,
32-
A: ChainApi<Block = B>,
3331
{
3432
pub fn is_mining(&self) -> RpcResult<bool> {
3533
Ok(self.is_authority)

client/rpc/src/eth/mod.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use jsonrpsee::core::{async_trait, RpcResult};
3636
// Substrate
3737
use sc_client_api::backend::{Backend, StorageProvider};
3838
use sc_network_sync::SyncingService;
39-
use sc_transaction_pool::{ChainApi, Pool};
4039
use sc_transaction_pool_api::TransactionPool;
4140
use sp_api::{CallApiAt, ProvideRuntimeApi};
4241
use sp_block_builder::BlockBuilder as BlockBuilderApi;
@@ -71,9 +70,9 @@ impl<B: BlockT, C> EthConfig<B, C> for () {
7170
}
7271

7372
/// Eth API implementation.
74-
pub struct Eth<B: BlockT, C, P, CT, BE, A: ChainApi, CIDP, EC> {
73+
pub struct Eth<B: BlockT, C, P, CT, BE, CIDP, EC> {
7574
pool: Arc<P>,
76-
graph: Arc<Pool<A>>,
75+
graph: Arc<P>,
7776
client: Arc<C>,
7877
convert_transaction: Option<CT>,
7978
sync: Arc<SyncingService<B>>,
@@ -94,19 +93,18 @@ pub struct Eth<B: BlockT, C, P, CT, BE, A: ChainApi, CIDP, EC> {
9493
_marker: PhantomData<(BE, EC)>,
9594
}
9695

97-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
96+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
9897
where
9998
B: BlockT,
10099
C: ProvideRuntimeApi<B>,
101100
C::Api: EthereumRuntimeRPCApi<B>,
102101
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
103102
BE: Backend<B> + 'static,
104-
A: ChainApi<Block = B>,
105103
{
106104
pub fn new(
107105
client: Arc<C>,
108106
pool: Arc<P>,
109-
graph: Arc<Pool<A>>,
107+
graph: Arc<P>,
110108
convert_transaction: Option<CT>,
111109
sync: Arc<SyncingService<B>>,
112110
signers: Vec<Box<dyn EthSigner>>,
@@ -247,13 +245,12 @@ where
247245
}
248246
}
249247

250-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
248+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
251249
where
252250
B: BlockT,
253-
A: ChainApi<Block = B>,
254251
EC: EthConfig<B, C>,
255252
{
256-
pub fn replace_config<EC2: EthConfig<B, C>>(self) -> Eth<B, C, P, CT, BE, A, CIDP, EC2> {
253+
pub fn replace_config<EC2: EthConfig<B, C>>(self) -> Eth<B, C, P, CT, BE, CIDP, EC2> {
257254
let Self {
258255
client,
259256
pool,
@@ -297,16 +294,15 @@ where
297294
}
298295

299296
#[async_trait]
300-
impl<B, C, P, CT, BE, A, CIDP, EC> EthApiServer for Eth<B, C, P, CT, BE, A, CIDP, EC>
297+
impl<B, C, P, CT, BE, CIDP, EC> EthApiServer for Eth<B, C, P, CT, BE, CIDP, EC>
301298
where
302299
B: BlockT,
303300
C: CallApiAt<B> + ProvideRuntimeApi<B>,
304301
C::Api: BlockBuilderApi<B> + ConvertTransactionRuntimeApi<B> + EthereumRuntimeRPCApi<B>,
305302
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
306303
BE: Backend<B> + 'static,
307-
P: TransactionPool<Block = B> + 'static,
304+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
308305
CT: ConvertTransaction<<B as BlockT>::Extrinsic> + Send + Sync + 'static,
309-
A: ChainApi<Block = B> + 'static,
310306
CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
311307
EC: EthConfig<B, C>,
312308
{

client/rpc/src/eth/pending.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
// Substrate
2020
use sc_client_api::backend::{Backend, StorageProvider};
21-
use sc_transaction_pool::ChainApi;
22-
use sc_transaction_pool_api::InPoolTransaction;
21+
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
2322
use sp_api::{ApiExt, ApiRef, Core, ProvideRuntimeApi};
2423
use sp_block_builder::BlockBuilder as BlockBuilderApi;
2524
use sp_blockchain::{ApplyExtrinsicFailed, HeaderBackend};
@@ -50,16 +49,16 @@ pub(crate) enum Error {
5049
ApplyExtrinsicFailed(#[from] ApplyExtrinsicFailed),
5150
}
5251

53-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
52+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
5453
where
5554
B: BlockT,
5655
C: ProvideRuntimeApi<B>,
5756
C::Api: BlockBuilderApi<B>,
5857
C::Api: EthereumRuntimeRPCApi<B>,
5958
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
6059
BE: Backend<B>,
61-
A: ChainApi<Block = B>,
6260
CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
61+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
6362
{
6463
/// Creates a pending runtime API.
6564
pub(crate) async fn pending_runtime_api(&self) -> Result<(B::Hash, ApiRef<C::Api>), Error> {
@@ -123,7 +122,6 @@ where
123122
// Get all extrinsics from the ready queue.
124123
let extrinsics: Vec<<B as BlockT>::Extrinsic> = self
125124
.graph
126-
.validated_pool()
127125
.ready()
128126
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
129127
.collect::<Vec<<B as BlockT>::Extrinsic>>();

client/rpc/src/eth/state.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use jsonrpsee::core::RpcResult;
2121
use scale_codec::Encode;
2222
// Substrate
2323
use sc_client_api::backend::{Backend, StorageProvider};
24-
use sc_transaction_pool::ChainApi;
2524
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
2625
use sp_api::ProvideRuntimeApi;
2726
use sp_block_builder::BlockBuilder as BlockBuilderApi;
@@ -34,15 +33,14 @@ use fp_rpc::EthereumRuntimeRPCApi;
3433

3534
use crate::{eth::Eth, frontier_backend_client, internal_err};
3635

37-
impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
36+
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
3837
where
3938
B: BlockT,
4039
C: ProvideRuntimeApi<B>,
4140
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
4241
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
4342
BE: Backend<B> + 'static,
44-
P: TransactionPool<Block = B> + 'static,
45-
A: ChainApi<Block = B>,
43+
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
4644
CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
4745
{
4846
pub async fn balance(

0 commit comments

Comments
 (0)