Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use primary error as context of NoWitnessLeft error #477

Merged
merged 1 commit into from
Jul 24, 2020
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
17 changes: 12 additions & 5 deletions light-client/src/peer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ impl<T> PeerList<T> {
/// ## Errors
/// - If there are no witness left, returns `ErrorKind::NoWitnessLeft`.
#[post(ret.is_ok() ==> Self::invariant(&self))]
pub fn replace_faulty_primary(&mut self) -> Result<PeerId, Error> {
pub fn replace_faulty_primary(
&mut self,
primary_error: Option<Error>,
) -> Result<PeerId, Error> {
self.faulty_nodes.insert(self.primary);

if let Some(new_primary) = self.witnesses.iter().next().copied() {
Expand All @@ -145,7 +148,11 @@ impl<T> PeerList<T> {
return Ok(new_primary);
}

bail!(ErrorKind::NoWitnessLeft)
if let Some(err) = primary_error {
bail!(ErrorKind::NoWitnessLeft.context(err))
} else {
bail!(ErrorKind::NoWitnessLeft)
}
}
}

Expand Down Expand Up @@ -281,7 +288,7 @@ mod tests {
fn replace_faulty_primary_succeeds() {
let mut peer_list = dummy_peer_list();
assert_eq!(peer_list.primary(), &1);
let new_primary = peer_list.replace_faulty_primary();
let new_primary = peer_list.replace_faulty_primary(None);
assert_eq!(new_primary.unwrap(), b());
assert_eq!(peer_list.primary(), &2);
assert!(peer_list.witnesses_ids().is_empty());
Expand All @@ -290,8 +297,8 @@ mod tests {
#[test]
fn replace_faulty_primary_fails_if_no_more_witnesses() {
let mut peer_list = dummy_peer_list();
let _ = peer_list.replace_faulty_primary().unwrap();
let new_primary = peer_list.replace_faulty_primary();
let _ = peer_list.replace_faulty_primary(None).unwrap();
let new_primary = peer_list.replace_faulty_primary(None);
assert_eq!(
new_primary.err().map(|e| e.kind().clone()),
Some(ErrorKind::NoWitnessLeft)
Expand Down
6 changes: 2 additions & 4 deletions light-client/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,9 @@ impl Supervisor {
}
}
// Verification failed
Err(_err) => {
// TODO: Log/record error

Err(err) => {
// Swap primary, and continue with new primary, if there is any witness left.
self.peers.replace_faulty_primary()?;
self.peers.replace_faulty_primary(Some(err))?;
Copy link
Member

@liamsi liamsi Jul 24, 2020

Choose a reason for hiding this comment

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

When putting together the light-node, I also stumbled upon this: I was seeing "no witness left" in the log and it wasn't really informing what went wrong.
@romac does anything speak against this approach? The todo is indicating you already had sth in mind for this?

self.verify(height)
}
}
Expand Down