From 7ef570fc17b3565dbc4668f72288b87e91afdc98 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:29:20 -0500 Subject: [PATCH] fix: set AutoSealConsensus best_block correctly (#6612) --- crates/consensus/auto-seal/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 3fb6c02ca220..47bfca4f7ff0 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -186,15 +186,17 @@ pub(crate) struct Storage { // == impl Storage === impl Storage { - fn new(header: SealedHeader) -> Self { - let (header, best_hash) = header.split(); + /// Initializes the [Storage] with the given best block. This should be initialized with the + /// highest block in the chain, if there is a chain already stored on-disk. + fn new(best_block: SealedHeader) -> Self { + let (header, best_hash) = best_block.split(); let mut storage = StorageInner { best_hash, total_difficulty: header.difficulty, best_block: header.number, ..Default::default() }; - storage.headers.insert(0, header); + storage.headers.insert(header.number, header); storage.bodies.insert(best_hash, BlockBody::default()); Self { inner: Arc::new(RwLock::new(storage)) } }