{"record":{"id":"57cc168da243f700","repo":"nautechsystems/nautilus_trader","slug":"failed-to-update-pool-last-synced-block-e","errorCode":null,"errorMessage":"Failed to update pool last synced block: {e}","messagePattern":"Failed to update pool last synced block: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1493,"sourceCode":"        block_number: u64,\n    ) -> anyhow::Result<()> {\n        sqlx::query(\n            \"\n            UPDATE pool\n            SET last_full_sync_block_number = $4\n            WHERE chain_id = $1\n            AND dex_name = $2\n            AND pool_identifier = $3\n            \",\n        )\n        .bind(chain_id as i32)\n        .bind(dex.to_string())\n        .bind(pool_identifier.as_ref())\n        .bind(block_number as i64)\n        .execute(&self.pool)\n        .await\n        .map(|_| ())\n        .map_err(|e| anyhow::anyhow!(\"Failed to update pool last synced block: {e}\"))\n    }\n\n    /// Retrieves the saved checkpoint block number from the last completed pool synchronization for a specific DEX.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database query fails.\n    pub async fn get_dex_last_synced_block(\n        &self,\n        chain_id: u32,\n        dex: &DexType,\n    ) -> anyhow::Result<Option<u64>> {\n        let result = sqlx::query_as::<_, (Option<i64>,)>(\n            \"\n            SELECT\n                last_full_sync_pools_block_number\n            FROM dex\n            WHERE chain_id = $1","sourceCodeStart":1475,"sourceCodeEnd":1511,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1475-L1511","documentation":"Wraps a sqlx error from the UPDATE that persists the last synced block for a specific pool of a DEX. This checkpoint lets the indexer resume per-pool event syncing. Failure means the pool's sync progress was not durably recorded.","triggerScenarios":"Calling `update_pool_last_synced_block(chain_id, dex, pool_identifier, block_number)` when the pool connection fails, the row/table does not exist because migrations are missing, or a constraint (e.g. FK to a dex/pool table) is violated.","commonSituations":"Migrations not applied on a new deployment; database failover during indexing; writing pool checkpoints for a pool not yet registered in the database.","solutions":["Apply pending migrations so the pool checkpoint table exists","Verify the pool identifier matches how the pool was registered (checksummed vs lowercase address)","Inspect the sqlx error for constraint violations and ensure the parent dex/pool row exists first","Check DB connectivity and retry; transient errors are common during long sync runs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify pool row exists before checkpointing\nlet exists = sqlx::query(\"SELECT 1 FROM pools WHERE identifier = $1\").bind(pool_identifier).fetch_optional(&pool).await?;","typeGuard":null,"tryCatchPattern":"if let Err(e) = update_pool_last_synced_block(chain_id, dex, pool_id, block).await {\n    tracing::error!(\"pool checkpoint write failed: {e}\");\n    return Err(e);\n}","preventionTips":["Register pools before writing their checkpoints","Normalize pool identifiers (lowercase addresses) consistently","Ensure migrations run before indexing starts"],"tags":["database","sqlx","write-failure","sync-checkpoint"],"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"}