Skip to content

Commit 7373cbf

Browse files
authored
fix(db): use ru height for history indices & events instead of using the host block number (#11)
* fix(db): update ru history indices instead of using the host block number This will cause issues since we're not providing the correct number for changeset updates on the L2. * fix(db): Insert enters to `SignetEvents` table with their RU height * chore(db): rename every ambiguous height parameter to ru height or host, where appropriate * chore: clippy
1 parent 118c62f commit 7373cbf

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

crates/db/src/provider.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ where
4343
BlockNumReader::last_block_number(&self.0)
4444
}
4545

46-
fn insert_journal_hash(&self, rollup_height: u64, hash: B256) -> ProviderResult<()> {
47-
self.tx_ref().put::<JournalHashes>(rollup_height, hash)?;
46+
fn insert_journal_hash(&self, ru_height: u64, hash: B256) -> ProviderResult<()> {
47+
self.tx_ref().put::<JournalHashes>(ru_height, hash)?;
4848
Ok(())
4949
}
5050

51-
fn remove_journal_hash(&self, rollup_height: u64) -> ProviderResult<()> {
52-
self.tx_ref().delete::<JournalHashes>(rollup_height, None)?;
51+
fn remove_journal_hash(&self, ru_height: u64) -> ProviderResult<()> {
52+
self.tx_ref().delete::<JournalHashes>(ru_height, None)?;
5353
Ok(())
5454
}
5555

56-
fn get_journal_hash(&self, rollup_height: u64) -> ProviderResult<Option<B256>> {
57-
self.tx_ref().get::<JournalHashes>(rollup_height).map_err(Into::into)
56+
fn get_journal_hash(&self, ru_height: u64) -> ProviderResult<Option<B256>> {
57+
self.tx_ref().get::<JournalHashes>(ru_height).map_err(Into::into)
5858
}
5959

6060
fn latest_journal_hash(&self) -> ProviderResult<B256> {
@@ -67,9 +67,9 @@ where
6767
/// Insert an enter into the DB
6868
/// This is a signet-specific function that inserts an enter event into the
6969
/// [`SignetEvents`] table.
70-
fn insert_enter(&self, height: u64, index: u64, enter: Enter) -> ProviderResult<()> {
70+
fn insert_enter(&self, ru_height: u64, index: u64, enter: Enter) -> ProviderResult<()> {
7171
self.tx_ref()
72-
.put::<SignetEvents>(height, DbSignetEvent::Enter(index, enter))
72+
.put::<SignetEvents>(ru_height, DbSignetEvent::Enter(index, enter))
7373
.map_err(Into::into)
7474
}
7575

@@ -78,23 +78,29 @@ where
7878
/// into the [`SignetEvents`] table.
7979
fn insert_enter_token(
8080
&self,
81-
height: u64,
81+
ru_height: u64,
8282
index: u64,
8383
enter_token: EnterToken,
8484
) -> ProviderResult<()> {
85-
self.tx_ref().put::<SignetEvents>(height, DbSignetEvent::EnterToken(index, enter_token))?;
85+
self.tx_ref()
86+
.put::<SignetEvents>(ru_height, DbSignetEvent::EnterToken(index, enter_token))?;
8687
Ok(())
8788
}
8889

8990
/// Insert a Transact into the DB
9091
/// This is a signet-specific function that inserts a transact event into the
9192
/// [`SignetEvents`] table.
92-
fn insert_transact(&self, height: u64, index: u64, transact: &Transact) -> ProviderResult<()> {
93+
fn insert_transact(
94+
&self,
95+
ru_height: u64,
96+
index: u64,
97+
transact: &Transact,
98+
) -> ProviderResult<()> {
9399
// this is unfortunate, but probably fine because the large part is the
94100
// shared Bytes object.
95101
let t = transact.clone();
96102
self.tx_ref()
97-
.put::<SignetEvents>(height, DbSignetEvent::Transact(index, t))
103+
.put::<SignetEvents>(ru_height, DbSignetEvent::Transact(index, t))
98104
.map_err(Into::into)
99105
}
100106

@@ -453,24 +459,24 @@ where
453459

454460
let mut index: u64 = 0;
455461
for enter in enters.into_iter() {
456-
self.insert_enter(host_height, index, enter)?;
457-
debug!(host_height, index, "inserted enter");
462+
self.insert_enter(ru_height, index, enter)?;
463+
debug!(ru_height, index, "inserted enter");
458464
index += 1;
459465
}
460466

461467
for enter_token in enter_tokens.into_iter() {
462-
self.insert_enter_token(host_height, index, enter_token)?;
463-
debug!(host_height, index, "inserted enter token");
468+
self.insert_enter_token(ru_height, index, enter_token)?;
469+
debug!(ru_height, index, "inserted enter token");
464470
index += 1;
465471
}
466472

467473
for transact in transacts.into_iter() {
468-
self.insert_transact(host_height, index, &transact)?;
469-
debug!(host_height, index, "inserted transact");
474+
self.insert_transact(ru_height, index, &transact)?;
475+
debug!(ru_height, index, "inserted transact");
470476
index += 1;
471477
}
472478

473-
self.update_history_indices(host_height..=host_height)?;
479+
self.update_history_indices(ru_height..=ru_height)?;
474480

475481
self.update_pipeline_stages(ru_height, false)?;
476482

0 commit comments

Comments
 (0)