diff --git a/scripts/update_network_account.ts b/scripts/update_network_account.ts index 449bf63..1bbfba7 100644 --- a/scripts/update_network_account.ts +++ b/scripts/update_network_account.ts @@ -7,7 +7,7 @@ import * as dbstore from '../src/dbstore' import * as AccountDB from '../src/dbstore/accounts' import { startSaving } from '../src/saveConsoleOutput' import * as Logger from '../src/Logger' -import { accountSpecificHash } from '../src/shardeum/calculateAccountHash' +import { calculateAccountHash } from '../src/shardeum/calculateAccountHash' import { addSigListeners } from '../src/State' import { Utils as StringUtils } from '@shardeum-foundation/lib-types' import { initAjvSchemas } from '../src/types/ajv/Helpers' @@ -62,7 +62,7 @@ const runProgram = async (): Promise => { // cycle: 0, // Set shutdown cycle number for tracking of the config changes // }) - const calculatedAccountHash = accountSpecificHash(networkAccount.data) + const calculatedAccountHash = calculateAccountHash(networkAccount.data) networkAccount.hash = calculatedAccountHash networkAccount.data.hash = calculatedAccountHash diff --git a/src/Data/Data.ts b/src/Data/Data.ts index 59fce47..6044c5f 100644 --- a/src/Data/Data.ts +++ b/src/Data/Data.ts @@ -1123,8 +1123,7 @@ export async function subscribeNodeFromThisSubset( let newSenderInfo = nodeList[Math.floor(Math.random() * nodeList.length)] let connectionStatus = false let retry = 0 - const MAX_RETRY_SUBSCRIPTION = 3 * numberOfNodesToSubsribe - while (retry < MAX_RETRY_SUBSCRIPTION && subscribedNodesFromThisSubset.length < numberOfNodesToSubsribe) { + while (subscribedNodesFromThisSubset.length < numberOfNodesToSubsribe) { if (!dataSenders.has(newSenderInfo.publicKey)) { connectionStatus = await createDataTransferConnection(newSenderInfo) if (connectionStatus) { @@ -1151,6 +1150,17 @@ export async function subscribeNodeFromThisSubset( } else { subsetList = [...nodeList] retry++ + // Linear delay (retry * 1s, max 5s) when subsetList runs out + const delay = Math.min(retry, 5) * 1000 + Logger.mainLogger.debug(`subsetList exhausted, retry ${retry}, waiting ${delay}ms`) + if (retry > 10) { + Logger.fatalLogger.fatal( + `subscribeNodeFromThisSubset: failed to subscribe after ${retry} retries, nodeList: ${JSON.stringify( + nodeList + )}}` + ) + } + await Utils.sleep(delay) } } } diff --git a/src/GlobalAccount.ts b/src/GlobalAccount.ts index dc54aeb..a21139f 100644 --- a/src/GlobalAccount.ts +++ b/src/GlobalAccount.ts @@ -23,7 +23,6 @@ export interface GlobalAccountsHashAndTimestamp { timestamp: number } export const globalAccountsMap = new Map() -const appliedConfigChanges = new Set() export function getGlobalNetworkAccount(hash: boolean): object | string { if (hash) { @@ -79,39 +78,25 @@ export const updateGlobalNetworkAccount = async (cycleNumber: number): Promise() for (const change of changes) { - // skip future changes - if (change.cycle > cycleNumber) { + // skip changes that are not for the current cycle + if (change.cycle !== cycleNumber) { continue } - const changeHash = Crypto.hashObj(change) - // skip handled changes - if (appliedConfigChanges.has(changeHash)) { - activeConfigChanges.add(changeHash) - continue - } - // apply this change - appliedConfigChanges.add(changeHash) - activeConfigChanges.add(changeHash) - const changeObj = change.change const appData = change.appData - // If there is initShutdown change, if the latest cycle is greater than the cycle of the change, then skip it - if (changeObj['p2p'] && changeObj['p2p']['initShutdown'] && change.cycle !== cycleNumber) continue - const newChanges = pruneNetworkChangeQueue(changes, cycleNumber) networkAccount.data.listOfChanges = newChanges - // https://github.com/shardeum/shardeum/blob/c449ecd21391747c5b7173da3a74415da2acb0be/src/index.ts#L6958 - // Increase the timestamp by 1 second + // https://github.com/Liberdus/server/blob/06fd6d6301a2879dae106fd9fb79ca78840618be/src/index.ts#L1983 + // Increase the timestamp by 1 second for the change ( must be the same as on the dapp ) // networkAccount.data.timestamp += 1000 if (appData) { updateNetworkChangeQueue(networkAccount.data, appData) console.log('[updateGlobalNetworkAccount] updateNetworkChangeQueue called') console.dir(networkAccount.data, { depth: null }) - // https://github.com/shardeum/shardeum/blob/c449ecd21391747c5b7173da3a74415da2acb0be/src/index.ts#L6889 - // Increase the timestamp by 1 second + // https://github.com/Liberdus/server/blob/06fd6d6301a2879dae106fd9fb79ca78840618be/src/index.ts#L1983 + // Increase the timestamp by 1 second for the change ( must be the same as on the dapp ) // networkAccount.data.timestamp += 1000 } @@ -121,14 +106,6 @@ export const updateGlobalNetworkAccount = async (cycleNumber: number): Promise 0) { - // clear the entries from appliedConfigChanges that are no longer in the changes list - for (const changeHash of appliedConfigChanges) { - if (!activeConfigChanges.has(changeHash)) { - appliedConfigChanges.delete(changeHash) - } - } - } } const generatePathKeys = (obj: any, prefix = ''): string[] => {