Skip to content

Commit a0cd9f2

Browse files
authored
fix: count stx mint data at block 0 towards account balances (#2289)
* fix: always treat block 0 boot data as canonical * fix: tests
1 parent d1df9a4 commit a0cd9f2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/datastore/pg-write-store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ export class PgWriteStore extends PgStore {
284284
if ((await this.updateBlock(sql, data.block)) !== 0) {
285285
const q = new PgWriteQueue();
286286
q.enqueue(() => this.updateMinerRewards(sql, data.minerRewards));
287-
if (isCanonical) {
287+
// Block 0 is non-canonical, but we need to make sure its STX mint events get considered in
288+
// balance calculations.
289+
if (data.block.block_height == 0 || isCanonical) {
288290
// Use `data.txs` directly instead of `newTxData` for these STX/FT balance updates because
289291
// we don't want to skip balance changes in transactions that were previously confirmed
290292
// via microblocks.

tests/2.5/block-zero-handling.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,18 @@ describe('Block-zero event handling', () => {
175175
const firstMintEvent = mintTxEvents.filter(r => r.event_index === 0)[0];
176176
expect(firstMintEvent).toBeDefined();
177177
expect(firstMintEvent).toEqual(stxMintEvent);
178+
179+
// Compare balance endpoints for receiver address
180+
const address = firstMintEvent.asset.recipient;
181+
let result = await supertest(testEnv.api.server).get(`/extended/v1/address/${address}/stx`);
182+
expect(result.status).toBe(200);
183+
expect(result.type).toBe('application/json');
184+
const v1balance = JSON.parse(result.text).balance;
185+
result = await supertest(testEnv.api.server).get(
186+
`/extended/v2/addresses/${address}/balances/stx`
187+
);
188+
expect(result.status).toBe(200);
189+
expect(result.type).toBe('application/json');
190+
expect(JSON.parse(result.text).balance).toBe(v1balance);
178191
});
179192
});

0 commit comments

Comments
 (0)