{"record":{"id":"d2ee376777f975ad","repo":"nautechsystems/nautilus_trader","slug":"failed-to-record-verified-finality-receipt-e","errorCode":null,"errorMessage":"Failed to record verified finality receipt: {e}","messagePattern":"Failed to record verified finality receipt: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7130,"sourceCode":"            \"\n            UPDATE execution_transaction_hash\n            SET status = $3, block_number = $4, block_hash = $5,\n                receipt_success = $6, gas_used = $7, effective_gas_price = $8,\n                updated_at = NOW()\n            WHERE intent_id = $1 AND transaction_hash = $2\n            \",\n        )\n        .bind(finality.intent_id)\n        .bind(finality.transaction_hash)\n        .bind(finality.status.as_str())\n        .bind(block_number)\n        .bind(finality.block_hash)\n        .bind(finality.receipt_success)\n        .bind(gas_used)\n        .bind(finality.effective_gas_price)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to record verified finality receipt: {e}\"))?;\n        anyhow::ensure!(\n            hash_result.rows_affected() == 1,\n            \"Finality transaction hash was not found\"\n        );\n\n        let active = !fill_emitted && !terminal_emitted;\n        sqlx::query(\n            \"UPDATE execution_intent SET status = $2, active = $3, updated_at = NOW() WHERE id = $1\",\n        )\n        .bind(finality.intent_id)\n        .bind(finality.status.as_str())\n        .bind(active)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to record verified finality intent: {e}\"))?;\n\n        let transition_key = format!(\n            \"{}:{}:{}:{}\",","sourceCodeStart":7112,"sourceCodeEnd":7148,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7112-L7148","documentation":"Wraps a sqlx failure on the UPDATE/INSERT that records the verified finality receipt (block_hash, receipt_success, gas_used, effective_gas_price) — the adjacent statement updates `execution_transaction_hash` status. A failure aborts the finality transaction before the subsequent rows_affected check can run. The underlying database error is embedded via `{e}`.","triggerScenarios":"The receipt-recording statement fails: connection loss mid-transaction, schema mismatch on receipt columns, invalid gas_used/effective_gas_price encoding, lock contention on the receipt or transaction-hash rows, or statement timeout.","commonSituations":"Schema drift after an adapter upgrade adding receipt columns; gas values exceeding column bounds (e.g. i32 vs i64); concurrent writers updating the same transaction-hash row causing lock waits; pool exhaustion during a burst of finalized blocks.","solutions":["Read the interpolated `{e}` to identify the exact sqlx/Postgres failure","Verify receipt table schema (columns and numeric types for gas_used/effective_gas_price) matches current migrations","Shorten the surrounding transaction and check for lock contention on the same transaction hash rows","Confirm database connectivity and pool health","Check numeric ranges of gas fields fit the column types"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify receipt fields fit before persisting\nlet ok = finality.block_number >= 0\n    && gas_used >= 0\n    && !finality.transaction_hash.is_empty();","typeGuard":"fn receipt_is_recordable(finality: &VerifiedFinality, gas_used: i64) -> bool {\n    !finality.transaction_hash.is_empty()\n        && !finality.block_hash.is_empty()\n        && gas_used >= 0\n}","tryCatchPattern":"match record_finality_receipt(...).await {\n    Err(e) if is_transient_db_error(&e) => retry_with_backoff(3, || record_finality_receipt(...)),\n    Err(e) => return Err(e),\n    Ok(()) => {},\n}","preventionTips":["Match gas field widths (i64/BIGINT) to expected Ethereum values","Re-run migrations after adapter upgrades that touch receipt tables","Minimize lock hold time on execution_transaction_hash rows","Monitor pool health during batch finalization windows"],"tags":["database","sqlx","receipt","persistence"],"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-14T00:17:10.932Z"}