Skip to content

Commit df1f0ec

Browse files
committed
apollo_l1_provider: rename catch_up_height and historic height
1 parent a6c9554 commit df1f0ec

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

crates/apollo_l1_provider/src/bootstrapper.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::debug;
2020
/// Caches commits to be applied later. This flow is only relevant while the node is starting up.
2121
#[derive(Clone)]
2222
pub struct Bootstrapper {
23-
pub catch_up_height: BlockNumber,
23+
pub target_height: BlockNumber,
2424
pub sync_retry_interval: Duration,
2525
pub commit_block_backlog: Vec<CommitBlockBacklog>,
2626
pub l1_provider_client: SharedL1ProviderClient,
@@ -49,13 +49,13 @@ impl Bootstrapper {
4949
n_sync_health_check_failures: Default::default(),
5050
// This is overriden when starting the sync task (e.g., when provider starts
5151
// bootstrapping).
52-
catch_up_height: BlockNumber(0),
52+
target_height: BlockNumber(0),
5353
}
5454
}
5555

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

6060
self.sync_task_health_check(is_caught_up);
6161

@@ -84,9 +84,9 @@ impl Bootstrapper {
8484
pub fn start_l2_sync(
8585
&mut self,
8686
current_provider_height: BlockNumber,
87-
catch_up_height: BlockNumber,
87+
target_height: BlockNumber,
8888
) {
89-
self.catch_up_height = catch_up_height;
89+
self.target_height = target_height;
9090
// FIXME: spawning a task like this is evil.
9191
// However, we aren't using the task executor, so no choice :(
9292
// Once we start using a centralized threadpool, spawn through it instead of the
@@ -95,15 +95,15 @@ impl Bootstrapper {
9595
self.l1_provider_client.clone(),
9696
self.sync_client.clone(),
9797
current_provider_height,
98-
catch_up_height,
98+
target_height,
9999
self.sync_retry_interval,
100100
));
101101

102102
self.sync_task_handle = SyncTaskHandle::Started(sync_task_handle.into());
103103
}
104104

105-
pub fn catch_up_height(&self) -> BlockNumber {
106-
self.catch_up_height
105+
pub fn target_height(&self) -> BlockNumber {
106+
self.target_height
107107
}
108108

109109
fn sync_task_health_check(&self, is_caught_up: bool) {
@@ -129,7 +129,7 @@ impl Bootstrapper {
129129

130130
impl PartialEq for Bootstrapper {
131131
fn eq(&self, other: &Self) -> bool {
132-
self.catch_up_height == other.catch_up_height
132+
self.target_height == other.target_height
133133
&& self.commit_block_backlog == other.commit_block_backlog
134134
}
135135
}
@@ -139,7 +139,7 @@ impl Eq for Bootstrapper {}
139139
impl std::fmt::Debug for Bootstrapper {
140140
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
141141
f.debug_struct("Bootstrapper")
142-
.field("catch_up_height", &self.catch_up_height)
142+
.field("target_height", &self.target_height)
143143
.field("commit_block_backlog", &self.commit_block_backlog)
144144
.field("sync_task_handle", &self.sync_task_handle)
145145
.finish_non_exhaustive()
@@ -150,14 +150,14 @@ async fn l2_sync_task(
150150
l1_provider_client: SharedL1ProviderClient,
151151
sync_client: SharedStateSyncClient,
152152
mut current_height: BlockNumber,
153-
catch_up_height: BlockNumber,
153+
target_height: BlockNumber,
154154
retry_interval: Duration,
155155
) {
156-
while current_height <= catch_up_height {
156+
while current_height <= target_height {
157157
// TODO(Gilad): add tracing instrument.
158158
debug!(
159159
"Syncing L1Provider with L2 height: {} to target height: {}",
160-
current_height, catch_up_height
160+
current_height, target_height
161161
);
162162
let block = sync_client.get_block(current_height).await.inspect_err(|err| debug!("{err}"));
163163

crates/apollo_l1_provider/src/l1_provider.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ use crate::L1ProviderConfig;
2929
#[path = "l1_provider_tests.rs"]
3030
pub mod l1_provider_tests;
3131

32+
/// Note on height specification:
33+
/// - start_height: height of the next block after "historic" blocks, meaning blocks that were
34+
/// already proved and sent to L1, and will not be scraped. Transactions from blocks lower than
35+
/// start_height are already committed. The Provider is not interested in any block lower than
36+
/// start_height.
37+
/// - 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.
43+
3244
// TODO(Gilad): optimistic proposer support, will add later to keep things simple, but the design
3345
// here is compatible with it.
3446
#[derive(Debug, Clone)]
@@ -84,7 +96,7 @@ impl L1Provider {
8496
// Start the provider, get first-scrape events, start L2 sync.
8597
pub async fn initialize(
8698
&mut self,
87-
historic_l2_height: BlockNumber,
99+
start_height: BlockNumber,
88100
events: Vec<Event>,
89101
) -> L1ProviderResult<()> {
90102
info!("Initializing l1 provider");
@@ -103,8 +115,8 @@ impl L1Provider {
103115
// The current_height is set to a very old height, that doesn't include any of the events
104116
// sent now, or to be scraped in the future. The provider will begin bootstrapping when the
105117
// batcher calls commit_block with a height above the current height.
106-
self.start_height = Some(historic_l2_height);
107-
self.current_height = historic_l2_height;
118+
self.start_height = Some(start_height);
119+
self.current_height = start_height;
108120
self.state = ProviderState::Pending;
109121
self.add_events(events)?;
110122

@@ -310,7 +322,7 @@ impl L1Provider {
310322
if self.state.is_uninitialized() {
311323
warn!(
312324
"Provider received a block height ({height}) while it is uninitialized. \
313-
Cannot start bootstrapping until getting the historic_height from the \
325+
Cannot start bootstrapping until getting the start_height from the \
314326
scraper during the initialize call."
315327
);
316328
} else {

crates/apollo_l1_provider/src/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ macro_rules! make_bootstrapper {
4343
committed_txs: [$(tx_hash!($tx)),*].into()
4444
}),*
4545
].into_iter().collect(),
46-
catch_up_height: BlockNumber(0),
46+
target_height: BlockNumber(0),
4747
l1_provider_client: Arc::new(FakeL1ProviderClient::default()),
4848
sync_client: Arc::new(MockStateSyncClient::default()),
4949
sync_task_handle: SyncTaskHandle::default(),
@@ -636,7 +636,7 @@ impl L1ProviderClient for FakeL1ProviderClient {
636636

637637
async fn initialize(
638638
&self,
639-
_last_historic_l2_height: BlockNumber,
639+
_start_height: BlockNumber,
640640
_events: Vec<Event>,
641641
) -> L1ProviderClientResult<()> {
642642
todo!()

0 commit comments

Comments
 (0)