Skip to content

Commit a84cdd4

Browse files
authored
Optimize synchronize_received_certificates_from_validator. (#2737)
* Parallelize fetching chain info, download certificates in one batch. * Simplify synchronize_received_certificates_from_validator. * Don't track new chains unless they were opened by a tracked chain. * Add more comments to track_newly_created_chains. * Fix next_height - chain ID mapping. * Rename HandleCertificateResult → CheckCertificateResult * Extract some code from synchronize_received_certificates_from_validator. * Leave the chain worker limit at 20. * Expand the CHAIN_WORKER_LIMIT documentation.
1 parent 28ec6d1 commit a84cdd4

File tree

3 files changed

+192
-181
lines changed

3 files changed

+192
-181
lines changed

linera-core/src/chain_worker/state/mod.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,21 @@ where
380380
self.recent_blobs.insert(blob).await
381381
}
382382

383-
/// Adds any newly created chains to the set of `tracked_chains`.
384-
fn track_newly_created_chains(&self, block: &ExecutedBlock) {
383+
/// Adds any newly created chains to the set of `tracked_chains`, if the parent chain is
384+
/// also tracked.
385+
///
386+
/// Chains that are not tracked are usually processed only because they sent some message
387+
/// to one of the tracked chains. In most use cases, their children won't be of interest.
388+
fn track_newly_created_chains(&self, executed_block: &ExecutedBlock) {
385389
if let Some(tracked_chains) = self.tracked_chains.as_ref() {
386-
let messages = block.messages().iter().flatten();
390+
if !tracked_chains
391+
.read()
392+
.expect("Panics should not happen while holding a lock to `tracked_chains`")
393+
.contains(&executed_block.block.chain_id)
394+
{
395+
return; // The parent chain is not tracked; don't track the child.
396+
}
397+
let messages = executed_block.messages().iter().flatten();
387398
let open_chain_message_indices =
388399
messages
389400
.enumerate()
@@ -392,7 +403,7 @@ where
392403
_ => None,
393404
});
394405
let open_chain_message_ids =
395-
open_chain_message_indices.map(|index| block.message_id(index as u32));
406+
open_chain_message_indices.map(|index| executed_block.message_id(index as u32));
396407
let new_chain_ids = open_chain_message_ids.map(ChainId::child);
397408

398409
tracked_chains

0 commit comments

Comments
 (0)