Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only scan for BRC-20 after its genesis height #263

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading