Skip to content

Commit

Permalink
Summonerd: Fix sorting order, use rank + 1 in message
Browse files Browse the repository at this point in the history
The sorting order was previously reversed, giving us lowest bids first,
which is the opposite of what we want.

It's also clearer if one uses rank + 1, so that one sees, e.g. 1/2
instead of 0/2
  • Loading branch information
cronokirby committed Oct 12, 2023
1 parent d1da8b1 commit 5de1b33
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/summonerd/src/coordinator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, time::Duration};
use std::{cmp, collections::HashMap, time::Duration};

use anyhow::{anyhow, Result};
use penumbra_keys::Address;
Expand Down Expand Up @@ -42,13 +42,15 @@ impl ContributionHandler {
#[tracing::instrument(skip(self))]
pub async fn run(mut self) -> Result<()> {
loop {
tracing::debug!("start of contribution handler loop");
let (who, participant) = match self.start_contribution_rx.recv().await {
None => {
tracing::debug!("start channel closed.");
return Ok(());
}
Some((w, p)) => (w, p),
};
tracing::debug!(?who, "waiting for contribution");
self.contribute(who, participant).await?;
self.done_contribution_tx.send(()).await?;
}
Expand Down Expand Up @@ -80,6 +82,7 @@ impl ContributionHandler {
let parent = self.storage.current_crs().await?;
let maybe = participant.contribute(&parent).await?;
if let Some(unvalidated) = maybe {
tracing::debug!("validating contribution");
if let Some(contribution) =
unvalidated.validate(&mut OsRng, &self.storage.root().await?)
{
Expand Down Expand Up @@ -131,7 +134,7 @@ impl ParticipantQueue {

fn score(&self) -> Vec<Address> {
let mut out: Vec<Address> = self.participants.keys().cloned().collect();
out.sort_by_cached_key(|addr| self.participants[addr].1);
out.sort_by_cached_key(|addr| cmp::Reverse(self.participants[addr].1));
out
}

Expand All @@ -146,7 +149,7 @@ impl ParticipantQueue {
.get(address)
.expect("Ranked participants are chosen from the set of connections");
if let Err(e) =
connection.try_notify(i as u32, ranked.len() as u32, contributor_bid, *bid)
connection.try_notify((i + 1) as u32, ranked.len() as u32, contributor_bid, *bid)
{
tracing::info!(?e, ?address, "pruning connection that we failed to notify");
self.participants.remove(address);
Expand Down

0 comments on commit 5de1b33

Please sign in to comment.