Skip to content

Instantly share code, notes, and snippets.

@ImmunefiEditor
Last active October 29, 2024 10:54
Show Gist options
  • Select an option

  • Save ImmunefiEditor/323ccb166a47f3ac4e6463b23c510b14 to your computer and use it in GitHub Desktop.

Select an option

Save ImmunefiEditor/323ccb166a47f3ac4e6463b23c510b14 to your computer and use it in GitHub Desktop.
export function selectNodes(maxAllowed: number): void {
const standbyNodesInfo = getStandbyNodesInfoMap()
/* prettier-ignore */ if (logFlags.p2pNonFatal && logFlags.console) console.log('selecting from standbyNodesInfo', standbyNodesInfo)
// construct a list of objects that we'll sort by `selectionNum`. we'll use
// the public key to get the join request associated with the public key and
// inform the node later that it has been accepted
const objs: {
publicKey: string
selectionNum: string
appJoinData?: Record<string, any> | null //appJoinData is required for golden ticket
}[] = []
for (const [publicKey, info] of standbyNodesInfo) {
objs.push({
publicKey,
selectionNum: info.selectionNum,
appJoinData: info.appJoinData,
})
}
/* snippet of code */
// If golden ticket is enabled, add nodes with adminCert + golden ticket to selectedPublicKeys if they are not already there
if (shardus.config.p2p.goldenTicketEnabled === true) {
for (const obj of objs) {
if (obj.appJoinData?.adminCert?.goldenTicket === true && !selectedPublicKeys.has(obj.publicKey)) { // @audit no golden ticket verification
/* prettier-ignore */ if (logFlags.p2pNonFatal && logFlags.console) console.log('selecting golden ticket nodes from standbyNodesInfo')
selectedPublicKeys.add(obj.publicKey)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment