Skip to content

Commit

Permalink
Finish subscription when all hashes have been provided
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Sep 4, 2024
1 parent 74b2a6a commit eb25ff9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ where
};

let mut hashes = HashSet::<Blake3Hash>::from_iter(hashes.into_iter().map(|hash| *hash));
let hash_count = hashes.len();

// The genesis segment isn't included in this stream, see
// `subscribe_archived_object_mappings` for details.
Expand All @@ -906,11 +907,14 @@ where
let objects = archived_segment_notification
.archived_segment
.global_object_mappings()
.filter(|object| hashes.contains(&object.hash))
.filter(|object| hashes.remove(&object.hash))
.collect::<Vec<_>>();

stream::iter(objects)
})
// Stop when we've returned mappings for all the hashes. Since we only yield each hash
// once, we don't need to check if hashes is empty here.
.take(hash_count)
// Typically batches will be larger than the hash limit, but we want to allow CLI
// options to change that.
.ready_chunks(OBJECT_MAPPING_BATCH_SIZE)
Expand Down

0 comments on commit eb25ff9

Please sign in to comment.