Skip to content

Commit

Permalink
fix(collator): fixed msgs groups precalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
SmaGMan committed Jun 10, 2024
1 parent 0fe264e commit 7143fb4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
25 changes: 13 additions & 12 deletions collator/src/collator/execution_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl ExecutionManager {
pub fn set_msgs_for_execution(&mut self, msgs: Vec<AsyncMessage>) {
tracing::debug!(target: tracing_targets::EXEC_MANAGER, "adding set of {} messages for execution", msgs.len());
let _ = std::mem::replace(&mut self.messages_set, msgs);
self.messages_groups = Some(pre_calculate_groups(&self.messages_set, self.group_limit));
}

/// Run one execution tick of parallel transactions
Expand All @@ -107,14 +108,14 @@ impl ExecutionManager {
tracing::trace!(target: tracing_targets::EXEC_MANAGER, "messages set execution tick with offset {}", offset);

// let (new_offset, group) = calculate_group(&self.messages_set, self.group_limit, offset);
let messages_groups = self
.messages_groups
.get_or_insert(pre_calculate_groups(&self.messages_set, self.group_limit));
let messages_groups = self.messages_groups.as_ref().unwrap();
let (new_offset, group) = match messages_groups.get(&offset) {
Some(g) => (offset + 1, g.clone()), // TODO: need to optimize without clone()
None => return Ok((offset, vec![], true)),
};
let finished = messages_groups.contains_key(&new_offset);
let finished = !messages_groups.contains_key(&new_offset);

tracing::debug!(target: tracing_targets::EXEC_MANAGER, "offset {} group len: {}", offset, group.len());

let mut futures: FuturesUnordered<_> = Default::default();

Expand Down Expand Up @@ -263,8 +264,8 @@ impl ExecutionManager {
mut account_stuff: ShardAccountStuff,
) -> Result<()> {
tracing::trace!(target: tracing_targets::EXEC_MANAGER, "updating shard account {}", account_id);
tracing::trace!(target: tracing_targets::EXEC_MANAGER, "updated Account: {:?}",
account_stuff.shard_account.account.load()?,
tracing::debug!(target: tracing_targets::EXEC_MANAGER, "updated account {account_id} balance: {}",
account_stuff.shard_account.account.load()?.balance().tokens,
);
let binding = &account_stuff.shard_account.account;
let account_root = binding.inner();
Expand Down Expand Up @@ -463,21 +464,21 @@ pub fn pre_calculate_groups(
};

let mut g_idx = 0;
let mut group = res.entry(g_idx).or_default();
let mut group_entry;
loop {
if group.len() == group_limit as usize {
group_entry = res.entry(g_idx).or_default();
if group_entry.len() == group_limit as usize {
g_idx += 1;
group = res.entry(g_idx).or_default();
continue;
}
let group_acc = group.entry(account_id);
match group_acc {
let account_entry = group_entry.entry(account_id);
match account_entry {
Entry::Vacant(entry) => {
entry.insert(msg.clone());
break;
}
Entry::Occupied(_entry) => {
g_idx += 1;
group = res.entry(g_idx).or_default();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions collator/src/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ impl CollatorStdImpl {
self.do_collate(next_chain_time, None).await?;
} else {
// otherwise import next anchor and return it notify to manager
tracing::info!(target: tracing_targets::COLLATOR,
tracing::debug!(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::info!(target: tracing_targets::COLLATOR,
tracing::debug!(target: tracing_targets::COLLATOR,
"just imported anchor has externals for master",
);
}
Expand Down Expand Up @@ -697,7 +697,7 @@ impl CollatorStdImpl {
|| force_mc_block_by_uncommitted_chain
{
if no_pending_msgs {
tracing::info!(target: tracing_targets::COLLATOR,
tracing::debug!(target: tracing_targets::COLLATOR,
"there are no internals or pending externals, will import next anchor",
);
} else if force_mc_block_by_uncommitted_chain {
Expand Down Expand Up @@ -740,7 +740,7 @@ impl CollatorStdImpl {
force_mc_block_by_uncommitted_chain,
);
} else {
tracing::info!(target: tracing_targets::COLLATOR,
tracing::debug!(target: tracing_targets::COLLATOR,
"just imported anchor has no externals for current shard, will notify collation manager",
);
}
Expand Down

0 comments on commit 7143fb4

Please sign in to comment.