Skip to content

Commit

Permalink
agent: Strengthen Agent init for repeated network identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Jun 28, 2023
1 parent 6320934 commit af9ec50
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,25 @@ function createMultiNetworks(
networks: Network[],
operators: Operator[],
): MultiNetworks<NetworkAndOperator> {
// Check if inputs have uneven lenghts and if they have the same network identifiers
// Validate that Networks and Operator arrays have even lengths and
// contain unique, matching network identifiers.
const visited = new Set()
const validInputs =
networks.length === operators.length &&
networks.every(
(network, index) =>
networks.every((network, index) => {
const sameIdentifier =
network.specification.networkIdentifier ===
operators[index].specification.networkIdentifier,
)
operators[index].specification.networkIdentifier
if (!sameIdentifier) {
return false
}
if (visited.has(network.specification.networkIdentifier)) {
return false
}
visited.add(network.specification.networkIdentifier)
return true
})

if (!validInputs) {
throw new Error(
'Invalid Networks and Operator pairs used in Agent initialization',
Expand Down Expand Up @@ -510,8 +521,6 @@ export class Agent {
},
)



join({
ticker: timer(240_000),
currentEpochNumber,
Expand Down

0 comments on commit af9ec50

Please sign in to comment.