add cpfp progress marker to avoid reindexing early blocks
This commit is contained in:
parent
b50936f001
commit
01c96f80f9
@ -350,7 +350,7 @@ class Blocks {
|
|||||||
let countThisRun = 0;
|
let countThisRun = 0;
|
||||||
let timer = new Date().getTime() / 1000;
|
let timer = new Date().getTime() / 1000;
|
||||||
const startedAt = new Date().getTime() / 1000;
|
const startedAt = new Date().getTime() / 1000;
|
||||||
|
let lastHeight;
|
||||||
for (const block of unindexedBlocks) {
|
for (const block of unindexedBlocks) {
|
||||||
// Logging
|
// Logging
|
||||||
const elapsedSeconds = Math.max(1, new Date().getTime() / 1000 - timer);
|
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
|
await this.$indexCPFP(block.hash, block.height); // Calculate and save CPFP data for transactions in this block
|
||||||
|
|
||||||
|
lastHeight = block.height;
|
||||||
// Logging
|
// Logging
|
||||||
count++;
|
count++;
|
||||||
countThisRun++;
|
countThisRun++;
|
||||||
}
|
}
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
await cpfpRepository.$insertProgressMarker(lastHeight);
|
||||||
logger.notice(`CPFP indexing completed: indexed ${count} blocks`);
|
logger.notice(`CPFP indexing completed: indexed ${count} blocks`);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`CPFP indexing completed: indexed ${count} blocks`);
|
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 {
|
public pack(txs: Ancestor[]): ArrayBuffer {
|
||||||
const buf = new ArrayBuffer(44 * txs.length);
|
const buf = new ArrayBuffer(44 * txs.length);
|
||||||
const view = new DataView(buf);
|
const view = new DataView(buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user