Skip to content

Commit 74c06c6

Browse files
authored
fix: issue with block_time receipt not being written to db (#1961)
* fix: issue with block_time receipt not being written to db * chore: fix tests
1 parent a5bec61 commit 74c06c6

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/datastore/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ export interface BlockInsertValues {
12571257
parent_microblock_hash: PgBytea;
12581258
parent_microblock_sequence: number;
12591259
block_height: number;
1260+
block_time: number;
12601261
burn_block_time: number;
12611262
burn_block_hash: PgBytea;
12621263
burn_block_height: number;

src/datastore/pg-write-store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ export class PgWriteStore extends PgStore {
465465
parent_microblock_hash: block.parent_microblock_hash,
466466
parent_microblock_sequence: block.parent_microblock_sequence,
467467
block_height: block.block_height,
468+
block_time: block.block_time,
468469
burn_block_time: block.burn_block_time,
469470
burn_block_hash: block.burn_block_hash,
470471
burn_block_height: block.burn_block_height,
@@ -3056,6 +3057,7 @@ export class PgWriteStore extends PgStore {
30563057
async insertBlockBatch(sql: PgSqlClient, blocks: DbBlock[]) {
30573058
const values: BlockInsertValues[] = blocks.map(block => ({
30583059
block_hash: block.block_hash,
3060+
block_time: block.block_time,
30593061
index_block_hash: block.index_block_hash,
30603062
parent_index_block_hash: block.parent_index_block_hash,
30613063
parent_block_hash: block.parent_block_hash,

src/event-stream/event-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async function handleBlockMessage(
252252
// TODO: if the core node can give use the stacks-block count/index for the current tenure/burn_block then we should
253253
// increment this by that value so that timestampts increase monotonically.
254254
const stacksBlockReceiptDate = db.isEventReplay
255-
? msg.parent_burn_block_timestamp
255+
? msg.burn_block_time
256256
: Math.round(Date.now() / 1000);
257257
blockData.block_time = stacksBlockReceiptDate;
258258
}
@@ -320,7 +320,7 @@ async function handleBlockMessage(
320320
execution_cost_write_count: 0,
321321
execution_cost_write_length: 0,
322322
tx_count: msg.transactions.length,
323-
block_time: msg.block_time,
323+
block_time: blockData.block_time,
324324
signer_bitvec: signerBitvec,
325325
};
326326

src/tests/block-tests.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ describe('block tests', () => {
257257
canonical: true,
258258
height: 1,
259259
hash: block_hash,
260-
block_time: 94869286,
261-
block_time_iso: '1973-01-03T00:34:46.000Z',
260+
block_time: 94869287,
261+
block_time_iso: '1973-01-03T00:34:47.000Z',
262262
parent_block_hash: '0x',
263263
burn_block_time: 94869286,
264264
burn_block_time_iso: '1973-01-03T00:34:46.000Z',
@@ -440,8 +440,8 @@ describe('block tests', () => {
440440
index_block_hash: '0x0001',
441441
hash: '0x0001',
442442
height: 1,
443-
block_time: 94869286,
444-
block_time_iso: '1973-01-03T00:34:46.000Z',
443+
block_time: 94869287,
444+
block_time_iso: '1973-01-03T00:34:47.000Z',
445445
microblocks_accepted: [],
446446
microblocks_streamed: [
447447
microblock1.microblocks[0].microblock_hash,
@@ -492,8 +492,8 @@ describe('block tests', () => {
492492
index_block_hash: '0x0002',
493493
hash: '0x0002',
494494
height: 2,
495-
block_time: 94869286,
496-
block_time_iso: '1973-01-03T00:34:46.000Z',
495+
block_time: 94869287,
496+
block_time_iso: '1973-01-03T00:34:47.000Z',
497497
microblocks_accepted: [microblock1.microblocks[0].microblock_hash],
498498
microblocks_streamed: [],
499499
miner_txid: '0x4321',
@@ -672,8 +672,8 @@ describe('block tests', () => {
672672

673673
// Filter by burn hash
674674
const block5 = {
675-
block_time: 94869286,
676-
block_time_iso: '1973-01-03T00:34:46.000Z',
675+
block_time: 94869287,
676+
block_time_iso: '1973-01-03T00:34:47.000Z',
677677
burn_block_hash: '0x00000000000000000001e2ee7f0c6bd5361b5e7afd76156ca7d6f524ee5ca3d8',
678678
burn_block_height: 700000,
679679
burn_block_time: 94869286,
@@ -709,8 +709,8 @@ describe('block tests', () => {
709709

710710
// Get latest block
711711
const block8 = {
712-
block_time: 94869286,
713-
block_time_iso: '1973-01-03T00:34:46.000Z',
712+
block_time: 94869287,
713+
block_time_iso: '1973-01-03T00:34:47.000Z',
714714
burn_block_hash: '0x000000000000000000028eacd4e6e58405d5a37d06b5d7b93776f1eab68d2494',
715715
burn_block_height: 700001,
716716
burn_block_time: 94869286,
@@ -762,8 +762,8 @@ describe('block tests', () => {
762762

763763
// Get latest
764764
const block5 = {
765-
block_time: 94869286,
766-
block_time_iso: '1973-01-03T00:34:46.000Z',
765+
block_time: 94869287,
766+
block_time_iso: '1973-01-03T00:34:47.000Z',
767767
burn_block_hash: '0x00000000000000000001e2ee7f0c6bd5361b5e7afd76156ca7d6f524ee5ca3d8',
768768
burn_block_height: 700000,
769769
burn_block_time: 94869286,

src/tests/datastore-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ describe('postgres datastore', () => {
605605
parent_block_hash: '0xff0011',
606606
parent_microblock_hash: '0x00',
607607
block_height: 1235,
608-
block_time: 94869286,
608+
block_time: 94869287,
609609
burn_block_time: 94869286,
610610
burn_block_hash: '0x1234',
611611
burn_block_height: 123,
@@ -634,7 +634,7 @@ describe('postgres datastore', () => {
634634
index_block_hash: block.index_block_hash,
635635
block_hash: block.block_hash,
636636
block_height: 68456,
637-
block_time: 2837565,
637+
block_time: 2837566,
638638
burn_block_time: 2837565,
639639
parent_burn_block_time: 1626122935,
640640
type_id: DbTxTypeId.Coinbase,

0 commit comments

Comments
 (0)