Skip to content

Commit 3579e8e

Browse files
committed
chore: better tx filtering on executeTransaction
Signed-off-by: Tomás Migone <[email protected]>
1 parent 112e1e8 commit 3579e8e

File tree

1 file changed

+42
-50
lines changed

1 file changed

+42
-50
lines changed

packages/indexer-common/src/indexer-management/allocations.ts

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@ export class AllocationManager {
186186
// We need to process both staking contract and subgraph service transactions separately
187187
// as they cannot be multicalled
188188
// Realistically, the only scenario where a batch would have both is shortly after the horizon upgrade
189+
const stakingTransactions = preparedTransactions.filter(
190+
(tx: TransactionRequest) =>
191+
tx.to === this.network.contracts.HorizonStaking.target,
192+
)
193+
const subgraphServiceTransactions = preparedTransactions.filter(
194+
(tx: TransactionRequest) =>
195+
tx.to === this.network.contracts.SubgraphService.target,
196+
)
189197

190198
// -- STAKING CONTRACT --
191-
const callDataStakingContract = preparedTransactions
192-
.filter(
193-
(tx: TransactionRequest) =>
194-
tx.to === this.network.contracts.HorizonStaking.target,
195-
)
199+
const callDataStakingContract = stakingTransactions
196200
.filter((tx: TransactionRequest) => !!tx.data)
197201
.map((tx) => tx.data as string)
198202

@@ -221,41 +225,33 @@ export class AllocationManager {
221225
)
222226

223227
// Mark all actions with staking contract transactions as successful
224-
for (const preparedTransaction of preparedTransactions) {
225-
if (preparedTransaction.to === this.network.contracts.HorizonStaking.target) {
226-
actionResults.push({
227-
actionID: preparedTransaction.actionID,
228-
success: true,
229-
result: stakingTransactionResult,
230-
})
231-
}
228+
for (const transaction of stakingTransactions) {
229+
actionResults.push({
230+
actionID: transaction.actionID,
231+
success: true,
232+
result: stakingTransactionResult,
233+
})
232234
}
233235
} catch (error) {
234236
logger.error('Failed to execute staking contract transaction', { error })
235237

236238
// Mark all actions with staking contract transactions as failed
237-
for (const preparedTransaction of preparedTransactions) {
238-
if (preparedTransaction.to === this.network.contracts.HorizonStaking.target) {
239-
actionResults.push({
240-
actionID: preparedTransaction.actionID,
241-
success: false,
242-
result: {
243-
actionID: preparedTransaction.actionID,
244-
failureReason: `Failed to execute staking contract transaction: ${error.message}`,
245-
protocolNetwork: preparedTransaction.protocolNetwork,
246-
},
247-
})
248-
}
239+
for (const transaction of stakingTransactions) {
240+
actionResults.push({
241+
actionID: transaction.actionID,
242+
success: false,
243+
result: {
244+
actionID: transaction.actionID,
245+
failureReason: `Failed to execute staking contract transaction: ${error.message}`,
246+
protocolNetwork: transaction.protocolNetwork,
247+
},
248+
})
249249
}
250250
}
251251
}
252252

253253
// -- SUBGRAPH SERVICE --
254-
const callDataSubgraphService = preparedTransactions
255-
.filter(
256-
(tx: TransactionRequest) =>
257-
tx.to === this.network.contracts.SubgraphService.target,
258-
)
254+
const callDataSubgraphService = subgraphServiceTransactions
259255
// Reallocate of a legacy allocation during the transition period can result in
260256
// a staking and subgraph service transaction in the same batch. If the staking tx failed we
261257
// should not execute the subgraph service tx.
@@ -291,31 +287,27 @@ export class AllocationManager {
291287
)
292288

293289
// Mark all actions with subgraph service transactions as successful
294-
for (const preparedTransaction of preparedTransactions) {
295-
if (preparedTransaction.to === this.network.contracts.SubgraphService.target) {
296-
actionResults.push({
297-
actionID: preparedTransaction.actionID,
298-
success: true,
299-
result: subgraphServiceTransactionResult,
300-
})
301-
}
290+
for (const transaction of subgraphServiceTransactions) {
291+
actionResults.push({
292+
actionID: transaction.actionID,
293+
success: true,
294+
result: subgraphServiceTransactionResult,
295+
})
302296
}
303297
} catch (error) {
304298
logger.error('Failed to execute subgraph service transaction', { error })
305299

306300
// Mark all actions with subgraph service transactions as failed
307-
for (const preparedTransaction of preparedTransactions) {
308-
if (preparedTransaction.to === this.network.contracts.SubgraphService.target) {
309-
actionResults.push({
310-
actionID: preparedTransaction.actionID,
311-
success: false,
312-
result: {
313-
actionID: preparedTransaction.actionID,
314-
failureReason: `Failed to execute subgraph service transaction: ${error.message}`,
315-
protocolNetwork: preparedTransaction.protocolNetwork,
316-
},
317-
})
318-
}
301+
for (const transaction of subgraphServiceTransactions) {
302+
actionResults.push({
303+
actionID: transaction.actionID,
304+
success: false,
305+
result: {
306+
actionID: transaction.actionID,
307+
failureReason: `Failed to execute subgraph service transaction: ${error.message}`,
308+
protocolNetwork: transaction.protocolNetwork,
309+
},
310+
})
319311
}
320312
}
321313
}

0 commit comments

Comments
 (0)