Skip to content

Commit 322378a

Browse files
authored
Improve logs for issue #2107 (#2108)
* Improve logs for issue #2107 * Oops
1 parent c9d02b4 commit 322378a

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

light-base/src/runtime_service.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use alloc::{
6666
vec::Vec,
6767
};
6868
use async_lock::Mutex;
69-
use core::{cmp, iter, mem, num::NonZero, ops, pin::Pin, time::Duration};
69+
use core::{cmp, fmt, iter, mem, num::NonZero, ops, pin::Pin, time::Duration};
7070
use derive_more::derive;
7171
use futures_channel::oneshot;
7272
use futures_lite::FutureExt as _;
@@ -449,9 +449,15 @@ pub struct SubscribeAll<TPlat: PlatformRef> {
449449
pub new_blocks: Subscription<TPlat>,
450450
}
451451

452-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
452+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
453453
pub struct SubscriptionId(u64);
454454

455+
impl fmt::Debug for SubscriptionId {
456+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
457+
fmt::Debug::fmt(&self.0, f)
458+
}
459+
}
460+
455461
pub struct Subscription<TPlat: PlatformRef> {
456462
subscription_id: u64,
457463
channel: Pin<Box<async_channel::Receiver<Notification>>>,

light-base/src/sync_service/parachain.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ impl<TPlat: PlatformRef> ParachainBackgroundTask<TPlat> {
333333
"relay-chain-new-subscription",
334334
finalized_hash = HashDisplay(&header::hash_from_scale_encoded_header(
335335
&relay_chain_subscribe_all.finalized_block_scale_encoded_header
336-
))
336+
)),
337+
subscription_id = ?relay_chain_subscribe_all.new_blocks.id(),
337338
);
338339
log!(
339340
&self.platform,

light-base/src/transactions_service.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ async fn background_task<TPlat: PlatformRef>(
537537
&config.log_target,
538538
"reset",
539539
new_finalized = HashDisplay(&initial_finalized_block_hash),
540+
subscription_id = ?subscribe_all.new_blocks.id(),
540541
dropped_transactions
541542
);
542543

@@ -751,10 +752,6 @@ async fn background_task<TPlat: PlatformRef>(
751752

752753
// Remove finalized blocks from the pool when possible.
753754
for block in worker.pending_transactions.prune_finalized_with_body() {
754-
// All blocks in `pending_transactions` are pinned within the runtime service.
755-
// Unpin them when they're removed.
756-
subscribe_all.new_blocks.unpin_block(block.block_hash).await;
757-
758755
log!(
759756
&worker.platform,
760757
Debug,
@@ -768,6 +765,10 @@ async fn background_task<TPlat: PlatformRef>(
768765
.join(", ")
769766
);
770767

768+
// All blocks in `pending_transactions` are pinned within the runtime service.
769+
// Unpin them when they're removed.
770+
subscribe_all.new_blocks.unpin_block(block.block_hash).await;
771+
771772
debug_assert!(!block.user_data.downloading);
772773
for mut tx in block.included_transactions {
773774
// We assume that there's no more than 2<<32 transactions per block.
@@ -853,6 +854,14 @@ async fn background_task<TPlat: PlatformRef>(
853854
worker.set_best_block(&config.log_target, &best_block_hash_if_changed);
854855
}
855856
for pruned in worker.pending_transactions.set_finalized_block(&hash) {
857+
log!(
858+
&worker.platform,
859+
Debug,
860+
&config.log_target,
861+
"pruned-block-discard",
862+
block = HashDisplay(&pruned.0),
863+
);
864+
856865
// All blocks in `pending_transactions` are pinned within the
857866
// runtime service. Unpin them when they're removed.
858867
subscribe_all.new_blocks.unpin_block(pruned.0).await;

0 commit comments

Comments
 (0)