Skip to content

Commit

Permalink
add unit test for links
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 24, 2024
1 parent a0290f5 commit fb784c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion tx-pool/src/component/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ impl TxLinksMap {
relation_ids.insert(id);
}
// for direct parents, we don't store children in links map
// so filter those not in links map now, they maybe removed from tx-pool now
// so filter those not in links map, they maybe removed from tx-pool now
if relation == Relation::DirectParents {
relation_ids.retain(|id| self.inner.contains_key(id));
}
relation_ids
}

pub fn add_link(&mut self, short_id: ProposalShortId, links: TxLinks) {
self.inner.insert(short_id, links);
}

pub fn calc_ancestors(&self, short_id: &ProposalShortId) -> HashSet<ProposalShortId> {
self.calc_relative_ids(short_id, Relation::Parents)
}
Expand Down
14 changes: 8 additions & 6 deletions tx-pool/src/component/pool_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,14 @@ impl PoolMap {
self.links.add_child(parent, short_id.clone());
}

let links = TxLinks {
parents,
direct_parents,
children: Default::default(),
};
self.links.inner.insert(short_id, links);
self.links.add_link(
short_id,
TxLinks {
parents,
direct_parents,
children: Default::default(),
},
);

Ok(true)
}
Expand Down
1 change: 1 addition & 0 deletions tx-pool/src/component/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod chunk;
mod entry;
mod links;
mod orphan;
mod pending;
mod proposed;
Expand Down

0 comments on commit fb784c0

Please sign in to comment.