{"record":{"id":"0fe755f109778f4a","repo":"nautechsystems/nautilus_trader","slug":"canonical-nonce-overflow","errorCode":null,"errorMessage":"Canonical nonce overflow","messagePattern":"Canonical nonce overflow","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":4040,"sourceCode":"        {\n            anyhow::ensure!(\n                bootstrap.migration.is_none(),\n                \"Verification migration was supplied for an initialized signer\"\n            );\n            anyhow::ensure!(\n                manifest_version == bootstrap.manifest_version\n                    && manifest_digest == bootstrap.manifest_digest,\n                \"Execution verification manifest identity changed\"\n            );\n            anyhow::ensure!(\n                stored_nonce == next_canonical_nonce,\n                \"Canonical nonce ledger changed during verification bootstrap\"\n            );\n\n            if observed_canonical_nonce != stored_nonce {\n                let expected_observed_nonce = stored_nonce\n                    .checked_add(1)\n                    .ok_or_else(|| anyhow::anyhow!(\"Canonical nonce overflow\"))?;\n                anyhow::ensure!(\n                    observed_canonical_nonce == expected_observed_nonce,\n                    \"Verified finalized transaction count is outside the owned recovery range\"\n                );\n                let recovery = sqlx::query_as::<_, (Option<i64>, String, i64)>(\n                    \"\n                    SELECT\n                        intent.nonce,\n                        intent.status,\n                        COUNT(hash.id) FILTER (\n                            WHERE hash.current\n                              AND hash.payload_expected\n                              AND ((hash.raw_transaction IS NOT NULL)::INTEGER\n                                   + (hash.sealed_transaction IS NOT NULL)::INTEGER) = 1\n                              AND hash.status IN (\n                                  'broadcast', 'included', 'replaced', 'dropped', 'reorged'\n                              )\n                        )","sourceCodeStart":4022,"sourceCodeEnd":4058,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L4022-L4058","documentation":"When the observed canonical nonce differs from the stored one, the code computes stored_nonce + 1 with checked_add; if the stored nonce is i64::MAX the increment overflows and crates/adapters/blockchain/src/cache/database.rs:4040 returns this error. It means the durable nonce ledger has reached the maximum representable value, so no further canonical nonce can be produced.","triggerScenarios":"Bootstrapping verification where execution_verification_nonce.next_canonical_nonce == i64::MAX and the observed finalized transaction count is greater than the stored nonce, forcing the checked_add(1) overflow path.","commonSituations":"Corrupted or poisoned ledger row with a sentinel/max value; a bug elsewhere writing huge nonce values; an i64 counter saturated after an astronomically implausible number of transactions (practically only via data corruption).","solutions":["Inspect the ledger row (SELECT next_canonical_nonce FROM execution_verification_nonce ...) — a value at i64::MAX indicates corruption, since real wallets cannot send 2^63-1 transactions.","Verify the wallet's actual on-chain nonce and rebuild the canonical nonce ledger from verified finalized transaction history.","Audit any code paths that write next_canonical_nonce for missing bounds checks or sentinel-value misuse.","Escalate as a data-integrity incident; do not hand-edit the value without reconstructing from on-chain state."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let stored = sqlx::query_scalar::<_, i64>(\n    \"SELECT next_canonical_nonce FROM execution_verification_nonce WHERE chain_id=$1 AND wallet_address=$2\",\n).bind(chain_id).bind(wallet).fetch_one(&pool).await?;\nif stored >= i64::MAX - 1 {\n    return Err(anyhow::anyhow!(\"canonical nonce at i64 bound; ledger is corrupt\"));\n}","typeGuard":null,"tryCatchPattern":"match bootstrap_verification(...).await {\n    Err(e) if e.to_string().contains(\"Canonical nonce overflow\") => {\n        // halt trading for this signer; escalate as data-integrity incident, rebuild ledger from chain\n    }\n    other => other?,\n}","preventionTips":["Alert on any ledger nonce value that is implausibly large for the wallet's age","Audit all writers of next_canonical_nonce for bounds checks","Reconcile the ledger against the on-chain nonce periodically"],"tags":["database","overflow","arithmetic","data-corruption"],"backgroundTag":"value-out-of-range","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"}