@@ -134,9 +134,10 @@ export class PgWriteStore extends PgStore {
134134 }
135135
136136 async getChainTip (
137- sql : PgSqlClient
137+ sql : PgSqlClient ,
138+ useMaterializedView = true
138139 ) : Promise < { blockHeight : number ; blockHash : string ; indexBlockHash : string } > {
139- if ( ! this . isEventReplay ) {
140+ if ( ! this . isEventReplay && useMaterializedView ) {
140141 return super . getChainTip ( sql ) ;
141142 }
142143 // The `chain_tip` materialized view is not available during event replay.
@@ -188,7 +189,7 @@ export class PgWriteStore extends PgStore {
188189 const tokenMetadataQueueEntries : DbTokenMetadataQueueEntry [ ] = [ ] ;
189190 let garbageCollectedMempoolTxs : string [ ] = [ ] ;
190191 await this . sql . begin ( async sql => {
191- const chainTip = await this . getChainTip ( sql ) ;
192+ const chainTip = await this . getChainTip ( sql , false ) ;
192193 await this . handleReorg ( sql , data . block , chainTip . blockHeight ) ;
193194 // If the incoming block is not of greater height than current chain tip, then store data as non-canonical.
194195 const isCanonical = data . block . block_height > chainTip . blockHeight ;
@@ -532,7 +533,7 @@ export class PgWriteStore extends PgStore {
532533 // Sanity check: ensure incoming microblocks have a `parent_index_block_hash` that matches the API's
533534 // current known canonical chain tip. We assume this holds true so incoming microblock data is always
534535 // treated as being built off the current canonical anchor block.
535- const chainTip = await this . getChainTip ( sql ) ;
536+ const chainTip = await this . getChainTip ( sql , false ) ;
536537 const nonCanonicalMicroblock = data . microblocks . find (
537538 mb => mb . parent_index_block_hash !== chainTip . indexBlockHash
538539 ) ;
@@ -1270,7 +1271,7 @@ export class PgWriteStore extends PgStore {
12701271 async updateMempoolTxs ( { mempoolTxs : txs } : { mempoolTxs : DbMempoolTx [ ] } ) : Promise < void > {
12711272 const updatedTxs : DbMempoolTx [ ] = [ ] ;
12721273 await this . sql . begin ( async sql => {
1273- const chainTip = await this . getChainTip ( sql ) ;
1274+ const chainTip = await this . getChainTip ( sql , false ) ;
12741275 for ( const tx of txs ) {
12751276 const values : MempoolTxInsertValues = {
12761277 pruned : tx . pruned ,
@@ -2441,7 +2442,7 @@ export class PgWriteStore extends PgStore {
24412442 if ( this . isEventReplay && skipDuringEventReplay ) {
24422443 return ;
24432444 }
2444- await sql `REFRESH MATERIALIZED VIEW ${ sql ( viewName ) } ` ;
2445+ await sql `REFRESH MATERIALIZED VIEW ${ isProdEnv ? sql `CONCURRENTLY` : sql `` } ${ sql ( viewName ) } ` ;
24452446 }
24462447
24472448 /**
0 commit comments