Skip to content

Commit

Permalink
Summonerd: send error message when timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby authored and conorsch committed Nov 13, 2023
1 parent 332185d commit 14e65e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tools/summonerd/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,26 @@ impl Coordinator {
}

#[tracing::instrument(skip_all, fields(address = ?contributor.address().display_short_form()))]
async fn contribute<P: Phase>(&mut self, contributor: Participant) -> Result<()> {
async fn contribute<P: Phase>(&mut self, mut contributor: Participant) -> Result<()> {
let address = contributor.address();
match tokio::time::timeout(
Duration::from_secs(P::contribution_time(self.config)),
self.contribute_inner::<P>(contributor),
self.contribute_inner::<P>(&mut contributor),
)
.await
{
Ok(Ok(_)) => Ok(()),
Err(_) => {
tracing::info!("STRIKE (timeout)");
self.storage.strike(&address).await?;
contributor.try_notify_timeout();
Ok(())
}
Ok(Err(e)) => Err(e),
}
}

async fn contribute_inner<P: Phase>(&mut self, mut contributor: Participant) -> Result<()> {
async fn contribute_inner<P: Phase>(&mut self, contributor: &mut Participant) -> Result<()> {
let address = contributor.address();
let parent = P::current_crs(&self.storage)
.await?
Expand Down
6 changes: 6 additions & 0 deletions tools/summonerd/src/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ impl Participant {
self.tx.send(Ok(response)).await?;
Ok(())
}

pub fn try_notify_timeout(&mut self) {
if let Err(e) = self.tx.try_send(Err(Status::deadline_exceeded("Unfortunately, it took too long to complete your contribution. We only allow a certain amount of time in order to allow as many people as possible to contribute. Your machine has too poor a network connection or processor to contribute fast enough. If you try again, you will run into this error again, and your contribution will still not be included. We kindly ask that you improve your machine if you would like to contribute."))) {
tracing::debug!(?e, "failed to notify of timeout");
}
}
}

0 comments on commit 14e65e0

Please sign in to comment.