{"record":{"id":"ae7dc5693ea2cf53","repo":"nautechsystems/nautilus_trader","slug":"failed-to-read-verified-action-nonce-ledger-e","errorCode":null,"errorMessage":"Failed to read verified action nonce ledger: {e}","messagePattern":"Failed to read verified action nonce ledger: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6080,"sourceCode":"        let mut transaction = self\n            .pool\n            .begin()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to start verified action evidence: {e}\"))?;\n        let (manifest_version, manifest_digest, revision) =\n            sqlx::query_as::<_, (String, String, i64)>(\n                \"\n                SELECT manifest_version, manifest_digest, revision\n                FROM execution_verification_nonce\n                WHERE chain_id = $1 AND wallet_address = $2\n                FOR SHARE\n                \",\n            )\n            .bind(chain_id)\n            .bind(batch.wallet_address)\n            .fetch_optional(&mut *transaction)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to read verified action nonce ledger: {e}\"))?\n            .ok_or_else(|| anyhow::anyhow!(\"Canonical nonce ledger is not initialized\"))?;\n        anyhow::ensure!(\n            manifest_version == batch.manifest_version && manifest_digest == batch.manifest_digest,\n            \"Verified action manifest identity changed\"\n        );\n        let intent_nonce = sqlx::query_scalar::<_, Option<i64>>(\n            \"\n            SELECT nonce\n            FROM execution_intent\n            WHERE id = $1 AND chain_id = $2 AND wallet_address = $3 AND active\n            FOR UPDATE\n            \",\n        )\n        .bind(batch.intent_id)\n        .bind(chain_id)\n        .bind(batch.wallet_address)\n        .fetch_optional(&mut *transaction)\n        .await","sourceCodeStart":6062,"sourceCodeEnd":6098,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6062-L6098","documentation":"Thrown when the SELECT on execution_verification_nonce (the canonical nonce ledger for the chain/wallet) fails with a database error. This is distinct from a missing ledger row (which yields 'Canonical nonce ledger is not initialized'); this error means the query itself errored.","triggerScenarios":"fetch_optional on the execution_verification_nonce SELECT returns Err — connection dropped, statement timeout, permission error on the table, or malformed query bindings.","commonSituations":"Role lacking SELECT privilege on execution_verification_nonce after a migration; connection pool connection killed by a proxy idle timeout; database failover during the read.","solutions":["Check database connectivity and retry; the transaction aborts cleanly on failure.","Verify the database role has SELECT permission on execution_verification_nonce.","Inspect Postgres logs for the underlying SQL error (timeout, permission, deadlock) at the failure time.","Check for connection-terminating infrastructure (pgbouncer idle timeouts, proxies, k8s probes)."],"exampleFix":"// before: no permission check\nlet row = read_ledger(&db, chain_id, wallet).await?;\n// after: fail fast with a privileged check\nsqlx::query(\"SELECT 1 FROM execution_verification_nonce LIMIT 1\").execute(&db).await.context(\"cannot read nonce ledger; check grants\")?;\nlet row = read_ledger(&db, chain_id, wallet).await?;","handlingStrategy":"retry","validationCode":"// Rust: verify read access to the ledger up front\nsqlx::query(\"SELECT 1 FROM execution_verification_nonce LIMIT 1\")\n    .fetch_optional(&db).await\n    .context(\"cannot read execution_verification_nonce; check grants\")?;","typeGuard":null,"tryCatchPattern":"// Rust\nmatch record_batch().await {\n    Err(e) if e.to_string().contains(\"Failed to read verified action nonce ledger\") => {\n        log_underlying(&e);\n        retry_with_backoff(record_batch)\n    }\n    res => res,\n}","preventionTips":["Grant SELECT on execution_verification_nonce to the app role in migrations.","Avoid idle-connection-killers between app and Postgres, or lower pool idle timeouts.","Log the database error chain (via anyhow source) for diagnosis."],"tags":["database","sql","ledger","rust"],"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"}