From f522d795cef9b3f3ac0f1222b74a261f332c3065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Fri, 5 Apr 2024 10:56:25 -0600 Subject: [PATCH 1/2] fix: batch drop mempool transactions (#1920) (#1927) --- src/datastore/pg-write-store.ts | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/datastore/pg-write-store.ts b/src/datastore/pg-write-store.ts index ed4c463381..4438d4bc7a 100644 --- a/src/datastore/pg-write-store.ts +++ b/src/datastore/pg-write-store.ts @@ -1809,22 +1809,24 @@ export class PgWriteStore extends PgStore { } async dropMempoolTxs({ status, txIds }: { status: DbTxStatus; txIds: string[] }): Promise { - const updateResults = await this.sql<{ tx_id: string }[]>` - WITH pruned AS ( - UPDATE mempool_txs - SET pruned = TRUE, status = ${status} - WHERE tx_id IN ${this.sql(txIds)} AND pruned = FALSE - RETURNING tx_id - ), - count_update AS ( - UPDATE chain_tip SET - mempool_tx_count = mempool_tx_count - (SELECT COUNT(*) FROM pruned), - mempool_updated_at = NOW() - ) - SELECT tx_id FROM pruned - `; - for (const txId of updateResults.map(r => r.tx_id)) { - await this.notifier?.sendTx({ txId }); + for (const batch of batchIterate(txIds, INSERT_BATCH_SIZE)) { + const updateResults = await this.sql<{ tx_id: string }[]>` + WITH pruned AS ( + UPDATE mempool_txs + SET pruned = TRUE, status = ${status} + WHERE tx_id IN ${this.sql(batch)} AND pruned = FALSE + RETURNING tx_id + ), + count_update AS ( + UPDATE chain_tip SET + mempool_tx_count = mempool_tx_count - (SELECT COUNT(*) FROM pruned), + mempool_updated_at = NOW() + ) + SELECT tx_id FROM pruned + `; + for (const txId of updateResults.map(r => r.tx_id)) { + await this.notifier?.sendTx({ txId }); + } } } From c7c9869015207aaa9a83cbd596c2714863d7ba95 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 5 Apr 2024 17:06:01 +0000 Subject: [PATCH 2/2] chore(release): 7.9.1 [skip ci] ## [7.9.1](https://github.com/hirosystems/stacks-blockchain-api/compare/v7.9.0...v7.9.1) (2024-04-05) ### Bug Fixes * batch drop mempool transactions ([#1920](https://github.com/hirosystems/stacks-blockchain-api/issues/1920)) ([#1927](https://github.com/hirosystems/stacks-blockchain-api/issues/1927)) ([f522d79](https://github.com/hirosystems/stacks-blockchain-api/commit/f522d795cef9b3f3ac0f1222b74a261f332c3065)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b0af2e5e6..64a8246881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [7.9.1](https://github.com/hirosystems/stacks-blockchain-api/compare/v7.9.0...v7.9.1) (2024-04-05) + + +### Bug Fixes + +* batch drop mempool transactions ([#1920](https://github.com/hirosystems/stacks-blockchain-api/issues/1920)) ([#1927](https://github.com/hirosystems/stacks-blockchain-api/issues/1927)) ([f522d79](https://github.com/hirosystems/stacks-blockchain-api/commit/f522d795cef9b3f3ac0f1222b74a261f332c3065)) + ## [7.9.0](https://github.com/hirosystems/stacks-blockchain-api/compare/v7.8.2...v7.9.0) (2024-03-15)