Skip to content

Commit 7119318

Browse files
authored
Merge pull request #2237 from hirosystems/develop
Cut release `v8.8.0-beta.1`
2 parents 2634313 + 0fe8fd5 commit 7119318

File tree

13 files changed

+622
-64
lines changed

13 files changed

+622
-64
lines changed

.github/workflows/ci.yml

+40-36
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ jobs:
2626
with:
2727
node-version-file: ".nvmrc"
2828

29+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
30+
- name: Get npm cache directory
31+
id: npm-cache-dir
32+
shell: bash
33+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
34+
2935
- name: Cache node modules
3036
uses: actions/cache@v4
31-
env:
32-
cache-name: cache-node-modules
37+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
3338
with:
34-
path: |
35-
~/.npm
36-
**/node_modules
37-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
39+
path: ${{ steps.npm-cache-dir.outputs.dir }}
40+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
3841
restore-keys: |
39-
${{ runner.os }}-build-${{ env.cache-name }}-
40-
${{ runner.os }}-build-
41-
${{ runner.os }}-
42+
${{ runner.os }}-node-
4243
4344
- name: Install deps
4445
run: npm ci --audit=false
@@ -75,19 +76,20 @@ jobs:
7576
with:
7677
node-version-file: ".nvmrc"
7778

79+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
80+
- name: Get npm cache directory
81+
id: npm-cache-dir
82+
shell: bash
83+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
84+
7885
- name: Cache node modules
7986
uses: actions/cache@v4
80-
env:
81-
cache-name: cache-node-modules
87+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
8288
with:
83-
path: |
84-
~/.npm
85-
**/node_modules
86-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
89+
path: ${{ steps.npm-cache-dir.outputs.dir }}
90+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
8791
restore-keys: |
88-
${{ runner.os }}-build-${{ env.cache-name }}-
89-
${{ runner.os }}-build-
90-
${{ runner.os }}-
92+
${{ runner.os }}-node-
9193
9294
- name: Install deps
9395
run: npm ci --audit=false
@@ -157,19 +159,20 @@ jobs:
157159
with:
158160
node-version-file: ".nvmrc"
159161

162+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
163+
- name: Get npm cache directory
164+
id: npm-cache-dir
165+
shell: bash
166+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
167+
160168
- name: Cache node modules
161169
uses: actions/cache@v4
162-
env:
163-
cache-name: cache-node-modules
170+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
164171
with:
165-
path: |
166-
~/.npm
167-
**/node_modules
168-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
172+
path: ${{ steps.npm-cache-dir.outputs.dir }}
173+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
169174
restore-keys: |
170-
${{ runner.os }}-build-${{ env.cache-name }}-
171-
${{ runner.os }}-build-
172-
${{ runner.os }}-
175+
${{ runner.os }}-node-
173176
174177
- name: Install deps
175178
run: npm ci --audit=false
@@ -220,19 +223,20 @@ jobs:
220223
with:
221224
node-version-file: ".nvmrc"
222225

226+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
227+
- name: Get npm cache directory
228+
id: npm-cache-dir
229+
shell: bash
230+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
231+
223232
- name: Cache node modules
224233
uses: actions/cache@v4
225-
env:
226-
cache-name: cache-node-modules
234+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
227235
with:
228-
path: |
229-
~/.npm
230-
**/node_modules
231-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
236+
path: ${{ steps.npm-cache-dir.outputs.dir }}
237+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
232238
restore-keys: |
233-
${{ runner.os }}-build-${{ env.cache-name }}-
234-
${{ runner.os }}-build-
235-
${{ runner.os }}-
239+
${{ runner.os }}-node-
236240
237241
- name: Install deps
238242
run: npm ci --audit=false

.github/workflows/vercel.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@ jobs:
2020
url: ${{ github.ref_name == 'master' && 'https://stacks-blockchain-api.vercel.app/' || 'https://stacks-blockchain-api-pbcblockstack-blockstack.vercel.app/' }}
2121

2222
steps:
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v4
2424
with:
2525
fetch-depth: 0
2626

2727
- name: Use Node.js
28-
uses: actions/setup-node@v2
28+
uses: actions/setup-node@v4
2929
with:
3030
node-version-file: '.nvmrc'
3131

