From d91bd014d470578094aa2c224019581c6f7ec1e4 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 5 Sep 2023 14:23:11 +0000 Subject: [PATCH] Fix transactions service being stuck before warp sync finishes (#1110) * Fix transactions service being stuck before warp sync finishes * PR link --- light-base/src/transactions_service.rs | 72 +++++++++++++++++++------- wasm-node/CHANGELOG.md | 9 ++++ 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/light-base/src/transactions_service.rs b/light-base/src/transactions_service.rs index bf8403f0ee..4b5735c6ee 100644 --- a/light-base/src/transactions_service.rs +++ b/light-base/src/transactions_service.rs @@ -85,6 +85,7 @@ use core::{ time::Duration, }; use futures_channel::mpsc; +use futures_lite::FutureExt as _; use futures_util::stream::FuturesUnordered; use futures_util::{future, FutureExt as _, SinkExt as _, StreamExt as _}; use itertools::Itertools as _; @@ -352,19 +353,51 @@ async fn background_task(mut config: BackgroundTaskConfig { + let _ = updates_report + .send(TransactionStatus::Dropped(DropReason::GapInChain)) + .await; + } + Some(ToBackground::SubmitTransaction { .. }) => {} + None => break None, + } + } + }; + + match sub_future.or(messages_process).await { + Some(s) => s, + None => return, + } + }; - // The buffer size should be large enough so that, if the CPU is busy, it doesn't - // become full before the execution of the transactions service resumes. - // The maximum number of pinned block is ignored, as this maximum is a way to avoid - // malicious behaviors. This code is by definition not considered malicious. - let mut subscribe_all = worker - .runtime_service - .subscribe_all( - "transactions-service", - 32, - NonZeroUsize::new(usize::max_value()).unwrap(), - ) - .await; let initial_finalized_block_hash = header::hash_from_scale_encoded_header( &subscribe_all.finalized_block_scale_encoded_header, ); @@ -491,7 +524,7 @@ async fn background_task(mut config: BackgroundTaskConfig(mut config: BackgroundTaskConfig(mut config: BackgroundTaskConfig(mut config: BackgroundTaskConfig