Skip to content

Commit ad386d3

Browse files
authored
fix: get rosetta latest block from chain_tip view (#1445)
* fix: get rosetta latest block from chain_tip view * fix: datastore test that did not refresh view
1 parent 21f9120 commit ad386d3

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/datastore/pg-store.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,8 @@ export class PgStore {
418418
async getCurrentBlockInternal(sql: PgSqlClient): Promise<FoundOrNot<DbBlock>> {
419419
const result = await sql<BlockQueryResult[]>`
420420
SELECT ${sql(BLOCK_COLUMNS)}
421-
FROM blocks
422-
WHERE canonical = true
423-
ORDER BY block_height DESC
421+
FROM blocks b
422+
INNER JOIN chain_tip t USING (index_block_hash, block_hash, block_height)
424423
LIMIT 1
425424
`;
426425
if (result.length === 0) {

src/tests/datastore-tests.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ describe('postgres datastore', () => {
326326
});
327327

328328
test('pg address STX balances', async () => {
329-
const dbBlock: DbBlock = {
329+
const block = new TestBlockBuilder({
330330
block_hash: '0x9876',
331331
index_block_hash: '0x5432',
332-
block_height: 68456,
332+
block_height: 1,
333333
parent_index_block_hash: '0x00',
334334
parent_block_hash: '0xff0011',
335335
parent_microblock_hash: '0x00',
@@ -339,13 +339,8 @@ describe('postgres datastore', () => {
339339
miner_txid: '0x4321',
340340
canonical: true,
341341
parent_microblock_sequence: 0,
342-
execution_cost_read_count: 0,
343-
execution_cost_read_length: 0,
344-
execution_cost_runtime: 0,
345-
execution_cost_write_count: 0,
346-
execution_cost_write_length: 0,
347-
};
348-
await db.updateBlock(client, dbBlock);
342+
}).build();
343+
await db.update(block);
349344

350345
const createMinerReward = (
351346
recipient: string,
@@ -359,7 +354,7 @@ describe('postgres datastore', () => {
359354
block_hash: '0x9876',
360355
index_block_hash: '0x5432',
361356
from_index_block_hash: '0x6789',
362-
mature_block_height: 68456,
357+
mature_block_height: 1,
363358
canonical: canonical,
364359
recipient: recipient,
365360
coinbase_amount: amount,
@@ -388,7 +383,7 @@ describe('postgres datastore', () => {
388383
raw_tx: '0x',
389384
index_block_hash: '0x5432',
390385
block_hash: '0x9876',
391-
block_height: 68456,
386+
block_height: 1,
392387
burn_block_time: 2837565,
393388
parent_burn_block_time: 1626122935,
394389
type_id: DbTxTypeId.Coinbase,
@@ -494,8 +489,8 @@ describe('postgres datastore', () => {
494489
totalFeesSent: 1334n,
495490
totalMinerRewardsReceived: 100010n,
496491
burnchainLockHeight: 123,
497-
burnchainUnlockHeight: 68656,
498-
lockHeight: 68456,
492+
burnchainUnlockHeight: 201,
493+
lockHeight: 1,
499494
lockTxId: '0x1234',
500495
locked: 400n,
501496
});

0 commit comments

Comments
 (0)