This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Transaction pool: Ensure that we prune transactions properly #8963
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ use parking_lot::Mutex; | |
|
||
use sp_runtime::{ | ||
generic::BlockId, | ||
traits::{Block as BlockT, NumberFor, AtLeast32Bit, Extrinsic, Zero}, | ||
traits::{Block as BlockT, NumberFor, AtLeast32Bit, Extrinsic, Zero, Header as HeaderT}, | ||
}; | ||
use sp_core::traits::SpawnNamed; | ||
use sp_transaction_pool::{ | ||
|
@@ -357,6 +357,7 @@ where | |
Block: BlockT, | ||
Client: sp_api::ProvideRuntimeApi<Block> | ||
+ sc_client_api::BlockBackend<Block> | ||
+ sc_client_api::blockchain::HeaderBackend<Block> | ||
+ sp_runtime::traits::BlockIdTo<Block>, | ||
Client: sc_client_api::ExecutorProvider<Block> + Send + Sync + 'static, | ||
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>, | ||
|
@@ -387,6 +388,7 @@ where | |
Block: BlockT, | ||
Client: sp_api::ProvideRuntimeApi<Block> | ||
+ sc_client_api::BlockBackend<Block> | ||
+ sc_client_api::blockchain::HeaderBackend<Block> | ||
+ sp_runtime::traits::BlockIdTo<Block>, | ||
Client: Send + Sync + 'static, | ||
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>, | ||
|
@@ -523,19 +525,32 @@ async fn prune_known_txs_for_block<Block: BlockT, Api: ChainApi<Block = Block>>( | |
api: &Api, | ||
pool: &sc_transaction_graph::Pool<Api>, | ||
) -> Vec<ExtrinsicHash<Api>> { | ||
let hashes = api.block_body(&block_id).await | ||
let extrinsics = api.block_body(&block_id).await | ||
.unwrap_or_else(|e| { | ||
log::warn!("Prune known transactions: error request {:?}!", e); | ||
None | ||
}) | ||
.unwrap_or_default() | ||
.into_iter() | ||
.unwrap_or_default(); | ||
|
||
let hashes = extrinsics.iter() | ||
.map(|tx| pool.hash_of(&tx)) | ||
.collect::<Vec<_>>(); | ||
|
||
log::trace!(target: "txpool", "Pruning transactions: {:?}", hashes); | ||
|
||
if let Err(e) = pool.prune_known(&block_id, &hashes) { | ||
let header = match api.block_header(&block_id) { | ||
Ok(Some(h)) => h, | ||
Ok(None) => { | ||
log::debug!(target: "txpool", "Could not find header for {:?}.", block_id); | ||
return hashes | ||
}, | ||
Err(e) => { | ||
log::debug!(target: "txpool", "Error retrieving header for {:?}: {:?}", block_id, e); | ||
return hashes | ||
} | ||
}; | ||
|
||
if let Err(e) = pool.prune(&block_id, &BlockId::hash(*header.parent_hash()), &extrinsics).await { | ||
log::error!("Cannot prune known in the pool {:?}!", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the error line be updated to not say |
||
} | ||
|
||
|
@@ -681,6 +696,15 @@ impl<PoolApi, Block> MaintainedTransactionPool for BasicPool<PoolApi, Block> | |
move || Box::new(extra_pool.validated_pool().ready()), | ||
); | ||
|
||
// if let Err(e) = pool.validated_pool().clear_stale(&id) { | ||
// log::debug!( | ||
// target: "txpool", | ||
// "Error while clearing stale transaction at {:?}: {:?}", | ||
bkchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// e, | ||
// id, | ||
// ); | ||
// } | ||
|
||
if next_action.revalidate { | ||
let hashes = pool.validated_pool() | ||
.ready() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning here was meant to indicate more serious pruning issue or pool inconsistency - it was triggered when we detected invalid transaction during block production.
I understand that warning is not desirable cause it is not actionable by node operator, but I'd still differentiate the log message depending on the fact when we detected the transaction to be invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nobody ever looked at these warnings, especially as they were also triggered by re-validating inherents for example.
If we want to improve this, we should print proper messages where this function is called, but not down here where we have no idea what actually happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. The problem is that these warnings are not some rare event but get printed extremely often. At the beginning people were concerned, but over time they have learned to completely ignore them.