diff --git a/src/Data/Cycles.ts b/src/Data/Cycles.ts index aaffe8e6..f4aa04ce 100644 --- a/src/Data/Cycles.ts +++ b/src/Data/Cycles.ts @@ -266,7 +266,7 @@ function updateNodeList(cycle: P2PTypes.CycleCreatorTypes.CycleData): void { ip: joinRequest.nodeInfo.externalIp, port: joinRequest.nodeInfo.externalPort, })) - NodeList.addNodes(NodeList.NodeStatus.STANDBY, standbyNodeList) + NodeList.addStandbyNodes(standbyNodeList) } if (standbyRemove.length > 0) { diff --git a/src/NodeList.ts b/src/NodeList.ts index aec5daa1..c0b92c26 100644 --- a/src/NodeList.ts +++ b/src/NodeList.ts @@ -146,14 +146,6 @@ 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 @@ -172,7 +164,7 @@ export function addNodes(status: NodeStatus, nodes: Node[]): void { } } } -export function refreshNodes(status: NodeStatus, nodes: Node[]): void { +export function refreshNodes(status: NodeStatus, nodes: ConsensusNodeInfo[] | JoinedConsensor[]): void { if (nodes.length === 0) return Logger.mainLogger.debug('Refreshing nodes', nodes.length, nodes) for (const node of nodes) { @@ -184,9 +176,6 @@ export function refreshNodes(status: NodeStatus, nodes: Node[]): void { Logger.mainLogger.debug('adding new node during refresh', node.publicKey) list.push(node) switch (status) { - case NodeStatus.STANDBY: - standbyList.set(node.publicKey, node) - break case NodeStatus.SYNCING: syncingList.set(node.publicKey, node) break @@ -254,6 +243,15 @@ 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) { diff --git a/src/sync-v2/index.ts b/src/sync-v2/index.ts index ab8677dc..d13359c4 100644 --- a/src/sync-v2/index.ts +++ b/src/sync-v2/index.ts @@ -18,7 +18,7 @@ import { import { ArchiverNodeInfo, resetActiveArchivers } from '../State' import { getActiveNodeListFromArchiver } from '../NodeList' import * as NodeList from '../NodeList' -import { verifyArchiverList, verifyCycleRecord, verifyStandbyList, verifyValidatorList } from './verify' +import { verifyArchiverList, verifyCycleRecord, verifyValidatorList } from './verify' import * as Logger from '../Logger' /** @@ -112,7 +112,7 @@ export function syncV2( })) NodeList.addNodes(NodeList.NodeStatus.SYNCING, syncingNodeList) NodeList.addNodes(NodeList.NodeStatus.ACTIVE, activeNodeList) - NodeList.addNodes(NodeList.NodeStatus.STANDBY, standbyNodeList) + NodeList.addStandbyNodes(standbyNodeList) // reset the active archivers list with the new list resetActiveArchivers(archiverList) @@ -172,9 +172,7 @@ function syncStandbyNodeList( return robustQueryForStandbyNodeListHash(activeNodes).andThen(({ value, winningNodes }) => // get full standby list from one of the winning nodes getStandbyNodeListFromNode(winningNodes[0], value.standbyNodeListHash).andThen((standbyList) => - verifyStandbyList(standbyList, value.standbyNodeListHash).map( - () => [standbyList, value.standbyNodeListHash] as [P2PTypes.JoinTypes.JoinRequest[], hexstring] - ) + okAsync([standbyList, value.standbyNodeListHash] as [P2PTypes.JoinTypes.JoinRequest[], hexstring]) ) ) }