Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
feat: improve fork diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Jan 18, 2021
1 parent 0e4d05f commit dbf9807
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ impl Section {
}

// TODO: handle forks
self.chain
.merge(other.chain)
.map_err(|_| Error::InvalidMessage)?;
match self.chain.merge(other.chain.clone()) {
Ok(()) => (),
Err(_) => {
error!(
"fork attempt detected: new chain: {:?}, new prefix: ({:b}), current chain: {:?}, current prefix: ({:b})",
other.chain.keys().format("->"),
other.prefix(),
self.chain.keys().format("->"),
self.prefix(),
);
return Err(Error::InvalidMessage);
}
}

match cmp_section_chain_position(
&self.elders_info.proof,
Expand Down Expand Up @@ -136,10 +146,12 @@ impl Section {
.push(new_elders_info.proof.public_key, new_key_proof.signature)
{
error!(
"fork attempt detected: new key: {:?}, expected current key: {:?}, actual current chain: {:?}",
"fork attempt detected: new key: {:?}, new prefix: ({:b}), expected current key: {:?}, current chain: {:?}, current prefix: ({:b})",
new_elders_info.proof.public_key,
new_elders_info.value.prefix,
new_key_proof.public_key,
self.chain.keys().format("->"),
self.prefix(),
);
return false;
}
Expand Down

0 comments on commit dbf9807

Please sign in to comment.