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 all 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::{ | ||
|
@@ -379,6 +379,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> | ||
+ sc_client_api::ExecutorProvider<Block> | ||
+ sc_client_api::UsageProvider<Block> | ||
|
@@ -419,6 +420,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>, | ||
|
@@ -555,19 +557,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 |
||
} | ||
|
||
|
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
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.