fix(exex): do not finalize WAL with a block higher than finalized header (#11420)

This commit is contained in:
Alexey Shekhirin
2024-10-02 14:58:45 +03:00
committed by GitHub
parent b44fff4dd0
commit b66e4f5ad3

View File

@ -350,14 +350,17 @@ where
.collect::<Result<Vec<_>, _>>()?;
if exex_finished_heights.iter().all(|(_, _, is_canonical)| *is_canonical) {
// If there is a finalized header and all ExExs are on the canonical chain, finalize
// the WAL with the lowest finished height among all ExExes
// the WAL with either the lowest finished height among all ExExes, or finalized header
// whichever is lower.
let lowest_finished_height = exex_finished_heights
.iter()
.copied()
.filter_map(|(_, num_hash, _)| num_hash)
.min_by_key(|num_hash| num_hash.number);
self.wal
.finalize(lowest_finished_height.expect("ExExManager has at least one ExEx"))?;
.chain([(finalized_header.num_hash())])
.min_by_key(|num_hash| num_hash.number)
.unwrap();
self.wal.finalize(lowest_finished_height)?;
} else {
let unfinalized_exexes = exex_finished_heights
.into_iter()