{"record":{"id":"d671ce3e0ee962c6","repo":"nautechsystems/nautilus_trader","slug":"verified-finalized-headers-are-nonempty","errorCode":null,"errorMessage":"verified finalized headers are nonempty","messagePattern":"verified finalized headers are nonempty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":4515,"sourceCode":"            .map_err(|e| anyhow::anyhow!(\"Failed to validate finalized header ledger: {e}\"))?;\n            anyhow::ensure!(\n                stored\n                    == (\n                        header.hash.clone(),\n                        header.parent_hash.clone(),\n                        timestamp,\n                        base_fee,\n                        bootstrap.manifest_digest.to_string(),\n                    ),\n                \"Finalized header ledger conflicts at height {}\",\n                header.number\n            );\n        }\n\n        let finalized_height = bootstrap\n            .finalized_headers\n            .last()\n            .expect(\"verified finalized headers are nonempty\")\n            .number;\n\n        for (index, decision) in bootstrap.decisions.iter().enumerate() {\n            let height_start = decision\n                .height_start\n                .map(i64::try_from)\n                .transpose()\n                .context(\"Connect verification height exceeds PostgreSQL BIGINT\")?;\n            let height_end = decision\n                .height_end\n                .map(i64::try_from)\n                .transpose()\n                .context(\"Connect verification height exceeds PostgreSQL BIGINT\")?;\n            let transition_key = format!(\"connect:{finalized_height}:{revision}:{index}\");\n            sqlx::query(\n                \"\n                INSERT INTO execution_verification_decision (\n                    intent_id, nonce, decision_class, read_class, height_start, height_end,","sourceCodeStart":4497,"sourceCodeEnd":4533,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L4497-L4533","documentation":"While loading a bootstrap, the code takes the last element of `bootstrap.finalized_headers` and panics with \"verified finalized headers are nonempty\" if the list is empty. This is an internal invariant: headers that were verified upstream are expected to always contain at least one (the latest finalized) header.","triggerScenarios":"A bootstrap response whose `finalized_headers` vector is empty despite having been through verification — e.g. a checkpoint/provider returning no finalized headers, or a corrupted/partial bootstrap payload.","commonSituations":"Syncing against a weak-subjectivity checkpoint source that returns no finalized headers; upstream verification logic bug; truncated bootstrap data from an RPC/consensus provider.","solutions":["Check the checkpoint/bootstrap provider is returning finalized headers and that the fetch succeeded.","Verify the verification step actually populated `finalized_headers` before reaching this code.","If you control the caller, validate `!finalized_headers.is_empty()` earlier and surface a proper error instead of panicking.","Update/patch the adapter if the upstream verification invariant is broken in your version."],"exampleFix":"// before\nlet finalized_height = bootstrap.finalized_headers.last()\n    .expect(\"verified finalized headers are nonempty\").number;\n// after\nlet Some(latest) = bootstrap.finalized_headers.last() else {\n    return Err(anyhow!(\"bootstrap returned no finalized headers\"));\n};\nlet finalized_height = latest.number;","handlingStrategy":"validation","validationCode":"if bootstrap.finalized_headers.is_empty() {\n    return Err(anyhow!(\"bootstrap returned no finalized headers\"));\n}","typeGuard":"fn has_finalized_headers(b: &Bootstrap) -> bool { !b.finalized_headers.is_empty() }","tryCatchPattern":"// Rust: convert panic into a Result by checking last() yourself\nlet Some(latest) = bootstrap.finalized_headers.last() else {\n    return Err(anyhow!(\"no finalized headers in bootstrap\"));\n};","preventionTips":["Validate bootstrap payloads (non-empty finalized headers) immediately after fetch.","Use a reputable checkpoint/finality provider and verify fetch success.","Keep the consensus adapter updated; report empty-header responses upstream."],"tags":["blockchain","consensus","panic","empty-collection"],"backgroundTag":"empty-required-field","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"}