Skip to content

Commit

Permalink
refactor(collator): improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SmaGMan committed Jun 7, 2024
1 parent caae584 commit 734866f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
8 changes: 6 additions & 2 deletions collator/src/collator/do_collate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl CollatorStdImpl {
let mc_data = &self.working_state().mc_data;
let prev_shard_data = &self.working_state().prev_shard_data;

tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"Start collating block: top_shard_blocks_ids: {:?}",
top_shard_blocks_info.as_ref().map(|v| {
v.iter()
Expand Down Expand Up @@ -230,6 +230,7 @@ impl CollatorStdImpl {
// 4. When all externals and existing internals finished (the collected set is empty here)
// fill next messages sets with new internals
if msgs_set.is_empty() {
let mut new_internal_messages_in_set = 0;
while remaining_capacity > 0 && !all_new_internals_finished {
match internal_messages_iterator.next(true)? {
Some(int_msg) => {
Expand All @@ -247,11 +248,11 @@ impl CollatorStdImpl {
let async_message = AsyncMessage::NewInt(int_msg_info, cell);

msgs_set.push(async_message);

internal_messages_in_set.push((
message_with_source.shard_id,
message_with_source.message.key(),
));
new_internal_messages_in_set += 1;

remaining_capacity -= 1;
}
Expand All @@ -260,6 +261,9 @@ impl CollatorStdImpl {
}
}
}
tracing::debug!(target: tracing_targets::COLLATOR,
"read {} new internals from iterator", new_internal_messages_in_set,
);
}

if msgs_set.is_empty() {
Expand Down
43 changes: 25 additions & 18 deletions collator/src/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl CollatorStdImpl {
/// that will route next collation steps
#[tracing::instrument(name = "try_collate_next_master_block", skip_all, fields(block_id = %self.next_block_id_short))]
async fn try_collate_next_master_block_impl(&mut self) -> Result<()> {
tracing::trace!(target: tracing_targets::COLLATOR,
tracing::debug!(target: tracing_targets::COLLATOR,
"Check if can collate next master block",
);

Expand All @@ -609,19 +609,19 @@ impl CollatorStdImpl {
.ok_or(anyhow::anyhow!("has_pending internals doesn't init"))?;
if has_internals {
// collate if has internals
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"there are unprocessed internals from previous block, will collate next block",
);
let next_chain_time = self.working_state().prev_shard_data.gen_chain_time() as u64;
self.do_collate(next_chain_time, None).await?;
} else {
// otherwise import next anchor and return it notify to manager
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"there are no internals, will import next anchor",
);
let (next_anchor, has_externals) = self.import_next_anchor().await?;
if has_externals {
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"just imported anchor has externals for master",
);
}
Expand All @@ -641,7 +641,7 @@ impl CollatorStdImpl {
/// that will route next collation steps
#[tracing::instrument(name = "try_collate_next_shard_block", skip_all, fields(block_id = %self.next_block_id_short))]
async fn try_collate_next_shard_block_impl(&mut self) -> Result<()> {
tracing::trace!(target: tracing_targets::COLLATOR,
tracing::debug!(target: tracing_targets::COLLATOR,
"Check if can collate next shard block",
);

Expand All @@ -655,15 +655,15 @@ impl CollatorStdImpl {
.ok_or(anyhow::anyhow!("has_pending internals doesn't init"))?;

if has_internals {
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"there are unprocessed internals from previous block, will collate next block",
);
}

// check pending externals
let mut has_externals = self.has_pending_externals;
if has_externals {
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"there are pending externals from previously imported anchors, will collate next block",
);
}
Expand Down Expand Up @@ -697,24 +697,24 @@ impl CollatorStdImpl {
|| force_mc_block_by_uncommitted_chain
{
if no_pending_msgs {
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"there are no internals or pending externals, will import next anchor",
);
} else if force_import_anchor_by_uncommitted_chain {
tracing::debug!(target: tracing_targets::COLLATOR,
"uncommitted chain interval to import anchor {} reached on length {}, will import next anchor",
self.config.uncommitted_chain_to_import_next_anchor, uncommitted_chain_length,
);
} else if force_mc_block_by_uncommitted_chain {
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"max_uncommitted_chain_length {} reached, will import next anchor",
self.config.max_uncommitted_chain_length,
);
} else if force_import_anchor_by_uncommitted_chain {
tracing::info!(target: tracing_targets::COLLATOR,
"uncommitted chain interval to import anchor {} reached on length {}, will import next anchor",
self.config.uncommitted_chain_to_import_next_anchor, uncommitted_chain_length,
);
}
let (next_anchor, next_anchor_has_externals) = self.import_next_anchor().await?;
has_externals = next_anchor_has_externals;
if has_externals && !force_mc_block_by_uncommitted_chain {
tracing::debug!(target: tracing_targets::COLLATOR,
tracing::info!(target: tracing_targets::COLLATOR,
"just imported anchor has externals, will collate next block",
);
}
Expand All @@ -734,9 +734,16 @@ impl CollatorStdImpl {
// notify manager when next anchor was imported but id does not contain externals
if !next_anchor_has_externals || force_mc_block_by_uncommitted_chain {
// this may start master block collation or next shard block collation attempt
tracing::debug!(target: tracing_targets::COLLATOR,
"just imported anchor has no externals for current shard, will notify collation manager",
);
if force_mc_block_by_uncommitted_chain {
tracing::info!(target: tracing_targets::COLLATOR,
"force_mc_block_by_uncommitted_chain={}, will notify collation manager",
force_mc_block_by_uncommitted_chain,
);
} else {
tracing::info!(target: tracing_targets::COLLATOR,
"just imported anchor has no externals for current shard, will notify collation manager",
);
}
self.listener
.on_skipped_anchor(
self.next_block_id_short,
Expand Down

0 comments on commit 734866f

Please sign in to comment.