Skip to content

Commit 1936ba6

Browse files
authored
feat: ingestion and querying for new PoX-2 events (#1403)
* test: Rosetta PoX-2 rewards and unlock events * feat: progress on parsing and writing PoX2 events to postgres * feat: sql insert for pox2 event data * feat: reading pox2 event data from db, sql constraints on named pox event types * feat: db-controller and initial GET route for reading & parsing pox2 events * chore: progress on e2e testing for pox-2 delegation functionality * chore: e2e testing for pox-2 delegation commit operation * chore: e2e testing for pox-2 delegate-stack-increase * chore: e2e testing for pox-2 delegate-stack-extend * chore: e2e testing for pox-2 handle-unlock (missed reward slot) * chore: lint fix, possible test fix * chore: validation tests for each of the pox2-event payloads * chore: potential test fixes * chore: test fixes num 2 * chore: additional flaky test fixes * feat: use pox2-events table to calculate account STX locked amount in /extended/v1/address balance endpoints * chore: Rosetta integration tests for using segwit address in stacking operation * test: ensure stacks RPC reports expected locked balance after Rosetta lock op * chore: bump to latest pox2-events stacks-node image * chore: move pox2-event parsing code into separate file * ci: bump stacks2.1 test suite time to account for longer block mining interval from latest stacks-node changes * chore: speed up tests with better "wait for pox cycle" logic * ci: test fixes * fix: adjustments to `handle-unlock` processing * feat: add support for latest additions to pox2: `stack-aggregation-commit-indexed` and `stack-aggregation-increase` * chore: integration tests for `stack-aggregation-commit-indexed` and `stack-aggregation-increase` pox2 event handling * feat: store pox_v1_unlock_height as singleton in pg * chore: initial setup for stacks-2.1 transition test suite * chore: fix pox_state migrations * feat: make account balance drop pox1-locked state after pox_v1_unlock_height is reached * fix: rosetta block unlock events were limited to one account * fix: off-by-one bug causing accounts to be reported as unlocked one block too early * feat: add burn_block_height to db chainTip and /extended/status * chore: fix datastore-tests from new status endpoint field * chore: fix datastore-tests from new status endpoint field, second pass * fix: adjust pox2_events query to handle special case with `handle-unlock` * feat: add `contract_name` processing for the `stx_lock_event`, see stacks-network/stacks-core#3413 * chore: bump to latest stacks-network/stacks-core#3415 * chore: add account balance test for consistency between RPC and API balances throughout pox transition * ci: matrix for stacks2.1-transition tests * chore: start of Rosetta pox transition period tests * chore: test Rosetta account balance endpoint in pox-2 stacking test suite * ci: use unique account key for pox-2 rosetta test suite * chore: test for pox_v1_unlock_height in Rosetta pox transition tests * chore: refactor giant pox-2 test file into multiple files, run separately in ci * feat: generate synthetic Rosetta stx unlock operations for the pox_v1_unlock_height block * feat: generate Rosetta unlock operations from pox2 auto-unlock events * fix: store locked balance from `handle-unlock` event rather than resetting to zero * chore: remove todos * chore: remove todos * chore: remove no-longer correct sanity check * chore: address PR feedback, composite index for pox2_events ordering
1 parent 6cd5083 commit 1936ba6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5999
-967
lines changed

.github/workflows/ci.yml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@ jobs:
346346
parallel: true
347347

348348
test-2_1:
349+
strategy:
350+
matrix:
351+
suite: [
352+
pox-2-auto-unlock,
353+
pox-2-btc-address-formats,
354+
pox-2-delegate-aggregation,
355+
pox-2-delegate-stacking,
356+
pox-2-stack-extend-increase,
357+
pox-2-rosetta
358+
]
349359
runs-on: ubuntu-latest
350360
steps:
351361
- uses: actions/checkout@v2
@@ -382,7 +392,7 @@ jobs:
382392
npm run devenv:logs:2.1 -- --no-color &> docker-compose-logs.txt &
383393
384394
- name: Run tests
385-
run: npm run test:2.1
395+
run: npm run test:2.1 -- --testPathPattern "${{ matrix.suite }}"
386396

387397
- name: Print integration environment logs
388398
run: cat docker-compose-logs.txt
@@ -404,6 +414,72 @@ jobs:
404414
flag-name: run-${{ github.job }}
405415
parallel: true
406416

417+
test-2_1-transition:
418+
strategy:
419+
matrix:
420+
suite: [
421+
Stacking on pox-2 after pox-1 force unlock,
422+
Consistent API and RPC account balances through pox transitions,
423+
Rosetta - Stacks 2.1 transition tests,
424+
]
425+
runs-on: ubuntu-latest
426+
steps:
427+
- uses: actions/checkout@v2
428+
429+
- name: Use Node.js
430+
uses: actions/setup-node@v2
431+
with:
432+
node-version-file: '.nvmrc'
433+
434+
- name: Cache node modules
435+
uses: actions/cache@v2
436+
env:
437+
cache-name: cache-node-modules
438+
with:
439+
path: |
440+
~/.npm
441+
**/node_modules
442+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
443+
restore-keys: |
444+
${{ runner.os }}-build-${{ env.cache-name }}-
445+
${{ runner.os }}-build-
446+
${{ runner.os }}-
447+
448+
- name: Install deps
449+
run: npm ci --audit=false
450+
451+
- name: Setup env vars
452+
run: echo "STACKS_CORE_EVENT_HOST=http://0.0.0.0" >> $GITHUB_ENV
453+
454+
- name: Setup integration environment
455+
run: |
456+
sudo ufw disable
457+
npm run devenv:deploy:2.1-transition -- -d
458+
npm run devenv:logs:2.1-transition -- --no-color &> docker-compose-logs.txt &
459+
460+
- name: Run tests
461+
run: npm run test:2.1-transition -- -t "${{ matrix.suite }}"
462+
463+
- name: Print integration environment logs
464+
run: cat docker-compose-logs.txt
465+
if: failure()
466+
467+
- name: Teardown integration environment
468+
run: npm run devenv:stop:2.1-transition
469+
if: always()
470+
471+
- name: Upload coverage to Codecov
472+
uses: codecov/codecov-action@v2
473+
if: always()
474+
475+
- name: Upload coverage to Coveralls
476+
uses: coverallsapp/github-action@master
477+
if: always()
478+
with:
479+
github-token: ${{ secrets.github_token }}
480+
flag-name: run-${{ github.job }}
481+
parallel: true
482+
407483
test-rosetta:
408484
runs-on: ubuntu-latest
409485
steps:
@@ -647,6 +723,7 @@ jobs:
647723
needs:
648724
- test
649725
- test-2_1
726+
- test-2_1-transition
650727
- test-bns
651728
- test-rosetta
652729
- test-rosetta-cli-construction
@@ -666,6 +743,7 @@ jobs:
666743
- lint-docs
667744
- test
668745
- test-2_1
746+
- test-2_1-transition
669747
- test-bns
670748
- test-rosetta
671749
- test-rosetta-cli-construction

.vscode/launch.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,28 @@
227227
"outputCapture": "std",
228228
"console": "integratedTerminal",
229229
"preLaunchTask": "deploy:krypton",
230-
"postDebugTask": "stop:krypton"
230+
"postDebugTask": "stop:krypton",
231+
"smartStep": false,
232+
"sourceMaps": true,
233+
},
234+
{
235+
"type": "node",
236+
"request": "launch",
237+
"name": "Jest: 2.1 transition",
238+
"program": "${workspaceFolder}/node_modules/.bin/jest",
239+
"args": [
240+
"--testTimeout=3600000",
241+
"--runInBand",
242+
"--no-cache",
243+
"--config",
244+
"${workspaceRoot}/tests/jest.config.2.1-transition.js",
245+
],
246+
"outputCapture": "std",
247+
"console": "integratedTerminal",
248+
"preLaunchTask": "deploy:krypton-2.1-transition",
249+
"postDebugTask": "stop:krypton-2.1-transition",
250+
"smartStep": false,
251+
"sourceMaps": true,
231252
},
232253
{
233254
"type": "node",

docker/docker-compose.dev.stacks-krypton-2.1-transition.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
version: '3.7'
22
services:
33
stacks-blockchain:
4-
image: "zone117x/stacks-api-e2e:stacks2.1-transition-a7d904e"
4+
image: "zone117x/stacks-api-e2e:stacks2.1-transition-feat-segwit-events-8fb6fad"
55
ports:
66
- "18443:18443" # bitcoin regtest JSON-RPC interface
77
- "18444:18444" # bitcoin regtest p2p
88
- "20443:20443" # stacks-node RPC interface
99
- "20444:20444" # stacks-node p2p
1010
environment:
11-
MINE_INTERVAL: 2s
12-
REWARD_RECIPIENT: STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN
11+
MINE_INTERVAL: 0.1s
12+
# REWARD_RECIPIENT: STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN
1313
STACKS_EVENT_OBSERVER: host.docker.internal:3700
1414
# STACKS_LOG_TRACE: 1
1515
# STACKS_LOG_DEBUG: 1

docker/docker-compose.dev.stacks-krypton.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22
services:
33
stacks-blockchain:
4-
image: "zone117x/stacks-api-e2e:stacks2.1-a7d904e"
4+
image: "zone117x/stacks-api-e2e:stacks2.1-feat-segwit-events-8fb6fad"
55
ports:
66
- "18443:18443" # bitcoin regtest JSON-RPC interface
77
- "18444:18444" # bitcoin regtest p2p

docs/api/info/get-status.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"type": "string",
1616
"description": "the current server status"
1717
},
18+
"pox_v1_unlock_height": {
19+
"type": "integer",
20+
"nullable": true
21+
},
1822
"chain_tip": {
1923
"$ref": "../../entities/info/chain-tip.schema.json"
2024
}

