Skip to content

Commit

Permalink
fixup! refactor(storage): merge counters with headers table
Browse files Browse the repository at this point in the history
  • Loading branch information
CHr15F0x committed Mar 8, 2024
1 parent 1edb7cf commit 6f5ea9c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Binary file modified crates/rpc/fixtures/mainnet.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/storage/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl<'inner> Transaction<'inner> {
block_number: BlockNumber,
counts: &StateUpdateCounts,
) -> anyhow::Result<()> {
state_update::insert_state_update_counts(self, block_number, counts)
state_update::update_state_update_counts(self, block_number, counts)
}

pub fn state_update(&self, block: BlockId) -> anyhow::Result<Option<StateUpdate>> {
Expand Down
17 changes: 11 additions & 6 deletions crates/storage/src/connection/state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,29 @@ pub(super) fn insert_state_update(
}

/// Inserts a [StateUpdateCounts] instance into storage.
pub(super) fn insert_state_update_counts(
pub(super) fn update_state_update_counts(
tx: &Transaction<'_>,
block_number: BlockNumber,
counts: &StateUpdateCounts,
) -> anyhow::Result<()> {
let mut stmt = tx
.inner()
.prepare_cached(
"INSERT INTO block_headers (block_number, storage_diffs, nonce_updates, declared_classes, deployed_contracts) VALUES (?, ?, ?, ?, ?)",
r"UPDATE block_headers SET
storage_diffs_count=?,
nonce_updates_count=?,
declared_classes_count=?,
deployed_contracts_count=?
WHERE number=?",
)
.context("Preparing insert statement")?;

stmt.execute(params![
&block_number,
&counts.storage_diffs,
&counts.nonce_updates,
&counts.declared_classes,
&counts.deployed_contracts
&counts.deployed_contracts,
&block_number,
])
.context("Inserting state update counts")?;

Expand Down Expand Up @@ -326,8 +331,8 @@ pub(super) fn state_update_counts(
let mut stmt = tx
.inner()
.prepare_cached(
r"SELECT storage_diffs, nonce_updates, declared_classes, deployed_contracts
FROM block_headers WHERE block_number >= ? ORDER BY block_number ASC LIMIT ?",
r"SELECT storage_diffs_count, nonce_updates_count, declared_classes_count, deployed_contracts_count
FROM block_headers WHERE number >= ? ORDER BY number ASC LIMIT ?",
)
.context("Preparing get state update counts statement")?;

Expand Down

0 comments on commit 6f5ea9c

Please sign in to comment.