32+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
33+
- name: Get npm cache directory
34+
id: npm-cache-dir
35+
shell: bash
36+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
37+
3238
- name: Cache node modules
33-
uses: actions/cache@v2
34-
env:
35-
cache-name: cache-node-modules
39+
uses: actions/cache@v4
40+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
3641
with:
37-
path: |
38-
~/.npm
39-
**/node_modules
40-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
42+
path: ${{ steps.npm-cache-dir.outputs.dir }}
43+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
4144
restore-keys: |
42-
${{ runner.os }}-build-${{ env.cache-name }}-
43-
${{ runner.os }}-build-
44-
${{ runner.os }}-
45+
${{ runner.os }}-node-
4546
4647
- name: Install deps
4748
run: npm ci --audit=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// @ts-check
2+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
3+
exports.up = pgm => {
4+
/**
5+
* A previous migration used `order` instead of `sort` in the index definition which caused it to be ignored and default to ASC.
6+
* The `@ts-check` directive at the top of the file will catch these errors in the future.
7+
*/
8+
9+
pgm.dropIndex('principal_stx_txs', [], { name: 'idx_principal_stx_txs_optimized' });
10+
pgm.dropIndex('ft_events', [], { name: 'idx_ft_events_optimized' });
11+
pgm.dropIndex('nft_events', [], { name: 'idx_nft_events_optimized' });
12+
pgm.dropIndex('mempool_txs', [], { name: 'idx_mempool_txs_optimized' });
13+
14+
pgm.createIndex(
15+
'principal_stx_txs',
16+
[
17+
'principal',
18+
{ name: 'block_height', sort: 'DESC' },
19+
{ name: 'microblock_sequence', sort: 'DESC' },
20+
{ name: 'tx_index', sort: 'DESC' }],
21+
{
22+
name: 'idx_principal_stx_txs_optimized',
23+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
24+
}
25+
);
26+
27+
pgm.createIndex(
28+
'nft_events',
29+
[
30+
'sender',
31+
'recipient',
32+
{ name: 'block_height', sort: 'DESC' },
33+
{ name: 'microblock_sequence', sort: 'DESC' },
34+
{ name: 'tx_index', sort: 'DESC' },
35+
{ name: 'event_index', sort: 'DESC' }
36+
],
37+
{
38+
name: 'idx_nft_events_optimized',
39+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
40+
}
41+
);
42+
43+
pgm.createIndex(
44+
'ft_events',
45+
[
46+
'sender',
47+
{ name: 'block_height', sort: 'DESC' },
48+
{ name: 'microblock_sequence', sort: 'DESC' },
49+
{ name: 'tx_index', sort: 'DESC' },
50+
{ name: 'event_index', sort: 'DESC' }
51+
],
52+
{
53+
name: 'idx_ft_events_optimized_sender',
54+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
55+
}
56+
);
57+
58+
pgm.createIndex(
59+
'ft_events',
60+
[
61+
'recipient',
62+
{ name: 'block_height', sort: 'DESC' },
63+
{ name: 'microblock_sequence', sort: 'DESC' },
64+
{ name: 'tx_index', sort: 'DESC' },
65+
{ name: 'event_index', sort: 'DESC' }
66+
],
67+
{
68+
name: 'idx_ft_events_optimized_recipient',
69+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
70+
}
71+
);
72+
73+
pgm.createIndex(
74+
'mempool_txs',
75+
[
76+
{ name: 'receipt_time', sort: 'DESC' }
77+
],
78+
{
79+
name: 'idx_mempool_txs_optimized',
80+
where: 'pruned = FALSE',
81+
}
82+
);
83+
84+
};
85+
86+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
87+
exports.down = pgm => {
88+
pgm.dropIndex('principal_stx_txs', [], { name: 'idx_principal_stx_txs_optimized' });
89+
pgm.dropIndex('ft_events', [], { name: 'idx_ft_events_optimized_sender' });
90+
pgm.dropIndex('ft_events', [], { name: 'idx_ft_events_optimized_recipient' });
91+
pgm.dropIndex('nft_events', [], { name: 'idx_nft_events_optimized' });
92+
pgm.dropIndex('mempool_txs', [], { name: 'idx_mempool_txs_optimized' });
93+
94+
pgm.createIndex(
95+
'principal_stx_txs',
96+
[
97+
'principal',
98+
// @ts-ignore
99+
{ name: 'block_height', order: 'DESC' },
100+
// @ts-ignore
101+
{ name: 'microblock_sequence', order: 'DESC' },
102+
// @ts-ignore
103+
{ name: 'tx_index', order: 'DESC' }],
104+
{
105+
name: 'idx_principal_stx_txs_optimized',
106+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
107+
}
108+
);
109+
110+
pgm.createIndex(
111+
'ft_events',
112+
[
113+
'sender',
114+
'recipient',
115+
// @ts-ignore
116+
{ name: 'block_height', order: 'DESC' },
117+
// @ts-ignore
118+
{ name: 'microblock_sequence', order: 'DESC' },
119+
// @ts-ignore
120+
{ name: 'tx_index', order: 'DESC' },
121+
// @ts-ignore
122+
{ name: 'event_index', order: 'DESC' }
123+
],
124+
{
125+
name: 'idx_ft_events_optimized',
126+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
127+
}
128+
);
129+
130+
pgm.createIndex(
131+
'nft_events',
132+
[
133+
'sender',
134+
'recipient',
135+
// @ts-ignore
136+
{ name: 'block_height', order: 'DESC' },
137+
// @ts-ignore
138+
{ name: 'microblock_sequence', order: 'DESC' },
139+
// @ts-ignore
140+
{ name: 'tx_index', order: 'DESC' },
141+
// @ts-ignore
142+
{ name: 'event_index', order: 'DESC' }
143+
],
144+
{
145+
name: 'idx_nft_events_optimized',
146+
where: 'canonical = TRUE AND microblock_canonical = TRUE',
147+
}
148+
);
149+
150+
pgm.createIndex(
151+
'mempool_txs',
152+
[
153+
'sender_address',
154+
'sponsor_address',
155+
'token_transfer_recipient_address',
156+
// @ts-ignore
157+
{ name: 'receipt_time', order: 'DESC' }
158+
],
159+
{
160+
name: 'idx_mempool_txs_optimized',
161+
where: 'pruned = FALSE',
162+
}
163+
);
164+
};

