Quickly skip invalid transactions during block authorship. (#9789)

* Support skipping invalid transactions in the iterator.

* Expose concrete iterator.

* cargo +nightly fmt --all

* More consistent placement.

* Update Cargo.lock

* Pass transaction to 'report_invalid'
This commit is contained in:
Tomasz Drwięga
2021-10-01 16:25:13 +02:00
committed by GitHub
parent 29ff036463
commit 085935dd0a
8 changed files with 159 additions and 71 deletions
@@ -344,7 +344,7 @@ where
let mut t2 =
futures_timer::Delay::new(deadline.saturating_duration_since((self.now)()) / 8).fuse();
let pending_iterator = select! {
let mut pending_iterator = select! {
res = t1 => res,
_ = t2 => {
log::warn!(
@@ -363,7 +363,7 @@ where
let mut transaction_pushed = false;
let mut hit_block_size_limit = false;
for pending_tx in pending_iterator {
while let Some(pending_tx) = pending_iterator.next() {
if (self.now)() > deadline {
debug!(
"Consensus deadline reached when pushing block transactions, \
@@ -378,6 +378,7 @@ where
let block_size =
block_builder.estimate_block_size(self.include_proof_in_block_size_estimation);
if block_size + pending_tx_data.encoded_size() > block_size_limit {
pending_iterator.report_invalid(&pending_tx);
if skipped < MAX_SKIPPED_TRANSACTIONS {
skipped += 1;
debug!(
@@ -400,6 +401,7 @@ where
debug!("[{:?}] Pushed to the block.", pending_tx_hash);
},
Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => {
pending_iterator.report_invalid(&pending_tx);
if skipped < MAX_SKIPPED_TRANSACTIONS {
skipped += 1;
debug!(
@@ -412,6 +414,7 @@ where
}
},
Err(e) if skipped > 0 => {
pending_iterator.report_invalid(&pending_tx);
trace!(
"[{:?}] Ignoring invalid transaction when skipping: {}",
pending_tx_hash,
@@ -419,6 +422,7 @@ where
);
},
Err(e) => {
pending_iterator.report_invalid(&pending_tx);
debug!("[{:?}] Invalid transaction: {}", pending_tx_hash, e);
unqueue_invalid.push(pending_tx_hash);
},