Skip to content

Commit 631448f

Browse files
committed
fix: mempool etag
1 parent 6c036d2 commit 631448f

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/api/controllers/cache-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ async function calculateETag(
141141
principal,
142142
etagType == ETagType.principalMempool
143143
);
144-
if (!activity.length) return ETAG_EMPTY;
145-
return sha256(activity.join(':'));
144+
if (!activity.confirmed && !activity.mempool) return ETAG_EMPTY;
145+
return sha256(`${activity.confirmed ?? ''}:${activity.mempool ?? ''}`);
146146
}
147147
} catch (error) {
148148
logger.error(error, `Unable to calculate ${etagType} etag`);

src/datastore/pg-store.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4447,24 +4447,23 @@ export class PgStore extends BasePgStore {
44474447
* Retrieves the last transaction IDs with STX, FT or NFT activity for a principal, with or
44484448
* without mempool transactions.
44494449
* @param includeMempool - include mempool transactions
4450-
* @returns a list of transaction IDs
4450+
* @returns the last confirmed and mempool transaction IDs for the principal
44514451
*/
44524452
async getPrincipalLastActivityTxIds(
44534453
principal: string,
44544454
includeMempool: boolean = false
4455-
): Promise<string[]> {
4456-
const result = await this.sql<{ tx_id: string }[]>`
4457-
WITH activity AS (
4458-
(
4455+
): Promise<{ confirmed: string | null; mempool: string | null }> {
4456+
const result = await this.sql<{ confirmed: string | null; mempool: string | null }[]>`
4457+
SELECT (
44594458
SELECT '0x' || encode(tx_id, 'hex') AS tx_id
44604459
FROM principal_txs
44614460
WHERE principal = ${principal} AND canonical = true AND microblock_canonical = true
44624461
ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC
44634462
LIMIT 1
4464-
)
4463+
) AS confirmed,
44654464
${
44664465
includeMempool
4467-
? this.sql`UNION
4466+
? this.sql`
44684467
(
44694468
SELECT '0x' || encode(tx_id, 'hex') AS tx_id
44704469
FROM mempool_txs
@@ -4475,12 +4474,11 @@ export class PgStore extends BasePgStore {
44754474
ORDER BY receipt_time DESC
44764475
LIMIT 1
44774476
)`
4478-
: this.sql``
4477+
: this.sql`NULL`
44794478
}
4480-
)
4481-
SELECT tx_id FROM activity WHERE tx_id IS NOT NULL
4479+
AS mempool
44824480
`;
4483-
return result.map(r => r.tx_id);
4481+
return result[0];
44844482
}
44854483

44864484
/** Returns the `index_block_hash` and canonical status of a single block */

src/datastore/pg-write-store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,9 +1404,9 @@ export class PgWriteStore extends PgStore {
14041404
const addPrincipal = (principal: string, data?: Partial<PrincipalRow>) => {
14051405
const entry = principals.get(principal);
14061406
principals.set(principal, {
1407-
stx: entry?.stx ?? data?.stx ?? false,
1408-
ft: entry?.ft ?? data?.ft ?? false,
1409-
nft: entry?.nft ?? data?.nft ?? false,
1407+
stx: entry?.stx || data?.stx || false,
1408+
ft: entry?.ft || data?.ft || false,
1409+
nft: entry?.nft || data?.nft || false,
14101410
stx_sent: (entry?.stx_sent ?? 0n) + (data?.stx_sent ?? 0n),
14111411
stx_received: (entry?.stx_received ?? 0n) + (data?.stx_received ?? 0n),
14121412
stx_mints: (entry?.stx_mints ?? 0) + (data?.stx_mints ?? 0),

0 commit comments

Comments
 (0)