From 040ee04b0906106fdece3f00d34fb4817d7f318e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Sat, 9 Mar 2024 12:50:32 -0600 Subject: [PATCH] fix: remove gap detection (#330) --- src/env.ts | 2 - src/pg/helpers.ts | 32 -------------- src/pg/pg-store.ts | 11 +---- tests/ordhook/server.test.ts | 83 ------------------------------------ 4 files changed, 1 insertion(+), 127 deletions(-) diff --git a/src/env.ts b/src/env.ts index 21aeef65..956d42f3 100644 --- a/src/env.ts +++ b/src/env.ts @@ -67,8 +67,6 @@ const schema = Type.Object({ /** Enables BRC-20 processing in write mode APIs */ BRC20_BLOCK_SCAN_ENABLED: Type.Boolean({ default: true }), - /** Enables inscription gap detection to prevent ingesting unordered blocks */ - INSCRIPTION_GAP_DETECTION_ENABLED: Type.Boolean({ default: true }), }); type Env = Static; diff --git a/src/pg/helpers.ts b/src/pg/helpers.ts index 607ea80f..033a1ece 100644 --- a/src/pg/helpers.ts +++ b/src/pg/helpers.ts @@ -1,12 +1,10 @@ import { PgBytea, logger, toEnumValue } from '@hirosystems/api-toolkit'; import { hexToBuffer, normalizedHexString, parseSatPoint } from '../api/util/helpers'; import { - BadPayloadRequestError, BitcoinEvent, BitcoinInscriptionRevealed, BitcoinInscriptionTransferred, } from '@hirosystems/chainhook-client'; -import { ENV } from '../env'; import { DbLocationTransferType, InscriptionEventData, @@ -15,36 +13,6 @@ import { } from './types'; import { OrdinalSatoshi } from '../api/util/ordinal-satoshi'; -/** - * Check if writing the next block would create an inscription number gap - * @param currentNumber - Current max blessed number - * @param writes - Incoming inscription event data - * @param currentBlockHeight - Current height - * @param nextBlockHeight - Height to be inserted - */ -export function assertNoBlockInscriptionGap(args: { - currentNumber: number; - writes: InscriptionEventData[]; - currentBlockHeight: number; - nextBlockHeight: number; -}) { - if (!ENV.INSCRIPTION_GAP_DETECTION_ENABLED) return; - const nextReveal = args.writes.find( - w => - 'inscription' in w && - w.inscription.number >= 0 && - // Spent as fee come first in the block - w.location.address != null && - w.location.address != '' - ); - if (!nextReveal) return; - const next = (nextReveal as InscriptionRevealData).inscription.number; - if (next !== args.currentNumber + 1) - throw new BadPayloadRequestError( - `Block inscription gap detected: Attempting to insert #${next} (${args.nextBlockHeight}) but current max is #${args.currentNumber}. Chain tip is at ${args.currentBlockHeight}.` - ); -} - /** * Returns a list of referenced inscription ids from inscription content. * @param content - Inscription content diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index 20b33abc..f08df0c2 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -17,7 +17,7 @@ import { ENV } from '../env'; import { Brc20PgStore } from './brc20/brc20-pg-store'; import { CountsPgStore } from './counts/counts-pg-store'; import { getIndexResultCountType } from './counts/helpers'; -import { assertNoBlockInscriptionGap, revealInsertsFromOrdhookEvent } from './helpers'; +import { revealInsertsFromOrdhookEvent } from './helpers'; import { DbFullyLocatedInscriptionResult, DbInscriptionContent, @@ -33,7 +33,6 @@ import { DbPaginatedResult, InscriptionEventData, LOCATIONS_COLUMNS, - InscriptionRevealData, InscriptionInsert, LocationInsert, LocationData, @@ -109,11 +108,9 @@ export class PgStore extends BasePgStore { // Check where we're at in terms of ingestion, e.g. block height and max blessed inscription // number. This will let us determine if we should skip ingesting this block or throw an // error if a gap is detected. - const currentNumber = (await this.getMaxInscriptionNumber()) ?? -1; const currentBlockHeight = await this.getChainTipBlockHeight(); const event = applyEvent as BitcoinEvent; if ( - ENV.INSCRIPTION_GAP_DETECTION_ENABLED && event.block_identifier.index <= currentBlockHeight && event.block_identifier.index !== ORDINALS_GENESIS_BLOCK ) { @@ -125,12 +122,6 @@ export class PgStore extends BasePgStore { logger.info(`PgStore ingesting block ${event.block_identifier.index}`); const time = stopwatch(); const writes = revealInsertsFromOrdhookEvent(event); - assertNoBlockInscriptionGap({ - currentNumber, - writes, - currentBlockHeight, - nextBlockHeight: event.block_identifier.index, - }); for (const writeChunk of batchIterate(writes, INSERT_BATCH_SIZE)) await this.insertInscriptions(writeChunk, payload.chainhook.is_streaming_blocks); updatedBlockHeightMin = Math.min(updatedBlockHeightMin, event.block_identifier.index); diff --git a/tests/ordhook/server.test.ts b/tests/ordhook/server.test.ts index b44c4e4f..e8035854 100644 --- a/tests/ordhook/server.test.ts +++ b/tests/ordhook/server.test.ts @@ -546,89 +546,6 @@ describe('EventServer', () => { }); describe('gap detection', () => { - test('server rejects payload with first inscription gap', async () => { - await db.updateInscriptions( - new TestChainhookPayloadBuilder() - .apply() - .block({ - height: 778575, - hash: '0x00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - timestamp: 1676913207, - }) - .transaction({ - hash: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201', - }) - .inscriptionRevealed({ - content_bytes: '0x48656C6C6F', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - inscription_number: { classic: 0, jubilee: 0 }, - inscription_fee: 705, - inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0', - inscription_output_value: 10000, - inscriber_address: 'bc1pscktlmn99gyzlvymvrezh6vwd0l4kg06tg5rvssw0czg8873gz5sdkteqj', - ordinal_number: 257418248345364, - ordinal_block_height: 650000, - ordinal_offset: 0, - satpoint_post_inscription: - '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201:0:0', - inscription_input_index: 0, - transfers_pre_inscription: 0, - tx_index: 0, - curse_type: null, - inscription_pointer: null, - delegate: null, - metaprotocol: null, - metadata: null, - parent: null, - }) - .build() - ); - const errorPayload = new TestChainhookPayloadBuilder() - .apply() - .block({ - height: 778576, - hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d', - timestamp: 1676913207, - }) - .transaction({ - hash: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc', - }) - .inscriptionRevealed({ - content_bytes: '0x48656C6C6F', - content_type: 'text/plain;charset=utf-8', - content_length: 5, - inscription_number: { classic: 5, jubilee: 5 }, // Gap at 5 - inscription_fee: 705, - inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', - inscription_output_value: 10000, - inscriber_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', - ordinal_number: 1050000000000000, - ordinal_block_height: 650000, - ordinal_offset: 0, - satpoint_post_inscription: - '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', - inscription_input_index: 0, - transfers_pre_inscription: 0, - tx_index: 0, - curse_type: null, - inscription_pointer: null, - delegate: null, - metaprotocol: null, - metadata: null, - parent: null, - }) - .build(); - await expect(db.updateInscriptions(errorPayload)).rejects.toThrow(BadPayloadRequestError); - const response = await server['fastify'].inject({ - method: 'POST', - url: `/payload`, - headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` }, - payload: errorPayload, - }); - expect(response.statusCode).toBe(400); - }); - test('server ignores past blocks', async () => { const payload = new TestChainhookPayloadBuilder() .apply()