{"record":{"id":"16c1bb829c7495de","repo":"nautechsystems/nautilus_trader","slug":"replacement-execution-transaction-retains-signe","errorCode":null,"errorMessage":"Replacement execution transaction {} retains signed bytes","messagePattern":"Replacement execution transaction (.+?) retains signed bytes","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5213,"sourceCode":"                LIMIT $2\n                \",\n            )\n            .bind(cursor)\n            .bind(batch_size)\n            .fetch_all(&mut *transaction)\n            .await\n            .context(\"failed to load execution payload check batch\")?;\n\n            if rows.is_empty() {\n                break;\n            }\n\n            for hash in &rows {\n                cursor = hash.id;\n                plaintext_rows += u64::from(hash.raw_transaction.is_some());\n                if !hash.payload_expected {\n                    replacement_rows += 1;\n                    anyhow::ensure!(\n                        hash.raw_transaction.is_none() && hash.sealed_transaction.is_none(),\n                        \"Replacement execution transaction {} retains signed bytes\",\n                        hash.id\n                    );\n                    continue;\n                }\n                original_rows += 1;\n                let intent = load_execution_intent(&mut transaction, hash.intent_id).await?;\n                let raw_transaction = if let (Some(keys), Some(deployment_id)) =\n                    (keys, deployment_id.as_deref())\n                {\n                    anyhow::ensure!(\n                        hash.raw_transaction.is_none(),\n                        \"Protected execution transaction {} contains plaintext\",\n                        hash.id\n                    );\n                    let envelope = hash.sealed_transaction.as_deref().ok_or_else(|| {\n                        anyhow::anyhow!(","sourceCodeStart":5195,"sourceCodeEnd":5231,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5195-L5231","documentation":"During the execution-payload storage scan, a row marked as a replacement execution transaction (payload_expected == false) still carries either raw (plaintext) signed transaction bytes or a sealed envelope. The database schema expects replacement rows to retain no transaction payload at all, so this invariant-violation ensure! aborts the scan. It indicates corrupted or incorrectly migrated payload storage.","triggerScenarios":"Raised by the payload scan inside rewrap_execution_payload_storage / begin_execution_payload_rewrap processing when iterating rows: a row with payload_expected=false whose raw_transaction or sealed_transaction column is non-NULL.","commonSituations":"A failed or partial migration left signed bytes in rows that were later reclassified as replacement transactions; a bug in the payload-sealing writer wrote plaintext into replacement rows; manual DB edits or restore from a divergent backup.","solutions":["Identify the offending row id from the message and inspect its raw_transaction/sealed_transaction columns in the execution transactions table.","Clear the retained payload columns for that replacement row (NULL out raw_transaction and sealed_transaction) after confirming the transaction is truly a replacement that needs no payload.","Restore the database from a backup taken before the corrupting migration or write.","Re-run rewrap_execution_payload_storage after fixing the row; it will re-validate the invariant."],"exampleFix":"// Row data before (corrupt)\n{ id: \"0xabc\", payload_expected: false, raw_transaction: \"0x02f8...\", sealed_transaction: null }\n// After (replacement rows must hold no payload)\n{ id: \"0xabc\", payload_expected: false, raw_transaction: null, sealed_transaction: null }","handlingStrategy":"validation","validationCode":"-- Detect replacement rows retaining payload before rewrap\nSELECT id FROM execution_transactions\nWHERE payload_expected = false\n  AND (raw_transaction IS NOT NULL OR sealed_transaction IS NOT NULL);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the preflight SQL above as a scheduled health check.","Test migrations that reclassify rows end-to-end before applying to production.","Restrict direct writes to the execution transactions table to the sealing writer."],"tags":["database","invariant-violation","payload-storage","rust"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}