Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SYS-126: Undo changes made to the archiver for SYS-126 #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.addNodes(NodeList.NodeStatus.STANDBY, standbyNodeList)
NodeList.addStandbyNodes(standbyNodeList)
}

if (standbyRemove.length > 0) {
Expand Down
22 changes: 10 additions & 12 deletions src/NodeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions src/sync-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
)
)
}
Expand Down
Loading