From 2b99e6ea4961db5c9f4577f2375f7bcc367cb779 Mon Sep 17 00:00:00 2001 From: Sonali Thakur Date: Tue, 5 Aug 2025 17:46:28 +0530 Subject: [PATCH 1/2] ntroduced `debugFailToCommit` flag to allow intentional skipping of transaction commits for debugging purposes. --- src/state-manager/TransactionQueue.ts | 18 +++++++------- src/state-manager/index.ts | 34 ++++++++++++++++----------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/state-manager/TransactionQueue.ts b/src/state-manager/TransactionQueue.ts index 5b01bcadb..2c4fd7426 100644 --- a/src/state-manager/TransactionQueue.ts +++ b/src/state-manager/TransactionQueue.ts @@ -858,8 +858,7 @@ class TransactionQueue { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(req.txid)} ${req.timestamp} dbg:${ - this.stateManager.debugTXHistory[utils.stringifyReduce(req.txid)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(req.txid)} ${req.timestamp} dbg:${this.stateManager.debugTXHistory[utils.stringifyReduce(req.txid)] }` respond(response, serializeRequestStateForTxResp) // if a node cant get data it will have to get repaired by the patcher since we can only keep stuff en the archive queue for so long @@ -1448,6 +1447,12 @@ class TransactionQueue { * @param queueEntry */ async commitConsensedTransaction(queueEntry: QueueEntry): Promise { + // Debug flag to intentionally skip committing account data + if (this.stateManager.debugFailToCommit) { + /* prettier-ignore */ if (logFlags.debug) this.mainLogger.debug(`debugFailToCommit active. Skipping commit for tx: ${queueEntry.logID}`) + queueEntry.accountDataSet = true + return { success: true } + } let ourLockID = -1 let accountDataList: string | unknown[] let uniqueKeys = [] @@ -2732,10 +2737,8 @@ class TransactionQueue { fireAndForget(() => this.shareCompleteDataToNeighbours(queueEntry)) if (logFlags.debug || this.stateManager.consensusLog) { this.mainLogger.debug( - `queueEntryAddData hasAll: true for txId ${queueEntry.logID} ${ - queueEntry.acceptedTx.txId - } at timestamp: ${shardusGetTime()} nodeId: ${Self.id} collected ${ - Object.keys(queueEntry.collectedData).length + `queueEntryAddData hasAll: true for txId ${queueEntry.logID} ${queueEntry.acceptedTx.txId + } at timestamp: ${shardusGetTime()} nodeId: ${Self.id} collected ${Object.keys(queueEntry.collectedData).length } uniqueKeys ${queueEntry.uniqueKeys.length}` ) } @@ -2785,8 +2788,7 @@ class TransactionQueue { ) if (logFlags.debug || this.stateManager.consensusLog) { this.mainLogger.debug( - `shareCompleteDataToNeighbours: shared complete data for txId ${ - queueEntry.logID + `shareCompleteDataToNeighbours: shared complete data for txId ${queueEntry.logID } at timestamp: ${shardusGetTime()} nodeId: ${Self.id} to neighbours: ${Utils.safeStringify( neighboursNodes.map((node) => node.id) )}` diff --git a/src/state-manager/index.ts b/src/state-manager/index.ts index e6a2b8500..5b3016d9b 100644 --- a/src/state-manager/index.ts +++ b/src/state-manager/index.ts @@ -184,6 +184,7 @@ class StateManager { debugNoTxVoting: boolean debugSkipPatcherRepair: boolean + debugFailToCommit: boolean ignoreRecieptChance: number ignoreVoteChance: number @@ -341,6 +342,8 @@ class StateManager { this.processCycleSummaries = false //starts false and get enabled when startProcessingCycleSummaries() is called this.debugSkipPatcherRepair = config.debug.skipPatcherRepair + this.debugFailToCommit = false + this.feature_receiptMapResults = true this.feature_partitionHashes = true @@ -1292,6 +1295,16 @@ class StateManager { this.partitionStats.setupHandlers() + // Debug endpoint to toggle fail-to-commit flag + Context.network.registerExternalGet('debugFailToCommit', isDebugModeMiddleware, (req, res) => { + const { enable } = req.query + if (enable !== undefined) { + const val = enable === 'true' || enable === '1' + this.debugFailToCommit = val + } + res.json({ debugFailToCommit: this.debugFailToCommit }) + }) + // p2p ASK // this.p2p.registerInternal( // 'request_receipt_for_tx_old', @@ -1402,8 +1415,7 @@ class StateManager { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(deserialized.txid)} ${ - deserialized.timestamp + response.note = `failed to find queue entry: ${utils.stringifyReduce(deserialized.txid)} ${deserialized.timestamp } dbg:${this.debugTXHistory[utils.stringifyReduce(deserialized.txid)]}` respond(response, serializeRequestReceiptForTxResp) return @@ -1422,8 +1434,7 @@ class StateManager { if (response.receipt != null) { response.success = true } else { - response.note = `found queueEntry but no receipt: ${utils.stringifyReduce(deserialized.txid)} ${ - deserialized.txid + response.note = `found queueEntry but no receipt: ${utils.stringifyReduce(deserialized.txid)} ${deserialized.txid } ${deserialized.timestamp}` } respond(response, serializeRequestReceiptForTxResp) @@ -1562,16 +1573,14 @@ class StateManager { queueEntry = this.transactionQueue.getQueueEntryArchived(txId, route) } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(txId)} dbg:${ - this.debugTXHistory[utils.stringifyReduce(txId)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(txId)} dbg:${this.debugTXHistory[utils.stringifyReduce(txId)] }` /* prettier-ignore */ nestedCountersInstance.countEvent('stateManager', `${route} cant find queue entry`) return respond(response, serializeRequestStateForTxPostResp) } if (queueEntry.hasValidFinalData === false) { - response.note = `has queue entry but not final data: ${utils.stringifyReduce(txId)} dbg:${ - this.debugTXHistory[utils.stringifyReduce(txId)] + response.note = `has queue entry but not final data: ${utils.stringifyReduce(txId)} dbg:${this.debugTXHistory[utils.stringifyReduce(txId)] }` if (logFlags.error && logFlags.verbose) this.mainLogger.error(response.note) @@ -1767,8 +1776,7 @@ class StateManager { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${ - this.debugTXHistory[utils.stringifyReduce(txid)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)] }` if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`) @@ -1870,8 +1878,7 @@ class StateManager { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${ - this.debugTXHistory[utils.stringifyReduce(txid)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)] }` if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`) @@ -1901,8 +1908,7 @@ class StateManager { if (beforeState && beforeState.stateId === receipt2.proposal.beforeStateHashes[index]) { response.stateList.push(queueEntry.collectedData[accountId]) } else { - response.note = `has bad beforeStateAccount: ${utils.stringifyReduce(txid)} dbg:${ - this.debugTXHistory[utils.stringifyReduce(txid)] + response.note = `has bad beforeStateAccount: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)] }` if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`) respond(response, serializeRequestTxAndStateResp) From ea3d21fa0e93ad8090f46d8176fe877f6c1d17f2 Mon Sep 17 00:00:00 2001 From: Sonali Thakur Date: Tue, 5 Aug 2025 17:47:28 +0530 Subject: [PATCH 2/2] formatting in StateManager and TransactionQueue --- src/state-manager/TransactionQueue.ts | 12 ++++++++---- src/state-manager/index.ts | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/state-manager/TransactionQueue.ts b/src/state-manager/TransactionQueue.ts index 2c4fd7426..c4c7021c0 100644 --- a/src/state-manager/TransactionQueue.ts +++ b/src/state-manager/TransactionQueue.ts @@ -858,7 +858,8 @@ class TransactionQueue { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(req.txid)} ${req.timestamp} dbg:${this.stateManager.debugTXHistory[utils.stringifyReduce(req.txid)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(req.txid)} ${req.timestamp} dbg:${ + this.stateManager.debugTXHistory[utils.stringifyReduce(req.txid)] }` respond(response, serializeRequestStateForTxResp) // if a node cant get data it will have to get repaired by the patcher since we can only keep stuff en the archive queue for so long @@ -2737,8 +2738,10 @@ class TransactionQueue { fireAndForget(() => this.shareCompleteDataToNeighbours(queueEntry)) if (logFlags.debug || this.stateManager.consensusLog) { this.mainLogger.debug( - `queueEntryAddData hasAll: true for txId ${queueEntry.logID} ${queueEntry.acceptedTx.txId - } at timestamp: ${shardusGetTime()} nodeId: ${Self.id} collected ${Object.keys(queueEntry.collectedData).length + `queueEntryAddData hasAll: true for txId ${queueEntry.logID} ${ + queueEntry.acceptedTx.txId + } at timestamp: ${shardusGetTime()} nodeId: ${Self.id} collected ${ + Object.keys(queueEntry.collectedData).length } uniqueKeys ${queueEntry.uniqueKeys.length}` ) } @@ -2788,7 +2791,8 @@ class TransactionQueue { ) if (logFlags.debug || this.stateManager.consensusLog) { this.mainLogger.debug( - `shareCompleteDataToNeighbours: shared complete data for txId ${queueEntry.logID + `shareCompleteDataToNeighbours: shared complete data for txId ${ + queueEntry.logID } at timestamp: ${shardusGetTime()} nodeId: ${Self.id} to neighbours: ${Utils.safeStringify( neighboursNodes.map((node) => node.id) )}` diff --git a/src/state-manager/index.ts b/src/state-manager/index.ts index 5b3016d9b..fff939cb5 100644 --- a/src/state-manager/index.ts +++ b/src/state-manager/index.ts @@ -344,7 +344,6 @@ class StateManager { this.debugSkipPatcherRepair = config.debug.skipPatcherRepair this.debugFailToCommit = false - this.feature_receiptMapResults = true this.feature_partitionHashes = true this.feature_generateStats = false @@ -1415,7 +1414,8 @@ class StateManager { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(deserialized.txid)} ${deserialized.timestamp + response.note = `failed to find queue entry: ${utils.stringifyReduce(deserialized.txid)} ${ + deserialized.timestamp } dbg:${this.debugTXHistory[utils.stringifyReduce(deserialized.txid)]}` respond(response, serializeRequestReceiptForTxResp) return @@ -1434,7 +1434,8 @@ class StateManager { if (response.receipt != null) { response.success = true } else { - response.note = `found queueEntry but no receipt: ${utils.stringifyReduce(deserialized.txid)} ${deserialized.txid + response.note = `found queueEntry but no receipt: ${utils.stringifyReduce(deserialized.txid)} ${ + deserialized.txid } ${deserialized.timestamp}` } respond(response, serializeRequestReceiptForTxResp) @@ -1573,14 +1574,16 @@ class StateManager { queueEntry = this.transactionQueue.getQueueEntryArchived(txId, route) } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(txId)} dbg:${this.debugTXHistory[utils.stringifyReduce(txId)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(txId)} dbg:${ + this.debugTXHistory[utils.stringifyReduce(txId)] }` /* prettier-ignore */ nestedCountersInstance.countEvent('stateManager', `${route} cant find queue entry`) return respond(response, serializeRequestStateForTxPostResp) } if (queueEntry.hasValidFinalData === false) { - response.note = `has queue entry but not final data: ${utils.stringifyReduce(txId)} dbg:${this.debugTXHistory[utils.stringifyReduce(txId)] + response.note = `has queue entry but not final data: ${utils.stringifyReduce(txId)} dbg:${ + this.debugTXHistory[utils.stringifyReduce(txId)] }` if (logFlags.error && logFlags.verbose) this.mainLogger.error(response.note) @@ -1776,7 +1779,8 @@ class StateManager { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${ + this.debugTXHistory[utils.stringifyReduce(txid)] }` if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`) @@ -1878,7 +1882,8 @@ class StateManager { } if (queueEntry == null) { - response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)] + response.note = `failed to find queue entry: ${utils.stringifyReduce(txid)} dbg:${ + this.debugTXHistory[utils.stringifyReduce(txid)] }` if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`) @@ -1908,7 +1913,8 @@ class StateManager { if (beforeState && beforeState.stateId === receipt2.proposal.beforeStateHashes[index]) { response.stateList.push(queueEntry.collectedData[accountId]) } else { - response.note = `has bad beforeStateAccount: ${utils.stringifyReduce(txid)} dbg:${this.debugTXHistory[utils.stringifyReduce(txid)] + response.note = `has bad beforeStateAccount: ${utils.stringifyReduce(txid)} dbg:${ + this.debugTXHistory[utils.stringifyReduce(txid)] }` if (logFlags.error) this.mainLogger.error(`${route} ${response.note}`) respond(response, serializeRequestTxAndStateResp)