From e3c0ed7011333d57937dfc49466a3907c7579803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20T=C3=B3rz?= Date: Mon, 28 Aug 2023 12:46:32 +0200 Subject: [PATCH 1/2] Remove state update id on reorg for l2 tx --- .../src/core/collectors/FeederGatewayCollector.test.ts | 4 ++-- .../backend/src/core/collectors/FeederGatewayCollector.ts | 4 +++- .../src/peripherals/database/L2TransactionRepository.ts | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/collectors/FeederGatewayCollector.test.ts b/packages/backend/src/core/collectors/FeederGatewayCollector.test.ts index 4c3ddde22..ac180f821 100644 --- a/packages/backend/src/core/collectors/FeederGatewayCollector.test.ts +++ b/packages/backend/src/core/collectors/FeederGatewayCollector.test.ts @@ -440,7 +440,7 @@ describe(FeederGatewayCollector.name, () => { describe(FeederGatewayCollector.prototype.discardAfter.name, () => { const mockedL2TransactionRepository = mockObject({ - deleteAfterBlock: mockFn().resolvesTo(1), + removeStateUpdateIdAfterBlock: mockFn().resolvesTo(1), }) const feederGatewayCollector = new FeederGatewayCollector( mockObject(), @@ -455,7 +455,7 @@ describe(FeederGatewayCollector.name, () => { await feederGatewayCollector.discardAfter(blockNumber) expect( - mockedL2TransactionRepository.deleteAfterBlock + mockedL2TransactionRepository.removeStateUpdateIdAfterBlock ).toHaveBeenCalledWith(blockNumber) }) }) diff --git a/packages/backend/src/core/collectors/FeederGatewayCollector.ts b/packages/backend/src/core/collectors/FeederGatewayCollector.ts index 384667638..8299fb763 100644 --- a/packages/backend/src/core/collectors/FeederGatewayCollector.ts +++ b/packages/backend/src/core/collectors/FeederGatewayCollector.ts @@ -151,6 +151,8 @@ export class FeederGatewayCollector { } async discardAfter(blockNumber: number) { - await this.l2TransactionRepository.deleteAfterBlock(blockNumber) + await this.l2TransactionRepository.removeStateUpdateIdAfterBlock( + blockNumber + ) } } diff --git a/packages/backend/src/peripherals/database/L2TransactionRepository.ts b/packages/backend/src/peripherals/database/L2TransactionRepository.ts index c6f264e27..f9848ebee 100644 --- a/packages/backend/src/peripherals/database/L2TransactionRepository.ts +++ b/packages/backend/src/peripherals/database/L2TransactionRepository.ts @@ -87,7 +87,9 @@ export class L2TransactionRepository extends BaseRepository { this.findOldestByTransactionId ) this.findLatestIncluded = this.wrapFind(this.findLatestIncluded) - this.deleteAfterBlock = this.wrapDelete(this.deleteAfterBlock) + this.removeStateUpdateIdAfterBlock = this.wrapUpdate( + this.removeStateUpdateIdAfterBlock + ) this.deleteByTransactionIds = this.wrapDelete(this.deleteByTransactionIds) this.deleteAll = this.wrapDelete(this.deleteAll) this.runInTransactionWithLockedTable = this.wrapAny( @@ -607,11 +609,11 @@ export class L2TransactionRepository extends BaseRepository { return row ? toRecord(row) : undefined } - async deleteAfterBlock(blockNumber: number) { + async removeStateUpdateIdAfterBlock(blockNumber: number) { const knex = await this.knex() return knex('l2_transactions') .where('block_number', '>', blockNumber) - .delete() + .update({ state_update_id: null }) } async deleteByTransactionIds( From fe3fca86efe4849fbfc3be6ccdeb8b03d0d18340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20T=C3=B3rz?= Date: Mon, 28 Aug 2023 13:23:19 +0200 Subject: [PATCH 2/2] add missing env --- packages/backend/src/config/starkex/apex-goerli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/config/starkex/apex-goerli.ts b/packages/backend/src/config/starkex/apex-goerli.ts index f25295d38..b0aab3507 100644 --- a/packages/backend/src/config/starkex/apex-goerli.ts +++ b/packages/backend/src/config/starkex/apex-goerli.ts @@ -32,7 +32,7 @@ export function getApexGoerliConfig(env: Env): StarkexConfig { auth: clientAuth, }, l2Transactions: { - enabled: true, + enabled: env.boolean('L2_TRANSACTIONS_ENABLED', true), excludeTypes: ['OraclePricesTick'], feederGateway: { getUrl: (batchId: number) => {