{"record":{"id":"1c3ada9233ac35bd","repo":"nautechsystems/nautilus_trader","slug":"execution-payload-rewrap-context-does-not-match-th","errorCode":null,"errorMessage":"Execution payload rewrap context does not match this database","messagePattern":"Execution payload rewrap context does not match this database","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5348,"sourceCode":"    }\n\n    async fn begin_execution_payload_rewrap(&self, keys: &PayloadKeySet) -> anyhow::Result<()> {\n        let mut transaction = self\n            .pool\n            .begin()\n            .await\n            .context(\"failed to start execution payload rewrap\")?;\n        lock_execution_payload_operation(&mut transaction).await?;\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 UPDATE\",\n        )\n        .fetch_optional(&mut *transaction)\n        .await\n        .context(\"failed to lock execution payload state for rewrap\")?\n        .ok_or_else(|| anyhow::anyhow!(\"Execution payload protection is not active\"))?;\n        let state = execution_payload_state_from_row(&state_row)?;\n        anyhow::ensure!(\n            state.protocol_version == EXECUTION_PAYLOAD_PROTOCOL_VERSION\n                && state.deployment_id == keys.deployment_id(),\n            \"Execution payload rewrap context does not match this database\"\n        );\n\n        match state.operation.as_str() {\n            \"ready\" => {\n                let current_id: [u8; 32] = state\n                    .active_key_id\n                    .as_slice()\n                    .try_into()\n                    .context(\"database active payload key ID is invalid\")?;\n                anyhow::ensure!(\n                    keys.contains_key(&current_id),\n                    \"Current database payload key is not configured for rewrap\"\n                );\n                validate_execution_payload_key_inventory(&mut transaction, keys).await?;\n                if current_id == *keys.active_key_id() {","sourceCodeStart":5330,"sourceCodeEnd":5366,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5330-L5366","documentation":"After loading execution_payload_state, the rewrap verifies the recorded protocol_version matches EXECUTION_PAYLOAD_PROTOCOL_VERSION and that the state's deployment_id equals the deployment id in the supplied PayloadKeySet. A mismatch means the keys or tool invocation belong to a different deployment or protocol generation, and the ensure! aborts before touching any rows.","triggerScenarios":"Calling rewrap_execution_payload_storage with a PayloadKeySet whose deployment_id() differs from execution_payload_state.deployment_id, or when the stored protocol_version is not the current EXECUTION_PAYLOAD_PROTOCOL_VERSION.","commonSituations":"Running a rewrap tool configured for one deployment against another deployment's database; stale software version after a protocol bump; copying a database between environments without updating key/deployment configuration.","solutions":["Point the rewrap at the correct database for the deployment id in your key configuration (or fix the deployment id config).","Upgrade the software so EXECUTION_PAYLOAD_PROTOCOL_VERSION matches the database's recorded protocol_version.","Rebuild the PayloadKeySet from the key material provisioned for this specific deployment.","If the database was copied between environments, update execution_payload_state or use the source environment's key set."],"exampleFix":"// before: mismatched deployment\nlet keys = PayloadKeySet::for_deployment(\"deployment-b\");\nrewrap_execution_payload_storage(&keys, 500).await?; // db is deployment-a\n// after\nlet keys = PayloadKeySet::for_deployment(\"deployment-a\");\nrewrap_execution_payload_storage(&keys, 500).await?;","handlingStrategy":"validation","validationCode":"let (db_dep, ver): (String, i64) = sqlx::query_as(\n    \"SELECT deployment_id, protocol_version FROM execution_payload_state WHERE component='signed_transactions'\"\n).fetch_one(&pool).await?;\nassert_eq!(db_dep, keys.deployment_id(), \"rewrap keys are for a different deployment\");\nassert_eq!(ver, EXECUTION_PAYLOAD_PROTOCOL_VERSION, \"protocol version mismatch; upgrade software\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive the PayloadKeySet's deployment id from the same config source as the database connection.","Pin tooling versions to the deployed protocol version.","Never share one database across deployments without updating execution_payload_state."],"tags":["database","key-management","configuration-mismatch","rust"],"backgroundTag":"invalid-config-value","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"}