Skip to content

Commit 62edb0b

Browse files
committed
update rpc and default optimistic sync threshold
1 parent 355998a commit 62edb0b

File tree

8 files changed

+80
-43
lines changed

8 files changed

+80
-43
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
with:
9393
cache-on-failure: true
9494
- name: Run doc
95-
run: cargo docs --document-private-items
95+
run: cargo docs --document-private-items --exclude rollup-node-chain-orchestrator
9696
env:
9797
RUSTDOCFLAGS: --cfg docsrs --show-type-layout --generate-link-to-definition --enable-index-page -Zunstable-options -D warnings
9898

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export-sample-test-data:
9797

9898
.PHONY: docs
9999
docs:
100-
cargo docs --document-private-items
100+
cargo docs --document-private-items --exclude rollup-node-chain-orchestrator
101101

102102
.PHONY: pr
103103
pr: lint test docs

crates/chain-orchestrator/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,16 @@ impl<
329329
let _ = tx.send(self.event_listener());
330330
}
331331
ChainOrchestratorCommand::Status(tx) => {
332-
let status = ChainOrchestratorStatus {
333-
sync_state: self.sync_state.clone(),
334-
forkchoice_state: self.engine.fcs().clone(),
335-
};
332+
let db_tx = self.database.tx_mut().await?;
333+
let l1_latest = db_tx.get_latest_l1_block_number().await?;
334+
let l1_finalized = db_tx.get_finalized_l1_block_number().await?;
335+
db_tx.commit().await?;
336+
let status = ChainOrchestratorStatus::new(
337+
&self.sync_state,
338+
l1_latest,
339+
l1_finalized,
340+
self.engine.fcs().clone(),
341+
);
336342
let _ = tx.send(status);
337343
}
338344
ChainOrchestratorCommand::NetworkHandle(tx) => {
@@ -697,10 +703,7 @@ impl<
697703

698704
// Get all unprocessed batches that have been finalized by this L1 block
699705
// finalization.
700-
let finalized_block_number = tx
701-
.get_finalized_l1_block_number()
702-
.await?
703-
.expect("finalized block number must exist");
706+
let finalized_block_number = tx.get_finalized_l1_block_number().await?;
704707
if finalized_block_number >= block_number {
705708
let finalized_batches = tx
706709
.fetch_and_update_unprocessed_finalized_batches(finalized_block_number)
@@ -987,7 +990,7 @@ impl<
987990

988991
// If we did not find a common ancestor, we add all the fetched headers to the front of
989992
// the deque and continue fetching.
990-
for header in headers.into_iter() {
993+
for header in headers {
991994
new_headers.push_front(header);
992995
}
993996
}
Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
1-
use super::SyncState;
1+
use crate::sync::{SyncMode, SyncState};
22
use scroll_engine::ForkchoiceState;
33

44
/// The current status of the chain orchestrator.
55
#[derive(Debug, Clone)]
66
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
77
pub struct ChainOrchestratorStatus {
8-
/// The current sync state of the orchestrator.
9-
pub sync_state: SyncState,
10-
/// The current FCS for the manager.
11-
pub forkchoice_state: ForkchoiceState,
8+
/// The chain status for L1.
9+
pub l1: L1ChainStatus,
10+
/// The chain status for L2.
11+
pub l2: L2ChainStatus,
12+
}
13+
14+
impl ChainOrchestratorStatus {
15+
/// Creates a new [`ChainOrchestratorStatus`] from the given sync state, latest L1 block number,
16+
pub fn new(
17+
sync_state: &SyncState,
18+
l1_latest: u64,
19+
l1_finalized: u64,
20+
l2_fcs: ForkchoiceState,
21+
) -> Self {
22+
Self {
23+
l1: L1ChainStatus {
24+
status: sync_state.l1().clone(),
25+
latest: l1_latest,
26+
finalized: l1_finalized,
27+
},
28+
l2: L2ChainStatus { status: sync_state.l2().clone(), fcs: l2_fcs },
29+
}
30+
}
31+
}
32+
33+
/// The status of the L1 chain.
34+
#[derive(Debug, Clone)]
35+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36+
pub struct L1ChainStatus {
37+
/// The sync mode of the chain.
38+
pub status: SyncMode,
39+
/// The latest block number of the chain.
40+
pub latest: u64,
41+
/// The finalized block number of the chain.
42+
pub finalized: u64,
43+
}
44+
45+
/// The status of the L2 chain.
46+
#[derive(Debug, Clone)]
47+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48+
pub struct L2ChainStatus {
49+
/// The sync mode of the chain.
50+
pub status: SyncMode,
51+
/// The current fork choice state of the chain.
52+
#[cfg_attr(feature = "serde", serde(flatten))]
53+
pub fcs: ForkchoiceState,
1254
}

crates/database/db/src/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,4 @@ pub enum DatabaseError {
1919
/// The L1 message was not found in database.
2020
#[error("L1 message at key [{0}] not found in database")]
2121
L1MessageNotFound(L1MessageKey),
22-
/// The finalized L1 block was not found in database.
23-
#[error("Finalized L1 block not found in database")]
24-
FinalizedL1BlockNotFound,
25-
/// The latest L1 block was not found in database.
26-
#[error("Latest L1 block not found in database")]
27-
LatestL1BlockNotFound,
2822
}

crates/database/db/src/operations.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub trait DatabaseWriteOperations: WriteConnectionProvider + DatabaseReadOperati
231231
tracing::trace!(target: "scroll::db", "Fetching startup safe block from database.");
232232

233233
// Unwind the database to the last finalized L1 block saved in database.
234-
let finalized_block_number = self.get_finalized_l1_block_number().await?.unwrap_or(0);
234+
let finalized_block_number = self.get_finalized_l1_block_number().await?;
235235
self.unwind(genesis_hash, finalized_block_number).await?;
236236

237237
// Delete all unprocessed batches from the database and return starting l2 safe head and l1
@@ -528,27 +528,31 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
528528
}
529529

530530
/// Get the latest L1 block number from the database.
531-
async fn get_latest_l1_block_number(&self) -> Result<Option<u64>, DatabaseError> {
531+
async fn get_latest_l1_block_number(&self) -> Result<u64, DatabaseError> {
532532
Ok(models::metadata::Entity::find()
533533
.filter(models::metadata::Column::Key.eq("l1_latest_block"))
534534
.select_only()
535535
.column(models::metadata::Column::Value)
536536
.into_tuple::<String>()
537537
.one(self.get_connection())
538-
.await
539-
.map(|x| x.and_then(|x| x.parse::<u64>().ok()))?)
538+
.await?
539+
.expect("l1_latest_block should always be set")
540+
.parse::<u64>()
541+
.expect("l1_latest_block should always be a valid u64"))
540542
}
541543

542544
/// Get the finalized L1 block number from the database.
543-
async fn get_finalized_l1_block_number(&self) -> Result<Option<u64>, DatabaseError> {
545+
async fn get_finalized_l1_block_number(&self) -> Result<u64, DatabaseError> {
544546
Ok(models::metadata::Entity::find()
545547
.filter(models::metadata::Column::Key.eq("l1_finalized_block"))
546548
.select_only()
547549
.column(models::metadata::Column::Value)
548550
.into_tuple::<String>()
549551
.one(self.get_connection())
550-
.await
551-
.map(|x| x.and_then(|x| x.parse::<u64>().ok()))?)
552+
.await?
553+
.expect("l1_finalized_block should always be set")
554+
.parse::<u64>()
555+
.expect("l1_finalized_block should always be a valid u64"))
552556
}
553557

554558
/// Get the latest L2 head block info.
@@ -701,10 +705,7 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
701705
}
702706
}
703707
Some(L1MessageKey::NotIncluded(NotIncludedStart::Finalized)) => {
704-
let finalized_block_number = self
705-
.get_finalized_l1_block_number()
706-
.await?
707-
.ok_or(DatabaseError::FinalizedL1BlockNotFound)?;
708+
let finalized_block_number = self.get_finalized_l1_block_number().await?;
708709
let condition = Condition::all()
709710
.add(
710711
models::l1_message::Column::L1BlockNumber
@@ -721,10 +722,7 @@ pub trait DatabaseReadOperations: ReadConnectionProvider + Sync {
721722
))
722723
}
723724
Some(L1MessageKey::NotIncluded(NotIncludedStart::BlockDepth(depth))) => {
724-
let latest_block_number = self
725-
.get_latest_l1_block_number()
726-
.await?
727-
.ok_or(DatabaseError::LatestL1BlockNotFound)?;
725+
let latest_block_number = self.get_latest_l1_block_number().await?;
728726

729727
let target_block_number = latest_block_number.checked_sub(depth);
730728
if let Some(target_block_number) = target_block_number {

crates/node/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) const DEFAULT_PAYLOAD_BUILDING_DURATION: u64 = 800;
2727
pub(crate) const DEFAULT_PAYLOAD_SIZE_LIMIT: u64 = 122_880;
2828

2929
/// The gap in blocks between the P2P and EN which triggers sync.
30-
pub(crate) const BLOCK_GAP_TRIGGER: u64 = 100_000;
30+
pub(crate) const BLOCK_GAP_TRIGGER: u64 = 1_000;
3131

3232
/// The number of block headers to keep in the in-memory chain buffer in the chain orchestrator.
3333
pub(crate) const CHAIN_BUFFER_SIZE: usize = 2000;

crates/node/tests/e2e.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ async fn graceful_shutdown_sets_fcs_to_latest_sequenced_block_in_db_on_start_up(
11841184
let status = handle.status().await?;
11851185

11861186
// The fcs should be set to the database head.
1187-
assert_eq!(status.forkchoice_state.head_block_info(), &db_head_block_info);
1187+
assert_eq!(status.l2.fcs.head_block_info(), &db_head_block_info);
11881188

11891189
Ok(())
11901190
}
@@ -1269,8 +1269,8 @@ async fn can_handle_batch_revert() -> eyre::Result<()> {
12691269
let status = handle.status().await?;
12701270

12711271
// Assert the forkchoice state is above 4
1272-
assert!(status.forkchoice_state.head_block_info().number > 4);
1273-
assert!(status.forkchoice_state.safe_block_info().number > 4);
1272+
assert!(status.l2.fcs.head_block_info().number > 4);
1273+
assert!(status.l2.fcs.safe_block_info().number > 4);
12741274

12751275
// Send the third batch which should trigger the revert.
12761276
l1_watcher_tx.send(Arc::new(L1Notification::BatchCommit(revert_batch_data))).await?;
@@ -1281,8 +1281,8 @@ async fn can_handle_batch_revert() -> eyre::Result<()> {
12811281
let status = handle.status().await?;
12821282

12831283
// Assert the forkchoice state was reset to 4.
1284-
assert_eq!(status.forkchoice_state.head_block_info().number, 4);
1285-
assert_eq!(status.forkchoice_state.safe_block_info().number, 4);
1284+
assert_eq!(status.l2.fcs.head_block_info().number, 4);
1285+
assert_eq!(status.l2.fcs.safe_block_info().number, 4);
12861286

12871287
Ok(())
12881288
}

0 commit comments

Comments
 (0)