{"record":{"id":"411e370d1092d9ac","repo":"nautechsystems/nautilus_trader","slug":"execution-payload-rewrap-state-is-missing","errorCode":null,"errorMessage":"Execution payload rewrap state is missing","messagePattern":"Execution payload rewrap state is missing","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5421,"sourceCode":"    async fn rewrap_execution_payload_batch(\n        &self,\n        keys: &PayloadKeySet,\n        batch_size: i64,\n    ) -> anyhow::Result<bool> {\n        let mut transaction = self\n            .pool\n            .begin()\n            .await\n            .context(\"failed to start execution payload rewrap batch\")?;\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 rewrap state\")?\n        .ok_or_else(|| anyhow::anyhow!(\"Execution payload rewrap state is missing\"))?;\n        let state = execution_payload_state_from_row(&state_row)?;\n        validate_execution_payload_state(&state, keys)?;\n        if state.operation == \"ready\" {\n            transaction\n                .commit()\n                .await\n                .context(\"failed to complete execution payload rewrap\")?;\n            return Ok(true);\n        }\n        anyhow::ensure!(\n            state.operation == \"rewrap\",\n            \"Execution payload storage is not rewrapping\"\n        );\n        let rows = sqlx::query_as::<_, ExecutionTransactionHashRow>(\n            \"\n            SELECT\n                id, intent_id, chain_id, transaction_hash, payload_expected,\n                raw_transaction, sealed_transaction, status, block_number, block_hash,","sourceCodeStart":5403,"sourceCodeEnd":5439,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5403-L5439","documentation":"During execution-payload key rewrapping, `rewrap_execution_payload_batch` locks and reads the singleton `execution_payload_state` row for component 'signed_transactions' (`SELECT ... FOR UPDATE`). This error is raised when that row does not exist. The library requires the state row to have been initialized by `begin_execution_payload_rewrap` (or equivalent setup) before batch rewrapping can proceed, since it tracks the operation ('ready'/'rewrap') and active key ID in it.","triggerScenarios":"Calling the rewrap flow (which invokes `rewrap_execution_payload_batch`) against a database where `execution_payload_state` has no row with component='signed_transactions' — e.g. a freshly provisioned database whose migration/initialization step was skipped, or a row deleted manually or by a partial migration.","commonSituations":"Pointing the adapter at an empty/new Postgres schema created without running the execution-payload state initialization; restoring a partial backup that omitted the state table's row; manual SQL cleanup that deleted the bookkeeping row; running a newer adapter version against an old database that predates the `execution_payload_state` table.","solutions":["Run the database initialization/migration path that inserts the `execution_payload_state` row for component 'signed_transactions' (via `begin_execution_payload_rewrap` or the schema bootstrap) before starting the rewrap.","Check that the adapter is connecting to the intended database/schema — a wrong DATABASE_URL can point at an uninitialized database.","If the row was deleted accidentally, insert it manually with deployment_id/protocol_version matching the configured key set, operation='ready', and the current active_key_id.","Verify schema version: apply any pending migrations so the `execution_payload_state` table and its seed row exist."],"exampleFix":"// before: rewrap called directly on an uninitialized DB\nrewrap_execution_payload_batch(&keys, batch_size).await?;\n// after: ensure state is initialized first (inserts the state row if absent)\nbegin_execution_payload_rewrap(&keys).await?;\nrewrap_execution_payload_batch(&keys, batch_size).await?;","handlingStrategy":"validation","validationCode":"let state = sqlx::query(\"SELECT deployment_id, protocol_version, operation, active_key_id FROM execution_payload_state WHERE component = 'signed_transactions'\")\n    .fetch_optional(&mut *tx).await?;\nif state.is_none() {\n    // initialize via begin_execution_payload_rewrap / schema bootstrap before proceeding\n    return Err(anyhow!(\"execution_payload_state row missing; run initialization first\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run schema migrations plus the execution-payload state bootstrap on new environments before starting the adapter.","Add a startup health check that asserts the `execution_payload_state` row exists for component 'signed_transactions'.","Never manually delete rows from `execution_payload_state`; use the provided maintenance APIs.","Pin DATABASE_URL per environment and validate connectivity to the correct schema on boot."],"tags":["database","postgres","state-management","encryption","rust"],"backgroundTag":"record-not-found","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"}