{"record":{"id":"b99523da859e5d10","repo":"nautechsystems/nautilus_trader","slug":"legacy-payload-storage-contains-protected-state","errorCode":null,"errorMessage":"Legacy payload storage contains protected state","messagePattern":"Legacy payload storage contains protected state","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5149,"sourceCode":"            .context(\"failed to stabilize execution payload check\")?;\n        let marker = sqlx::query_scalar::<_, i16>(\n            \"SELECT version FROM execution_schema_version WHERE component = $1\",\n        )\n        .bind(EXECUTION_PAYLOAD_COMPONENT)\n        .fetch_optional(&mut *transaction)\n        .await\n        .context(\"failed to read execution payload marker\")?;\n        let deployment_id = match (marker, keys) {\n            (None, _) => {\n                let state = sqlx::query_scalar::<_, bool>(\n                    \"SELECT EXISTS (SELECT 1 FROM execution_payload_state) \\\n                     OR EXISTS (SELECT 1 FROM execution_transaction_hash \\\n                                WHERE sealed_transaction IS NOT NULL)\",\n                )\n                .fetch_one(&mut *transaction)\n                .await\n                .context(\"failed to check legacy payload state\")?;\n                anyhow::ensure!(!state, \"Legacy payload storage contains protected state\");\n                None\n            }\n            (Some(version), Some(keys)) => {\n                anyhow::ensure!(\n                    version == EXECUTION_PAYLOAD_PROTOCOL_VERSION,\n                    \"Unsupported execution payload protection version {version}\"\n                );\n                let state_row = sqlx::query(\n                    \"SELECT deployment_id, protocol_version, operation, active_key_id \\\n                     FROM execution_payload_state WHERE component = 'signed_transactions' FOR SHARE\",\n                )\n                .fetch_optional(&mut *transaction)\n                .await\n                .context(\"failed to lock execution payload state\")?\n                .ok_or_else(|| anyhow::anyhow!(\"Execution payload state is missing\"))?;\n                let state = execution_payload_state_from_row(&state_row)?;\n                validate_execution_payload_state(&state, keys)?;\n                anyhow::ensure!(","sourceCodeStart":5131,"sourceCodeEnd":5167,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5131-L5167","documentation":"When no protection version row exists (legacy storage), the initializer checks that no protected payload state (sealed transaction references) is present before starting fresh. If legacy tables already contain protected state, initializing would lose or orphan it, so it aborts.","triggerScenarios":"Initializing execution payload protection on a database where execution_transaction_hash rows already have sealed_transaction values but no version marker exists.","commonSituations":"A previous versioned deployment was rolled back/downgraded, deleting the version row but leaving data; mixing old and new node versions against one database.","solutions":["Re-run migration to re-establish the version row instead of initializing as legacy","Purge or migrate the protected state before legacy init","Never downgrade node versions against a shared database; restore a pre-protected backup instead","Audit how the version row disappeared"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let protected: bool = sqlx::query_scalar(\n    \"SELECT EXISTS (SELECT 1 FROM execution_transaction_hash WHERE sealed_transaction IS NOT NULL)\"\n).fetch_one(&mut conn).await?;\nlet versioned: Option<i32> = sqlx::query_scalar(\"SELECT version FROM execution_payload_version\").fetch_optional(&mut conn).await?;\nif versioned.is_none() && protected { return Err(anyhow::anyhow!(\"run migration, not legacy init\")); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never downgrade node versions against a shared database","Run the migration path instead of legacy init when protected data exists","Track version rows in deployment tooling","Back up before any version transition"],"tags":["database","migration","legacy"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}