Skip to content

Commit e606ab2

Browse files
committed
cli,common: remove protocolNetwork from actions cli commands
1 parent 0bf51df commit e606ab2

File tree

5 files changed

+40
-70
lines changed

5 files changed

+40
-70
lines changed

packages/indexer-cli/src/actions.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export async function buildActionInput(
3333
reason: string,
3434
status: ActionStatus,
3535
priority: number,
36-
protocolNetwork: string,
3736
): Promise<ActionInput> {
3837
await validateActionInput(type, actionParams)
3938
switch (type) {
@@ -46,7 +45,6 @@ export async function buildActionInput(
4645
reason,
4746
status,
4847
priority,
49-
protocolNetwork,
5048
}
5149
case ActionType.UNALLOCATE: {
5250
let poi = actionParams.param2
@@ -63,7 +61,6 @@ export async function buildActionInput(
6361
reason,
6462
status,
6563
priority,
66-
protocolNetwork,
6764
}
6865
}
6966
case ActionType.REALLOCATE: {
@@ -82,7 +79,6 @@ export async function buildActionInput(
8279
reason,
8380
status,
8481
priority,
85-
protocolNetwork,
8682
}
8783
}
8884
}
@@ -187,7 +183,6 @@ export async function queueActions(
187183
reason
188184
priority
189185
status
190-
protocolNetwork
191186
}
192187
}
193188
`,
@@ -241,7 +236,6 @@ export async function executeApprovedActions(
241236
mutation executeApprovedActions {
242237
executeApprovedActions {
243238
id
244-
protocolNetwork
245239
status
246240
type
247241
deploymentID
@@ -288,7 +282,6 @@ export async function approveActions(
288282
priority
289283
transaction
290284
status
291-
protocolNetwork
292285
}
293286
}
294287
`,
@@ -313,7 +306,6 @@ export async function cancelActions(
313306
mutation cancelActions($actionIDs: [Int!]!) {
314307
cancelActions(actionIDs: $actionIDs) {
315308
id
316-
protocolNetwork
317309
type
318310
allocationID
319311
deploymentID
@@ -349,7 +341,6 @@ export async function fetchAction(
349341
query action($actionID: Int!) {
350342
action(actionID: $actionID) {
351343
id
352-
protocolNetwork
353344
type
354345
allocationID
355346
deploymentID
@@ -398,7 +389,6 @@ export async function fetchActions(
398389
first: $first
399390
) {
400391
id
401-
protocolNetwork
402392
type
403393
allocationID
404394
deploymentID
@@ -435,7 +425,6 @@ export async function deleteActions(
435425
mutation deleteActions($actionIDs: [Int!]!) {
436426
deleteActions(actionIDs: $actionIDs) {
437427
id
438-
protocolNetwork
439428
type
440429
allocationID
441430
deploymentID
@@ -485,7 +474,6 @@ export async function updateActions(
485474
transaction
486475
status
487476
failureReason
488-
protocolNetwork
489477
}
490478
}
491479
`,

packages/indexer-cli/src/commands/indexer/actions/queue.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import chalk from 'chalk'
33

44
import { loadValidatedConfig } from '../../../config'
55
import { createIndexerManagementClient } from '../../../client'
6-
import {
7-
requireProtocolNetworkOption,
8-
printObjectOrArray,
9-
} from '../../../command-helpers'
6+
import { printObjectOrArray } from '../../../command-helpers'
107
import { buildActionInput, queueActions, validateActionType } from '../../../actions'
118
import {
129
ActionInput,
@@ -29,7 +26,6 @@ ${chalk.bold(
2926
${chalk.dim('Options:')}
3027
3128
-h, --help Show usage information
32-
-n, --network <STRING> [Required] The protocol network for this action (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
3329
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
3430
-s, --source <STRING> Specify the source of the action decision
3531
-r, --reason <STRING> Specify the reason for the action to be taken
@@ -73,16 +69,13 @@ module.exports = {
7369
)
7470
}
7571

76-
const networkIdentifier = requireProtocolNetworkOption(parameters.options)
77-
7872
actionInputParams = await buildActionInput(
7973
validateActionType(type),
8074
{ targetDeployment, param1, param2, param3, param4 },
8175
decisionSource,
8276
decisionReason,
8377
ActionStatus.QUEUED,
8478
executionPriority,
85-
networkIdentifier,
8679
)
8780

8881
inputSpinner.succeed(`Processed input parameters`)
@@ -111,7 +104,6 @@ module.exports = {
111104

112105
printObjectOrArray(print, outputFormat, queuedAction, [
113106
'id',
114-
'protocolNetwork',
115107
'type',
116108
'deploymentID',
117109
'allocationID',

packages/indexer-common/src/actions.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Logger } from '@graphprotocol/common-ts'
44
import { WhereOperators, WhereOptions } from 'sequelize'
55
import { Op } from 'sequelize'
66
import { WhereAttributeHashValue } from 'sequelize/types/model'
7-
import { validateNetworkIdentifier } from './parsers'
87

98
export interface ActionParamsInput {
109
deploymentID?: string
@@ -45,7 +44,6 @@ export interface ActionInput {
4544
reason: string
4645
status: ActionStatus
4746
priority: number | undefined
48-
protocolNetwork: string
4947
}
5048

5149
export const isValidActionInput = (
@@ -87,18 +85,6 @@ export const validateActionInputs = async (
8785
// Validate actions before adding to queue
8886
// TODO: Perform all checks simultaneously and throw combined error if 1 or more fail
8987
for (const action of actions) {
90-
// Must have a valid protocol network identifier
91-
if (!action.protocolNetwork) {
92-
throw Error("Cannot set an action without the field 'protocolNetwork'")
93-
}
94-
95-
try {
96-
// Set the parsed network identifier back in the action input object
97-
action.protocolNetwork = validateNetworkIdentifier(action.protocolNetwork)
98-
} catch (e) {
99-
throw Error(`Invalid value for the field 'protocolNetwork'. ${e}`)
100-
}
101-
10288
// Must have the required params for the action type
10389
if (!isValidActionInput(action)) {
10490
throw new Error(

packages/indexer-common/src/indexer-management/__tests__/resolvers/actions.test.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,6 @@ async function actionInputToExpected(
165165
}
166166
}
167167

168-
// We expect the protocol network to be transformed to it's CAIP2-ID
169-
// form for all inputs
170-
if (input.protocolNetwork === 'arbitrum-sepolia') {
171-
expected.protocolNetwork = 'eip155:421614'
172-
}
173-
174168
return expected
175169
}
176170

@@ -709,8 +703,6 @@ describe.skip('Actions', () => {
709703
source: 'indexerAgent',
710704
reason: 'indexingRule',
711705
priority: 0,
712-
// When writing directly to the database, `protocolNetwork` must be in the CAIP2-ID format.
713-
protocolNetwork: 'eip155:421614',
714706
} as ActionInput
715707

716708
const proposedAction = {
@@ -721,16 +713,20 @@ describe.skip('Actions', () => {
721713
source: 'indexerAgent',
722714
reason: 'indexingRule',
723715
priority: 0,
724-
protocolNetwork: 'arbitrum-sepolia',
725716
} as ActionInput
726717

727-
await managementModels.Action.create(failedAction, {
728-
validate: true,
729-
returning: true,
730-
})
718+
await managementModels.Action.create(
719+
{ ...failedAction, protocolNetwork: 'whatever' },
720+
{
721+
validate: true,
722+
returning: true,
723+
},
724+
)
731725

732726
const result = await client
733-
.mutation(QUEUE_ACTIONS_MUTATION, { actions: [proposedAction] })
727+
.mutation(QUEUE_ACTIONS_MUTATION, {
728+
actions: [{ ...proposedAction, protocolNetwork: 'whatever' }],
729+
})
734730
.toPromise()
735731

736732
expect(result).toHaveProperty(
@@ -779,10 +775,13 @@ describe.skip('Actions', () => {
779775
protocolNetwork: 'arbitrum-sepolia',
780776
} as ActionInput
781777

782-
await managementModels.Action.create(successfulAction, {
783-
validate: true,
784-
returning: true,
785-
})
778+
await managementModels.Action.create(
779+
{ ...successfulAction, protocolNetwork: 'whatever' },
780+
{
781+
validate: true,
782+
returning: true,
783+
},
784+
)
786785

787786
await expect(
788787
client.mutation(QUEUE_ACTIONS_MUTATION, { actions: [proposedAction] }).toPromise(),
@@ -833,10 +832,13 @@ describe.skip('Actions', () => {
833832
protocolNetwork: 'arbitrum-sepolia',
834833
} as ActionInput
835834

836-
await managementModels.Action.create(queuedUnallocateAction, {
837-
validate: true,
838-
returning: true,
839-
})
835+
await managementModels.Action.create(
836+
{ ...queuedUnallocateAction, protocolNetwork: 'whatever' },
837+
{
838+
validate: true,
839+
returning: true,
840+
},
841+
)
840842

841843
const queuedAllocateAction1 = { ...queuedAllocateAction }
842844
const queuedAllocateAction2 = { ...queuedAllocateAction }

packages/indexer-common/src/indexer-management/resolvers/actions.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
IndexerManagementModels,
1414
OrderDirection,
1515
validateActionInputs,
16+
validateNetworkIdentifier,
1617
} from '@graphprotocol/indexer-common'
1718
import { literal, Op, Transaction } from 'sequelize'
1819
import { ActionManager } from '../actions'
@@ -29,6 +30,7 @@ async function executeQueueOperation(
2930
recentlyAttemptedActions: Action[],
3031
models: IndexerManagementModels,
3132
transaction: Transaction,
33+
protocolNetwork: string,
3234
): Promise<ActionResult[]> {
3335
// Check for previously failed conflicting actions
3436
const conflictingActions = recentlyAttemptedActions.filter(function (recentAction) {
@@ -49,14 +51,18 @@ async function executeQueueOperation(
4951
const duplicateActions = actionsAwaitingExecution.filter(
5052
(a) => a.deploymentID === action.deploymentID,
5153
)
54+
5255
if (duplicateActions.length === 0) {
5356
logger.trace('Inserting Action in database', { action })
5457
return [
55-
await models.Action.create(action, {
56-
validate: true,
57-
returning: true,
58-
transaction,
59-
}),
58+
await models.Action.create(
59+
{ ...action, protocolNetwork },
60+
{
61+
validate: true,
62+
returning: true,
63+
transaction,
64+
},
65+
),
6066
]
6167
} else if (duplicateActions.length === 1) {
6268
if (
@@ -155,9 +161,9 @@ export default {
155161
throw Error('IndexerManagementClient must be in `network` mode to modify actions')
156162
}
157163

158-
actions.forEach((action) => {
159-
action.protocolNetwork = network.networkMonitor.networkCAIPID
160-
})
164+
const protocolNetwork = validateNetworkIdentifier(
165+
network.specification.networkIdentifier,
166+
)
161167

162168
// Let Network Monitors validate actions based on their protocol networks
163169
await validateActionInputs(actions, network.networkMonitor, logger)
@@ -218,6 +224,7 @@ export default {
218224
recentlyAttemptedActions,
219225
models,
220226
transaction,
227+
protocolNetwork,
221228
)
222229
results = results.concat(result)
223230
}
@@ -364,11 +371,6 @@ export default {
364371

365372
// Helper function to assess equality among a enqueued and a proposed actions
366373
function compareActions(enqueued: Action, proposed: ActionInput): boolean {
367-
// actions are not the same if they target different protocol networks
368-
if (enqueued.protocolNetwork !== proposed.protocolNetwork) {
369-
return false
370-
}
371-
372374
// actions are not the same if they target different deployments
373375
if (enqueued.deploymentID !== proposed.deploymentID) {
374376
return false

0 commit comments

Comments
 (0)