{"record":{"id":"82758ec4c2a05cf4","repo":"nautechsystems/nautilus_trader","slug":"verified-finalized-header-ledger-is-empty","errorCode":null,"errorMessage":"Verified finalized header ledger is empty","messagePattern":"Verified finalized header ledger is empty","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":3730,"sourceCode":"        anyhow::ensure!(\n            stored_version == manifest_version && stored_digest == manifest_digest,\n            \"Execution verification manifest identity changed\"\n        );\n        let row = sqlx::query_as::<_, (i64, String, String, i64, Option<String>, String)>(\n            \"\n            SELECT number, hash, parent_hash, timestamp, base_fee_per_gas, manifest_digest\n            FROM execution_verified_finalized_header\n            WHERE chain_id = $1 AND wallet_address = $2\n            ORDER BY number DESC\n            LIMIT 1\n            \",\n        )\n        .bind(chain_id)\n        .bind(wallet_address)\n        .fetch_optional(&self.pool)\n        .await\n        .context(\"failed to load verified finalized header tip\")?\n        .ok_or_else(|| anyhow::anyhow!(\"Verified finalized header ledger is empty\"))?;\n        let (number, hash, parent_hash, timestamp, base_fee, digest) = row;\n        anyhow::ensure!(\n            digest == manifest_digest,\n            \"Finalized header manifest identity changed\"\n        );\n        Ok(Some(ExecutionVerificationPosition {\n            next_canonical_nonce: u64::try_from(nonce).context(\"Canonical nonce is negative\")?,\n            revision: u64::try_from(revision).context(\"Canonical nonce revision is negative\")?,\n            finalized_tip: ExecutionVerifiedHeader {\n                number: u64::try_from(number).context(\"Finalized header number is negative\")?,\n                hash,\n                parent_hash,\n                timestamp: u64::try_from(timestamp)\n                    .context(\"Finalized header timestamp is negative\")?,\n                base_fee_per_gas: base_fee\n                    .map(|value| {\n                        value\n                            .parse::<u128>()","sourceCodeStart":3712,"sourceCodeEnd":3748,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L3712-L3748","documentation":"Raised in database.rs:3730 when the execution_verification_nonce row exists for the chain/wallet but the execution_verified_finalized_header ledger contains no rows. The nonce position cannot be loaded without a finalized-header tip to anchor it, so the library treats the missing ledger as an inconsistent state rather than returning an empty position.","triggerScenarios":"Calling load_execution_verification_position after the nonce row was written but before any finalized header was recorded, or after the header ledger was truncated/deleted while the nonce row survived.","commonSituations":"Partial/corrupted bootstrap that persisted the nonce but crashed before writing the first verified header; manual deletion of execution_verified_finalized_header rows; ledger retention/cleanup job removing all headers for the wallet.","solutions":["Re-run verification bootstrap to rebuild the finalized-header ledger for this chain/wallet.","Restore the ledger from backup if rows were deleted accidentally.","Check for a cleanup/retention job that removes execution_verified_finalized_header rows and exclude the active wallet/chain.","If bootstrapping, ensure it completes atomically (nonce row and first header committed together) before resuming verification."],"exampleFix":"-- before: inconsistent state\nSELECT COUNT(*) FROM execution_verified_finalized_header WHERE chain_id=$1 AND wallet_address=$2; -- 0\n\n-- after: re-bootstrap so the ledger holds at least one verified header\nSELECT COUNT(*) FROM execution_verified_finalized_header WHERE chain_id=$1 AND wallet_address=$2; -- >= 1","handlingStrategy":"validation","validationCode":"let headers: i64 = sqlx::query_scalar(\n    \"SELECT COUNT(*) FROM execution_verified_finalized_header \\\n     WHERE chain_id = $1 AND wallet_address = $2\",\n).bind(chain_id).bind(wallet).fetch_one(&pool).await?;\nif headers == 0 {\n    anyhow::bail!(\"header ledger empty; bootstrap verification first\");\n}","typeGuard":null,"tryCatchPattern":"match load_position(...).await {\n    Err(e) if e.to_string().contains(\"Verified finalized header ledger is empty\") => {\n        // re-run bootstrap to rebuild the ledger before resuming\n    },\n    other => other?,\n}","preventionTips":["Bootstrap nonce row and first verified header atomically","Exclude active wallets from ledger retention/cleanup jobs","Monitor ledger emptiness as an integrity alert"],"tags":["database","verification","empty","ledger"],"backgroundTag":"empty-result-set","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"}