Skip to content

Commit 64d861d

Browse files
authored
feat: Add logging & metrics for mempool (#3447)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent 7adb612 commit 64d861d

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

core/lib/dal/src/transactions_dal.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ impl TransactionsDal<'_, '_> {
17761776
limit: usize,
17771777
) -> DalResult<Vec<(Transaction, TransactionTimeRangeConstraint)>> {
17781778
let stashed_addresses: Vec<_> = stashed_accounts.iter().map(Address::as_bytes).collect();
1779-
sqlx::query!(
1779+
let result = sqlx::query!(
17801780
r#"
17811781
UPDATE transactions
17821782
SET
@@ -1794,8 +1794,15 @@ impl TransactionsDal<'_, '_> {
17941794
.execute(self.storage)
17951795
.await?;
17961796

1797+
tracing::debug!(
1798+
"Updated {} transactions for stashed accounts, stashed accounts amount: {}, stashed_accounts: {:?}",
1799+
result.rows_affected(),
1800+
stashed_addresses.len(),
1801+
stashed_accounts.iter().map(|a|format!("{:x}", a)).collect::<Vec<_>>()
1802+
);
1803+
17971804
let purged_addresses: Vec<_> = purged_accounts.iter().map(Address::as_bytes).collect();
1798-
sqlx::query!(
1805+
let result = sqlx::query!(
17991806
r#"
18001807
DELETE FROM transactions
18011808
WHERE
@@ -1809,6 +1816,12 @@ impl TransactionsDal<'_, '_> {
18091816
.execute(self.storage)
18101817
.await?;
18111818

1819+
tracing::debug!(
1820+
"Updated {} transactions for purged accounts, purged accounts amount: {}",
1821+
result.rows_affected(),
1822+
purged_addresses.len()
1823+
);
1824+
18121825
// Note, that transactions are updated in order of their hashes to avoid deadlocks with other UPDATE queries.
18131826
let transactions = sqlx::query_as!(
18141827
StorageTransaction,

core/lib/mempool/src/mempool_store.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ impl MempoolStore {
172172
.rfind(|el| el.matches_filter(filter))?
173173
.clone();
174174

175+
let initial_length = self.stashed_accounts.len();
176+
175177
// Stash all observed transactions that don't meet criteria
176178
for stashed_pointer in self
177179
.l2_priority_queue
@@ -187,6 +189,13 @@ impl MempoolStore {
187189

188190
self.stashed_accounts.push(stashed_pointer.account);
189191
}
192+
193+
tracing::debug!(
194+
"Stashed {} accounts by filter: {:?}",
195+
self.stashed_accounts.len() - initial_length,
196+
filter
197+
);
198+
190199
// insert pointer to the next transaction if it exists
191200
let (transaction, constraint, score) = self
192201
.l2_transactions_per_account

core/node/state_keeper/src/mempool_actor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ impl MempoolFetcher {
8383
let latency = KEEPER_METRICS.mempool_sync.start();
8484
let mut storage = self.pool.connection_tagged("state_keeper").await?;
8585
let mempool_info = self.mempool.get_mempool_info();
86+
87+
KEEPER_METRICS
88+
.mempool_stashed_accounts
89+
.set(mempool_info.stashed_accounts.len());
90+
KEEPER_METRICS
91+
.mempool_purged_accounts
92+
.set(mempool_info.purged_accounts.len());
93+
8694
let protocol_version = storage
8795
.blocks_dal()
8896
.pending_protocol_version()

core/node/state_keeper/src/metrics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ pub struct StateKeeperMetrics {
6464
/// Latency to synchronize the mempool with Postgres.
6565
#[metrics(buckets = Buckets::LATENCIES)]
6666
pub mempool_sync: Histogram<Duration>,
67+
/// Number of stashed accounts in mempool
68+
pub mempool_stashed_accounts: Gauge<usize>,
69+
/// Number of purged accounts in mempool
70+
pub mempool_purged_accounts: Gauge<usize>,
6771
/// Latency of the state keeper waiting for a transaction.
6872
#[metrics(buckets = Buckets::LATENCIES)]
6973
pub waiting_for_tx: Histogram<Duration>,

0 commit comments

Comments
 (0)