Skip to content

Commit a70c3d1

Browse files
authored
feat: add replaced_by_tx_id to replaced mempool transactions (#2271)
* feat: add replacing_tx_id * fix: schema * fix: tweak name * style: lint * style: nit * fix: tests * test: last * fix: revert launch * fix: rbf on insert * fix: rbf upon confirmation * test: sponsored tx * fix: tx counts * style: nit * style: lint * fix: limits * fix: tests * fix: tests 2 * fix: tests 3 * fix: rosetta tests
1 parent 82f3fea commit a70c3d1

18 files changed

+527
-105
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable camelcase */
2+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
3+
4+
exports.up = pgm => {
5+
pgm.addColumn('mempool_txs', {
6+
replaced_by_tx_id: {
7+
type: 'bytea',
8+
}
9+
});
10+
};
11+
12+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-disable camelcase */
2+
3+
exports.shorthands = undefined;
4+
5+
exports.up = pgm => {
6+
pgm.dropIndex('txs', ['sender_address']);
7+
pgm.createIndex('txs', ['sender_address', 'nonce'], {
8+
where: 'canonical = true AND microblock_canonical = true',
9+
});
10+
pgm.dropIndex('txs', ['sponsor_address']);
11+
pgm.createIndex('txs', ['sponsor_address', 'nonce'], {
12+
where: 'sponsor_address IS NOT NULL AND canonical = true AND microblock_canonical = true',
13+
});
14+
};
15+
16+
exports.down = pgm => {
17+
pgm.dropIndex('txs', ['sender_address', 'nonce']);
18+
pgm.createIndex('txs', ['sender_address']);
19+
pgm.dropIndex('txs', ['sponsor_address', 'nonce']);
20+
pgm.createIndex('txs', ['sponsor_address']);
21+
};

src/api/controllers/db-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ function parseDbAbstractMempoolTx(
11471147
const abstractMempoolTx: AbstractMempoolTransaction = {
11481148
...baseTx,
11491149
tx_status: getTxStatusString(dbMempoolTx.status) as MempoolTransactionStatus,
1150+
replaced_by_tx_id: dbMempoolTx.replaced_by_tx_id ?? null,
11501151
receipt_time: dbMempoolTx.receipt_time,
11511152
receipt_time_iso: unixEpochToIso(dbMempoolTx.receipt_time),
11521153
};

src/api/schemas/entities/transactions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ export const AbstractMempoolTransactionProperties = {
429429
description: 'Status of the transaction',
430430
}
431431
),
432+
replaced_by_tx_id: Nullable(
433+
Type.String({
434+
description: 'ID of another transaction which replaced this one',
435+
})
436+
),
432437
receipt_time: Type.Integer({
433438
description:
434439
'A unix timestamp (in seconds) indicating when the transaction broadcast was received by the node.',

src/datastore/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ export interface DbMempoolFeePriority {
306306
export interface DbMempoolTx extends BaseTx {
307307
pruned: boolean;
308308

309+
replaced_by_tx_id?: string;
310+
309311
receipt_time: number;
310312

311313
post_conditions: string;
@@ -897,6 +899,7 @@ export interface MempoolTxQueryResult {
897899
type_id: number;
898900
anchor_mode: number;
899901
status: number;
902+
replaced_by_tx_id?: string;
900903
receipt_time: number;
901904
receipt_block_height: number;
902905

@@ -1242,6 +1245,7 @@ export interface MempoolTxInsertValues {
12421245
type_id: DbTxTypeId;
12431246
anchor_mode: DbTxAnchorMode;
12441247
status: DbTxStatus;
1248+
replaced_by_tx_id: PgBytea | null;
12451249
receipt_time: number;
12461250
receipt_block_height: number;
12471251
post_conditions: PgBytea;

src/datastore/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const MEMPOOL_TX_COLUMNS = [
133133
'type_id',
134134
'anchor_mode',
135135
'status',
136+
'replaced_by_tx_id',
136137
'receipt_time',
137138
'receipt_block_height',
138139
'post_conditions',
@@ -302,6 +303,7 @@ export function parseMempoolTxQueryResult(result: MempoolTxQueryResult): DbMempo
302303
type_id: result.type_id as DbTxTypeId,
303304
anchor_mode: result.anchor_mode as DbTxAnchorMode,
304305
status: result.status,
306+
replaced_by_tx_id: result.replaced_by_tx_id,
305307
receipt_time: result.receipt_time,
306308
post_conditions: result.post_conditions,
307309
fee_rate: BigInt(result.fee_rate),
@@ -1283,6 +1285,7 @@ export function convertTxQueryResultToDbMempoolTx(txs: TxQueryResult[]): DbMempo
12831285
? BigInt(tx.token_transfer_amount)
12841286
: tx.token_transfer_amount,
12851287
sponsor_address: tx.sponsor_address ?? undefined,
1288+
status: DbTxStatus.Pending,
12861289
});
12871290
dbMempoolTxs.push(dbMempoolTx);
12881291
}

0 commit comments

Comments
 (0)