Skip to content

Commit 646cfa4

Browse files
authored
A0-3422: Deal with too many nonfinalized blocks on startup (#1470)
# 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
1 parent 8cd278d commit 646cfa4

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aleph-node"
3-
version = "0.12.0"
3+
version = "0.12.1"
44
description = "Aleph node binary"
55
build = "build.rs"
66
license = "GPL-3.0-or-later"

finality-aleph/src/sync/forest/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ where
158158
I: PeerId,
159159
J: Justification,
160160
{
161-
pub fn new<B, CS>(chain_status: &CS) -> Result<Self, InitializationError<B, J, CS>>
161+
/// Creates a new forest and returns whether we have too many nonfinalized blocks in the DB.
162+
//TODO(A0-2984): the latter part of the result should be removed after legacy sync is excised
163+
pub fn new<B, CS>(chain_status: &CS) -> Result<(Self, bool), InitializationError<B, J, CS>>
162164
where
163165
B: Block<Header = J::Header>,
164166
CS: ChainStatus<B, J>,
@@ -184,14 +186,17 @@ where
184186
.children(hash)
185187
.map_err(InitializationError::ChainStatus)?;
186188
for header in children.iter() {
187-
forest
188-
.update_body(header)
189-
.map_err(InitializationError::Error)?;
189+
if let Err(e) = forest.update_body(header) {
190+
match e {
191+
Error::TooNew => return Ok((forest, true)),
192+
e => return Err(InitializationError::Error(e)),
193+
}
194+
}
190195
}
191196
deque.extend(children.into_iter().map(|header| header.id()));
192197
}
193198

194-
Ok(forest)
199+
Ok((forest, false))
195200
}
196201

197202
fn special_state(&self, id: &BlockIdFor<J>) -> Option<SpecialState> {
@@ -579,7 +584,8 @@ mod tests {
579584
.expect("should return genesis")
580585
.header()
581586
.clone();
582-
let forest = Forest::new(&backend).expect("should initialize");
587+
let (forest, too_many_nonfinalized) = Forest::new(&backend).expect("should initialize");
588+
assert!(!too_many_nonfinalized);
583589
(header, forest)
584590
}
585591

finality-aleph/src/sync/handler/mod.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,29 @@ where
381381
block_importer,
382382
..
383383
} = database_io;
384-
let forest = Forest::new(&chain_status).map_err(Error::ForestInitialization)?;
384+
let (forest, too_many_nonfinalized) =
385+
Forest::new(&chain_status).map_err(Error::ForestInitialization)?;
386+
let mut missed_import_data = MissedImportData::new();
387+
if too_many_nonfinalized {
388+
missed_import_data
389+
.update(
390+
chain_status
391+
.best_block()
392+
.map_err(Error::ChainStatus)?
393+
.id()
394+
.number(),
395+
&chain_status,
396+
)
397+
.map_err(Error::ChainStatus)?;
398+
}
385399
Ok(Handler {
386400
chain_status,
387401
verifier,
388402
finalizer,
389403
forest,
390404
session_info,
391405
block_importer,
392-
missed_import_data: MissedImportData::new(),
406+
missed_import_data,
393407
phantom: PhantomData,
394408
})
395409
}

0 commit comments

Comments
 (0)