Skip to content
Open
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
2 changes: 2 additions & 0 deletions scripts/update_network_account_listOfChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ const runProgram = async (): Promise<void> => {
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
Expand Down
12 changes: 9 additions & 3 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,
cycleHash: hashes.cycleHash!,
receiptHash: hashes.receiptHash!,
originalTxHash: hashes.originalTxHash!,
};
}
}

reply.send({
Expand Down Expand Up @@ -1199,7 +1199,10 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,
return
}
const accountData = await AccountDataProvider.provideAccountDataByListRequest(payload)
// Logger.mainLogger.debug('Account Data By List result', accountData)
Logger.mainLogger.debug(
'[DEBUG RESTORE] Account Data By List result',
accountData.map((account) => `${account.accountId}: ${account.stateId}`)
)
const res = Crypto.sign({
success: true,
accountData,
Expand All @@ -1222,7 +1225,10 @@ export function registerRoutes(server: FastifyInstance<Server, IncomingMessage,
return
}
const report = await AccountDataProvider.provideGlobalAccountReportRequest()
// Logger.mainLogger.debug('Global Account Report result', report)
Logger.mainLogger.debug(
'[DEBUG RESTORE] Global Account Report result',
report.accounts.map((account) => `${account.id}: ${account.hash}`)
)
const res = Crypto.sign(report)
reply.send(res)
} finally {
Expand Down
17 changes: 14 additions & 3 deletions src/Data/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions src/GlobalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -207,6 +208,25 @@ export const loadGlobalAccounts = async (): Promise<void> => {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/src/API.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,7 @@ describe('API', () => {
totalAccounts: 1000,
totalBalance: '1000000000',
timestamp: 123456789,
accounts: [],
}

;(AccountDataProvider.validateGlobalAccountReportRequest as jest.Mock).mockReturnValue({ success: true })
Expand All @@ -2394,6 +2395,7 @@ describe('API', () => {
totalAccounts: 1000,
totalBalance: '1000000000',
timestamp: 123456789,
accounts: [],
})
)
})
Expand Down
Loading