Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add parent check to update_body
  • Loading branch information
Damian Leśniak committed Jan 3, 2023
commit effaadf3297065100c0adb074dbf6672b9b061fd
15 changes: 14 additions & 1 deletion finality-aleph/src/sync/forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub enum Error {
CriticalBug,
JustificationPruned,
HeaderMissingParentID,
ParentNotImported,
}

impl From<VertexError> for Error {
Expand Down Expand Up @@ -299,9 +300,21 @@ impl<I: PeerID, J: Justification> Forest<I, J> {
header: &J::Header,
holder: Option<I>,
) -> Result<HashSet<BlockIdFor<J>>, Error> {
use VertexState::Candidate;
use VertexState::*;
let id = header.id();
let mut modified = self.update_header(header, holder)?;
if let Candidate(vertex) = self.get_mut(&id)? {
let parent_id = vertex.parent().clone().ok_or(Error::MissingParent)?;
match self.get_mut(&parent_id)? {
Unknown | HopelessFork | BelowMinimal => return Err(Error::MissingVertex),
HighestFinalized => (),
Candidate(parent_vertex) => {
if !parent_vertex.is_imported() {
return Err(Error::ParentNotImported);
}
}
};
}
if let Candidate(vertex) = self.get_mut(&id)? {
let summary = vertex.try_insert_body(header)?;
self.process_transition(id, summary, &mut modified)?;
Expand Down
4 changes: 4 additions & 0 deletions finality-aleph/src/sync/forest/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ impl<I: PeerID, J: Justification> Vertex<I, J> {
Ok(self.state()? == (Content::Justification, Importance::Imported))
}

pub fn is_imported(&self) -> bool {
self.importance == Importance::Imported
}

pub fn know_most(&self) -> &HashSet<I> {
&self.know_most
}
Expand Down