{"record":{"id":"ba7af08cd5b2148c","repo":"nautechsystems/nautilus_trader","slug":"failed-to-get-pool-event-sync-state-e","errorCode":null,"errorMessage":"Failed to get pool event sync state: {e}","messagePattern":"Failed to get pool event sync state: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":1575,"sourceCode":"        chain_id: u32,\n        dex: &DexType,\n        pool_identifier: &PoolIdentifier,\n    ) -> anyhow::Result<PoolEventSyncState> {\n        let pool_state = sqlx::query_as::<_, (i32, Option<i64>)>(\n            \"\n            SELECT event_sync_version, last_full_sync_block_number\n            FROM pool\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        .fetch_optional(&self.pool)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to get pool event sync state: {e}\"))?;\n\n        let Some((version, last_full_sync_block)) = pool_state else {\n            return Ok(PoolEventSyncState::default());\n        };\n\n        let family_blocks = sqlx::query_as::<_, (String, i64)>(\n            \"\n            SELECT event_family, last_full_sync_block_number\n            FROM pool_event_sync\n            WHERE chain_id = $1\n            AND dex_name = $2\n            AND pool_identifier = $3\n            ORDER BY event_family\n            \",\n        )\n        .bind(chain_id as i32)\n        .bind(dex.to_string())\n        .bind(pool_identifier.as_ref())","sourceCodeStart":1557,"sourceCodeEnd":1593,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L1557-L1593","documentation":"Wraps a sqlx error from the SELECT that fetches the pool event sync state row (version and last full sync block). This drives incremental event syncing; failing here aborts determining the pool's event sync progress. An absent row is handled gracefully with PoolEventSyncState::default().","triggerScenarios":"Calling `get_pool_event_sync_state(chain_id, dex, pool_identifier)` when the connection is broken, the event sync state table does not exist, or the server returns an error (timeout, lock, etc.).","commonSituations":"Schema migrations for the event sync state table not applied; database restart during event indexing; connection pool saturation.","solutions":["Run migrations to ensure the pool event sync state table exists","Check connectivity and connection-pool health","Retry the read; it is a pure lookup","Inspect the wrapped sqlx error to distinguish missing-table vs connection errors"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"sqlx::query(\"SELECT 1 FROM pool_event_sync_state LIMIT 1\").fetch_optional(&pool).await?;","typeGuard":null,"tryCatchPattern":"let state = get_pool_event_sync_state(chain_id, dex, pool_id)\n    .await\n    .unwrap_or_else(|e| { tracing::warn!(\"sync state read failed: {e}\"); PoolEventSyncState::default() });","preventionTips":["Migrate schema before event indexing","Retry reads on transient DB errors","Monitor pool health metrics"],"tags":["database","sqlx","read-failure","event-sync"],"backgroundTag":"sql-query-failed","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"}