docs/entities/info/chain-tip.schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"required": [
77
"block_height",
88
"block_hash",
9-
"index_block_hash"
9+
"index_block_hash",
10+
"burn_block_height"
1011
],
1112
"properties": {
1213
"block_height": {
@@ -28,6 +29,10 @@
2829
"microblock_sequence": {
2930
"type": "integer",
3031
"description": "the current microblock sequence number"
32+
},
33+
"burn_block_height": {
34+
"type": "integer",
35+
"description": "the current burn chain block height"
3136
}
3237
}
3338
}

docs/generated.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ export interface ServerStatusResponse {
16091609
* the current server status
16101610
*/
16111611
status: string;
1612+
pox_v1_unlock_height?: number;
16121613
chain_tip?: ChainTip;
16131614
}
16141615
/**
@@ -1635,6 +1636,10 @@ export interface ChainTip {
16351636
* the current microblock sequence number
16361637
*/
16371638
microblock_sequence?: number;
1639+
/**
1640+
* the current burn chain block height
1641+
*/
1642+
burn_block_height: number;
16381643
}
16391644
/**
16401645
* GET request that returns network target block times

migrations/1605100253938_stx_lock_events.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ exports.up = pgm => {
5757
type: 'string',
5858
notNull: true,
5959
},
60+
contract_name: {
61+
type: 'string',
62+
notNull: true,
63+
}
6064
});
6165

6266
pgm.createIndex('stx_lock_events', [
@@ -71,4 +75,5 @@ exports.up = pgm => {
7175
pgm.createIndex('stx_lock_events', 'locked_address', { method: 'hash' });
7276
pgm.createIndex('stx_lock_events', [{ name: 'block_height', sort: 'DESC' }]);
7377
pgm.createIndex('stx_lock_events', [{ name: 'unlock_height', sort: 'DESC' }]);
78+
pgm.createIndex('stx_lock_events', 'contract_name');
7479
}

migrations/1643755236533_chain_tip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
exports.up = pgm => {
33
pgm.createMaterializedView('chain_tip', {}, `
44
WITH block_tip AS (
5-
SELECT block_height, block_hash, index_block_hash
5+
SELECT block_height, block_hash, index_block_hash, burn_block_height
66
FROM blocks
77
WHERE block_height = (SELECT MAX(block_height) FROM blocks WHERE canonical = TRUE)
88
),

0 commit comments

Comments
 (0)