mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
fix missing canonical hash on stale block responses
This commit is contained in:
parent
2db57928c4
commit
f654704169
1 changed files with 28 additions and 0 deletions
|
|
@ -575,6 +575,31 @@ class BlocksRepository {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canonical block hash at a given height
|
||||
* @asyncSafe
|
||||
*/
|
||||
public async $getCanonicalBlockHashByHeight(height: number): Promise<string | null> {
|
||||
try {
|
||||
const [rows]: any[] = await DB.query(`
|
||||
SELECT hash
|
||||
FROM blocks
|
||||
WHERE height = ? AND stale = 0
|
||||
LIMIT 1`,
|
||||
[height]
|
||||
);
|
||||
|
||||
if (rows.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return rows[0].hash;
|
||||
} catch (e) {
|
||||
logger.err(`Cannot get canonical block hash at height ${height}. Reason: ` + (e instanceof Error ? e.message : e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one block by hash
|
||||
* @asyncSafe
|
||||
|
|
@ -1258,6 +1283,9 @@ class BlocksRepository {
|
|||
blk.mediantime = dbBlk.mediantime;
|
||||
blk.indexVersion = dbBlk.index_version;
|
||||
blk.stale = dbBlk.stale;
|
||||
if (dbBlk.stale) {
|
||||
blk.canonical = await this.$getCanonicalBlockHashByHeight(dbBlk.height) || undefined;
|
||||
}
|
||||
// BlockExtension
|
||||
extras.totalFees = dbBlk.totalFees;
|
||||
extras.medianFee = dbBlk.medianFee;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue