diff --git a/src/p2p/Self.ts b/src/p2p/Self.ts index 8291c93c8..6e371eea1 100644 --- a/src/p2p/Self.ts +++ b/src/p2p/Self.ts @@ -78,6 +78,7 @@ let cyclesElapsedSinceRefresh = 0 const idErrorMessage = `id did not match the cycle record info` +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type const nodeMatch = (node) => node.externalIp === network.ipInfo.externalIp && node.externalPort === network.ipInfo.externalPort @@ -276,7 +277,10 @@ export function startupV2(): Promise { const resp = await Join.fetchJoinedV2(activeNodes) info(`startupV2: resp ${Utils.safeStringify(resp)}`) - nestedCountersInstance.countEvent('p2p', `fetchJoinedV2: isOnStandbyList: ${resp.isOnStandbyList} id: ${resp.id}`) + nestedCountersInstance.countEvent( + 'p2p', + `fetchJoinedV2: isOnStandbyList: ${resp.isOnStandbyList} id: ${resp.id}` + ) // note the list below is in priority order of what operation is the most important // mainly this matters on something like our node being selected to join but also on the @@ -293,7 +297,8 @@ export function startupV2(): Promise { /* prettier-ignore */ nestedCountersInstance.countEvent('p2p', `detected self as zombie ${latestCycle.counter} waiting ${Context.config.p2p.delayZombieRestartSec} before exiting`, 1) - utils.sleep(Context.config.p2p.delayZombieRestartSec * 1000 /*sec to ms*/).then(() => { //give the network a chance to see we are not active + utils.sleep(Context.config.p2p.delayZombieRestartSec * 1000 /*sec to ms*/).then(() => { + //give the network a chance to see we are not active //TODO in the future if we are more confident in our ablility to shut down the node from functioning // we could have a shutdown wait. (but there is a lot of surface area) // the other method would be to request to be shut down but that is tricky and may not be possible @@ -625,7 +630,7 @@ async function joinNetworkV2(activeNodes): Promise { info(`joinNetworkV2: got latest cycle :${mode}`) const publicKey = Context.crypto.getPublicKey() - try{ + try { const isReadyToJoin = await Context.shardus.app.isReadyToJoin(latestCycle, publicKey, activeNodes, mode) if (!isReadyToJoin) { /* prettier-ignore */ nestedCountersInstance.countEvent('p2p', `joinNetworkV2:isReadyToJoin:false`) @@ -634,7 +639,7 @@ async function joinNetworkV2(activeNodes): Promise { } else { /* prettier-ignore */ nestedCountersInstance.countEvent('p2p', `joinNetworkV2:isReadyToJoin:true`) } - } catch(ex){ + } catch (ex) { /* prettier-ignore */ nestedCountersInstance.countEvent('p2p', `joinNetworkV2:isReadyToJoin:crashed: ${ex?.message}`) warn(`joinNetworkV2: isReadyToJoin crashed :${utils.formatErrorMessage(ex)}`) return @@ -844,7 +849,7 @@ async function checkNodeId(nodeMatch: (node: any) => boolean, selfId: string): P if (logFlags.p2pNonFatal) info('Node passed id check') } -async function contactArchiver(dbgContex:string): Promise { +async function contactArchiver(dbgContex: string): Promise { const maxRetries = 10 let retry = maxRetries const failArchivers: string[] = [] @@ -859,7 +864,7 @@ async function contactArchiver(dbgContex:string): Promise { archiver = getRandomAvailableArchiver() info(`contactArchiver: communicate with:${archiver?.ip}`) - if (!failArchivers.includes(archiver.ip + ':' + archiver.port)){ + if (!failArchivers.includes(archiver.ip + ':' + archiver.port)) { failArchivers.push(archiver.ip + ':' + archiver.port) } @@ -870,14 +875,16 @@ async function contactArchiver(dbgContex:string): Promise { activeNodesSigned.nodeList.length === 0 ) { /* prettier-ignore */ nestedCountersInstance.countEvent('p2p', `contactArchiver: no nodes in nodelist yet. ${dbgContex}`, 1) - info(`contactArchiver: no nodes in nodelist yet, or seedlist null ${Utils.safeStringify(activeNodesSigned)}`) + info( + `contactArchiver: no nodes in nodelist yet, or seedlist null ${Utils.safeStringify( + activeNodesSigned + )}` + ) await utils.sleep(1000) // no nodes in nodelist yet so please take a breather. would be smarter to ask each archiver only once but - // but do not want to refactor that much right now + // but do not want to refactor that much right now if (retry === 1) { /* prettier-ignore */ nestedCountersInstance.countEvent('p2p', `contactArchiver: no nodes in nodelist yet out of retries. ${dbgContex}`, 1) - throw Error( - `contactArchiver: nodelist null or empty after ${maxRetries} retries:` - ) + throw Error(`contactArchiver: nodelist null or empty after ${maxRetries} retries:`) } continue } @@ -904,7 +911,11 @@ async function contactArchiver(dbgContex:string): Promise { info(`contactArchiver: passed ${archiver.ip} retry:${retry}`) - info(`contactArchiver: activeNodesSigned:${Utils.safeStringify(activeNodesSigned?.joinRequest)} restartCycleRecord:${Utils.safeStringify(activeNodesSigned?.restartCycleRecord)}`) + info( + `contactArchiver: activeNodesSigned:${Utils.safeStringify( + activeNodesSigned?.joinRequest + )} restartCycleRecord:${Utils.safeStringify(activeNodesSigned?.restartCycleRecord)}` + ) const joinRequest: P2P.ArchiversTypes.Request | undefined = activeNodesSigned.joinRequest as | P2P.ArchiversTypes.Request @@ -995,6 +1006,10 @@ async function getActiveNodesFromArchiver( archiver: ActiveNode ): Promise> { const nodeInfo = getPublicNodeInfo() + const joinRequest = { + nodeInfo: nodeInfo, + appJoinData: Context.shardus.app.getNodeInfoAppData(), + } const seedListResult: Result< P2P.P2PTypes.SignedObject, Error @@ -1002,7 +1017,7 @@ async function getActiveNodesFromArchiver( archiver, 'nodelist', Context.crypto.sign({ - nodeInfo, + joinRequest, }), 10000 ) @@ -1157,12 +1172,12 @@ function acceptedTrigger(): Promise { * @returns */ export function waitForQ1SendRequests(): Promise { - return new Promise(resolve => { + return new Promise((resolve) => { const intervalId = setInterval(() => { if (currentQuarter === 1 && q1SendRequests === true) { - clearInterval(intervalId); - resolve(); + clearInterval(intervalId) + resolve() } - }, Context.config.p2p.secondsToCheckForQ1); - }); + }, Context.config.p2p.secondsToCheckForQ1) + }) }