diff --git a/scripts/update_network_account_listOfChanges.ts b/scripts/update_network_account_listOfChanges.ts index 55ba795f..a7de781a 100644 --- a/scripts/update_network_account_listOfChanges.ts +++ b/scripts/update_network_account_listOfChanges.ts @@ -337,7 +337,9 @@ const runProgram = async (): Promise => { const confirmation = (await askQuestion('Are you sure you want to proceed with these changes? (yes/no): ')).trim() console.log(`User input: ${confirmation}`) if (confirmation.toLowerCase() === 'yes' || confirmation.toLowerCase() === 'y') { + console.log('List of changes before length:', networkAccount.data.listOfChanges.length) networkAccount.data.listOfChanges.push(changes) + console.log('List of changes after length:', networkAccount.data.listOfChanges.length) const calculatedAccountHash = accountSpecificHash(networkAccount.data) networkAccount.hash = calculatedAccountHash diff --git a/src/API.ts b/src/API.ts index 82b00432..9bd62964 100644 --- a/src/API.ts +++ b/src/API.ts @@ -399,7 +399,7 @@ export function registerRoutes(server: FastifyInstance `${account.accountId}: ${account.stateId}`) + ) const res = Crypto.sign({ success: true, accountData, @@ -1222,7 +1225,10 @@ export function registerRoutes(server: FastifyInstance `${account.id}: ${account.hash}`) + ) const res = Crypto.sign(report) reply.send(res) } finally { diff --git a/src/Data/Collector.ts b/src/Data/Collector.ts index 62144a3f..61f99f91 100644 --- a/src/Data/Collector.ts +++ b/src/Data/Collector.ts @@ -878,7 +878,9 @@ export const storeReceiptData = async ( // timestamp: tx.timestamp, // }) const { afterStates, cycle, tx, appReceiptData, signedReceipt, globalModification } = receipt - const sortedVoteOffsets = globalModification ? [] : [...(signedReceipt as Receipt.SignedReceipt).voteOffsets].sort((a, b) => a - b) + const sortedVoteOffsets = globalModification + ? [] + : [...(signedReceipt as Receipt.SignedReceipt).voteOffsets].sort((a, b) => a - b) const medianOffset = sortedVoteOffsets[Math.floor(sortedVoteOffsets.length / 2)] ?? 0 const applyTimestamp = tx.timestamp + medianOffset * 1000 if (config.VERBOSE) console.log('RECEIPT', 'Save', txId, timestamp, senderInfo) @@ -931,8 +933,17 @@ export const storeReceiptData = async ( } if (account.timestamp !== account.data['timestamp']) Logger.mainLogger.error('Mismatched account timestamp', txId, account.accountId) - if (account.hash !== account.data['hash']) - Logger.mainLogger.error('Mismatched account hash', txId, account.accountId) + if (account.hash !== account.data['hash']) { + Logger.mainLogger.error( + '[DEBUG RESTORE] Mismatched account hash', + txId, + account.accountId, + 'account.hash:', + account.hash, + 'account.data.hash:', + account.data['hash'] + ) + } const accountExist = await Account.queryAccountByAccountId(account.accountId) if (accountExist) { diff --git a/src/GlobalAccount.ts b/src/GlobalAccount.ts index 87559925..be09537f 100644 --- a/src/GlobalAccount.ts +++ b/src/GlobalAccount.ts @@ -9,6 +9,7 @@ import { robustQuery, deepCopy } from './Utils' import { isDeepStrictEqual } from 'util' import { accountSpecificHash } from './shardeum/calculateAccountHash' import { allowedArchiversManager } from './shardeum/allowedArchiversManager' +import { Utils as StringUtils } from '@shardeum-foundation/lib-types' let cachedGlobalNetworkAccount: AccountDB.AccountsCopy let cachedGlobalNetworkAccountHash: string @@ -207,6 +208,25 @@ export const loadGlobalAccounts = async (): Promise => { const values = [] const accounts = await AccountDB.fetchAccountsBySqlQuery(sql, values) for (const account of accounts) { + const recalculatedHash = accountSpecificHash(account.data) + + if (recalculatedHash && recalculatedHash !== account.hash) { + Logger.mainLogger.warn( + '[DEBUG RESTORE] loadGlobalAccounts() - recalculatedHash !== account.hash', + 'accountId:', + account.accountId, + 'account.hash:', + account.hash, + 'recalculatedHash:', + recalculatedHash, + '\naccount data:', + StringUtils.safeStringify(account) + ) + account.hash = recalculatedHash + account.data.hash = recalculatedHash + await AccountDB.updateAccount(account) + } + globalAccountsMap.set(account.accountId, { hash: account.hash, timestamp: account.timestamp }) if (account.accountId === config.globalNetworkAccount) { setGlobalNetworkAccount(account) diff --git a/src/State.ts b/src/State.ts index f81c1628..84fbe239 100644 --- a/src/State.ts +++ b/src/State.ts @@ -264,7 +264,7 @@ export async function compareCycleRecordWithOtherArchivers( }) .catch((error) => { // Handle any errors that occurred - console.error(error) + console.error('compareCycleRecordWithOtherArchivers Error', error) }) return foundMatch } diff --git a/test/unit/src/API.test.ts b/test/unit/src/API.test.ts index 0758751d..6102cc86 100644 --- a/test/unit/src/API.test.ts +++ b/test/unit/src/API.test.ts @@ -2380,6 +2380,7 @@ describe('API', () => { totalAccounts: 1000, totalBalance: '1000000000', timestamp: 123456789, + accounts: [], } ;(AccountDataProvider.validateGlobalAccountReportRequest as jest.Mock).mockReturnValue({ success: true }) @@ -2394,6 +2395,7 @@ describe('API', () => { totalAccounts: 1000, totalBalance: '1000000000', timestamp: 123456789, + accounts: [], }) ) })