Skip to content

Commit b23445c

Browse files
committed
fix: perform status endpoint sql inside transactions
1 parent a0df9fb commit b23445c

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/api/routes/status.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,25 @@ export const StatusRoutes: FastifyPluginAsync<
2828
status: 'ready',
2929
};
3030
try {
31-
const poxForceUnlockHeights = await fastify.db.getPoxForceUnlockHeights();
32-
if (poxForceUnlockHeights.found) {
33-
response.pox_v1_unlock_height = poxForceUnlockHeights.result.pox1UnlockHeight as number;
34-
response.pox_v2_unlock_height = poxForceUnlockHeights.result.pox2UnlockHeight as number;
35-
response.pox_v3_unlock_height = poxForceUnlockHeights.result.pox3UnlockHeight as number;
36-
}
37-
const chainTip = await fastify.db.getChainTip(fastify.db.sql);
38-
if (chainTip.block_height > 0) {
39-
response.chain_tip = {
40-
block_height: chainTip.block_height,
41-
block_hash: chainTip.block_hash,
42-
index_block_hash: chainTip.index_block_hash,
43-
microblock_hash: chainTip.microblock_hash,
44-
microblock_sequence: chainTip.microblock_sequence,
45-
burn_block_height: chainTip.burn_block_height,
46-
};
47-
}
31+
await fastify.db.sqlTransaction(async sql => {
32+
const poxForceUnlockHeights = await fastify.db.getPoxForcedUnlockHeightsInternal(sql);
33+
if (poxForceUnlockHeights.found) {
34+
response.pox_v1_unlock_height = poxForceUnlockHeights.result.pox1UnlockHeight as number;
35+
response.pox_v2_unlock_height = poxForceUnlockHeights.result.pox2UnlockHeight as number;
36+
response.pox_v3_unlock_height = poxForceUnlockHeights.result.pox3UnlockHeight as number;
37+
}
38+
const chainTip = await fastify.db.getChainTip(sql);
39+
if (chainTip.block_height > 0) {
40+
response.chain_tip = {
41+
block_height: chainTip.block_height,
42+
block_hash: chainTip.block_hash,
43+
index_block_hash: chainTip.index_block_hash,
44+
microblock_hash: chainTip.microblock_hash,
45+
microblock_sequence: chainTip.microblock_sequence,
46+
burn_block_height: chainTip.burn_block_height,
47+
};
48+
}
49+
});
4850
} catch (error) {
4951
// ignore error
5052
}

0 commit comments

Comments
 (0)