Skip to content

Commit

Permalink
fix: only scan BRC-20 after its genesis height (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Nov 2, 2023
1 parent 1ff72c0 commit 6381760
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 61 deletions.
4 changes: 4 additions & 0 deletions src/pg/brc20/brc20-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import { Brc20Deploy, Brc20Mint, Brc20Transfer, brc20FromInscriptionContent } fr
import { Brc20TokenOrderBy } from '../../api/schemas';
import { objRemoveUndefinedValues } from '../helpers';

/** The block at which BRC-20 activity began */
export const BRC20_GENESIS_BLOCK = 779832;

export class Brc20PgStore extends BasePgStoreModule {
sqlOr(partials: postgres.PendingQuery<postgres.Row[]>[] | undefined) {
return partials?.reduce((acc, curr) => this.sql`${acc} OR ${curr}`);
Expand All @@ -43,6 +46,7 @@ export class Brc20PgStore extends BasePgStoreModule {
*/
async scanBlocks(startBlock: number, endBlock: number): Promise<void> {
for (let blockHeight = startBlock; blockHeight <= endBlock; blockHeight++) {
if (blockHeight < BRC20_GENESIS_BLOCK) continue;
logger.info(`Brc20PgStore scanning block ${blockHeight}`);
await this.sqlWriteTransaction(async sql => {
const limit = 100_000;
Expand Down
3 changes: 2 additions & 1 deletion src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import { toEnumValue } from '@hirosystems/api-toolkit';

export const MIGRATIONS_DIR = path.join(__dirname, '../../migrations');
export const ORDINALS_GENESIS_BLOCK = 767430;

type InscriptionIdentifier = { genesis_id: string } | { number: number };

Expand Down Expand Up @@ -125,7 +126,7 @@ export class PgStore extends BasePgStore {
for (const applyEvent of payload.apply) {
const event = applyEvent as BitcoinEvent;
const block_height = event.block_identifier.index;
if (block_height <= currentBlockHeight && block_height !== 767430) {
if (block_height <= currentBlockHeight && block_height !== ORDINALS_GENESIS_BLOCK) {
logger.info(
`PgStore skipping ingestion for previously seen block ${block_height}, current chain tip is at ${currentBlockHeight}`
);
Expand Down
Loading

0 comments on commit 6381760

Please sign in to comment.