Skip to content
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
4 changes: 2 additions & 2 deletions scripts/update_network_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -62,7 +62,7 @@ const runProgram = async (): Promise<void> => {
// 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
Expand Down
14 changes: 12 additions & 2 deletions src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
Expand Down
35 changes: 6 additions & 29 deletions src/GlobalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface GlobalAccountsHashAndTimestamp {
timestamp: number
}
export const globalAccountsMap = new Map<string, GlobalAccountsHashAndTimestamp>()
const appliedConfigChanges = new Set<string>()

export function getGlobalNetworkAccount(hash: boolean): object | string {
if (hash) {
Expand Down Expand Up @@ -79,39 +78,25 @@ export const updateGlobalNetworkAccount = async (cycleNumber: number): Promise<v
if (!changes || !Array.isArray(changes)) {
return
}
const activeConfigChanges = new Set<string>()
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
}

Expand All @@ -121,14 +106,6 @@ export const updateGlobalNetworkAccount = async (cycleNumber: number): Promise<v
await AccountDB.updateAccount(networkAccount)
setGlobalNetworkAccount(networkAccount)
}
if (activeConfigChanges.size > 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[] => {
Expand Down
Loading