src/api/controllers/cache-controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { BlockParams } from '../routes/v2/schemas';
1515
* state of the chain depending on the type of information being requested by the endpoint.
1616
* This entry will have an `ETag` string as the value.
1717
*/
18-
enum ETagType {
18+
export enum ETagType {
1919
/** ETag based on the latest `index_block_hash` or `microblock_hash`. */
2020
chainTip = 'chain_tip',
2121
/** ETag based on a digest of all pending mempool `tx_id`s. */
@@ -149,7 +149,7 @@ async function calculateETag(
149149
}
150150
}
151151

152-
async function handleCache(type: ETagType, request: FastifyRequest, reply: FastifyReply) {
152+
export async function handleCache(type: ETagType, request: FastifyRequest, reply: FastifyReply) {
153153
const metrics = getETagMetrics();
154154
const ifNoneMatch = parseIfNoneMatchHeader(request.headers['if-none-match']);
155155
const etag = await calculateETag(request.server.db, type, request);

src/api/pagination.ts

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export enum ResourceType {
4040
PoxCycle,
4141
TokenHolders,
4242
BlockSignerSignature,
43+
FtBalance,
4344
}
4445

4546
export const pagingQueryLimits: Record<ResourceType, { defaultLimit: number; maxLimit: number }> = {
@@ -99,6 +100,10 @@ export const pagingQueryLimits: Record<ResourceType, { defaultLimit: number; max
99100
defaultLimit: 500,
100101
maxLimit: 1000,
101102
},
103+
[ResourceType.FtBalance]: {
104+
defaultLimit: 100,
105+
maxLimit: 200,
106+
},
102107
};
103108

104109
export function getPagingQueryLimit(

src/api/routes/address.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ export const AddressRoutes: FastifyPluginAsync<
9191
{
9292
preHandler: handlePrincipalMempoolCache,
9393
schema: {
94+
deprecated: true,
9495
operationId: 'get_account_stx_balance',
9596
summary: 'Get account STX balance',
96-
description: `Retrieves STX token balance for a given Address or Contract Identifier.`,
97+
description: `**NOTE:** This endpoint is deprecated in favor of [Get address STX balance](/api/get-principal-stx-balance).
98+
99+
Retrieves STX token balance for a given Address or Contract Identifier.`,
97100
tags: ['Accounts'],
98101
params: Type.Object({
99102
principal: PrincipalSchema,
@@ -159,9 +162,12 @@ export const AddressRoutes: FastifyPluginAsync<
159162
{
160163
preHandler: handlePrincipalMempoolCache,
161164
schema: {
165+
deprecated: true,
162166
operationId: 'get_account_balance',
163167
summary: 'Get account balances',
164-
description: `Retrieves total account balance information for a given Address or Contract Identifier. This includes the balances of STX Tokens, Fungible Tokens and Non-Fungible Tokens for the account.`,
168+
description: `**NOTE:** This endpoint is deprecated in favor of [Get address FT balances](/api/get-principal-ft-balances).
169+
170+
Retrieves total account balance information for a given Address or Contract Identifier. This includes the balances of STX Tokens, Fungible Tokens and Non-Fungible Tokens for the account.`,
165171
tags: ['Accounts'],
166172
params: Type.Object({
167173
principal: PrincipalSchema,

0 commit comments

Comments
 (0)