Fix version update & error handling in Goggles indexing
This commit is contained in:
parent
58f143f867
commit
8ca2b2b5c0
@ -606,6 +606,7 @@ class Blocks {
|
|||||||
logger.debug(`Classifying blocks and templates from #${currentBlockHeight} to #${minHeight}`, logger.tags.goggles);
|
logger.debug(`Classifying blocks and templates from #${currentBlockHeight} to #${minHeight}`, logger.tags.goggles);
|
||||||
|
|
||||||
for (let height = currentBlockHeight; height >= 0; height--) {
|
for (let height = currentBlockHeight; height >= 0; height--) {
|
||||||
|
try {
|
||||||
let txs: TransactionExtended[] | null = null;
|
let txs: TransactionExtended[] | null = null;
|
||||||
if (unclassifiedBlocks[height]) {
|
if (unclassifiedBlocks[height]) {
|
||||||
const blockHash = unclassifiedBlocks[height];
|
const blockHash = unclassifiedBlocks[height];
|
||||||
@ -615,7 +616,7 @@ class Blocks {
|
|||||||
const cpfpSummary = Common.calculateCpfp(height, txs, true);
|
const cpfpSummary = Common.calculateCpfp(height, txs, true);
|
||||||
// classify
|
// classify
|
||||||
const { transactions: classifiedTxs } = this.summarizeBlockTransactions(blockHash, cpfpSummary.transactions);
|
const { transactions: classifiedTxs } = this.summarizeBlockTransactions(blockHash, cpfpSummary.transactions);
|
||||||
BlocksSummariesRepository.$saveTransactions(height, blockHash, classifiedTxs, 1);
|
await BlocksSummariesRepository.$saveTransactions(height, blockHash, classifiedTxs, 1);
|
||||||
}
|
}
|
||||||
if (unclassifiedTemplates[height]) {
|
if (unclassifiedTemplates[height]) {
|
||||||
// classify template
|
// classify template
|
||||||
@ -654,7 +655,10 @@ class Blocks {
|
|||||||
return tx;
|
return tx;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
BlocksSummariesRepository.$saveTemplate({ height, template: { id: blockHash, transactions: classifiedTemplate }, version: 1 });
|
await BlocksSummariesRepository.$saveTemplate({ height, template: { id: blockHash, transactions: classifiedTemplate }, version: 1 });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(`Failed to classify template or block summary at ${height}`, logger.tags.goggles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// timing & logging
|
// timing & logging
|
||||||
|
@ -281,6 +281,7 @@ export interface BlockExtended extends IEsploraApi.Block {
|
|||||||
export interface BlockSummary {
|
export interface BlockSummary {
|
||||||
id: string;
|
id: string;
|
||||||
transactions: TransactionClassified[];
|
transactions: TransactionClassified[];
|
||||||
|
version?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuditSummary extends BlockAudit {
|
export interface AuditSummary extends BlockAudit {
|
||||||
|
@ -23,8 +23,8 @@ class BlocksSummariesRepository {
|
|||||||
await DB.query(`
|
await DB.query(`
|
||||||
INSERT INTO blocks_summaries
|
INSERT INTO blocks_summaries
|
||||||
SET height = ?, transactions = ?, id = ?, version = ?
|
SET height = ?, transactions = ?, id = ?, version = ?
|
||||||
ON DUPLICATE KEY UPDATE transactions = ?`,
|
ON DUPLICATE KEY UPDATE transactions = ?, version = ?`,
|
||||||
[blockHeight, transactionsStr, blockId, version, transactionsStr]);
|
[blockHeight, transactionsStr, blockId, version, transactionsStr, version]);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.debug(`Cannot save block summary transactions for ${blockId}. Reason: ${e instanceof Error ? e.message : e}`);
|
logger.debug(`Cannot save block summary transactions for ${blockId}. Reason: ${e instanceof Error ? e.message : e}`);
|
||||||
throw e;
|
throw e;
|
||||||
@ -39,8 +39,9 @@ class BlocksSummariesRepository {
|
|||||||
INSERT INTO blocks_templates (id, template, version)
|
INSERT INTO blocks_templates (id, template, version)
|
||||||
VALUE (?, ?, ?)
|
VALUE (?, ?, ?)
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
template = ?
|
template = ?,
|
||||||
`, [blockId, transactions, params.version, transactions]);
|
version = ?
|
||||||
|
`, [blockId, transactions, params.version, transactions, params.version]);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.errno === 1062) { // ER_DUP_ENTRY - This scenario is possible upon node backend restart
|
if (e.errno === 1062) { // ER_DUP_ENTRY - This scenario is possible upon node backend restart
|
||||||
logger.debug(`Cannot save block template for ${blockId} because it has already been indexed, ignoring`);
|
logger.debug(`Cannot save block template for ${blockId} because it has already been indexed, ignoring`);
|
||||||
@ -57,6 +58,7 @@ class BlocksSummariesRepository {
|
|||||||
return {
|
return {
|
||||||
id: templates[0].id,
|
id: templates[0].id,
|
||||||
transactions: JSON.parse(templates[0].template),
|
transactions: JSON.parse(templates[0].template),
|
||||||
|
version: templates[0].version,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user