BlockId removal: tx-pool refactor (#1678)

It changes following APIs:
- trait `ChainApi`
-- `validate_transaction`

- trait `TransactionPool` 
--`submit_at`
--`submit_one`
--`submit_and_watch`

and some implementation details, in particular:
- impl `Pool` 
--`submit_at`
--`resubmit_at`
--`submit_one`
--`submit_and_watch`
--`prune_known`
--`prune`
--`prune_tags`
--`resolve_block_number`
--`verify`
--`verify_one`

- revalidation queue

All tests are also adjusted.

---------

Co-authored-by: command-bot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Michal Kucharczyk
2023-09-27 11:58:39 +02:00
committed by GitHub
parent a846b74604
commit ab3a3bc278
20 changed files with 609 additions and 460 deletions
+20 -24
View File
@@ -166,8 +166,11 @@ where
finalized_hash: Block::Hash,
) -> (Self, Pin<Box<dyn Future<Output = ()> + Send>>) {
let pool = Arc::new(graph::Pool::new(Default::default(), true.into(), pool_api.clone()));
let (revalidation_queue, background_task) =
revalidation::RevalidationQueue::new_background(pool_api.clone(), pool.clone());
let (revalidation_queue, background_task) = revalidation::RevalidationQueue::new_background(
pool_api.clone(),
pool.clone(),
finalized_hash,
);
(
Self {
api: pool_api,
@@ -203,8 +206,11 @@ where
RevalidationType::Light =>
(revalidation::RevalidationQueue::new(pool_api.clone(), pool.clone()), None),
RevalidationType::Full => {
let (queue, background) =
revalidation::RevalidationQueue::new_background(pool_api.clone(), pool.clone());
let (queue, background) = revalidation::RevalidationQueue::new_background(
pool_api.clone(),
pool.clone(),
finalized_hash,
);
(queue, Some(background))
},
};
@@ -254,46 +260,43 @@ where
fn submit_at(
&self,
at: &BlockId<Self::Block>,
at: <Self::Block as BlockT>::Hash,
source: TransactionSource,
xts: Vec<TransactionFor<Self>>,
) -> PoolFuture<Vec<Result<TxHash<Self>, Self::Error>>, Self::Error> {
let pool = self.pool.clone();
let at = *at;
self.metrics
.report(|metrics| metrics.submitted_transactions.inc_by(xts.len() as u64));
async move { pool.submit_at(&at, source, xts).await }.boxed()
async move { pool.submit_at(at, source, xts).await }.boxed()
}
fn submit_one(
&self,
at: &BlockId<Self::Block>,
at: <Self::Block as BlockT>::Hash,
source: TransactionSource,
xt: TransactionFor<Self>,
) -> PoolFuture<TxHash<Self>, Self::Error> {
let pool = self.pool.clone();
let at = *at;
self.metrics.report(|metrics| metrics.submitted_transactions.inc());
async move { pool.submit_one(&at, source, xt).await }.boxed()
async move { pool.submit_one(at, source, xt).await }.boxed()
}
fn submit_and_watch(
&self,
at: &BlockId<Self::Block>,
at: <Self::Block as BlockT>::Hash,
source: TransactionSource,
xt: TransactionFor<Self>,
) -> PoolFuture<Pin<Box<TransactionStatusStreamFor<Self>>>, Self::Error> {
let at = *at;
let pool = self.pool.clone();
self.metrics.report(|metrics| metrics.submitted_transactions.inc());
async move {
let watcher = pool.submit_and_watch(&at, source, xt).await?;
let watcher = pool.submit_and_watch(at, source, xt).await?;
Ok(watcher.into_stream().boxed())
}
@@ -433,11 +436,7 @@ where
let validity = self
.api
.validate_transaction_blocking(
&BlockId::hash(at),
TransactionSource::Local,
xt.clone(),
)?
.validate_transaction_blocking(at, TransactionSource::Local, xt.clone())?
.map_err(|e| {
Self::Error::Pool(match e {
TransactionValidityError::Invalid(i) => TxPoolError::InvalidTransaction(i),
@@ -577,10 +576,7 @@ async fn prune_known_txs_for_block<Block: BlockT, Api: graph::ChainApi<Block = B
},
};
if let Err(e) = pool
.prune(&BlockId::Hash(block_hash), &BlockId::hash(*header.parent_hash()), &extrinsics)
.await
{
if let Err(e) = pool.prune(block_hash, *header.parent_hash(), &extrinsics).await {
log::error!("Cannot prune known in the pool: {}", e);
}
@@ -691,7 +687,7 @@ where
if let Err(e) = pool
.resubmit_at(
&BlockId::Hash(*hash),
*hash,
// These transactions are coming from retracted blocks, we should
// simply consider them external.
TransactionSource::External,
@@ -717,7 +713,7 @@ where
if next_action.revalidate {
let hashes = pool.validated_pool().ready().map(|tx| tx.hash).collect();
self.revalidation_queue.revalidate_later(*block_number, hashes).await;
self.revalidation_queue.revalidate_later(*hash, hashes).await;
self.revalidation_strategy.lock().clear();
}