Skip to content

Conversation

@clabby
Copy link
Collaborator

@clabby clabby commented Sep 23, 2025

Overview

Swaps the map type in buffered::Engine from HashMap to BTreeMap. This change makes the iteration over values returned by buffered::Mailbox::get deterministically ordered.

I ran into this causing issues in broadcast order over in #1680.

/// Searches through all maintained messages for a match.
fn find_messages(
&mut self,
peer: &Option<P>,
commitment: M::Commitment,
digest: Option<M::Digest>,
all: bool,
) -> Vec<M> {
match peer {
// Only consider messages from the peer filter
Some(s) => self
.deques
.get(s)
.into_iter()
.flat_map(|dq| dq.iter())
.filter(|pair| pair.commitment == commitment)
.filter_map(|pair| {
self.items
.get(&pair.commitment)
.and_then(|m| m.get(&pair.digest))
})
.cloned()
.collect(),
// Search by commitment
None => match self.items.get(&commitment) {
// If there are no messages for the commitment, return an empty vector
None => Vec::new(),
// If there are messages, return the ones that match the digest filter
Some(msgs) => match digest {
// If a digest is provided, return whatever matches it.
Some(dg) => msgs.get(&dg).cloned().into_iter().collect(),
// If no digest was provided, return `all` messages for the commitment.
None if all => msgs.values().cloned().collect(),
None => msgs.values().next().cloned().into_iter().collect(),
},
},
}
}

@BrendanChou BrendanChou self-requested a review September 23, 2025 18:10
Copy link
Contributor

@patrick-ogrady patrick-ogrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, we'd also add some regression test for a case like this? Refer to consensus for some examples of this (run a test on the same seed twice and assert the "Auditor State" is identical).

BrendanChou
BrendanChou previously approved these changes Sep 23, 2025
BrendanChou
BrendanChou previously approved these changes Sep 23, 2025
## Overview

Swaps the map type in `buffered::Engine` from `HashMap` to `BTreeMap`. This change makes the iteration over values returned by `buffered::Mailbox::get` deterministically ordered.
@BrendanChou BrendanChou merged commit 1d01f6a into main Sep 23, 2025
66 checks passed
@BrendanChou BrendanChou deleted the cl/buf-mailbox-order branch September 23, 2025 22:39
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.20%. Comparing base (a0d076b) to head (4bfcbf2).
⚠️ Report is 3 commits behind head on main.

@@           Coverage Diff            @@
##             main    #1687    +/-   ##
========================================
  Coverage   92.20%   92.20%            
========================================
  Files         294      296     +2     
  Lines       75325    75557   +232     
========================================
+ Hits        69456    69670   +214     
- Misses       5869     5887    +18     
Files with missing lines Coverage Δ
broadcast/src/buffered/engine.rs 92.76% <100.00%> (ø)
broadcast/src/buffered/mod.rs 99.55% <100.00%> (+0.03%) ⬆️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b835347...4bfcbf2. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants