{"id":"XE-8799","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":1930,"title":"Node block producers sign prev=0 blocks when a local chain read fails — Ledger.GetChain swallows store errors; Node.Receive/autoAcceptLease lack the len==0 abort","area":"node-api","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T00:58:17.058003+00:00","updated_at":"2026-11-20T00:15:32.195837+00:00","source_created_at":null,"told_at":"2026-11-20T00:15:30.918172+00:00","status_changed_at":"2026-11-20T00:15:29.643822+00:00","url":"https://bounty.xe.network/XE-8799","body":"# Node-side block producers sign prev=0 blocks on a failed local chain read — `core.Ledger.GetChain` swallows store errors, and `Node.Receive` / `autoAcceptLease` are the only node producers with no len==0 abort\n\n- **Track:** Round 2 / B1 — chain-status blindness, sibling hunt beyond XE-0121 / XE-2706 / XE-6695\n- **Repo / HEAD:** `github.com/xeprotocol/xe` @ `89a542ea51d38375299aee54c6c99102e9bfa666` (testnet-0005), static analysis only, nothing filed\n- **Suggested tier: Minor (ceiling 650 XE)** — reasoning in §5. This is deliberately *not* claimed at the Medium tier of the CLI family; the trigger is narrower, for reasons stated honestly in §4.\n\n## 1. Summary\n\nXE-0121 / XE-2706 / XE-6695 are all one root cause in one helper: the **HTTP** client\n`client.Client.GetChain` (`client/client.go:35`) ignores HTTP status, and the five CLI commands\nin `cmd/xe/main.go` discard its error (`chain, _ :=`) and fall back to `prev := \"0\"`.\n\nThere is a **second, independent chain-read helper** with the same defect shape, and fixing the\nHTTP helper or any of the five CLI commands does not touch it:\n\n`core.Ledger.GetChain` (`core/ledger.go:2374-2389`) **has no error return at all.** When the\nunderlying store read fails it logs and returns `nil`, indistinguishable from \"this account has\nno chain\":\n\n```go\nfunc (l *Ledger) GetChain(account string) []*Block {\n\tchain, err := l.store.GetAccountChain(account)\n\tif err != nil {\n\t\tstoreReadErrors.Add(1)\n\t\tlog.Printf(\"ERROR: GetChain: store read for %s failed: %v — surfacing as no chain, NOT a genuine miss\", shortAddr(account), err)\n\t\treturn nil\n\t}\n\tif chain == nil {\n\t\treturn nil\n\t}\n\t...\n}\n```\n\n(The log line itself concedes the value is wrong: \"surfacing as no chain, **NOT** a genuine miss\"\n— but the function's signature makes that distinction unrepresentable to every caller.)\n\nEvery block producer in `node/` reads its `Previous` through this helper. Five of them fail\nclosed on an empty result — `Node.Send` (node.go:761, \"account not open\"), `Node.CreateLeaseBlock`\n(node.go:2090), `Node.RenewLease` (node/lease_renew.go:45), `settleLease` (node.go:1990) and\n`forceSettleLease` (node.go:1923) all abort when `len(chain) == 0`. **Two do not:**\n\n### Instance A — `Node.Receive` (node/node.go:803-818)\n\n```go\nchain := n.Ledger.GetChain(myAddr)\nprev := \"0\"\nif len(chain) > 0 {\n\tprev = chain[len(chain)-1].Hash\n}\n...\nassetBal := n.Ledger.GetAssetBalances(myAddr)[asset]\nif len(chain) == 0 {\n\tassetBal = 0\n}\n\nb := &core.Block{\n\tType:      core.BlockReceive,\n\tAccount:   myAddr,\n\tPrevious:  prev,                 // \"0\" on a failed read\n\tBalance:   assetBal + p.Amount,  // balance forcibly reset to 0 + amount on a failed read\n\t...\n}\n```\n\nOn a failed read of an **already-open** account this signs an *open* receive block\n(`core.SignBlock`, core/crypto.go:100-104, treats `Previous == \"0\"` as an open block and fills\n`PubKey`). The balance reset is the worst part: the signed `Balance` is exactly\n`0 + pending.Amount`, which is precisely what staged-conflict validation at `prev=0` expects\n(see §3), so the bad block is shaped to *pass* the fork-staging check, not merely to be signed.\n\n### Instance B — `autoAcceptLease` (node/node.go:1573-1588) — remotely initiated, daemon-reachable\n\n```go\nchain := n.Ledger.GetChain(myAddr)\nprev := \"0\"\nif len(chain) > 0 {\n\tprev = chain[len(chain)-1].Hash\n}\nxusdBal = n.Ledger.GetAssetBalances(myAddr)[\"XUSD\"]\n...\nb := &core.Block{\n\tType:     core.BlockLeaseAccept,\n\tAccount:  myAddr,\n\tPrevious: prev,   // \"0\" on a failed read, no len==0 abort anywhere in the function\n\tBalance:  xusdBal - stake,\n\t...\n}\n```\n\n`autoAcceptLease` is not a local CLI action: it is triggered **by a remote consumer's lease\nblock** (`handleIncoming`, node.go:725, and the lease-watch loop, node.go:1695) on any provider\nnode. It also provisions the consumer's VM *before* this code runs, so even the failure modes\nbelow burn a full VM boot first. At HEAD `LeaseStake()` returns 0 for every lease\n(`LeaseStakeDivisor = 0`, core/ledger.go:44-48,116), so the earlier\n`stake > GetAssetBalances(...)` guards pass trivially for an XUSD-unfunded provider.\n\n### Instance C — the same swallowed error is served to remote clients as a clean 200\n\n`node.Node.GetChain` (node.go:879-881) is a pass-through to the same helper, and\n`api.Handler.handleGetChain` (api/handler.go:457-476) reports `Total: len(blocks)`. A store-read\nfailure on the *serving* node therefore leaves the node as HTTP **200 with `total=0`** — a\nresponse no client-side status check (the XE-0121 fix) can distinguish from a genuinely\nunopened account. The helper's error-swallowing thus re-creates the XE-0121 end state through a\n200 response, on a path that family's fix does not cover.\n\n## 2. Trigger\n\n- The store read behind the helper is `BadgerStore.GetAccountChain`\n  (store/badger_store.go:127-166). It returns a real error — not `nil, nil` — when the chain's\n  hash list references a missing block body (`chain references missing block %s`), when a block\n  body fails to unmarshal, or on DB/transaction failure. That Badger reads of exactly this kind\n  do fail in the wild is already on the board (XE-7371: \"GetAccountChain referencing a missing\n  block errors on BadgerStore but succeeds on MemStore\").\n- Instance B needs no operator action at all: any consumer lease addressed to the provider\n  starts the accept path. Instance A is an exported `Node` API (`Node.Receive`); it has no\n  caller inside the shipped daemon binary, which is one reason for the Minor tier (§4).\n\n## 3. Why the bad block is not harmlessly rejected (staging arithmetic, verified in code)\n\n`Ledger.AddBlock` (core/ledger.go:807-918) checks for a conflict sibling *before* per-type\nvalidation: `detectConflictSibling` (core/conflict.go:40-50) matches **any** stored block with\nthe same `Previous`. A `prev=\"0\"` block on an open account is therefore a sibling of the\naccount's first block and is **staged as a conflict and accepted (`AddBlock` returns nil)**,\nprovided `ValidateStagedBlock` passes. In the conflict branch the parent balance is forced to\n0 for `prev=\"0\"` blocks (ledger.go:832-833: the parent-balance walk runs only\n`if chain != nil && b.Previous != \"0\"`), and staged validation (ledger.go:2757-2806) requires:\n\n- receive: `Balance == 0 + pending.Amount` — Instance A's forced `assetBal = 0` makes its\n  signed balance match **exactly, by construction**.\n- lease_accept: `Amount <= 0` and `Balance == 0 - Amount` — at HEAD `Amount = stake = 0`\n  (divisor 0), so this matches for a provider whose XUSD balance is 0 (account open in XE\n  only — e.g. faucet-funded — but never funded in XUSD).\n\nA staged block conflict-locks the account (\"account has unresolved conflict — block rejected\npending resolution\" for subsequent blocks) until quorum resolves the position — the same end\nstate as XE-0121, reached through the node's own producers instead of the CLI.\n\n## 4. Honest limits (why this is Minor, not Medium)\n\n- **The failure must be transient between build and admission.** `AddBlock` re-reads the same\n  store (conflict detection, ledger.go:807). If the store error *persists*, that re-read errors\n  too, `AddBlock` returns the error, and the op fails closed with no fork. The fork in §3 needs\n  the read to fail at `GetChain` time and succeed milliseconds later at admission — a transient\n  Badger error, not the persistent-corruption case. This is materially narrower than the CLI\n  family, where the read node and the submit node are *different machines* and the failure is\n  an ordinary 429/5xx.\n- **Finalized first block = safe.** If the sibling (the account's first block) is already\n  finalized, the staged path rejects outright (\"block conflicts with finalized block\"),\n  same window as XE-0121.\n- **Instance B with a non-zero XUSD balance fails closed at staging** (`Balance != 0`), leaving\n  only the wasted VM provisioning — a cost the board already knows from the\n  provision-before-commit family (XE-4694, XE-0748).\n- **Instance A harms only the operator's own account**, and only via the exported library\n  surface; Instance B harms the provider's own account, triggered by a remote lease but with\n  no third-party funds at risk. No funds are stolen in any variant; worst case is a\n  conflict-locked account plus a wasted VM boot.\n\n## 5. Tier reasoning\n\nMinor (ceiling 650 XE). Same *impact class* as a Medium family (false-signed open block,\nstaged fork, account conflict-lock), but: trigger requires a transient local store failure\nrather than an ordinary HTTP condition; one of the two signing instances is not reachable from\nthe shipped daemon; the other needs a zero XUSD balance to pass staging at current parameters.\nClaiming Medium would overstate it. The durable value of the report is the helper: as long as\n`Ledger.GetChain` cannot return an error, every current and future node producer has to\nremember to treat `nil` as \"unknown\" — and two already don't.\n\n**Suggested fix:** give the helper an error-bearing sibling (`GetChainE` / change the\nsignature), abort in `Receive` and `autoAcceptLease` on `len(chain) == 0` for accounts that\nhave pending/lease state (mirroring the five sibling producers), and have `handleGetChain`\nsurface a store failure as 5xx instead of `200, total=0`.\n\n## 6. Dedupe evidence\n\nClosest tickets, read in full on 2026-11-12 (plus a title sweep of the 890-ticket public\nindex snapshot of 2026-11-11 23:47 + targeted title searches for `prev`, `GetChain`,\n`previous`, `stale`, `frontier`, `autoAccept`, `lease_accept`, `unopened`, `wallet.js`):\n\n- **XE-0121** — `client.Client.GetChain` HTTP-status blindness + `cmdSend` only; its\n  \"same class in the web wallet\" section is `web/assets/wallet.js`. Never names\n  `core.Ledger.GetChain`, `node/`, or any node producer. Fixing it (status checks in the HTTP\n  client) leaves Instances A/B/C fully intact.\n- **XE-2706 / XE-6695** — the same HTTP root cause in CLI `receive`/`mint`/`burn`/`lease`\n  (`cmd/xe/main.go:748/836/910/1057`). CLI commands only; `Node.Receive` (node.go:792) is a\n  different function in a different package that never calls the HTTP client, and\n  `autoAcceptLease` has no CLI counterpart at all.\n- **XE-5418** — Go client pagination termination on server-reported `total` (200-response\n  truncation, stale-but-non-zero previous, CLI consumers). Different helper behaviour,\n  different trigger, CLI only.\n- **XE-6928 / XE-6786 / XE-6654 / XE-7546 / XE-8572 / XE-0625 (per XE-5418's thread)** — HTTP\n  client transport/pagination/read-getter status issues. None touches the core ledger helper\n  or node producers.\n- **XE-7821 / XE-7857** — web wallet prev=0 / same-previous concurrency. Different client,\n  already separated from the Go paths by XE-7821's own dedupe section.\n- **XE-8012** — concurrent CLI processes signing the same previous (no inter-process lock).\n  Concurrency, not a failed read; node producers hold `blockCreateMu` and are not its subject.\n- **XE-0479** — TypeScript SDK `frontier()` on an unsynced node. Different repo/codebase.\n- **XE-7371** — Badger-vs-Mem `GetAccountChain` divergence on a missing block (store-layer\n  split in multisig validation). Cited here as evidence the store error is real; it does not\n  follow the error into any signing path.\n- **XE-4694 / XE-0748 / XE-8378** — auto-accept provisioning/retry-scheduler economics. They\n  cover *when* accept retries or burns a boot, not a prev=0 block signed on a failed chain\n  read; none names `GetChain`, `Previous`, or the len==0 asymmetry among node producers.\n\nNo title in the sweep names a node producer (`Node.Receive`, `Node.Send`, `autoAcceptLease`)\ntogether with `prev`/`GetChain`/chain-status, and no full-text read above covers\n`core/ledger.go:2374`. Residual risk, stated plainly: a triager may still group this under\nXE-0121's \"GetChain trusts the node\" umbrella — but here there is no node/network in the loop\nat all; the untrusted read is the node's own store, and the fix lives in `core`/`node`, not\n`client`/`cmd`.","patch_refs":[],"thread":[{"id":12905,"source":"desk","source_ref":"reply:10927","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have read it against the code and confirmed the behaviour it describes. It is being handled; the assessment follows the fix.","created_at":"2026-11-20T00:15:30.907884+00:00"}]}