Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/app/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{pin::Pin, task::Poll};

use futures::{FutureExt, Stream, ready};
use pin_project_lite::pin_project;
use std::{pin::Pin, task::Poll};
use void_types::Block;

#[cfg(test)]
Expand Down Expand Up @@ -95,9 +94,11 @@ where
*this.post_extension = Some(post_extension);
break Some((block, derived));
} else if let Some(block) = ready!(this.stream.as_mut().poll_next(cx)) {
let state_transition_func = this.state_transition_func.take().unwrap();
let pre_extension = this.pre_extension.take().unwrap();
let post_extension = this.post_extension.take().unwrap();
// Process block.
let state_transition_func =
this.state_transition_func.take().expect("is always Some");
let pre_extension = this.pre_extension.take().expect("is always Some");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought that the pre and post extensions were optional and might very well be None... I may have imagined that though.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, ignore my previous comment, this is fine in this context.

let post_extension = this.post_extension.take().expect("is always Some");
let state = this.state.clone();
this.access_fut.set(Some(
async move {
Expand All @@ -120,6 +121,7 @@ where
.boxed(),
));
} else {
// Stream ended.
break None;
}
})
Expand Down
17 changes: 10 additions & 7 deletions crates/app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![deny(missing_docs)]
//! This create provides helpers for building streams that turn blocks into state and state into proofs.

use std::collections::VecDeque;
use std::pin::Pin;
use std::task::Poll;
use tracing::{Instrument, debug, error, info, instrument, instrument::Instrumented, warn};

use futures::FutureExt;
use futures::Stream;
use futures::ready;
use pin_project_lite::pin_project;
use std::collections::VecDeque;
use std::pin::Pin;
use std::task::Poll;
use tracing::{Instrument, debug, error, info, instrument, instrument::Instrumented, warn};
use void_types::Block;
use void_types::Height;
use void_types::Signed;
Expand Down Expand Up @@ -434,6 +433,7 @@ where
*this.state_transition_func = Some(state_transition_func);
break Some((block, derived));
} else if let Some(block) = ready!(this.stream.as_mut().poll_next(cx)) {
// Process block.
let state_transition_func = this.state_transition_func.take().unwrap();
let state = this.state.clone();
this.access_fut.set(Some(
Expand All @@ -449,6 +449,7 @@ where
.boxed(),
));
} else {
// Stream ended.
break None;
}
})
Expand Down Expand Up @@ -697,12 +698,14 @@ impl Notification {

/// Notify all receivers.
pub fn notify(&self) {
// Ignore send error - if no receivers are listening, notification can be dropped
let _ = self.tx.send(());
}

/// Wait for a notification.
pub async fn wait(&mut self) {
let _ = self.rx.changed().await;
/// Returns an error if the sender has been dropped.
pub async fn wait(&mut self) -> Result<(), tokio::sync::watch::error::RecvError> {
self.rx.changed().await
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ impl<T> Lock<T> {
where
F: FnOnce(&mut T) -> R,
{
let mut lock = self.lock.lock().unwrap();
// Not attempting poison recovery.
let mut lock = self.lock.lock().expect("poisoned lock");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is ok? We're trying to build our software to avoid panics so I would think that a PoisonError should never happen in production. (Not in general, but in parts ofvoid-base dealing with locks specifically).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's poisoned then something has panicked so the only thing you can really do is also panic

f(&mut lock)
}
}
Expand Down