Skip to content

Commit 9a159e1

Browse files
authored
feat: SNP integration (#2291)
* chore: upgrade to nodejs LTS (from v20 to v22) * feat: snp integration tests * chore: lint fix * ci: run snp ci step separate * ci: attempt fix on linux with ExtraHosts config * chore: use onceWhen from api-toolkit lib
1 parent a70c3d1 commit 9a159e1

23 files changed

+1031
-56
lines changed

.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,10 @@ STACKS_NODE_TYPE=L1
209209

210210
# Folder with events to be imported by the event-replay.
211211
STACKS_EVENTS_DIR=./events
212+
213+
# If enabled this service will connect to the specified SNP redis server and consume events from the SNP stream.
214+
# This is an alternative to consuming events directly from a stacks-node.
215+
# SNP_EVENT_STREAMING=true
216+
# SNP_REDIS_URL=redis://127.0.0.1:6379
217+
# Only specify `SNP_REDIS_STREAM_KEY_PREFIX` if `REDIS_STREAM_KEY_PREFIX` is configured on the SNP server.
218+
# SNP_REDIS_STREAM_KEY_PREFIX=

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,45 @@ jobs:
131131
token: ${{ secrets.CODECOV_TOKEN }}
132132
if: always()
133133

134+
test-snp:
135+
runs-on: ubuntu-latest
136+
steps:
137+
- uses: actions/checkout@v4
138+
139+
- name: Use Node.js
140+
uses: actions/setup-node@v4
141+
with:
142+
node-version-file: ".nvmrc"
143+
144+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
145+
- name: Get npm cache directory
146+
id: npm-cache-dir
147+
shell: bash
148+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
149+
150+
- name: Cache node modules
151+
uses: actions/cache@v4
152+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
153+
with:
154+
path: ${{ steps.npm-cache-dir.outputs.dir }}
155+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
156+
restore-keys: |
157+
${{ runner.os }}-node-
158+
159+
- name: Install deps
160+
run: npm ci --audit=false
161+
162+
- name: Install client deps
163+
working-directory: client
164+
run: npm ci --audit=false
165+
- name: Run tests
166+
run: npm run test:snp -- --coverage
167+
- name: Upload coverage to Codecov
168+
uses: codecov/codecov-action@v4
169+
with:
170+
token: ${{ secrets.CODECOV_TOKEN }}
171+
if: always()
172+
134173
test-2_5:
135174
strategy:
136175
fail-fast: false

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20
1+
v22

.vscode/launch.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"skipFiles": [
5555
"<node_internals>/**"
5656
],
57-
"runtimeVersion": "20",
57+
"runtimeVersion": "22",
5858
"runtimeArgs": ["-r", "ts-node/register/transpile-only", "-r", "tsconfig-paths/register"],
5959
"args": ["${workspaceFolder}/src/index.ts"],
6060
"outputCapture": "std",
@@ -446,6 +446,23 @@
446446
"STACKS_CHAIN_ID": "0x80000000"
447447
}
448448
},
449+
{
450+
"type": "node",
451+
"request": "launch",
452+
"name": "Jest: SNP",
453+
"program": "${workspaceFolder}/node_modules/.bin/jest",
454+
"args": [
455+
"--testTimeout=3600000",
456+
"--runInBand",
457+
"--no-cache",
458+
"--config",
459+
"${workspaceRoot}/tests/jest.config.snp.js"
460+
],
461+
"outputCapture": "std",
462+
"console": "integratedTerminal",
463+
"nodeVersionHint": 22,
464+
"runtimeVersion": "22"
465+
},
449466
{
450467
"type": "node",
451468
"request": "launch",

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:20-bookworm-slim
1+
FROM node:22-bookworm-slim
22

33
WORKDIR /app
44
COPY . .

docker/rosetta.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ARG ARCHIVE_VERSION=latest
1212

1313
#######################################################################
1414
## Build the stacks-blockchain-api
15-
FROM node:20-bookworm-slim as stacks-blockchain-api-build
15+
FROM node:22-bookworm-slim as stacks-blockchain-api-build
1616
ARG STACKS_API_VERSION
1717
ENV STACKS_API_REPO=hirosystems/stacks-blockchain-api
1818
ENV STACKS_API_VERSION=${STACKS_API_VERSION}

docker/standalone-regtest.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM node:20-bookworm-slim as api-builder
3+
FROM node:22-bookworm-slim as api-builder
44

55
ARG API_GIT_COMMIT
66
ARG STACKS_API_VERSION

migrations/1748256987656_snp-state.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @ts-check
2+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
3+
exports.up = pgm => {
4+
pgm.createTable('snp_state', {
5+
id: {
6+
type: 'boolean',
7+
primaryKey: true,
8+
default: true,
9+
},
10+
last_redis_msg_id: {
11+
type: 'text',
12+
notNull: true,
13+
default: '0',
14+
},
15+
});
16+
// Ensure only a single row can exist
17+
pgm.addConstraint('snp_state', 'snp_state_one_row', 'CHECK(id)');
18+
// Create the single row
19+
pgm.sql('INSERT INTO snp_state VALUES(DEFAULT)');
20+
};
21+
22+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
23+
exports.down = pgm => {
24+
pgm.dropTable('snp_state');
25+
};

0 commit comments

Comments
 (0)