Skip to content

Commit 6907bd7

Browse files
committed
fix: clippy
1 parent 9cc3bf2 commit 6907bd7

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

crates/db/src/consistency.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ where
8787
// The updated `highest_block` may have decreased if we healed from a pruning
8888
// interruption.
8989
let mut highest_block = sfp.get_highest_static_file_block(segment);
90-
span.record("highest_block", &highest_block);
90+
span.record("highest_block", highest_block);
9191

9292
if initial_highest_block != highest_block {
9393
update_last_good_height(highest_block.unwrap_or_default());
@@ -100,7 +100,7 @@ where
100100
// being able to update the last block of the static file segment.
101101
let highest_tx = sfp.get_highest_static_file_tx(segment);
102102
if let Some(highest_tx) = highest_tx {
103-
span.record("highest_tx", &highest_tx);
103+
span.record("highest_tx", highest_tx);
104104
let mut last_block = highest_block.unwrap_or_default();
105105
loop {
106106
if let Some(indices) = self.block_body_indices(last_block)? {
@@ -191,13 +191,7 @@ where
191191
// database, then we have most likely lost static file data and
192192
// need to unwind so we can load it again
193193
if !(db_first_entry <= highest_entry || highest_entry + 1 == db_first_entry) {
194-
info!(
195-
?db_first_entry,
196-
?highest_entry,
197-
unwind_target = highest_block,
198-
?segment,
199-
"Setting unwind target."
200-
);
194+
info!(unwind_target = highest_block, "Setting unwind target.");
201195
return Ok(Some(highest_block));
202196
}
203197
}

crates/node/src/node.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::metrics;
22
use alloy::{
33
consensus::BlockHeader,
44
eips::NumHash,
5-
primitives::{B256, b256},
5+
primitives::{B256, BlockNumber, b256},
66
};
77
use eyre::Context;
88
use futures_util::StreamExt;
@@ -25,7 +25,7 @@ use signet_node_config::SignetNodeConfig;
2525
use signet_node_types::{NodeStatus, NodeTypesDbTrait, SignetNodeTypes};
2626
use signet_rpc::RpcServerGuard;
2727
use signet_types::{PairedHeights, constants::SignetSystemConstants};
28-
use std::{fmt, sync::Arc};
28+
use std::{fmt, mem::MaybeUninit, sync::Arc};
2929
use tokio::sync::watch;
3030
use tracing::{debug, info, instrument};
3131

@@ -179,7 +179,9 @@ where
179179
/// errors.
180180
#[instrument(skip(self), fields(host = ?self.host.config.chain.chain()))]
181181
pub async fn start(mut self) -> eyre::Result<()> {
182-
self.ru_provider.ru_check_consistency()?;
182+
if let Some(height) = self.ru_provider.ru_check_consistency()? {
183+
self.unwind_to(height).wrap_err("failed to unwind RU database to consistent state")?;
184+
}
183185

184186
// This exists only to bypass the `tracing::instrument(err)` macro to
185187
// ensure that full sources get reported.
@@ -299,8 +301,7 @@ where
299301
// NB: REVERTS MUST RUN FIRST
300302
let mut reverted = None;
301303
if let Some(chain) = notification.reverted_chain() {
302-
reverted =
303-
self.on_host_revert(&chain).await.wrap_err("error encountered during revert")?;
304+
reverted = self.on_host_revert(&chain).wrap_err("error encountered during revert")?;
304305
}
305306

306307
let mut committed = None;
@@ -614,9 +615,23 @@ where
614615
}
615616
}
616617

618+
/// Unwind the RU chain DB to the target block number.
619+
fn unwind_to(&self, target: BlockNumber) -> eyre::Result<RuChain> {
620+
let mut reverted = MaybeUninit::uninit();
621+
self.ru_provider
622+
.provider_rw()?
623+
.update(|writer| {
624+
reverted.write(writer.ru_take_blocks_and_execution_above(target)?);
625+
Ok(())
626+
})
627+
// SAFETY: if the closure above returns Ok, reverted is initialized.
628+
.map(|_| unsafe { reverted.assume_init() })
629+
.map_err(Into::into)
630+
}
631+
617632
/// Called when the host chain has reverted a block or set of blocks.
618633
#[instrument(skip_all, fields(first = chain.first().number(), tip = chain.tip().number()))]
619-
pub async fn on_host_revert(&self, chain: &Arc<Chain<Host>>) -> eyre::Result<Option<RuChain>> {
634+
pub fn on_host_revert(&self, chain: &Arc<Chain<Host>>) -> eyre::Result<Option<RuChain>> {
620635
// If the end is before the RU genesis, we don't need to do anything at
621636
// all.
622637
if chain.tip().number() <= self.constants.host_deploy_height() {
@@ -632,12 +647,6 @@ where
632647
.unwrap_or_default() // 0 if the block is before the deploy height
633648
.saturating_sub(1); // still 0 if 0, otherwise the block BEFORE.
634649

635-
let mut reverted = None;
636-
self.ru_provider.provider_rw()?.update(|writer| {
637-
reverted = Some(writer.ru_take_blocks_and_execution_above(target)?);
638-
Ok(())
639-
})?;
640-
641-
Ok(reverted)
650+
self.unwind_to(target).map(Some)
642651
}
643652
}

0 commit comments

Comments
 (0)