Skip to content

Commit

Permalink
refactor: replace addStandbyNodes with standard addNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
muni-corn committed Apr 23, 2024
1 parent 1b27987 commit 3748c29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Data/Cycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function updateNodeList(cycle: P2PTypes.CycleCreatorTypes.CycleData): void {
ip: joinRequest.nodeInfo.externalIp,
port: joinRequest.nodeInfo.externalPort,
}))
NodeList.addStandbyNodes(standbyNodeList)
NodeList.addNodes(NodeList.NodeStatus.STANDBY, standbyNodeList)
}

if (standbyRemove.length > 0) {
Expand Down
17 changes: 8 additions & 9 deletions src/NodeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ export function addNodes(status: NodeStatus, nodes: Node[]): void {
// activeListByIdSorted.map((node) => node.id)
// )
break
case NodeStatus.STANDBY:
if (activeList.has(key)) {
activeList.delete(key)
activeListByIdSorted = activeListByIdSorted.filter((node) => node.publicKey === key)
}
if (syncingList.has(key)) syncingList.delete(key)
if (!standbyList.has(key)) standbyList.set(key, node)
break
}
/* eslint-disable security/detect-object-injection */
byPublicKey[node.publicKey] = node
Expand Down Expand Up @@ -243,15 +251,6 @@ export function removeNodes(publicKeys: string[]): void {
}
}

export const addStandbyNodes = (nodes: ConsensusNodeInfo[]): void => {
if (nodes.length === 0) return
Logger.mainLogger.debug('Adding standby nodes to the list', nodes.length, nodes)
for (const node of nodes) {
if (standbyList.has(node.publicKey)) continue
standbyList.set(node.publicKey, node)
}
}

export const removeStandbyNodes = (publicKeys: string[]): void => {
if (publicKeys.length > 0) Logger.mainLogger.debug('Removing standby nodes', publicKeys)
for (const key of publicKeys) {
Expand Down
2 changes: 1 addition & 1 deletion src/sync-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function syncV2(
}))
NodeList.addNodes(NodeList.NodeStatus.SYNCING, syncingNodeList)
NodeList.addNodes(NodeList.NodeStatus.ACTIVE, activeNodeList)
NodeList.addStandbyNodes(standbyNodeList)
NodeList.addNodes(NodeList.NodeStatus.STANDBY, standbyNodeList)

// reset the active archivers list with the new list
resetActiveArchivers(archiverList)
Expand Down

0 comments on commit 3748c29

Please sign in to comment.