Skip to content

Commit 810624e

Browse files
committed
Refactor exit and state logging to remove timestamp match reporting
1 parent 227a1ac commit 810624e

3 files changed

Lines changed: 35 additions & 81 deletions

File tree

src/exit-handler/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,11 @@ class ExitHandler {
174174
const totalMismatches = report.summary.totalAccounts - report.summary.fullyMatching
175175
if (totalMismatches > 0) {
176176
this.exitLogger.fatal(`Total mismatches found: ${totalMismatches}`)
177-
this.exitLogger.fatal(
178-
`Cache-Trie timestamp matches: ${report.summary.ctt}/${report.summary.totalAccounts}`
179-
)
180177
this.exitLogger.fatal(`Cache-Trie hash matches: ${report.summary.cth}/${report.summary.totalAccounts}`)
181178
this.exitLogger.fatal(
182179
`Cache-Storage timestamp matches: ${report.summary.cst}/${report.summary.totalAccounts}`
183180
)
184181
this.exitLogger.fatal(`Cache-Storage hash matches: ${report.summary.csh}/${report.summary.totalAccounts}`)
185-
this.exitLogger.fatal(
186-
`Trie-Storage timestamp matches: ${report.summary.tst}/${report.summary.totalAccounts}`
187-
)
188182
this.exitLogger.fatal(`Trie-Storage hash matches: ${report.summary.tsh}/${report.summary.totalAccounts}`)
189183
} else {
190184
this.exitLogger.fatal('All accounts are fully consistent across cache, trie, and storage!')

src/state-manager/AccountPatcher.ts

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,19 +1744,16 @@ class AccountPatcher {
17441744
res.write(`Total execution time: ${totalTimeMs}ms\n`)
17451745
res.write(`Total accounts processed: ${report.summary.totalAccounts}\n`)
17461746
res.write(`Fully matching accounts: ${report.summary.fullyMatching}\n`)
1747-
res.write(`Cache-Trie timestamp matches: ${report.summary.ctt}\n`)
17481747
res.write(`Cache-Trie hash matches: ${report.summary.cth}\n`)
17491748
res.write(`Cache-Storage timestamp matches: ${report.summary.cst}\n`)
17501749
res.write(`Cache-Storage hash matches: ${report.summary.csh}\n`)
1751-
res.write(`Trie-Storage timestamp matches: ${report.summary.tst}\n`)
17521750
res.write(`Trie-Storage hash matches: ${report.summary.tsh}\n\n`)
17531751

17541752
res.write('=== CHUNK PERFORMANCE ===\n')
17551753
for (const chunk of report.summary.chunks) {
17561754
if (chunk.recordsProcessed > 0) {
17571755
res.write(
1758-
`Chunk ${chunk.chunkIndex}: ${chunk.recordsProcessed} records in ${
1759-
chunk.timeSpentMs
1756+
`Chunk ${chunk.chunkIndex}: ${chunk.recordsProcessed} records in ${chunk.timeSpentMs
17601757
}ms (${chunk.low.substring(0, 4)}...)\n`
17611758
)
17621759
}
@@ -1769,7 +1766,7 @@ class AccountPatcher {
17691766
let accountsToShow = report.accounts
17701767
if (onlyMismatch) {
17711768
accountsToShow = report.accounts.filter(
1772-
(account) => !account.ctt || !account.cth || !account.cst || !account.csh || !account.tst || !account.tsh
1769+
(account) => !account.cth || !account.cst || !account.csh || !account.tsh
17731770
)
17741771
}
17751772

@@ -1788,7 +1785,7 @@ class AccountPatcher {
17881785
}
17891786
if (account.trie) {
17901787
res.write(
1791-
` Trie: hash=${account.trie.hash.substring(0, 8)}... timestamp=${account.trie.timestamp || 'N/A'}\n`
1788+
` Trie: hash=${account.trie.hash.substring(0, 8)}...\n`
17921789
)
17931790
} else {
17941791
res.write(` Trie: [missing]\n`)
@@ -1801,7 +1798,7 @@ class AccountPatcher {
18011798
res.write(` Storage: [missing]\n`)
18021799
}
18031800
res.write(
1804-
` Matches: ctt=${account.ctt} cth=${account.cth} cst=${account.cst} csh=${account.csh} tst=${account.tst} tsh=${account.tsh}\n\n`
1801+
` Matches: cth=${account.cth} cst=${account.cst} csh=${account.csh} tsh=${account.tsh}\n\n`
18051802
)
18061803
}
18071804
}
@@ -2454,8 +2451,7 @@ class AccountPatcher {
24542451
if (coverageEntry == null || coverageEntry.firstChoice == null) {
24552452
const numActiveNodes = this.stateManager.currentCycleShardData.nodes.length
24562453
this.statemanager_fatal(
2457-
`getNodeForQuery null ${coverageEntry == null} ${
2458-
coverageEntry?.firstChoice == null
2454+
`getNodeForQuery null ${coverageEntry == null} ${coverageEntry?.firstChoice == null
24592455
} numActiveNodes:${numActiveNodes}`,
24602456
`getNodeForQuery null ${coverageEntry == null} ${coverageEntry?.firstChoice == null}`
24612457
)
@@ -2973,8 +2969,7 @@ class AccountPatcher {
29732969
/* prettier-ignore */ nestedCountersInstance.countEvent(`accountPatcher`, `not enough votes ${radix} ${utils.makeShortHash(votesMap.bestHash)} uniqueVotes: ${votesMap.allVotes.size}`, 1)
29742970
this.statemanager_fatal(
29752971
'debug findBadAccounts',
2976-
`debug findBadAccounts ${cycle}: ${radix} bestVotes${
2977-
votesMap.bestVotes
2972+
`debug findBadAccounts ${cycle}: ${radix} bestVotes${votesMap.bestVotes
29782973
} < minVotes:${minVotes} uniqueVotes: ${votesMap.allVotes.size} ${utils.stringifyReduce(simpleMap)}`
29792974
)
29802975
}
@@ -3042,10 +3037,8 @@ class AccountPatcher {
30423037
}
30433038
this.statemanager_fatal(
30443039
'debug findBadAccounts',
3045-
`debug findBadAccounts ${cycle}: ${
3046-
radixToFix.radix
3047-
} isInNonConsensusRange: ${hasNonConsensusRange} isInNonStorageRange: ${hasNonStorageRange} bestVotes ${
3048-
votesMap.bestVotes
3040+
`debug findBadAccounts ${cycle}: ${radixToFix.radix
3041+
} isInNonConsensusRange: ${hasNonConsensusRange} isInNonStorageRange: ${hasNonStorageRange} bestVotes ${votesMap.bestVotes
30493042
} minVotes:${minVotes} uniqueVotes: ${votesMap.allVotes.size} ${utils.stringifyReduce(simpleMap)}`
30503043
)
30513044
}
@@ -3799,8 +3792,7 @@ class AccountPatcher {
37993792

38003793
if (logFlags.debug) {
38013794
this.mainLogger.debug(
3802-
`badAccounts cycle: ${cycle}, ourBadAccounts: ${
3803-
results.badAccounts.length
3795+
`badAccounts cycle: ${cycle}, ourBadAccounts: ${results.badAccounts.length
38043796
}, ourBadAccounts: ${Utils.safeStringify(results.badAccounts)}`
38053797
)
38063798
}
@@ -3810,8 +3802,7 @@ class AccountPatcher {
38103802
accountsTheyNeedToRepair = accountsTheyNeedToRepair.concat(results.extraBadAccounts)
38113803
}
38123804
this.mainLogger.debug(
3813-
`badAccounts cycle: ${cycle}, accountsTheyNeedToRepair: ${
3814-
accountsTheyNeedToRepair.length
3805+
`badAccounts cycle: ${cycle}, accountsTheyNeedToRepair: ${accountsTheyNeedToRepair.length
38153806
}, accountsTheyNeedToRepair: ${Utils.safeStringify(accountsTheyNeedToRepair)}`
38163807
)
38173808
fireAndForget(() => this.requestOtherNodesToRepair(accountsTheyNeedToRepair))
@@ -3883,8 +3874,7 @@ class AccountPatcher {
38833874
'checkAndSetAccountData updateTooOld',
38843875
`checkAndSetAccountData updateTooOld ${cycle}: acc:${utils.stringifyReduce(
38853876
wrappedData.accountId
3886-
)} updateTS:${wrappedData.timestamp} updateHash:${utils.stringifyReduce(wrappedData.stateId)} cacheTS:${
3887-
accountMemData.t
3877+
)} updateTS:${wrappedData.timestamp} updateHash:${utils.stringifyReduce(wrappedData.stateId)} cacheTS:${accountMemData.t
38883878
} cacheHash:${utils.stringifyReduce(accountMemData.h)}`
38893879
)
38903880
filterStats.tooOld++
@@ -4101,8 +4091,7 @@ class AccountPatcher {
41014091
)
41024092
this.statemanager_fatal(
41034093
'isInSync = false',
4104-
`bad accounts cycle:${cycle} bad:${results.badAccounts.length} received:${wrappedDataList.length} failedH: ${
4105-
failedHashes.length
4094+
`bad accounts cycle:${cycle} bad:${results.badAccounts.length} received:${wrappedDataList.length} failedH: ${failedHashes.length
41064095
} filtered:${utils.stringifyReduce(filterStats)} stats:${utils.stringifyReduce(
41074096
results.stats
41084097
)} getAccountStats: ${utils.stringifyReduce(getAccountStats)} details: ${utils.stringifyReduceLimit(
@@ -4688,8 +4677,7 @@ class AccountPatcher {
46884677
}
46894678

46904679
stream.write(
4691-
`node: ${nodesCovered.id} ${nodesCovered.ipPort}\tgraph: ${partitionGraph}\thome: ${
4692-
nodesCovered.hP
4680+
`node: ${nodesCovered.id} ${nodesCovered.ipPort}\tgraph: ${partitionGraph}\thome: ${nodesCovered.hP
46934681
} data:${Utils.safeStringify(nodesCovered)}\n`
46944682
)
46954683
}
@@ -4737,11 +4725,9 @@ class AccountPatcher {
47374725
summary: {
47384726
totalAccounts: number
47394727
fullyMatching: number
4740-
ctt: number // cache-trie timestamp matches
47414728
cth: number // cache-trie hash matches
47424729
cst: number // cache-storage timestamp matches
47434730
csh: number // cache-storage hash matches
4744-
tst: number // trie-storage timestamp matches
47454731
tsh: number // trie-storage hash matches
47464732
chunks: Array<{
47474733
chunkIndex: number
@@ -4754,13 +4740,11 @@ class AccountPatcher {
47544740
accounts?: Array<{
47554741
accountId: string
47564742
cache?: { hash: string; timestamp: number }
4757-
trie?: { hash: string; timestamp?: number }
4743+
trie?: { hash: string }
47584744
storage?: { hash: string; timestamp: number }
4759-
ctt: boolean
47604745
cth: boolean
47614746
cst: boolean
47624747
csh: boolean
4763-
tst: boolean
47644748
tsh: boolean
47654749
}>
47664750
}> {
@@ -4770,11 +4754,9 @@ class AccountPatcher {
47704754
const summary = {
47714755
totalAccounts: 0,
47724756
fullyMatching: 0,
4773-
ctt: 0, // cache-trie timestamp matches
47744757
cth: 0, // cache-trie hash matches
47754758
cst: 0, // cache-storage timestamp matches
47764759
csh: 0, // cache-storage hash matches
4777-
tst: 0, // trie-storage timestamp matches
47784760
tsh: 0, // trie-storage hash matches
47794761
chunks: [] as Array<{
47804762
chunkIndex: number
@@ -4788,13 +4770,11 @@ class AccountPatcher {
47884770
const allAccountResults: Array<{
47894771
accountId: string
47904772
cache?: { hash: string; timestamp: number }
4791-
trie?: { hash: string; timestamp?: number }
4773+
trie?: { hash: string }
47924774
storage?: { hash: string; timestamp: number }
4793-
ctt: boolean
47944775
cth: boolean
47954776
cst: boolean
47964777
csh: boolean
4797-
tst: boolean
47984778
tsh: boolean
47994779
}> = []
48004780

@@ -4807,7 +4787,7 @@ class AccountPatcher {
48074787

48084788
// Maps to store data from each structure for this chunk
48094789
const cacheData = new Map<string, { hash: string; timestamp: number }>()
4810-
const trieData = new Map<string, { hash: string; timestamp?: number }>()
4790+
const trieData = new Map<string, { hash: string }>()
48114791
const storageData = new Map<string, { hash: string; timestamp: number }>()
48124792
const allAccountIds = new Set<string>()
48134793

@@ -4914,24 +4894,20 @@ class AccountPatcher {
49144894
const storage = storageData.get(accountId)
49154895

49164896
// Calculate comparison flags
4917-
const ctt = cache && trie ? cache.timestamp === (trie.timestamp || 0) : false
49184897
const cth = cache && trie ? cache.hash === trie.hash : false
49194898
const cst = cache && storage ? cache.timestamp === storage.timestamp : false
49204899
const csh = cache && storage ? cache.hash === storage.hash : false
4921-
const tst = trie && storage ? (trie.timestamp || 0) === storage.timestamp : false
49224900
const tsh = trie && storage ? trie.hash === storage.hash : false
49234901

49244902
// Update summary counters
49254903
summary.totalAccounts++
4926-
if (ctt) summary.ctt++
49274904
if (cth) summary.cth++
49284905
if (cst) summary.cst++
49294906
if (csh) summary.csh++
4930-
if (tst) summary.tst++
49314907
if (tsh) summary.tsh++
49324908

4933-
// Check if fully matching (all present and all match)
4934-
if (cache && trie && storage && ctt && cth && cst && csh && tst && tsh) {
4909+
// Check if fully matching (all present and all hash matches)
4910+
if (cache && trie && storage && cth && cst && csh && tsh) {
49354911
summary.fullyMatching++
49364912
}
49374913

@@ -4941,11 +4917,9 @@ class AccountPatcher {
49414917
cache,
49424918
trie,
49434919
storage,
4944-
ctt,
49454920
cth,
49464921
cst,
49474922
csh,
4948-
tst,
49494923
tsh,
49504924
})
49514925

src/state-manager/index.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ class StateManager {
359359
const totalMismatches = report.summary.totalAccounts - report.summary.fullyMatching
360360
if (totalMismatches > 0) {
361361
this.logger.getLogger('main').info(`Total mismatches found: ${totalMismatches}`)
362-
this.logger
363-
.getLogger('main')
364-
.info(`Cache-Trie timestamp matches: ${report.summary.ctt}/${report.summary.totalAccounts}`)
365362
this.logger
366363
.getLogger('main')
367364
.info(`Cache-Trie hash matches: ${report.summary.cth}/${report.summary.totalAccounts}`)
@@ -371,9 +368,6 @@ class StateManager {
371368
this.logger
372369
.getLogger('main')
373370
.info(`Cache-Storage hash matches: ${report.summary.csh}/${report.summary.totalAccounts}`)
374-
this.logger
375-
.getLogger('main')
376-
.info(`Trie-Storage timestamp matches: ${report.summary.tst}/${report.summary.totalAccounts}`)
377371
this.logger
378372
.getLogger('main')
379373
.info(`Trie-Storage hash matches: ${report.summary.tsh}/${report.summary.totalAccounts}`)
@@ -383,17 +377,16 @@ class StateManager {
383377
const mismatchedAccounts = report.accounts
384378
.filter(
385379
(account) =>
386-
!account.ctt || !account.cth || !account.cst || !account.csh || !account.tst || !account.tsh
380+
!account.cth || !account.cst || !account.csh || !account.tsh
387381
)
388382
.slice(0, 5)
389383

390384
for (const account of mismatchedAccounts) {
391385
this.logger
392386
.getLogger('main')
393387
.info(
394-
`Mismatch example: ${account.accountId.substring(0, 16)}... - Matches: ctt=${account.ctt} cth=${
395-
account.cth
396-
} cst=${account.cst} csh=${account.csh} tst=${account.tst} tsh=${account.tsh}`
388+
`Mismatch example: ${account.accountId.substring(0, 16)}... - Matches: cth=${account.cth
389+
} cst=${account.cst} csh=${account.csh} tsh=${account.tsh}`
397390
)
398391
}
399392
}
@@ -1476,9 +1469,8 @@ class StateManager {
14761469
}
14771470

14781471
if (queueEntry == null) {
1479-
response.note = `failed to find queue entry: ${utils.stringifyReduce(deserialized.txid)} ${
1480-
deserialized.timestamp
1481-
} dbg:${this.debugTXHistory[utils.stringifyReduce(deserialized.txid)]}`
1472+
response.note = `failed to find queue entry: ${utils.stringifyReduce(deserialized.txid)} ${deserialized.timestamp
1473+
} dbg:${this.debugTXHistory[utils.stringifyReduce(deserialized.txid)]}`
14821474
respond(response, serializeRequestReceiptForTxResp)
14831475
return
14841476
}
@@ -1496,9 +1488,8 @@ class StateManager {
14961488
if (response.receipt != null) {
14971489
response.success = true
14981490
} else {
1499-
response.note = `found queueEntry but no receipt: ${utils.stringifyReduce(deserialized.txid)} ${
1500-
deserialized.txid
1501-
} ${deserialized.timestamp}`
1491+
response.note = `found queueEntry but no receipt: ${utils.stringifyReduce(deserialized.txid)} ${deserialized.txid
1492+
} ${deserialized.timestamp}`
15021493
}
15031494
respond(response, serializeRequestReceiptForTxResp)
15041495
} catch (e) {
@@ -1636,17 +1627,15 @@ class StateManager {
16361627
queueEntry = this.transactionQueue.getQueueEntryArchived(txId, route)
16371628
}
16381629
if (queueEntry == null) {
1639-
response.note = `failed to find queue entry: ${utils.stringifyReduce(txId)} dbg:${
1640-
this.debugTXHistory[utils.stringifyReduce(txId)]
1641-
}`
1630+
response.note = `failed to find queue entry: ${utils.stringifyReduce(txId)} dbg:${this.debugTXHistory[utils.stringifyReduce(txId)]
1631+
}`
16421632
/* prettier-ignore */ nestedCountersInstance.countEvent('stateManager', `${route} cant find queue entry`)
16431633
return respond(response, serializeRequestStateForTxPostResp)
16441634
}
16451635

16461636
if (queueEntry.hasValidFinalData === false) {
1647-
response.note = `has queue entry but not final data: ${utils.stringifyReduce(txId)} dbg:${
1648-
this.debugTXHistory[utils.stringifyReduce(txId)]
1649-
}`
1637+
response.note = `has queue entry but not final data: ${utils.stringifyReduce(txId)} dbg:${this.debugTXHistory[utils.stringifyReduce(txId)]
1638+
}`
16501639

16511640
if (logFlags.error && logFlags.verbose) this.mainLogger.error(response.note)
16521641
/* prettier-ignore */ nestedCountersInstance.countEvent('stateManager', `${route} hasValidFinalData==false, tx state: ${queueEntry.state}`)
@@ -1841,9 +1830,8 @@ class StateManager {
18411830
}
18421831

18431832
if (queueEntry == null) {
1844-
response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${
1845-
this.debugTXHistory[utils.stringifyReduce(txid)]
1846-
}`
1833+
response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)]
1834+
}`
18471835

18481836
if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`)
18491837
respond(response, serializeRequestTxAndStateResp)
@@ -1944,9 +1932,8 @@ class StateManager {
19441932
}
19451933

19461934
if (queueEntry == null) {
1947-
response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${
1948-
this.debugTXHistory[utils.stringifyReduce(txid)]
1949-
}`
1935+
response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)]
1936+
}`
19501937

19511938
if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`)
19521939
respond(response, serializeRequestTxAndStateResp)
@@ -1975,9 +1962,8 @@ class StateManager {
19751962
if (beforeState && beforeState.stateId === receipt2.proposal.beforeStateHashes[index]) {
19761963
response.stateList.push(queueEntry.collectedData[accountId])
19771964
} else {
1978-
response.note = `has bad beforeStateAccount: ${utils.stringifyReduce(txid)} dbg:${
1979-
this.debugTXHistory[utils.stringifyReduce(txid)]
1980-
}`
1965+
response.note = `has bad beforeStateAccount: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)]
1966+
}`
19811967
if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`)
19821968
respond(response, serializeRequestTxAndStateResp)
19831969
return

0 commit comments

Comments
 (0)