Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
37bdb83
feat: handle pox-3 force unlocks
zone117x Dec 1, 2023
0359fe7
chore: todo note
zone117x Dec 8, 2023
aad6cca
feat: handle pox-3 force unlocks, pox-4 events, and revoke-delegate-s…
zone117x Dec 9, 2023
f1e3ff0
chore: rename pox-2 file
zone117x Dec 9, 2023
cd7b3ff
chore: simplified pox route paths
zone117x Dec 9, 2023
cddfaa2
feat: add migration to create pox4_events table
zone117x Dec 9, 2023
9f1541b
test: follow redirects in test fetch helper
zone117x Dec 9, 2023
bed4c6e
chore: fix storing different pox version events
zone117x Dec 9, 2023
85ec974
test: fix tests with missing pox4_events
zone117x Dec 9, 2023
dd9813a
chore: move delegations lookup endpoint into pox router
zone117x Dec 9, 2023
3b4325e
fix: handle pox4_events during reorgs
zone117x Dec 9, 2023
d0b2f09
test: fix pox4events reorg count
zone117x Dec 9, 2023
3f7f144
chore: update stacks-node image to stacks 3.0
zone117x Dec 9, 2023
007bae3
test: begin transitioning pox tests to use pox-4
zone117x Dec 9, 2023
753b8a4
chore: bump stacks-node to wip nakamoto branch
zone117x Dec 10, 2023
7e5d368
test: switch more tests from pox-3 to pox-4
zone117x Dec 10, 2023
6b7d5f4
fix: tx fee fall back in faucet
zone117x Dec 10, 2023
b7bf986
test: update delegation check endpoints
zone117x Dec 10, 2023
ff6c611
chore: isolate error in delegate-revoke test
zone117x Dec 10, 2023
fbdf822
chore: pox3 to pox4 misc renames
zone117x Dec 10, 2023
d5fb7d1
ci: rename 2.4 to 2.5
zone117x Dec 10, 2023
f8b4aa8
test: remove no-longer applicable delegate-stx while stacking test
zone117x Dec 10, 2023
d8c91d5
chore: remove incorrect commend in pox4 test
zone117x Dec 12, 2023
f46a19e
Merge branch 'nakamoto' into feat/pox-3-force-unlocks
zone117x Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api/info/get-status.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"type": "integer",
"nullable": true
},
"pox_v3_unlock_height": {
"type": "integer",
"nullable": true
},
"chain_tip": {
"$ref": "../../entities/info/chain-tip.schema.json"
}
Expand Down
1 change: 1 addition & 0 deletions docs/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@ export interface ServerStatusResponse {
status: string;
pox_v1_unlock_height?: number;
pox_v2_unlock_height?: number;
pox_v3_unlock_height?: number;
chain_tip?: ChainTip;
}
/**
Expand Down
8 changes: 8 additions & 0 deletions migrations/1701368149776_nakamoto-txs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
exports.up = pgm => {
pgm.addColumn('pox_state', {
pox_v3_unlock_height: {
type: 'bigint',
notNull: true,
default: 0,
},
});

pgm.addColumns('txs', {
// `nakamoto-coinbase` tx types
coinbase_vrf_proof: 'bytea',
Expand Down
203 changes: 203 additions & 0 deletions migrations/1702134678728_pox_4_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
exports.up = pgm => {
// Adds pox4_events table which matches previous pox2_events table
pgm.createTable('pox4_events', {
id: {
type: 'bigserial',
primaryKey: true,
},
event_index: {
type: 'integer',
notNull: true,
},
tx_id: {
notNull: true,
type: 'bytea',
},
tx_index: {
type: 'smallint',
notNull: true,
},
block_height: {
type: 'integer',
notNull: true,
},
index_block_hash: {
type: 'bytea',
notNull: true,
},
parent_index_block_hash: {
type: 'bytea',
notNull: true,
},
microblock_hash: {
type: 'bytea',
notNull: true,
},
microblock_sequence: {
type: 'integer',
notNull: true,
},
microblock_canonical: {
type: 'boolean',
notNull: true,
},
canonical: {
type: 'boolean',
notNull: true,
},
stacker: {
type: 'string',
notNull: true,
},
locked: {
type: 'numeric',
notNull: true,
},
balance: {
type: 'numeric',
notNull: true,
},
burnchain_unlock_height: {
type: 'bigint',
notNull: true,
},
name: {
type: 'string',
notNull: true,
},
pox_addr: {
type: 'string',
},
pox_addr_raw: {
type: 'bytea',
},
first_cycle_locked: {
// unique to handle-unlock
type: 'numeric',
},
first_unlocked_cycle: {
// unique to handle-unlock
type: 'numeric',
},
delegate_to: {
// unique to delegate-stx
type: 'string',
},
lock_period: {
// unique to stack-stx, delegate-stack-stx
type: 'numeric',
},
lock_amount: {
// unique to stack-stx, delegate-stack-stx
type: 'numeric',
},
start_burn_height: {
// unique to stack-stx, delegate-stack-stx
type: 'numeric',
},
unlock_burn_height: {
// unique to stack-stx, stack-extend, delegate-stack-stx, delegate-stack-extend, delegate-stx
type: 'numeric',
},
delegator: {
// unique to delegate-stack-stx, delegate-stack-increase, delegate-stack-extend
type: 'string',
},
increase_by: {
// unique to stack-increase, delegate-stack-increase
type: 'numeric',
},
total_locked: {
// unique to stack-increase, delegate-stack-increase
type: 'numeric',
},
extend_count: {
// unique to stack-extend, delegate-stack-extend
type: 'numeric',
},
reward_cycle: {
// unique to stack-aggregation-*
type: 'numeric',
},
amount_ustx: {
// unique to stack-aggregation-*, delegate-stx
type: 'numeric',
},
});

pgm.addConstraint(
'pox4_events',
'valid_event_specific_columns',
`CHECK (
CASE name
WHEN 'handle-unlock' THEN
first_cycle_locked IS NOT NULL AND
first_unlocked_cycle IS NOT NULL
WHEN 'stack-stx' THEN
lock_period IS NOT NULL AND
lock_amount IS NOT NULL AND
start_burn_height IS NOT NULL AND
unlock_burn_height IS NOT NULL
WHEN 'stack-increase' THEN
increase_by IS NOT NULL AND
total_locked IS NOT NULL
WHEN 'stack-extend' THEN
extend_count IS NOT NULL AND
unlock_burn_height IS NOT NULL
WHEN 'delegate-stx' THEN
amount_ustx IS NOT NULL AND
delegate_to IS NOT NULL
WHEN 'delegate-stack-stx' THEN
lock_period IS NOT NULL AND
lock_amount IS NOT NULL AND
start_burn_height IS NOT NULL AND
unlock_burn_height IS NOT NULL AND
delegator IS NOT NULL
WHEN 'delegate-stack-increase' THEN
increase_by IS NOT NULL AND
total_locked IS NOT NULL AND
delegator IS NOT NULL
WHEN 'delegate-stack-extend' THEN
extend_count IS NOT NULL AND
unlock_burn_height IS NOT NULL AND
delegator IS NOT NULL
WHEN 'stack-aggregation-commit' THEN
reward_cycle IS NOT NULL AND
amount_ustx IS NOT NULL
WHEN 'stack-aggregation-commit-indexed' THEN
reward_cycle IS NOT NULL AND
amount_ustx IS NOT NULL
WHEN 'stack-aggregation-increase' THEN
reward_cycle IS NOT NULL AND
amount_ustx IS NOT NULL
ELSE false
END
)`
);

pgm.createIndex('pox4_events', [
{ name: 'block_height', sort: 'DESC' },
{ name: 'microblock_sequence', sort: 'DESC' },
{ name: 'tx_index', sort: 'DESC' },
{ name: 'event_index', sort: 'DESC' },
]);

pgm.createIndex('pox4_events', 'tx_id');
pgm.createIndex('pox4_events', 'index_block_hash');
pgm.createIndex('pox4_events', 'microblock_hash');

pgm.createIndex('pox4_events', 'stacker');
pgm.createIndex('pox4_events', 'burnchain_unlock_height');
pgm.createIndex('pox4_events', 'pox_addr');
pgm.createIndex('pox4_events', 'delegator');
pgm.createIndex('pox4_events', 'name');

pgm.createIndex('pox4_events', 'delegate_to');
pgm.createIndex('pox4_events', 'unlock_burn_height');
};

/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
exports.down = pgm => {
pgm.dropTable('pox4_events');
};
40 changes: 24 additions & 16 deletions src/api/controllers/db-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ import {
BaseTx,
DbMinerReward,
StxUnlockEvent,
DbPox2Event,
DbPox3Event,
DbPoxSyntheticEvent,
} from '../../datastore/common';
import { unwrapOptional, FoundOrNot, unixEpochToIso, EMPTY_HASH_256, ChainID } from '../../helpers';
import { serializePostCondition, serializePostConditionMode } from '../serializers/post-conditions';
import { getOperations, parseTransactionMemo } from '../../rosetta/rosetta-helpers';
import { PgStore } from '../../datastore/pg-store';
import { Pox2EventName } from '../../pox-helpers';
import { SyntheticPoxEventName } from '../../pox-helpers';
import { logger } from '../../logger';

export function parseTxTypeStrings(values: string[]): TransactionType[] {
Expand Down Expand Up @@ -193,7 +192,7 @@ export function getAssetEventTypeString(
}
}

export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
export function parsePoxSyntheticEvent(poxEvent: DbPoxSyntheticEvent) {
const baseInfo = {
block_height: poxEvent.block_height,
tx_id: poxEvent.tx_id,
Expand All @@ -208,7 +207,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
name: poxEvent.name,
};
switch (poxEvent.name) {
case Pox2EventName.HandleUnlock: {
case SyntheticPoxEventName.HandleUnlock: {
return {
...baseInfo,
data: {
Expand All @@ -217,7 +216,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.StackStx: {
case SyntheticPoxEventName.StackStx: {
return {
...baseInfo,
data: {
Expand All @@ -228,7 +227,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.StackIncrease: {
case SyntheticPoxEventName.StackIncrease: {
return {
...baseInfo,
data: {
Expand All @@ -237,7 +236,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.StackExtend: {
case SyntheticPoxEventName.StackExtend: {
return {
...baseInfo,
data: {
Expand All @@ -246,7 +245,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.DelegateStx: {
case SyntheticPoxEventName.DelegateStx: {
return {
...baseInfo,
data: {
Expand All @@ -256,7 +255,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.DelegateStackStx: {
case SyntheticPoxEventName.DelegateStackStx: {
return {
...baseInfo,
data: {
Expand All @@ -268,7 +267,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.DelegateStackIncrease: {
case SyntheticPoxEventName.DelegateStackIncrease: {
return {
...baseInfo,
data: {
Expand All @@ -278,7 +277,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.DelegateStackExtend: {
case SyntheticPoxEventName.DelegateStackExtend: {
return {
...baseInfo,
data: {
Expand All @@ -288,7 +287,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.StackAggregationCommit: {
case SyntheticPoxEventName.StackAggregationCommit: {
return {
...baseInfo,
data: {
Expand All @@ -297,7 +296,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.StackAggregationCommitIndexed: {
case SyntheticPoxEventName.StackAggregationCommitIndexed: {
return {
...baseInfo,
data: {
Expand All @@ -306,7 +305,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case Pox2EventName.StackAggregationIncrease: {
case SyntheticPoxEventName.StackAggregationIncrease: {
return {
...baseInfo,
data: {
Expand All @@ -315,8 +314,17 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
},
};
}
case SyntheticPoxEventName.RevokeDelegateStx: {
return {
...baseInfo,
data: {
amount_ustx: poxEvent.data.amount_ustx.toString(),
delegate_to: poxEvent.data.delegate_to,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious where this part is in the stacks-core codebase (haven't been able to find, would love to peek at that code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
};
}
default:
throw new Error(`Unexpected Pox2 event name ${(poxEvent as DbPox2Event).name}`);
throw new Error(`Unexpected Pox2 event name ${(poxEvent as DbPoxSyntheticEvent).name}`);
}
}

Expand Down
Loading