diff --git a/Cargo.lock b/Cargo.lock
index e9cd7ef29daf9..b0bed795e7463 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -24902,6 +24902,7 @@ dependencies = [
name = "substrate-test-runtime-transaction-pool"
version = "2.0.0"
dependencies = [
+ "async-trait",
"futures",
"log",
"parity-scale-codec",
diff --git a/prdoc/pr_8875.prdoc b/prdoc/pr_8875.prdoc
new file mode 100644
index 0000000000000..2c6a9b38eb9be
--- /dev/null
+++ b/prdoc/pr_8875.prdoc
@@ -0,0 +1,7 @@
+title: '`fatxpool`: `ChainApi` is now async'
+doc:
+- audience: Node Dev
+ description: Internal `ChainApi` is now `async_trait`, `validate_transaction` and `block_body` are now `async` methods. This is just cleanup - migrating from returning `Future` to `async` method'.
+crates:
+- name: sc-transaction-pool
+ bump: major
diff --git a/substrate/client/transaction-pool/benches/basics.rs b/substrate/client/transaction-pool/benches/basics.rs
index 0672d47f70431..bbd8b536abd1d 100644
--- a/substrate/client/transaction-pool/benches/basics.rs
+++ b/substrate/client/transaction-pool/benches/basics.rs
@@ -16,13 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-use criterion::{criterion_group, criterion_main, Criterion};
-
+use async_trait::async_trait;
use codec::Encode;
-use futures::{
- executor::block_on,
- future::{ready, Ready},
-};
+use criterion::{criterion_group, criterion_main, Criterion};
+use futures::executor::block_on;
use sc_transaction_pool::*;
use sp_blockchain::HashAndNumber;
use sp_crypto_hashing::blake2_256;
@@ -55,19 +52,18 @@ fn to_tag(nonce: u64, from: AccountId) -> Tag {
data.to_vec()
}
+#[async_trait]
impl ChainApi for TestApi {
type Block = Block;
type Error = sc_transaction_pool_api::error::Error;
- type ValidationFuture = Ready>;
- type BodyFuture = Ready>>>;
- fn validate_transaction(
+ async fn validate_transaction(
&self,
at: ::Hash,
_: TransactionSource,
uxt: Arc<::Extrinsic>,
_: ValidateTransactionPriority,
- ) -> Self::ValidationFuture {
+ ) -> Result {
let uxt = (*uxt).clone();
let transfer = TransferData::try_from(&uxt)
.expect("uxt is expected to be bench_call (carrying TransferData)");
@@ -75,11 +71,11 @@ impl ChainApi for TestApi {
let from = transfer.from;
match self.block_id_to_number(&BlockId::Hash(at)) {
- Ok(Some(num)) if num > 5 => return ready(Ok(Err(InvalidTransaction::Stale.into()))),
+ Ok(Some(num)) if num > 5 => return Ok(Err(InvalidTransaction::Stale.into())),
_ => {},
}
- ready(Ok(Ok(ValidTransaction {
+ Ok(Ok(ValidTransaction {
priority: 4,
requires: if nonce > 1 && self.nonce_dependant {
vec![to_tag(nonce - 1, from)]
@@ -89,7 +85,7 @@ impl ChainApi for TestApi {
provides: vec![to_tag(nonce, from)],
longevity: 10,
propagate: true,
- })))
+ }))
}
fn validate_transaction_blocking(
@@ -97,7 +93,7 @@ impl ChainApi for TestApi {
_at: ::Hash,
_source: TransactionSource,
_uxt: Arc<::Extrinsic>,
- ) -> sc_transaction_pool_api::error::Result {
+ ) -> Result {
unimplemented!();
}
@@ -128,8 +124,11 @@ impl ChainApi for TestApi {
(blake2_256(&encoded).into(), encoded.len())
}
- fn block_body(&self, _id: ::Hash) -> Self::BodyFuture {
- ready(Ok(None))
+ async fn block_body(
+ &self,
+ _id: ::Hash,
+ ) -> Result