{"id":"XE-12604","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":1875,"title":"Large conflict cascades deterministically fail Badger CommitCascade (transaction too big) after the full undo build — conflict never resolves, retries re-pay the cost","area":"consensus","claimed_tier":"high","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":true,"internal_ref":"#1043","internal_url":"https://github.com/xeprotocol/core/issues/1043","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T07:35:36.867549+00:00","updated_at":"2026-11-20T19:46:11.729354+00:00","source_created_at":null,"told_at":"2026-11-20T19:46:11.743476+00:00","status_changed_at":"2026-11-20T19:46:11.733463+00:00","url":"https://bounty.xe.network/XE-12604","body":"## Summary\n\nOn the production store (Badger), promoting a conflict winner whose\ncascade undoes ~1000 or more blocks deterministically fails at commit\ntime with a transaction-too-big error — after the node has already paid\nthe full quadratic undo-building cost. The failure is clean (the whole\ncascade is one database transaction, so nothing is durably applied),\nbut the conflict is left unresolved, and the failure is mislabeled as\na winner-validation failure, so the retry behaviour is governed by the\nfailed-promotion quarantine instead of by the storage error. The\nposition never resolves: when the conflict's previous block is\nunfinalized, every tally re-attempts immediately and re-pays the cost;\nwhen it is finalized, the attempt is withheld for 30 s and then\nre-pays the cost. A 1000-block cascade costs ~140 ms per attempt; the\nsame build costs ~5 s at 5000 blocks and ~21 s at 10000 blocks, each\ntime holding all involved account locks and the global quorum mutex.\n\n## Root cause\n\nTwo facts compose:\n\n1. **Quadratic pending-write volume.** `CommitCascade`\n   (`store/badger_store.go:1120`) applies every undo plus the winner\n   commit inside one `db.Update` transaction, and `applyUndoTxn`\n   writes the FULL remaining chain-hash list per undone block\n   (`badger_store.go:959-967`). One cascade's pending-write bytes\n   therefore grow ~quadratically with cascade length (~33.5 × n²\n   bytes for 64-hex hashes). Badger enforces `maxBatchSize = 15% of\n   MemTableSize` per transaction (default MemTableSize 64 MB, so\n   ~9.6 MB), checked per write; exceeding it returns\n   `ErrTxnTooBig`. The node uses default options\n   (`store/badger_store.go:48`). At n=1000 the cap is hit at undo\n   78 of 1002 — long before the winner commit is even attempted.\n2. **Mislabelled failure, quarantine-governed retry.** `swapBlockLocked`\n   wraps ANY `dispatchValidateAndAdd` error — including this commit\n   error — as `ErrWinnerFullValidation` (`core/ledger.go:3001-3008`:\n   \"winner failed full validation ..., loser kept\"). `confirmConflict`\n   then records it in `failedPromotions` for 30 s (`core/quorum.go:324-330`)\n   because \"Txn is too big\" matches none of the `IsRetryableError`\n   patterns. Whether the quarantine withholds the next attempt depends\n   on the conflict's previous block: `finalTally`'s `pickWinner`\n   returns the winner WITHOUT consulting `promotable()` when the\n   previous is not finalized, so those conflicts retry hot on every\n   tally; `promotable()` enforces the 30 s quarantine only when the\n   previous IS finalized (`core/quorum.go:231-250`).\n\n## Reproduction (pinned repo, local harness)\n\nHarness: `poc/goharness/h423_lane_c_test.go`,\n`TestH423BadgerTxnCapCascade` (go 1.25.0,\n`go test -run TestH423BadgerTxnCapCascade -v -count=1 .`), on a\nBadgerStore with default options — the production store wiring.\nFixture: Alice sends 100,000 XUSD to Bob; Bob receives (height 1),\nthen pads his chain with filler sends; a sibling send from Alice\nstages a conflict; the treasury (sole representative, ~100% weight)\nfinal-votes the winner.\n\n1. Control, n=100 fillers: `SwapBlock` succeeds on Badger in 10 ms.\n2. n=1000 fillers: `SwapBlock` fails in 138 ms with\n   `SwapBlock: winner failed full validation b6fbc4a3f83c..., loser\n   kept: CommitCascade: CommitCascade: 1002 undo(s) + winner: undo\n   78/1002 (37cd6b6fc683): Txn is too big to fit into one request`.\n   Bob's chain length, both accounts' balances, and the on-chain\n   presence of the loser and the receive are exactly unchanged.\n3. Identical retry: fails again in 145 ms with the same error —\n   the retry is not short-circuited.\n4. Retally path, previous unfinalized: first Retally 92 ms (fails),\n   immediate second Retally 96 ms (fails again) — hot retry.\n5. Retally path, previous finalized (Alice's receive finalized\n   first): first Retally 139 ms (fails, quarantined); immediate\n   second Retally 224 µs (withheld); third Retally after a 31 s\n   sleep 117 ms (re-attempt, fails again).\n\nThe small-cascade control succeeding on the same store wiring proves\nthe harness can tell the two outcomes apart, and the unchanged\nchain/balances after each failure prove the rollback is clean.\n\n## Impact\n\nPer affected conflict: the position can never resolve on a production\nnode — every attempt fails deterministically at the same cap, so the\nloser stays on-chain and the winner stays staged forever. Each\nattempt burns the full undo-build cost (~140 ms at 1000 blocks,\n~5 s at 5000, ~21 s at 10000, measured in H420) while holding the\ninvolved accounts' locks and the global quorum-manager mutex, so\nunrelated conflict resolution on that node stalls for the whole\nattempt, repeatedly. The trigger needs a staged conflict with a valid\nsender credential plus ≥67% final-vote weight behind the winner over\na ~1000+ block foreign chain — the same quorum-gated shape as ordinary\nconflict resolution, so an honest quorum resolving a legitimate\nconflict over a long chain triggers it with no adversary. No funds\nmove, no supply changes, no finality metadata is violated, and the\nnode does not crash.\n\n## Related tickets (distinguished, not duplicates)\n\n- XE-5826: conflict promotion after lease settle fails forever on\n  BadgerStore but succeeds on MemStore. Different root cause: a\n  missing pending escrow at undo time (`addToPendingAmount: pending\n  ... not found`, 1 undo, lease renew+settle ordering). This finding\n  is a transaction-size cap on large cascades (undo 78/1002, no lease\n  involved).\n- XE-8699: deterministic full-validation failures classify as\n  retryable and escape the failed-promotion quarantine. Converse\n  mechanism: there a validation failure escapes quarantine; here a\n  storage failure is mislabeled AS a validation failure and DOES get\n  quarantined (when the previous is finalized). Different defect site.\n- XE-4145: quorum withhold on a staged-valid / full-invalid winner\n  stalls a chain position permanently. Same outcome family, different\n  trigger: winner validity vs commit size cap. This finding's winner\n  passes full validation; the commit fails.\n- XE-8268: SwapBlock denial of service via unimplemented descendant\n  rollback (lease/multisig types abort the swap). This finding\n  unwinds only supported types (send/receive) and fails on size.\n- XE-8764: quadratic re-tally cost is vote-ingest cost, a different\n  cost center.\n\n## Suggested fix\n\nEither (a) bound the cascade commit (e.g. apply the undo chain in\nbounded chunks, or store chain tips by reference instead of rewriting\nthe full chain-hash list per undo, so pending-write volume grows\nlinearly, not quadratically), or (b) pre-check the expected\ntransaction size before building the cascade and refuse early with a\ndistinct, retryable error instead of paying the full build and\nmislabeling the failure as a winner-validation failure — and do not\nroute storage/commit errors through the `ErrWinnerFullValidation`\nquarantine path.\n\n## Live-config caveat\n\nThe reproduction is against the pinned source (`89a542ea`) on a\nBadgerStore with default options, matching the node's store wiring.\nLive testnet nodes report `xe/3019b76`, a build that diverges from\nthe public repo, so the exact live behaviour of the cascade commit\nshould be confirmed against the live build. The commit path exercised\nhere is core ledger/store code with no configuration flag gating it,\nand the transaction cap is a property of the Badger library defaults.\n\n## Payout\n\n915c3ac46209a4d19d2058e1284c4512c24c646bc15021f9b93365d8078434ac","patch_refs":[],"thread":[{"id":15642,"source":"desk","source_ref":"reply:13533","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-12604 and says what differs; it is read like any other.","created_at":"2026-11-20T19:46:11.729354+00:00"}]}