mirror of
https://github.com/mempool/mempool.git
synced 2025-02-24 06:47:52 +01:00
add cpfp progress marker to avoid reindexing early blocks
This commit is contained in:
parent
b50936f001
commit
01c96f80f9
2 changed files with 31 additions and 1 deletions
|
@ -350,7 +350,7 @@ class Blocks {
|
|||
let countThisRun = 0;
|
||||
let timer = new Date().getTime() / 1000;
|
||||
const startedAt = new Date().getTime() / 1000;
|
||||
|
||||
let lastHeight;
|
||||
for (const block of unindexedBlocks) {
|
||||
// Logging
|
||||
const elapsedSeconds = Math.max(1, new Date().getTime() / 1000 - timer);
|
||||
|
@ -365,11 +365,13 @@ class Blocks {
|
|||
|
||||
await this.$indexCPFP(block.hash, block.height); // Calculate and save CPFP data for transactions in this block
|
||||
|
||||
lastHeight = block.height;
|
||||
// Logging
|
||||
count++;
|
||||
countThisRun++;
|
||||
}
|
||||
if (count > 0) {
|
||||
await cpfpRepository.$insertProgressMarker(lastHeight);
|
||||
logger.notice(`CPFP indexing completed: indexed ${count} blocks`);
|
||||
} else {
|
||||
logger.debug(`CPFP indexing completed: indexed ${count} blocks`);
|
||||
|
|
|
@ -77,6 +77,34 @@ class CpfpRepository {
|
|||
}
|
||||
}
|
||||
|
||||
// insert a dummy row to mark that we've indexed as far as this block
|
||||
public async $insertProgressMarker(height: number): Promise<void> {
|
||||
try {
|
||||
const [rows]: any = await DB.query(
|
||||
`
|
||||
SELECT root
|
||||
FROM compact_cpfp_clusters
|
||||
WHERE height = ?
|
||||
`,
|
||||
[height]
|
||||
);
|
||||
if (!rows?.length) {
|
||||
const rootBuffer = Buffer.alloc(32);
|
||||
rootBuffer.writeInt32LE(height);
|
||||
await DB.query(
|
||||
`
|
||||
INSERT INTO compact_cpfp_clusters(root, height, fee_rate)
|
||||
VALUE (?, ?, ?)
|
||||
`,
|
||||
[rootBuffer, height, 0]
|
||||
);
|
||||
}
|
||||
} catch (e: any) {
|
||||
logger.err(`Cannot insert cpfp progress marker. Reason: ` + (e instanceof Error ? e.message : e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public pack(txs: Ancestor[]): ArrayBuffer {
|
||||
const buf = new ArrayBuffer(44 * txs.length);
|
||||
const view = new DataView(buf);
|
||||
|
|
Loading…
Add table
Reference in a new issue