Skip to content

Commit 3caf645

Browse files
Use multi_get for next_expected_event. (#4790)
## Motivation The `next_expected_event` is a `MapView` and so we can group the `get` operations. ## Proposal Straightforward from the description. ## Test Plan The CI. ## Release Plan Can be backported to TestNet Conway. ## Links None.
1 parent 4f9e497 commit 3caf645

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

linera-chain/src/chain.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,27 +1210,32 @@ where
12101210
&mut self,
12111211
block: &Block,
12121212
) -> Result<BTreeSet<StreamId>, ChainError> {
1213-
let mut emitted_streams: BTreeMap<StreamId, BTreeSet<u32>> = BTreeMap::new();
1213+
let mut emitted_streams = BTreeMap::<StreamId, BTreeSet<u32>>::new();
12141214
for event in block.body.events.iter().flatten() {
12151215
emitted_streams
12161216
.entry(event.stream_id.clone())
12171217
.or_default()
12181218
.insert(event.index);
12191219
}
1220+
let mut stream_ids = Vec::new();
1221+
let mut list_indices = Vec::new();
1222+
for (stream_id, indices) in emitted_streams {
1223+
stream_ids.push(stream_id);
1224+
list_indices.push(indices);
1225+
}
12201226

12211227
let mut updated_streams = BTreeSet::new();
1222-
for (stream_id, indices) in emitted_streams {
1228+
let next_indices = self.next_expected_events.multi_get(&stream_ids).await?;
1229+
for ((next_index, indices), stream_id) in
1230+
next_indices.into_iter().zip(list_indices).zip(stream_ids)
1231+
{
12231232
let initial_index = if stream_id == StreamId::system(EPOCH_STREAM_NAME) {
12241233
// we don't expect the epoch stream to contain event 0
12251234
1
12261235
} else {
12271236
0
12281237
};
1229-
let mut current_expected_index = self
1230-
.next_expected_events
1231-
.get(&stream_id)
1232-
.await?
1233-
.unwrap_or(initial_index);
1238+
let mut current_expected_index = next_index.unwrap_or(initial_index);
12341239
for index in indices {
12351240
if index == current_expected_index {
12361241
updated_streams.insert(stream_id.clone());

0 commit comments

Comments
 (0)