mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 06:21:11 +00:00
Refactor tx-pool maintenance and other high-level api (#4629)
* Reduction. * Reformation. * add locked timer stuff * fix issues and introduce full pool * arrange together * fix benches * fix new_light * Add revalidation test case * review fixes * review fixes * use just ready future * address review
This commit is contained in:
@@ -19,12 +19,13 @@
|
||||
use std::{marker::PhantomData, pin::Pin, sync::Arc};
|
||||
use codec::{Decode, Encode};
|
||||
use futures::{
|
||||
channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::{Future, FutureExt, ready},
|
||||
channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::{Future, FutureExt, ready, Ready},
|
||||
};
|
||||
|
||||
use sc_client_api::{
|
||||
blockchain::HeaderBackend,
|
||||
light::{Fetcher, RemoteCallRequest}
|
||||
light::{Fetcher, RemoteCallRequest, RemoteBodyRequest},
|
||||
BlockBody,
|
||||
};
|
||||
use sp_core::Hasher;
|
||||
use sp_runtime::{
|
||||
@@ -63,7 +64,7 @@ impl<Client, Block> FullChainApi<Client, Block> where
|
||||
|
||||
impl<Client, Block> sc_transaction_graph::ChainApi for FullChainApi<Client, Block> where
|
||||
Block: BlockT,
|
||||
Client: ProvideRuntimeApi<Block> + BlockIdTo<Block> + 'static + Send + Sync,
|
||||
Client: ProvideRuntimeApi<Block> + BlockBody<Block> + BlockIdTo<Block> + 'static + Send + Sync,
|
||||
Client::Api: TaggedTransactionQueue<Block>,
|
||||
sp_api::ApiErrorFor<Client, Block>: Send,
|
||||
{
|
||||
@@ -71,6 +72,11 @@ impl<Client, Block> sc_transaction_graph::ChainApi for FullChainApi<Client, Bloc
|
||||
type Hash = Block::Hash;
|
||||
type Error = error::Error;
|
||||
type ValidationFuture = Pin<Box<dyn Future<Output = error::Result<TransactionValidity>> + Send>>;
|
||||
type BodyFuture = Ready<error::Result<Option<Vec<<Self::Block as BlockT>::Extrinsic>>>>;
|
||||
|
||||
fn block_body(&self, id: &BlockId<Self::Block>) -> Self::BodyFuture {
|
||||
ready(self.client.block_body(&id).map_err(|e| error::Error::from(e)))
|
||||
}
|
||||
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
@@ -149,6 +155,7 @@ impl<Client, F, Block> sc_transaction_graph::ChainApi for LightChainApi<Client,
|
||||
type Hash = Block::Hash;
|
||||
type Error = error::Error;
|
||||
type ValidationFuture = Box<dyn Future<Output = error::Result<TransactionValidity>> + Send + Unpin>;
|
||||
type BodyFuture = Pin<Box<dyn Future<Output = error::Result<Option<Vec<<Self::Block as BlockT>::Extrinsic>>>> + Send>>;
|
||||
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
@@ -197,4 +204,33 @@ impl<Client, F, Block> sc_transaction_graph::ChainApi for LightChainApi<Client,
|
||||
(<<Block::Header as HeaderT>::Hashing as HashT>::hash(x), x.len())
|
||||
})
|
||||
}
|
||||
|
||||
fn block_body(&self, id: &BlockId<Self::Block>) -> Self::BodyFuture {
|
||||
let header = self.client.header(*id)
|
||||
.and_then(|h| h.ok_or(sp_blockchain::Error::UnknownBlock(format!("{}", id))));
|
||||
let header = match header {
|
||||
Ok(header) => header,
|
||||
Err(err) => {
|
||||
log::warn!(target: "txpool", "Failed to query header: {:?}", err);
|
||||
return Box::pin(ready(Ok(None)));
|
||||
}
|
||||
};
|
||||
|
||||
let fetcher = self.fetcher.clone();
|
||||
async move {
|
||||
let transactions = fetcher.remote_body({
|
||||
RemoteBodyRequest {
|
||||
header,
|
||||
retry_count: None,
|
||||
}
|
||||
})
|
||||
.await
|
||||
.unwrap_or_else(|e| {
|
||||
log::warn!(target: "txpool", "Failed to fetch block body: {:?}", e);
|
||||
Vec::new()
|
||||
});
|
||||
|
||||
Ok(Some(transactions))
|
||||
}.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user