{"record":{"id":"c978689eb4b344b3","repo":"nautechsystems/nautilus_trader","slug":"failed-to-update-execution-hash-transaction-hash","errorCode":null,"errorMessage":"Failed to update execution hash {transaction_hash}: {e}","messagePattern":"Failed to update execution hash (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6829,"sourceCode":"                block_hash = COALESCE($5, block_hash),\n                receipt_success = COALESCE($6, receipt_success),\n                gas_used = COALESCE($7, gas_used),\n                effective_gas_price = COALESCE($8, effective_gas_price),\n                updated_at = NOW()\n            WHERE intent_id = $1 AND transaction_hash = $2\n            \",\n        )\n        .bind(intent_id)\n        .bind(transaction_hash)\n        .bind(status.as_str())\n        .bind(block_number_db)\n        .bind(block_hash)\n        .bind(receipt_success)\n        .bind(gas_used_db)\n        .bind(effective_gas_price)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to update execution hash {transaction_hash}: {e}\"))?;\n        anyhow::ensure!(\n            hash_result.rows_affected() == 1,\n            \"Execution transaction hash {transaction_hash} was not found for intent {intent_id}\"\n        );\n\n        sqlx::query(\n            \"\n            UPDATE execution_intent\n            SET status = $2, active = $3, updated_at = NOW()\n            WHERE id = $1\n            \",\n        )\n        .bind(intent_id)\n        .bind(status.as_str())\n        .bind(active)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to update execution intent {intent_id}: {e}\"))?;","sourceCodeStart":6811,"sourceCodeEnd":6847,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6811-L6847","documentation":"Raised when the UPDATE that stores execution transaction details (block hash, receipt success, gas used, effective gas price) keyed by transaction_hash fails at the database level inside the transition transaction. The row-lock and status validation already succeeded, but persisting the receipt details errored, so the whole transaction rolls back.","triggerScenarios":"Calling the transition method when the execution-hash UPDATE statement errors: schema mismatch (column type/constraint change after migration), connection lost mid-transaction, numeric overflow binding gas values, or a CHECK constraint rejection on receipt data.","commonSituations":"Schema drift after upgrading the adapter without running migrations; Postgres numeric/bytea type mismatch for hashes; transaction aborted earlier in the session by a prior error ('current transaction is aborted'); connection pool idle timeout killing the socket mid-statement.","solutions":["Read the inner `{e}` for the exact SQL error; fix the schema/migration if it is a column or constraint issue.","Verify gas values and hash formats match the column types before binding (Decimal for gas, bytea/text for hashes).","Retry transient connection errors; ensure the transaction was not already aborted by a previous failed statement.","Confirm the UPDATE's WHERE clause matches the row layout — a persistent 0-rows case surfaces as error 2315 instead."],"exampleFix":"// before\n.execute(&mut *transaction)\n.await\n.map_err(|e| anyhow::anyhow!(\"Failed to update execution hash {transaction_hash}: {e}\"))?;\n// after\n.execute(&mut *transaction)\n.await\n.with_context(|| format!(\"Failed to update execution hash {transaction_hash} for intent {intent_id}\"))?;","handlingStrategy":"retry","validationCode":"// Pre-check schema compatibility before receipt processing\nsqlx::query(\"SELECT block_hash, receipt_success, gas_used, effective_gas_price FROM execution_transaction LIMIT 1\")\n    .execute(&pool).await?;","typeGuard":null,"tryCatchPattern":"match transition.await {\n    Err(e) if e.to_string().contains(\"Failed to update execution hash\") => {\n        tracing::error!(error = %e, \"receipt write failed; rolling back and retrying\");\n        retry_with_backoff();\n    }\n    other => other?,\n}","preventionTips":["Run migrations on every deploy before event processing starts.","Bind gas values as Decimal and hashes in the column's exact type/format.","Never reuse a transaction after an earlier statement error (it is aborted)."],"tags":["database","sqlx","update","transaction"],"backgroundTag":"database-write-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}