Skip to content

feat: add replaced_by_tx_id to replaced mempool transactions #2271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
12 changes: 12 additions & 0 deletions migrations/1715844926068_add-replacing-txid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable camelcase */
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */

exports.up = pgm => {
pgm.addColumn('mempool_txs', {
replaced_by_tx_id: {
type: 'bytea',
}
});
};


21 changes: 21 additions & 0 deletions migrations/1747760018771_txs-sender-nonce-indexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable camelcase */

exports.shorthands = undefined;

exports.up = pgm => {
pgm.dropIndex('txs', ['sender_address']);
pgm.createIndex('txs', ['sender_address', 'nonce'], {
where: 'canonical = true AND microblock_canonical = true',
});
pgm.dropIndex('txs', ['sponsor_address']);
pgm.createIndex('txs', ['sponsor_address', 'nonce'], {
where: 'sponsor_address IS NOT NULL AND canonical = true AND microblock_canonical = true',
});
};

exports.down = pgm => {
pgm.dropIndex('txs', ['sender_address', 'nonce']);
pgm.createIndex('txs', ['sender_address']);
pgm.dropIndex('txs', ['sponsor_address', 'nonce']);
pgm.createIndex('txs', ['sponsor_address']);
};
1 change: 1 addition & 0 deletions src/api/controllers/db-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ function parseDbAbstractMempoolTx(
const abstractMempoolTx: AbstractMempoolTransaction = {
...baseTx,
tx_status: getTxStatusString(dbMempoolTx.status) as MempoolTransactionStatus,
replaced_by_tx_id: dbMempoolTx.replaced_by_tx_id ?? null,
receipt_time: dbMempoolTx.receipt_time,
receipt_time_iso: unixEpochToIso(dbMempoolTx.receipt_time),
};
Expand Down
5 changes: 5 additions & 0 deletions src/api/schemas/entities/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ export const AbstractMempoolTransactionProperties = {
description: 'Status of the transaction',
}
),
replaced_by_tx_id: Nullable(
Type.String({
description: 'ID of another transaction which replaced this one',
})
),
receipt_time: Type.Integer({
description:
'A unix timestamp (in seconds) indicating when the transaction broadcast was received by the node.',
Expand Down
4 changes: 4 additions & 0 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ export interface DbMempoolFeePriority {
export interface DbMempoolTx extends BaseTx {
pruned: boolean;

replaced_by_tx_id?: string;

receipt_time: number;

post_conditions: string;
Expand Down Expand Up @@ -897,6 +899,7 @@ export interface MempoolTxQueryResult {
type_id: number;
anchor_mode: number;
status: number;
replaced_by_tx_id?: string;
receipt_time: number;
receipt_block_height: number;

Expand Down Expand Up @@ -1242,6 +1245,7 @@ export interface MempoolTxInsertValues {
type_id: DbTxTypeId;
anchor_mode: DbTxAnchorMode;
status: DbTxStatus;
replaced_by_tx_id: PgBytea | null;
receipt_time: number;
receipt_block_height: number;
post_conditions: PgBytea;
Expand Down
3 changes: 3 additions & 0 deletions src/datastore/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const MEMPOOL_TX_COLUMNS = [
'type_id',
'anchor_mode',
'status',
'replaced_by_tx_id',
'receipt_time',
'receipt_block_height',
'post_conditions',
Expand Down Expand Up @@ -302,6 +303,7 @@ export function parseMempoolTxQueryResult(result: MempoolTxQueryResult): DbMempo
type_id: result.type_id as DbTxTypeId,
anchor_mode: result.anchor_mode as DbTxAnchorMode,
status: result.status,
replaced_by_tx_id: result.replaced_by_tx_id,
receipt_time: result.receipt_time,
post_conditions: result.post_conditions,
fee_rate: BigInt(result.fee_rate),
Expand Down Expand Up @@ -1283,6 +1285,7 @@ export function convertTxQueryResultToDbMempoolTx(txs: TxQueryResult[]): DbMempo
? BigInt(tx.token_transfer_amount)
: tx.token_transfer_amount,
sponsor_address: tx.sponsor_address ?? undefined,
status: DbTxStatus.Pending,
});
dbMempoolTxs.push(dbMempoolTx);
}
Expand Down
Loading