Skip to content

Commit

Permalink
A0-3422: Deal with too many nonfinalized blocks on startup (#1470)
Browse files Browse the repository at this point in the history
# Description

Make sync handler understand having too many nonfinalized blocks on
startup instead of panicking.

## Type of change

- New feature (non-breaking change which adds functionality)

# Checklist:

- I have made corresponding changes to the existing documentation
- I have created new documentation
  • Loading branch information
timorleph authored Nov 3, 2023
1 parent 8cd278d commit 646cfa4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-node"
version = "0.12.0"
version = "0.12.1"
description = "Aleph node binary"
build = "build.rs"
license = "GPL-3.0-or-later"
Expand Down
18 changes: 12 additions & 6 deletions finality-aleph/src/sync/forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ where
I: PeerId,
J: Justification,
{
pub fn new<B, CS>(chain_status: &CS) -> Result<Self, InitializationError<B, J, CS>>
/// Creates a new forest and returns whether we have too many nonfinalized blocks in the DB.
//TODO(A0-2984): the latter part of the result should be removed after legacy sync is excised
pub fn new<B, CS>(chain_status: &CS) -> Result<(Self, bool), InitializationError<B, J, CS>>
where
B: Block<Header = J::Header>,
CS: ChainStatus<B, J>,
Expand All @@ -184,14 +186,17 @@ where
.children(hash)
.map_err(InitializationError::ChainStatus)?;
for header in children.iter() {
forest
.update_body(header)
.map_err(InitializationError::Error)?;
if let Err(e) = forest.update_body(header) {
match e {
Error::TooNew => return Ok((forest, true)),
e => return Err(InitializationError::Error(e)),
}
}
}
deque.extend(children.into_iter().map(|header| header.id()));
}

Ok(forest)
Ok((forest, false))
}

fn special_state(&self, id: &BlockIdFor<J>) -> Option<SpecialState> {
Expand Down Expand Up @@ -579,7 +584,8 @@ mod tests {
.expect("should return genesis")
.header()
.clone();
let forest = Forest::new(&backend).expect("should initialize");
let (forest, too_many_nonfinalized) = Forest::new(&backend).expect("should initialize");
assert!(!too_many_nonfinalized);
(header, forest)
}

Expand Down
18 changes: 16 additions & 2 deletions finality-aleph/src/sync/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,29 @@ where
block_importer,
..
} = database_io;
let forest = Forest::new(&chain_status).map_err(Error::ForestInitialization)?;
let (forest, too_many_nonfinalized) =
Forest::new(&chain_status).map_err(Error::ForestInitialization)?;
let mut missed_import_data = MissedImportData::new();
if too_many_nonfinalized {
missed_import_data
.update(
chain_status
.best_block()
.map_err(Error::ChainStatus)?
.id()
.number(),
&chain_status,
)
.map_err(Error::ChainStatus)?;
}
Ok(Handler {
chain_status,
verifier,
finalizer,
forest,
session_info,
block_importer,
missed_import_data: MissedImportData::new(),
missed_import_data,
phantom: PhantomData,
})
}
Expand Down

0 comments on commit 646cfa4

Please sign in to comment.