Skip to content

Commit 37bdb83

Browse files
committed
feat: handle pox-3 force unlocks
1 parent 7c45f53 commit 37bdb83

File tree

9 files changed

+38
-6
lines changed

9 files changed

+38
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"type": "integer",
2424
"nullable": true
2525
},
26+
"pox_v3_unlock_height": {
27+
"type": "integer",
28+
"nullable": true
29+
},
2630
"chain_tip": {
2731
"$ref": "../../entities/info/chain-tip.schema.json"
2832
}

docs/generated.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ export interface ServerStatusResponse {
16691669
status: string;
16701670
pox_v1_unlock_height?: number;
16711671
pox_v2_unlock_height?: number;
1672+
pox_v3_unlock_height?: number;
16721673
chain_tip?: ChainTip;
16731674
}
16741675
/**

migrations/1701368149776_nakamoto-txs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
22
exports.up = pgm => {
3+
pgm.addColumn('pox_state', {
4+
pox_v3_unlock_height: {
5+
type: 'bigint',
6+
notNull: true,
7+
default: 0,
8+
},
9+
});
10+
311
pgm.addColumns('txs', {
412
// `nakamoto-coinbase` tx types
513
coinbase_vrf_proof: 'bytea',

src/api/routes/status.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function createStatusRouter(db: PgStore): express.Router {
1717
if (poxForceUnlockHeights.found) {
1818
response.pox_v1_unlock_height = poxForceUnlockHeights.result.pox1UnlockHeight as number;
1919
response.pox_v2_unlock_height = poxForceUnlockHeights.result.pox2UnlockHeight as number;
20+
response.pox_v3_unlock_height = poxForceUnlockHeights.result.pox3UnlockHeight as number;
2021
}
2122
const chainTip = await db.getChainTip();
2223
if (chainTip.block_height > 0) {

src/datastore/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ export interface DataStoreBlockUpdateData {
569569
txs: DataStoreTxEventData[];
570570
pox_v1_unlock_height?: number;
571571
pox_v2_unlock_height?: number;
572+
pox_v3_unlock_height?: number;
572573
}
573574

574575
export interface DataStoreMicroblockUpdateData {

src/datastore/pg-store.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,17 @@ export class PgStore extends BasePgStore {
287287
});
288288
}
289289

290-
async getPoxForcedUnlockHeightsInternal(
291-
sql: PgSqlClient
292-
): Promise<FoundOrNot<{ pox1UnlockHeight: number | null; pox2UnlockHeight: number | null }>> {
293-
const query = await sql<{ pox_v1_unlock_height: string; pox_v2_unlock_height: string }[]>`
294-
SELECT pox_v1_unlock_height, pox_v2_unlock_height
290+
async getPoxForcedUnlockHeightsInternal(sql: PgSqlClient): Promise<
291+
FoundOrNot<{
292+
pox1UnlockHeight: number | null;
293+
pox2UnlockHeight: number | null;
294+
pox3UnlockHeight: number | null;
295+
}>
296+
> {
297+
const query = await sql<
298+
{ pox_v1_unlock_height: string; pox_v2_unlock_height: string; pox_v3_unlock_height: string }[]
299+
>`
300+
SELECT pox_v1_unlock_height, pox_v2_unlock_height, pox_v3_unlock_height
295301
FROM pox_state
296302
LIMIt 1
297303
`;
@@ -300,10 +306,11 @@ export class PgStore extends BasePgStore {
300306
}
301307
const pox1UnlockHeight = parseInt(query[0].pox_v1_unlock_height) || null;
302308
const pox2UnlockHeight = parseInt(query[0].pox_v2_unlock_height) || null;
309+
const pox3UnlockHeight = parseInt(query[0].pox_v3_unlock_height) || null;
303310
if (pox2UnlockHeight === 0) {
304311
return { found: false };
305312
}
306-
return { found: true, result: { pox1UnlockHeight, pox2UnlockHeight } };
313+
return { found: true, result: { pox1UnlockHeight, pox2UnlockHeight, pox3UnlockHeight } };
307314
}
308315

309316
async getPoxForceUnlockHeights() {

src/datastore/pg-write-store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ export class PgWriteStore extends PgStore {
325325
WHERE pox_v2_unlock_height != ${data.pox_v2_unlock_height}
326326
`;
327327
}
328+
if (isCanonical && data.pox_v3_unlock_height !== undefined) {
329+
// update the pox_state.pox_v3_unlock_height singleton
330+
await sql`
331+
UPDATE pox_state
332+
SET pox_v3_unlock_height = ${data.pox_v3_unlock_height}
333+
WHERE pox_v3_unlock_height != ${data.pox_v3_unlock_height}
334+
`;
335+
}
328336

329337
// When receiving first block, check if "block 0" boot data was received,
330338
// if so, update their properties to correspond to "block 1", since we treat

src/event-stream/core-node-message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export interface CoreNodeBlockMessage {
254254
}[];
255255
pox_v1_unlock_height?: number;
256256
pox_v2_unlock_height?: number;
257+
pox_v3_unlock_height?: number;
257258
}
258259

259260
export interface CoreNodeParsedTxMessage {

src/event-stream/event-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ async function handleBlockMessage(
321321
txs: parseDataStoreTxEventData(parsedTxs, msg.events, msg, chainId),
322322
pox_v1_unlock_height: msg.pox_v1_unlock_height,
323323
pox_v2_unlock_height: msg.pox_v2_unlock_height,
324+
pox_v3_unlock_height: msg.pox_v3_unlock_height,
324325
};
325326

326327
await db.update(dbData);

0 commit comments

Comments
 (0)