Skip to content

Commit 51e7385

Browse files
authored
Merge pull request #73 from spacesprotocol/releases
fix: use sliding windows for anchor sets so trust_ids stay resolvable
2 parents e2cd490 + f953360 commit 51e7385

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

fabric/rust/src/anchor.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ pub struct AnchorSets {
1212
impl AnchorSets {
1313
pub fn from_anchors(raw: Vec<RootAnchor>) -> Self {
1414
let mut sets = HashMap::new();
15-
for chunk in raw.chunks(ANCHOR_SET_SIZE) {
16-
let expanded = AnchorSet::from_anchors(chunk.to_vec());
17-
let trust_set = compute_trust_set(chunk);
15+
let insert = |sets: &mut HashMap<TrustId, AnchorSet>, window: &[RootAnchor]| {
16+
let expanded = AnchorSet::from_anchors(window.to_vec());
17+
let trust_set = compute_trust_set(window);
1818
sets.insert(TrustId::from(trust_set.id), expanded);
19+
};
20+
if raw.len() < ANCHOR_SET_SIZE {
21+
if !raw.is_empty() {
22+
insert(&mut sets, &raw);
23+
}
24+
} else {
25+
for window in raw.windows(ANCHOR_SET_SIZE) {
26+
insert(&mut sets, window);
27+
}
1928
}
2029
Self { sets }
2130
}

0 commit comments

Comments
 (0)