Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

collect_ancestors_to_send

Function collect_ancestors_to_send 

Source
pub async fn collect_ancestors_to_send(
    backend: &dyn BackendImpl,
    entry_ids: &[ID],
    their_tips: &[ID],
) -> Result<Vec<Entry>>
Expand description

Collect ancestors that need to be sent with the given entries.

This function performs DAG traversal to find all entries that need to be sent along with the given entry IDs, excluding entries that the peer already has (based on their tips). The algorithm ensures that all necessary parent entries are included for proper DAG reconstruction on the peer.

§Algorithm Complexity

  • Time: O(V + E) where V is the number of visited entries and E is the number of parent relationships
  • Space: O(V) for the visited set, queue storage, and result entries

§Arguments

  • backend - Database backend to retrieve entries
  • entry_ids - Starting entry IDs to collect ancestors for
  • their_tips - Entry IDs that the peer already has

§Returns

Vec of entries that need to be sent (including ancestors)

§Example

use eidetica::sync::utils::collect_ancestors_to_send;
use eidetica::backend::database::InMemory;

let backend = InMemory::new();
let our_tips = vec![ID::from("tip1"), ID::from("tip2")];
let their_tips = vec![ID::from("common_ancestor")];
let to_send = collect_ancestors_to_send(&backend, &our_tips, &their_tips).await?;
// Returns entries that peer needs, excluding what they already have