Skip to content

Commit 65141d3

Browse files
committed
apollo_l1_provider: replace bootstrapping with catching up
1 parent df1f0ec commit 65141d3

File tree

9 files changed

+124
-125
lines changed

9 files changed

+124
-125
lines changed

crates/apollo_l1_provider/src/bootstrapper.rs renamed to crates/apollo_l1_provider/src/catchupper.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use starknet_api::block::BlockNumber;
99
use starknet_api::transaction::TransactionHash;
1010
use tracing::debug;
1111

12-
// When the Provider gets a commit_block that is too high, it starts bootstrapping.
12+
// When the Provider gets a commit_block that is too high, it starts catching up.
1313
// The commit is rejected by the provider, so it must use sync to catch up to the height of the
1414
// commit, including that height. The sync task continues until reaching the target height,
1515
// inclusive, and only after the commit_block (from sync) causes the Provider's current height to be
@@ -19,7 +19,7 @@ use tracing::debug;
1919

2020
/// Caches commits to be applied later. This flow is only relevant while the node is starting up.
2121
#[derive(Clone)]
22-
pub struct Bootstrapper {
22+
pub struct Catchupper {
2323
pub target_height: BlockNumber,
2424
pub sync_retry_interval: Duration,
2525
pub commit_block_backlog: Vec<CommitBlockBacklog>,
@@ -30,7 +30,7 @@ pub struct Bootstrapper {
3030
pub n_sync_health_check_failures: Arc<AtomicU8>,
3131
}
3232

33-
impl Bootstrapper {
33+
impl Catchupper {
3434
// FIXME: this isn't added to configs, since this test shouldn't be made here, it should be
3535
// handled through a task management layer.
3636
pub const MAX_HEALTH_CHECK_FAILURES: u8 = 5;
@@ -48,12 +48,12 @@ impl Bootstrapper {
4848
sync_task_handle: SyncTaskHandle::NotStartedYet,
4949
n_sync_health_check_failures: Default::default(),
5050
// This is overriden when starting the sync task (e.g., when provider starts
51-
// bootstrapping).
51+
// catching up).
5252
target_height: BlockNumber(0),
5353
}
5454
}
5555

56-
/// Check if the caller has caught up with the bootstrapper.
56+
/// Check if the caller has caught up with the catchupper.
5757
pub fn is_caught_up(&self, current_provider_height: BlockNumber) -> bool {
5858
let is_caught_up = current_provider_height > self.target_height;
5959

@@ -127,18 +127,18 @@ impl Bootstrapper {
127127
}
128128
}
129129

130-
impl PartialEq for Bootstrapper {
130+
impl PartialEq for Catchupper {
131131
fn eq(&self, other: &Self) -> bool {
132132
self.target_height == other.target_height
133133
&& self.commit_block_backlog == other.commit_block_backlog
134134
}
135135
}
136136

137-
impl Eq for Bootstrapper {}
137+
impl Eq for Catchupper {}
138138

139-
impl std::fmt::Debug for Bootstrapper {
139+
impl std::fmt::Debug for Catchupper {
140140
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
141-
f.debug_struct("Bootstrapper")
141+
f.debug_struct("Catchupper")
142142
.field("target_height", &self.target_height)
143143
.field("commit_block_backlog", &self.commit_block_backlog)
144144
.field("sync_task_handle", &self.sync_task_handle)

crates/apollo_l1_provider/src/l1_provider.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use starknet_api::executable_transaction::L1HandlerTransaction;
2121
use starknet_api::transaction::TransactionHash;
2222
use tracing::{debug, error, info, instrument, trace, warn};
2323

24-
use crate::bootstrapper::Bootstrapper;
24+
use crate::catchupper::Catchupper;
2525
use crate::transaction_manager::TransactionManager;
2626
use crate::L1ProviderConfig;
2727

@@ -35,19 +35,19 @@ pub mod l1_provider_tests;
3535
/// start_height are already committed. The Provider is not interested in any block lower than
3636
/// start_height.
3737
/// - current_height: height of the next block that the Provider expects to see. It means the
38-
/// provider has seen commits forall the previous blocks up to (not including) current_height.
39-
/// - target_height: when bootstrapping, the height to which the bootstrapper will sync. After
40-
/// bootstrapping is done, we expect the current_height to be one above the target_height. If any
41-
/// more blocks are committed while bootstrapping, they are applied after the target_height, and
42-
/// the current_height will be set to one above the last block in the backlog.
38+
/// provider has seen commits for all the previous blocks up to (not including) current_height.
39+
/// - target_height: when catching up, the height to which the catchupper will sync. After catching
40+
/// up is done, we expect the current_height to be one above the target_height. If any more blocks
41+
/// are committed while catching up, they are applied after the target_height, and the
42+
/// current_height will be set to one above the last block in the backlog.
4343
4444
// TODO(Gilad): optimistic proposer support, will add later to keep things simple, but the design
4545
// here is compatible with it.
4646
#[derive(Debug, Clone)]
4747
pub struct L1Provider {
4848
pub config: L1ProviderConfig,
4949
/// Used for catching up at startup or after a crash.
50-
pub bootstrapper: Bootstrapper,
50+
pub catchupper: Catchupper,
5151
/// Represents the L2 block height being built.
5252
pub current_height: BlockNumber,
5353
pub tx_manager: TransactionManager,
@@ -65,14 +65,14 @@ impl L1Provider {
6565
state_sync_client: SharedStateSyncClient,
6666
clock: Option<Arc<dyn Clock>>,
6767
) -> Self {
68-
let bootstrapper = Bootstrapper::new(
68+
let catchupper = Catchupper::new(
6969
l1_provider_client,
7070
state_sync_client,
7171
config.startup_sync_sleep_retry_interval_seconds,
7272
);
7373
Self {
7474
config,
75-
bootstrapper,
75+
catchupper,
7676
current_height: BlockNumber(0),
7777
tx_manager: TransactionManager::new(
7878
config.l1_handler_proposal_cooldown_seconds,
@@ -84,10 +84,10 @@ impl L1Provider {
8484
start_height: None,
8585
}
8686
}
87-
pub fn reset_bootstrapper(&mut self) {
88-
self.bootstrapper = Bootstrapper::new(
89-
self.bootstrapper.l1_provider_client.clone(),
90-
self.bootstrapper.sync_client.clone(),
87+
pub fn reset_catchupper(&mut self) {
88+
self.catchupper = Catchupper::new(
89+
self.catchupper.l1_provider_client.clone(),
90+
self.catchupper.sync_client.clone(),
9191
self.config.startup_sync_sleep_retry_interval_seconds,
9292
);
9393
}
@@ -113,7 +113,7 @@ impl L1Provider {
113113

114114
// The provider now goes into Pending state.
115115
// The current_height is set to a very old height, that doesn't include any of the events
116-
// sent now, or to be scraped in the future. The provider will begin bootstrapping when the
116+
// sent now, or to be scraped in the future. The provider will begin catching up when the
117117
// batcher calls commit_block with a height above the current height.
118118
self.start_height = Some(start_height);
119119
self.current_height = start_height;
@@ -300,14 +300,14 @@ impl L1Provider {
300300
return Ok(());
301301
}
302302

303-
// Reroute this block to bootstrapper, either adding it to the backlog, or applying it and
304-
// ending the bootstrap.
305-
if self.state.is_bootstrapping() {
306-
// Once bootstrap completes it will transition to Pending state by itself.
307-
return self.accept_commit_while_bootstrapping(committed_txs, height);
303+
// Reroute this block to catchupper, either adding it to the backlog, or applying it and
304+
// ending the catchup.
305+
if self.state.is_catching_up() {
306+
// Once catchup completes it will transition to Pending state by itself.
307+
return self.accept_commit_while_catching_up(committed_txs, height);
308308
}
309309

310-
// If not historical height and not bootstrapping, must go into bootstrap state upon getting
310+
// If not historical height and not catching up, must go into catchup state upon getting
311311
// wrong height.
312312
match self.check_height_with_error(height) {
313313
Ok(_) => {
@@ -322,16 +322,16 @@ impl L1Provider {
322322
if self.state.is_uninitialized() {
323323
warn!(
324324
"Provider received a block height ({height}) while it is uninitialized. \
325-
Cannot start bootstrapping until getting the start_height from the \
326-
scraper during the initialize call."
325+
Cannot start catching up until getting the start_height from the scraper \
326+
during the initialize call."
327327
);
328328
} else {
329329
info!(
330330
"Provider received a block_height ({height}) that is higher than the \
331-
current height ({}), starting bootstrapping.",
331+
current height ({}), starting catch-up process.",
332332
self.current_height
333333
);
334-
self.start_bootstrapping(height);
334+
self.start_catching_up(height);
335335
}
336336
Err(err)
337337
}
@@ -340,11 +340,11 @@ impl L1Provider {
340340

341341
// Functions called internally.
342342

343-
/// Go from current state to Bootstrap state and start the L2 sync.
344-
pub fn start_bootstrapping(&mut self, target_height: BlockNumber) {
345-
self.reset_bootstrapper();
346-
self.state = ProviderState::Bootstrap;
347-
self.bootstrapper.start_l2_sync(self.current_height, target_height);
343+
/// Go from current state to CatchingUp state and start the L2 sync.
344+
pub fn start_catching_up(&mut self, target_height: BlockNumber) {
345+
self.reset_catchupper();
346+
self.state = ProviderState::CatchingUp;
347+
self.catchupper.start_l2_sync(self.current_height, target_height);
348348
}
349349

350350
/// Commit the given transactions, and increment the current height.
@@ -361,19 +361,19 @@ impl L1Provider {
361361
self.current_height = self.current_height.unchecked_next();
362362
}
363363

364-
/// Any commit_block call gets rerouted to this function when in bootstrap state.
364+
/// Any commit_block call gets rerouted to this function when in CatchingUp state.
365365
/// - If block number is higher than current height, block is backlogged.
366366
/// - If provider gets a block consistent with current_height, apply it and then the rest of the
367367
/// backlog, then transition to Pending state.
368368
/// - Blocks lower than current height are checked for consistency with existing transactions.
369-
fn accept_commit_while_bootstrapping(
369+
fn accept_commit_while_catching_up(
370370
&mut self,
371371
committed_txs: IndexSet<TransactionHash>,
372372
new_height: BlockNumber,
373373
) -> L1ProviderResult<()> {
374374
let current_height = self.current_height;
375375
debug!(
376-
"Bootstrapper processing commit-block at height: {new_height}, current height is \
376+
"Catchupper processing commit-block at height: {new_height}, current height is \
377377
{current_height}"
378378
);
379379
match new_height.cmp(&current_height) {
@@ -397,7 +397,7 @@ impl L1Provider {
397397
return Ok(());
398398
} else {
399399
// This is either a configuration error or a bug in the
400-
// batcher/sync/bootstrapper.
400+
// batcher/sync/catching up code.
401401
error!(
402402
"Duplicate commit block: commit block for {new_height:?} already \
403403
received, with DIFFERENT transaction_hashes: \
@@ -413,8 +413,8 @@ impl L1Provider {
413413
Equal => self.apply_commit_block(committed_txs, Default::default()),
414414
// We're still syncing, backlog it, it'll get applied later.
415415
Greater => {
416-
self.bootstrapper.add_commit_block_to_backlog(committed_txs, new_height);
417-
// No need to check the backlog or bootstrap completion, since those are only
416+
self.catchupper.add_commit_block_to_backlog(committed_txs, new_height);
417+
// No need to check the backlog or catchup completion, since those are only
418418
// applicable if we just increased the provider's height, like in the `Equal` case.
419419
return Ok(());
420420
}
@@ -423,12 +423,12 @@ impl L1Provider {
423423
// If caught up, apply the backlog and transition to Pending.
424424
// Note that at this point self.current_height is already incremented to the next height, it
425425
// is one more than the latest block that was committed.
426-
if self.bootstrapper.is_caught_up(self.current_height) {
426+
if self.catchupper.is_caught_up(self.current_height) {
427427
info!(
428-
"Bootstrapper sync completed, provider height is now {}, processing backlog...",
428+
"Catch up sync completed, provider height is now {}, processing backlog...",
429429
self.current_height
430430
);
431-
let backlog = std::mem::take(&mut self.bootstrapper.commit_block_backlog);
431+
let backlog = std::mem::take(&mut self.catchupper.commit_block_backlog);
432432
assert!(
433433
backlog.is_empty()
434434
|| self.current_height == backlog.first().unwrap().height
@@ -451,8 +451,8 @@ impl L1Provider {
451451
}
452452

453453
info!(
454-
"Bootstrapping done: commit-block backlog was processed, now transitioning to \
455-
Pending state at new height: {}.",
454+
"Catch up done: commit-block backlog was processed, now transitioning to Pending \
455+
state at new height: {}.",
456456
self.current_height
457457
);
458458

0 commit comments

Comments
 (0)