Skip to content

Commit 892d276

Browse files
greged93frisitano
andauthored
fix: database startup (#279)
* fix: database startup state * feat: improve logging --------- Co-authored-by: frisitano <[email protected]>
1 parent 387ed9f commit 892d276

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

crates/database/db/src/operations.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,22 @@ pub trait DatabaseOperations: DatabaseConnectionProvider {
352352
///
353353
/// This method first unwinds the database to the finalized L1 block. It then fetches the batch
354354
/// info for the latest safe L2 block. It takes note of the L1 block number at which
355-
/// this batch was produced. It then retrieves the latest block for the previous batch
356-
/// (i.e., the batch before the latest safe block). It returns a tuple of this latest
357-
/// fetched block and the L1 block number of the batch.
355+
/// this batch was produced (currently the finalized block for the batch until we implement
356+
/// issue #273). It then retrieves the latest block for the previous batch (i.e., the batch
357+
/// before the latest safe block). It returns a tuple of this latest fetched block and the
358+
/// L1 block number of the batch.
358359
async fn prepare_on_startup(
359360
&self,
360361
genesis_hash: B256,
361362
) -> Result<(Option<BlockInfo>, Option<u64>), DatabaseError> {
362363
tracing::trace!(target: "scroll::db", "Fetching startup safe block from database.");
364+
365+
// Unwind the database to the last finalized L1 block saved in database.
363366
let finalized_block_number = self.get_finalized_l1_block_number().await?.unwrap_or(0);
364367
self.unwind(genesis_hash, finalized_block_number).await?;
368+
369+
// Fetch the latest safe L2 block and the block number where its associated batch was
370+
// finalized.
365371
let safe = if let Some(batch_info) = self
366372
.get_latest_safe_l2_info()
367373
.await?
@@ -377,7 +383,10 @@ pub trait DatabaseOperations: DatabaseConnectionProvider {
377383
.await?
378384
.expect("Batch info must be present due to database query arguments");
379385
let l2_block = self.get_highest_block_for_batch_hash(previous_batch.hash).await?;
380-
(l2_block, Some(batch.block_number))
386+
(
387+
l2_block,
388+
Some(batch.finalized_block_number.expect("All blocks in database are finalized")),
389+
)
381390
} else {
382391
(None, None)
383392
};

crates/engine/src/driver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ where
237237
) -> Option<EngineDriverEvent> {
238238
match result {
239239
EngineDriverFutureResult::BlockImport(result) => {
240-
tracing::info!(target: "scroll::engine", ?result, "handling block import result");
240+
tracing::trace!(target: "scroll::engine", ?result, "handling block import result");
241241

242242
match result {
243243
Ok((block_info, block_import_outcome, payload_status)) => {
@@ -265,7 +265,7 @@ where
265265
}
266266
}
267267
EngineDriverFutureResult::L1Consolidation(result) => {
268-
tracing::info!(target: "scroll::engine", ?result, "handling L1 consolidation result");
268+
tracing::trace!(target: "scroll::engine", ?result, "handling L1 consolidation result");
269269

270270
match result {
271271
Ok(consolidation_outcome) => {
@@ -301,7 +301,7 @@ where
301301
}
302302
}
303303
EngineDriverFutureResult::PayloadBuildingJob(result) => {
304-
tracing::info!(target: "scroll::engine", result = ?result.as_ref().map(|b| b.header.as_ref()), "handling payload building result");
304+
tracing::trace!(target: "scroll::engine", result = ?result.as_ref().map(|b| b.header.as_ref()), "handling payload building result");
305305

306306
match result {
307307
Ok(block) => {
@@ -326,7 +326,7 @@ where
326326
}
327327
}
328328
EngineDriverFutureResult::OptimisticSync(result) => {
329-
tracing::info!(target: "scroll::engine", ?result, "handling optimistic sync result");
329+
tracing::trace!(target: "scroll::engine", ?result, "handling optimistic sync result");
330330

331331
match result {
332332
Err(err) => {
@@ -412,7 +412,7 @@ where
412412

413413
if let EngineDriverError::PayloadBuildingMissingPayloadId(attributes) = err
414414
{
415-
tracing::info!(target: "scroll::engine", "retrying payload building job for missing payload id");
415+
tracing::warn!(target: "scroll::engine", "retrying payload building job for missing payload id");
416416
this.sequencer_payload_attributes = Some(attributes);
417417
this.waker.wake();
418418
}

0 commit comments

Comments
 (0)