Skip to content

Commit 72de7d3

Browse files
committed
fix: missing txs from address/transactions endpoint #1119 #1098
1 parent b5f4c46 commit 72de7d3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/datastore/postgres-store.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,10 @@ export class PgDataStore
17061706
);
17071707
}
17081708

1709+
// TODO: [bug] This is can end up with incorrect canonical state due to missing the `index_block_hash` column
1710+
// which is required for the way micro-reorgs are handled. Queries against this table can work around the
1711+
// bug by using the `txs` table canonical state in the JOIN condition.
1712+
17091713
// Update `principal_stx_txs`
17101714
await client.query(
17111715
`UPDATE principal_stx_txs
@@ -5540,15 +5544,17 @@ export class PgDataStore
55405544
WITH stx_txs AS (
55415545
SELECT tx_id, ${countOverColumn()}
55425546
FROM principal_stx_txs
5543-
WHERE principal = $1 AND ${blockCond} AND canonical = TRUE AND microblock_canonical = TRUE
5547+
WHERE principal = $1 AND ${blockCond}
55445548
ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC
55455549
LIMIT $2
55465550
OFFSET $3
55475551
)
55485552
SELECT ${txColumns()}, ${abiColumn()}, count
55495553
FROM stx_txs
5550-
INNER JOIN txs USING (tx_id)
5551-
WHERE canonical = TRUE AND microblock_canonical = TRUE
5554+
INNER JOIN txs
5555+
ON stx_txs.tx_id = txs.tx_id
5556+
AND txs.canonical = TRUE
5557+
AND txs.microblock_canonical = TRUE
55525558
`,
55535559
[args.stxAddress, args.limit, args.offset, args.blockHeight]
55545560
);

0 commit comments

Comments
 (0)