{"id":"XE-0102","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"155","source_url":"https://github.com/xeprotocol/xe/issues/155","reporter_id":35,"title":"node: after any lease renewal the shipped client can never force-settle — renter escrow is permanently locked and later burned","area":"leasing-ledger","claimed_tier":"high","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:27.128367+00:00","updated_at":"2026-11-10T00:11:49.912312+00:00","source_created_at":"2026-10-29T01:19:41+00:00","told_at":"2026-11-08T20:19:04+00:00","status_changed_at":"2026-11-08T20:17:53.405070+00:00","url":"https://bounty.xe.network/XE-0102","body":"### Suggested tier: High (10,000 XE) — permanent loss of a renter's escrowed XUSD through the normal renewal flow. Falls back to Medium if this is read as a client-only defect.\n\n### Repo pin: 978785929bc17a2f4ab30c383e5fc9cf4d634512\n\n## Summary\n\n`lease_force_settle` is the renter's only remedy when a provider does not settle. The ledger validates the refund against the whole pending escrow (base cost plus every renewal top-up), but the node's own block builder signs the block with the base `lease.Cost` only. After a single renewal every force-settle block the shipped client can produce is rejected with a balance mismatch, so the renter can never recover the escrow; it survives until `LeaseEscrowExpiry` (365 days) and is then deleted by `archiveExpiredLease`.\n\n## What the ledger requires\n\n```go\n// core/ledger.go:1969-1976 (validateAndAddLeaseForceSettle)\noldBal := l.getAssetBalanceOverlay(b.Account, \"XUSD\")\nexpectedBal := oldBal + pending.Amount     // pending = escrow incl. renewal top-ups\nif expectedBal < oldBal {\n    return fmt.Errorf(\"lease_force_settle would overflow uint64 balance\")\n}\nif b.Balance != expectedBal {\n    return fmt.Errorf(\"balance mismatch: expected %d, got %d\", expectedBal, b.Balance)\n}\n```\n\nThe escrow grows on renewal: `core/lease_renew.go:137-138` sets `commit.TopUpPendingID = b.Source` / `commit.TopUpPendingAmount = b.Amount`, applied as `pending.Amount += topUp` (store/mem_store.go:338-345). `lease.Cost` is never updated by a renewal — `core/lease_renew.go:140-151` only appends a `LeaseSegment`. So after one renewal:\n\n```\npending.Amount = lease.Cost + sum(renewal.Cost)   <- what the validator wants\nlease.Cost     = base segment only                <- what the client builds with\n```\n\n## What the client builds\n\n```go\n// node/node.go:1930-1940 (forceSettleLease)\noldXUSD := n.Ledger.GetAssetBalances(myAddr)[\"XUSD\"]\nb := &core.Block{\n    Type:         core.BlockLeaseForceSettle,\n    Account:      myAddr,\n    Previous:     prev,\n    Balance:      oldXUSD + lease.Cost,   // base only, escrow is larger\n    Timestamp:    core.Now().UnixNano(),\n    Asset:        \"XUSD\",\n    Source:       lease.LeaseHash,\n    Amount:       lease.Cost,             // same problem on the amount\n    Attestations: attestations,\n}\n```\n\n`AddBlock` returns `balance mismatch: expected <escrow>, got <escrow - topUps>`; the node logs \"Failed to add lease_force_settle for <hash>\" (node/node.go:1948-1952) and gives up. There is no retry path and no CLI flag that recomputes the refund.\n\n## Reproduction (local, deterministic, no network)\n\nHarness: a `core.Ledger` over the Badger store with a timekeeper config, a certificate lookup, and R = 2000. Create a lease, accept it, renew it once, then run `forceSettleLease`.\n\nObserved:\n\n```\nafter renewal: base cost=160000 renewal cost=160000 escrow=320000 duration=7200\nclient force-settle block (Balance=old+lease.Cost=999840000): REJECTED:\n    balance mismatch: expected 1000000000, got 999840000\ncontrol block (Balance=old+escrow=1000000000): accepted; renter refunded 1000000000,\n    state=unfulfilled\n```\n\nThe control block proves the ledger side is fine and the defect is the block the client builds: a force-settle carrying the whole pending escrow is accepted and refunds the renter in full.\n\n## Impact\n\n- Permanent, unrecoverable loss of the renter's escrowed XUSD after any renewal when the provider does not settle — precisely the case force-settle exists for.\n- Loss includes the renewal top-ups, so extending a lease increases the loss.\n- No attacker key is needed: the provider only has to not settle, and in this build not settling is free because provider stake is zero (`LeaseStakeDivisor = uint64(0)`, core/ledger.go:116 — separately tracked in #20).\n- Affects every renter using the shipped client that ever renews; hand-crafting a block is the only escape.\n\n## Not a duplicate\n\n- #92 is the **ledger-side** `lease_cancel` path (`validateAndAddLeaseCancel` refunds `oldBal + leaseBlock.Amount` and deletes the whole escrow). Its fix PR #109 changes `lease_cancel` only.\n- This is the **client-side** `lease_force_settle` path in `node/node.go`: different block type, different code path, different failure mode (the block is rejected outright, funds stay escrowed rather than vanishing at cancel time).\n- #21 / #90 concern the provider settling without service; this concerns the renter's refundwhen the provider does not settle.\n- Checked against all 151 issues/PRs at the time of writing; none describes a force-settle balance computed from `lease.Cost`.\n\n## Suggested fix\n\n1. In `node.forceSettleLease`, read the pending escrow and use it for both fields: `Balance: oldXUSD + pending.Amount`, `Amount: pending.Amount` (fall back to `lease.Cost + sum(renewals)` if the store call is unavailable). The control block above is exactly this shape and is accepted.\n2. Add a regression test that renews once and force-settles, asserting the ledger accepts and the renter balance returns to its pre-lease value.\n3. Introduce a single accessor (`lease.TotalEscrow()` = cost + renewals) used by cancel, force-settle and the supply auditor, so the same class of bug cannot reappear (see #92).\n\n## Notes\n\nSource-level only: no traffic to testnet-0005, no accounts, no live node. PoC is a local `go test` under `nice`/`taskset`. Full report and test files available on request.\n\n================================================================================\nAPPENDIX A — RECORDED POC OUTPUT (go test, pinned commit, local only)\n================================================================================\n\n```bash\n=== RUN   TestF3_ForceSettleAfterRenewalIsUnbuildable\n2026/10/29 00:46:09 Genesis block applied: 42000000000000 XE to 378d0f5c2063...\n    f3_f4_test.go:62: after renewal: base cost=160000 renewal cost=160000 escrow=320000 duration=7200\n    f3_f4_test.go:92: client force-settle block (Balance=old+lease.Cost=999840000): REJECTED: balance mismatch: expected 1000000000, got 999840000\n    f3_f4_test.go:115: control block (Balance=old+escrow=1000000000): accepted; renter refunded 1000000000, state=unfulfilled\n    f3_f4_test.go:117: VULNERABLE: the shipped client can never produce the accepted form after a renewal — it under-refunds by 160000 uXUSD (the renewal top-up) and is rejected outright\n--- PASS: TestF3_ForceSettleAfterRenewalIsUnbuildable (0.01s)\n```\n\nReading it: the client's block (Balance = old + lease.Cost) is rejected because the ledger wants old + pending.Amount (escrow including the renewal top-up). The control block carrying the full escrow is accepted and refunds the renter in full — so the ledger is correct and the block the client builds is wrong.\n\n================================================================================\nAPPENDIX B — POC SOURCE (Go tests, package auditpoc)\n================================================================================\n\nReproduce with:\n\n    git clone https://github.com/xeprotocol/xe && cd xe\n    git checkout 978785929bc17a2f4ab30c383e5fc9cf4d634512\n    mkdir -p auditpoc && cp <the two files below> auditpoc/\n    nice -n 15 taskset -c 0-1 go test ./auditpoc/ -run TestF3 -v -count=1\n\nTestF3 is this report. TestF4 in the same file is the stale-certificate renewal issue\n(already filed as #97) and is included only because both live in one file.\n\n--- auditpoc/f3_f4_test.go -----------------------------------------------------\n\n```go\npackage auditpoc\n\n// F3  node/node.go:1901-1956 (forceSettleLease) vs core/ledger.go:1969-1976\n//     (validateAndAddLeaseForceSettle). The node refunds only lease.Cost while\n//     the ledger requires the whole escrow (base + every renewal top-up), so\n//     after one renewal the renter's force-settle block is rejected forever and\n//     the escrow cannot be recovered from the client: it burns at escrow expiry.\n//\n// F4  core/lease_renew.go:79-90 — a renewal only checks that the certificate is\n//     unexpired *at the renewal instant*; it never checks that the certificate\n//     covers the extension it is paying for, and it accepts any old (still\n//     valid) certificate of the provider. A renter can therefore pin a cheap\n//     quote for the whole LeaseMaxDuration (1 year).\n\nimport (\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/xeprotocol/xe/core\"\n\t\"github.com/xeprotocol/xe/perf\"\n)\n\nfunc TestF3_ForceSettleAfterRenewalIsUnbuildable(t *testing.T) {\n\tconsumer := seedKP(0xC1)\n\tprovider := seedKP(0xD2)\n\th := newHarness(t, 2, []*core.KeyPair{consumer, provider})\n\th.setNow(time.Now().UnixNano())\n\th.mint(consumer, 1_000_000_000)\n\th.mint(provider, 1_000_000)\n\n\tcert := h.issueCert(provider, core.RFallback, h.nowNanos, h.nowNanos+int64(7*24*time.Hour))\n\tleaseHash, baseCost := h.createLease(consumer, provider, 2, 2048, 20, 3600, cert, hexRepeat(\"ab\"))\n\n\th.acceptLease(leaseHash, provider, cert)\n\n\t// --- one renewal -------------------------------------------------------\n\trenewDur := uint64(3600)\n\trCost, err := core.LeaseCost(2, 2048, 20, renewDur, cert.PriceMultiplierMilli)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tcchain := h.ledger.GetChain(consumer.Address())\n\tbal := h.balance(consumer.Address(), \"XUSD\")\n\trenew := &core.Block{\n\t\tType:            core.BlockLeaseRenew,\n\t\tAccount:         consumer.Address(),\n\t\tPrevious:        cchain[len(cchain)-1].Hash,\n\t\tBalance:         bal - rCost,\n\t\tTimestamp:       h.nowNanos,\n\t\tAsset:           \"XUSD\",\n\t\tSource:          leaseHash,\n\t\tAmount:          rCost,\n\t\tDuration:        renewDur,\n\t\tCertificateHash: cert.Hash,\n\t\tLockedR:         core.RFallback,\n\t\tAttestations:    h.attest(leaseHash, 2),\n\t}\n\th.add(renew, consumer)\n\n\tl := h.lease(leaseHash)\n\tescrow := h.pendingAmount(leaseHash)\n\tt.Logf(\"after renewal: base cost=%d renewal cost=%d escrow=%d duration=%d\",\n\t\tbaseCost, rCost, escrow, l.EffectiveDurationSecs())\n\tif escrow != baseCost+rCost {\n\t\tt.Fatalf(\"escrow %d != %d+%d\", escrow, baseCost, rCost)\n\t}\n\n\t// --- the provider goes dark; the renter tries to force-settle ----------\n\th.setNow(l.EffectiveExpiry() + core.LeaseSettleGrace + core.LeaseForceSettleGap + int64(time.Minute))\n\toldXUSD := h.balance(consumer.Address(), \"XUSD\")\n\tcchain = h.ledger.GetChain(consumer.Address())\n\n\t// exactly what node.forceSettleLease builds (node/node.go:1930-1940):\n\tb := &core.Block{\n\t\tType:         core.BlockLeaseForceSettle,\n\t\tAccount:      consumer.Address(),\n\t\tPrevious:     cchain[len(cchain)-1].Hash,\n\t\tBalance:      oldXUSD + l.Cost, // <-- only the base segment\n\t\tTimestamp:    h.nowNanos,\n\t\tAsset:        \"XUSD\",\n\t\tSource:       leaseHash,\n\t\tAmount:       l.Cost,\n\t\tAttestations: h.attest(leaseHash, 2),\n\t}\n\tif err := core.SignBlock(b, consumer); err != nil {\n\t\tt.Fatal(err)\n\t}\n\terr = h.ledger.AddBlock(b)\n\tif err == nil {\n\t\tt.Fatalf(\"expected the client's force-settle block to be rejected\")\n\t}\n\tt.Logf(\"client force-settle block (Balance=old+lease.Cost=%d): REJECTED: %v\", oldXUSD+l.Cost, err)\n\tif h.lease(leaseHash).State != core.LeaseAccepted {\n\t\tt.Fatalf(\"lease state changed\")\n\t}\n\n\t// control: the same block with the real escrow refunds correctly.\n\tb2 := &core.Block{\n\t\tType:         core.BlockLeaseForceSettle,\n\t\tAccount:      consumer.Address(),\n\t\tPrevious:     cchain[len(cchain)-1].Hash,\n\t\tBalance:      oldXUSD + escrow,\n\t\tTimestamp:    h.nowNanos + 1,\n\t\tAsset:        \"XUSD\",\n\t\tSource:       leaseHash,\n\t\tAmount:       escrow,\n\t\tAttestations: h.attest(leaseHash, 2),\n\t}\n\tif err := core.SignBlock(b2, consumer); err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif err := h.ledger.AddBlock(b2); err != nil {\n\t\tt.Fatalf(\"control force-settle should succeed: %v\", err)\n\t}\n\tt.Logf(\"control block (Balance=old+escrow=%d): accepted; renter refunded %d, state=%s\",\n\t\toldXUSD+escrow, h.balance(consumer.Address(), \"XUSD\"), h.lease(leaseHash).State)\n\tt.Logf(\"VULNERABLE: the shipped client can never produce the accepted form after a renewal — \"+\n\t\t\"it under-refunds by %d uXUSD (the renewal top-up) and is rejected outright\", escrow-l.Cost)\n}\n\nfunc TestF4_RenewalPinsStaleCertificatePriceForAYear(t *testing.T) {\n\tconsumer := seedKP(0xE1)\n\tprovider := seedKP(0xF2)\n\th := newHarness(t, 2, []*core.KeyPair{consumer, provider})\n\tt0 := int64(1_800_000_000_000_000_000)\n\th.setNow(t0)\n\th.mint(consumer, 1_000_000_000)\n\th.mint(provider, 1_000_000)\n\n\t// The provider's opening quote: 0.5x, valid for 7 days.\n\tcheap := h.issueCert(provider, perf.PriceMultiplierMin, t0, t0+int64(7*24*time.Hour))\n\tleaseHash, _ := h.createLease(consumer, provider, 4, 8192, 50, 30*86400, cheap, hexRepeat(\"ef\"))\n\th.acceptLease(leaseHash, provider, cheap)\n\n\t// Two days later the provider raises its price to the 10x ceiling.\n\th.advance(48 * time.Hour)\n\tdear := h.issueCert(provider, perf.PriceMultiplierMax, h.nowNanos, h.nowNanos+int64(7*24*time.Hour))\n\tt.Logf(\"provider's current quote: multiplier=%d (hash %s)\", dear.PriceMultiplierMilli, dear.Hash[:12])\n\n\t// The renter renews for the maximum the protocol allows, still citing the\n\t// 5-day-old 0.5x certificate.\n\tmaxDur := uint64(core.LeaseMaxDuration) - 30*86400 // cumulative cap\n\tcost, err := core.LeaseCost(4, 8192, 50, maxDur, cheap.PriceMultiplierMilli)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tatCurrent, err := core.LeaseCost(4, 8192, 50, maxDur, dear.PriceMultiplierMilli)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tcchain := h.ledger.GetChain(consumer.Address())\n\tbal := h.balance(consumer.Address(), \"XUSD\")\n\tif cost > bal {\n\t\tt.Fatalf(\"harness balance %d < cost %d\", bal, cost)\n\t}\n\trenew := &core.Block{\n\t\tType:            core.BlockLeaseRenew,\n\t\tAccount:         consumer.Address(),\n\t\tPrevious:        cchain[len(cchain)-1].Hash,\n\t\tBalance:         bal - cost,\n\t\tTimestamp:       h.nowNanos,\n\t\tAsset:           \"XUSD\",\n\t\tSource:          leaseHash,\n\t\tAmount:          cost,\n\t\tDuration:        maxDur,\n\t\tCertificateHash: cheap.Hash, // 0.5x, issued 2 days ago, expires in 5 days\n\t\tLockedR:         core.RFallback,\n\t\tAttestations:    h.attest(leaseHash, 2),\n\t}\n\th.add(renew, consumer)\n\n\tl := h.lease(leaseHash)\n\tt.Logf(\"renewal accepted: certificate=%s multiplier=%d extension=%ds (lease now %ds)\",\n\t\tcheap.Hash[:12], cheap.PriceMultiplierMilli, maxDur, l.EffectiveDurationSecs())\n\tt.Logf(\"paid %d uXUSD at the stale 0.5x quote; the provider's live quote would be %d uXUSD (%.0fx)\",\n\t\tcost, atCurrent, float64(atCurrent)/float64(cost))\n\tif l.EffectiveDurationSecs() != 30*86400+maxDur {\n\t\tt.Fatalf(\"duration %d\", l.EffectiveDurationSecs())\n\t}\n\tt.Logf(\"VULNERABLE: a 7-day price quote priced a 1-year extension — the provider is bound \"+\n\t\t\"to serve 365 days at %.1f%% of its current rate\", 100*float64(cheap.PriceMultiplierMilli)/float64(dear.PriceMultiplierMilli))\n}\n\nfunc hexRepeat(s string) string {\n\tout := make([]byte, 0, 64)\n\tfor len(out) < 64 {\n\t\tout = append(out, s...)\n\t}\n\treturn string(out[:64])\n}\n```\n\n\n--- auditpoc/harness_test.go (required for TestF3 to compile) ------------------\n\n```go\n// Package auditpoc contains local, offline proofs-of-concept for the XE\n// compute-leasing / VM audit (FINDINGS-A). Nothing here talks to a network.\npackage auditpoc\n\nimport (\n\t\"encoding/hex\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/xeprotocol/xe/core\"\n\t\"github.com/xeprotocol/xe/perf\"\n\t\"github.com/xeprotocol/xe/store\"\n)\n\n// network id is bound into block hashes; any fixed value works for a local chain.\nfunc init() { core.SetNetworkID(\"xe-audit-local\") }\n\ntype harness struct {\n\tt        *testing.T\n\tledger   *core.Ledger\n\tstore    core.Store\n\ttks      []*core.KeyPair\n\tcfg      *core.TimekeeperConfig\n\tcerts    map[string]*perf.Certificate\n\tnowNanos int64\n}\n\nfunc seedKP(b byte) *core.KeyPair {\n\tvar seed [32]byte\n\tfor i := range seed {\n\t\tseed[i] = b\n\t}\n\tseed[0] = b\n\tseed[31] = b ^ 0x5a\n\treturn core.KeyPairFromSeed(seed[:])\n}\n\n// newHarness builds a ledger whose timekeepers are tks and whose certificate\n// lookup only ever returns certificates that pass perf.VerifyCertificateContent\n// (this mirrors node.ingestCertificate -> certSet.put on a real node).\nfunc newHarness(t *testing.T, threshold int, minter []*core.KeyPair) *harness {\n\tt.Helper()\n\tms := store.NewMemStore()\n\ttks := []*core.KeyPair{seedKP(0x11), seedKP(0x22), seedKP(0x33)}\n\tkeys := make([]string, 0, len(tks))\n\tfor _, k := range tks {\n\t\tkeys = append(keys, k.PubKeyHex())\n\t}\n\tcfg := &core.TimekeeperConfig{Threshold: threshold, Keys: keys}\n\th := &harness{t: t, tks: tks, cfg: cfg, certs: map[string]*perf.Certificate{}, nowNanos: time.Now().UnixNano()}\n\n\tvar minterKeys []string\n\tfor _, k := range minter {\n\t\tminterKeys = append(minterKeys, k.Address())\n\t}\n\n\th.ledger = core.NewLedger(ms, core.LedgerConfig{\n\t\tDifficulty:          0, // no PoW in the harness\n\t\tTimestampWindow:     0, // tests drive core.Now explicitly\n\t\tTimekeeperConfigFn:  func() *core.TimekeeperConfig { return cfg },\n\t\tMinterConfigFn:      func() *core.MinterConfig { return &core.MinterConfig{Keys: minterKeys} },\n\t\tCertificateLookupFn: h.lookupCert,\n\t})\n\th.store = ms\n\treturn h\n}\n\nfunc (h *harness) lookupCert(hash string) *core.CertificateInfo {\n\tc := h.certs[hash]\n\tif c == nil {\n\t\treturn nil\n\t}\n\treturn &core.CertificateInfo{Provider: c.Provider, ExpiresAt: c.ExpiresAt, PriceMultiplierMilli: c.PriceMultiplierMilli}\n}\n\n// setNow pins core.Now (used for attestation skew and block timestamps).\nfunc (h *harness) setNow(ns int64) {\n\th.nowNanos = ns\n\tcore.Now = func() time.Time { return time.Unix(0, ns) }\n}\n\nfunc (h *harness) advance(d time.Duration) { h.setNow(h.nowNanos + int64(d)) }\n\nfunc (h *harness) add(b *core.Block, kp *core.KeyPair) {\n\th.t.Helper()\n\tif err := core.SignBlock(b, kp); err != nil {\n\t\th.t.Fatalf(\"sign %s: %v\", b.Type, err)\n\t}\n\tif err := h.ledger.AddBlock(b); err != nil {\n\t\th.t.Fatalf(\"add %s: %v\", b.Type, err)\n\t}\n}\n\n// mint gives an account `amount` micro-XUSD. Open blocks (previous=0) are minted\n// as the account's first block; later mints extend the chain.\nfunc (h *harness) mint(kp *core.KeyPair, amount uint64) {\n\th.t.Helper()\n\tacct := kp.Address()\n\tchain := h.ledger.GetChain(acct)\n\tprev := \"0\"\n\tbal := uint64(0)\n\tif len(chain) > 0 {\n\t\tprev = chain[len(chain)-1].Hash\n\t\tbal = h.ledger.GetAssetBalances(acct)[\"XUSD\"]\n\t}\n\tb := &core.Block{\n\t\tType:      core.BlockMint,\n\t\tAccount:   acct,\n\t\tPrevious:  prev,\n\t\tBalance:   bal + amount,\n\t\tTimestamp: h.nowNanos,\n\t\tAsset:     \"XUSD\",\n\t\tAmount:    amount,\n\t}\n\th.add(b, kp)\n}\n\nfunc (h *harness) issueCert(provider *core.KeyPair, mult uint64, issuedAt, expiresAt int64) *perf.Certificate {\n\th.t.Helper()\n\tc := &perf.Certificate{\n\t\tProvider:             provider.Address(),\n\t\tSeed:                 hex.EncodeToString(bytes32(0x77)),\n\t\tWorkloadVersion:      perf.WorkloadVersion,\n\t\tPuzzles:              perf.PoWPuzzles,\n\t\tWorkProof:            hex.EncodeToString(bytes32(0x01)),\n\t\tCPUHash:              hex.EncodeToString(bytes32(0x02)),\n\t\tScore:                1.0,\n\t\tStartAttestationRoot: hex.EncodeToString(bytes32(0x03)),\n\t\tEndAttestationRoot:   hex.EncodeToString(bytes32(0x04)),\n\t\tStartMedian:          issuedAt,\n\t\tEndMedian:            issuedAt + int64(time.Second),\n\t\tIssuedAt:             issuedAt,\n\t\tExpiresAt:            expiresAt,\n\t\tPriceMultiplierMilli: mult,\n\t}\n\tif err := perf.SignCertificate(c, provider); err != nil {\n\t\th.t.Fatalf(\"sign cert: %v\", err)\n\t}\n\tif err := perf.VerifyCertificateContent(c); err != nil {\n\t\th.t.Fatalf(\"cert must be acceptable to a real node: %v\", err)\n\t}\n\th.certs[c.Hash] = c\n\treturn c\n}\n\nfunc bytes32(b byte) []byte {\n\tout := make([]byte, 32)\n\tfor i := range out {\n\t\tout[i] = b\n\t}\n\treturn out\n}\n\n// attest collects `n` timekeeper attestations for identifier at h.nowNanos.\nfunc (h *harness) attest(identifier string, n int) []core.TimekeeperAttestation {\n\th.t.Helper()\n\tout := make([]core.TimekeeperAttestation, 0, n)\n\tfor i := 0; i < n; i++ {\n\t\ta, err := core.SignAttestation(identifier, h.nowNanos, h.tks[i])\n\t\tif err != nil {\n\t\t\th.t.Fatalf(\"sign attestation: %v\", err)\n\t\t}\n\t\tout = append(out, *a)\n\t}\n\treturn out\n}\n\n// createLease writes the consumer's lease block and returns its hash.\nfunc (h *harness) createLease(consumer, provider *core.KeyPair, vcpus, memMB, diskGB, dur uint64, cert *perf.Certificate, accessPubKey string) (string, uint64) {\n\th.t.Helper()\n\tcost, err := core.LeaseCost(vcpus, memMB, diskGB, dur, cert.PriceMultiplierMilli)\n\tif err != nil {\n\t\th.t.Fatalf(\"LeaseCost: %v\", err)\n\t}\n\tchain := h.ledger.GetChain(consumer.Address())\n\tif len(chain) == 0 {\n\t\th.t.Fatalf(\"consumer chain not open\")\n\t}\n\tprev := chain[len(chain)-1].Hash\n\tbal := h.ledger.GetAssetBalances(consumer.Address())[\"XUSD\"]\n\tif cost > bal {\n\t\th.t.Fatalf(\"harness: consumer balance %d < cost %d\", bal, cost)\n\t}\n\tb := &core.Block{\n\t\tType:            core.BlockLease,\n\t\tAccount:         consumer.Address(),\n\t\tPrevious:        prev,\n\t\tBalance:         bal - cost,\n\t\tTimestamp:       h.nowNanos,\n\t\tAsset:           \"XUSD\",\n\t\tDestination:     provider.Address(),\n\t\tAmount:          cost,\n\t\tVCPUs:           vcpus,\n\t\tMemoryMB:        memMB,\n\t\tDiskGB:          diskGB,\n\t\tDuration:        dur,\n\t\tAccessPubKey:    accessPubKey,\n\t\tCertificateHash: cert.Hash,\n\t}\n\th.add(b, consumer)\n\treturn b.Hash, cost\n}\n\nfunc (h *harness) acceptLease(leaseHash string, provider *core.KeyPair, cert *perf.Certificate) *core.Block {\n\th.t.Helper()\n\tchain := h.ledger.GetChain(provider.Address())\n\tif len(chain) == 0 {\n\t\th.t.Fatalf(\"provider chain not open\")\n\t}\n\tbal := h.ledger.GetAssetBalances(provider.Address())[\"XUSD\"]\n\tb := &core.Block{\n\t\tType:            core.BlockLeaseAccept,\n\t\tAccount:         provider.Address(),\n\t\tPrevious:        chain[len(chain)-1].Hash,\n\t\tBalance:         bal, // stake is 0 because core.LeaseStakeDivisor == 0\n\t\tTimestamp:       h.nowNanos,\n\t\tAsset:           \"XUSD\",\n\t\tSource:          leaseHash,\n\t\tAmount:          0,\n\t\tAttestations:    h.attest(leaseHash, 2),\n\t\tCertificateHash: cert.Hash,\n\t\tLockedR:         core.RFallback,\n\t}\n\th.add(b, provider)\n\treturn b\n}\n\nfunc (h *harness) lease(hash string) *core.Lease {\n\th.t.Helper()\n\tls, ok := h.store.(core.LeaseStore)\n\tif !ok {\n\t\th.t.Fatalf(\"store is not a LeaseStore\")\n\t}\n\tl, err := ls.GetLease(hash)\n\tif err != nil || l == nil {\n\t\th.t.Fatalf(\"lease %s: %v\", hash[:12], err)\n\t}\n\treturn l\n}\n\nfunc (h *harness) balance(acct, asset string) uint64 {\n\treturn h.ledger.GetAssetBalances(acct)[asset]\n}\n\nfunc (h *harness) pendingAmount(sendHash string) uint64 {\n\th.t.Helper()\n\tp, err := h.store.GetPendingSend(sendHash)\n\tif err != nil || p == nil {\n\t\th.t.Fatalf(\"pending %s: %v\", sendHash[:12], err)\n\t}\n\treturn p.Amount\n}\n```\n\n\n================================================================================\nAPPENDIX C — NOTES FOR TRIAGE\n================================================================================\n\n- Source-level only: no traffic to testnet-0005, no accounts, no node joined to the mesh. Everything runs offline against the pinned tree.\n- The escrow is not merely stuck forever in-process: node/node.go:1884-1902 (archiveExpiredLease) deletes the pending send and marks the lease expired at expiry + LeaseEscrowExpiry + LeaseArchiveGap (365 days), so the renter's XUSD is destroyed.\n- Nothing in this report depends on the zero-stake issue (#20); the zero stake only makes\n- If you would like it as a PR: the fix is two fields in node/node.go (Balance and Amount from the pending escrow) plus a regression test that renews once and force-settles.","patch_refs":[{"id":173,"repo":"xeprotocol/xe","kind":"pr","ref":"173","title":"node: compute force-settle refund from full pending escrow (#155)","url":"https://github.com/xeprotocol/xe/pull/173","note":"","state":"open","author":"fangjian-bit","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":48,"source":"github","source_ref":"6489480337","author":"fangjian-bit","team":false,"body":"Submitted fix and regression test suite in #173.\n\nRefactored force-settle block creation into `BuildForceSettleBlock` which queries `pending.Amount` (with `lease.Cost + sum(renewals.Cost)` fallback) to match ledger's `expectedBal := oldBal + pending.Amount` check. Verified end-to-end with unit tests confirming rejection of partial refunds and successful processing of full escrow refunds.","created_at":"2026-10-29T06:17:10+00:00"},{"id":1170,"source":"github","source_ref":"6726598792","author":"Joseph Denne","team":true,"body":"Thanks for the detailed report. We have confirmed the behaviour and it is being handled; we will update this ticket when there is more to share.","created_at":"2026-11-08T20:19:04+00:00"},{"id":1902,"source":"github","source_ref":"6765026014","author":"Reyzz95","team":false,"body":"Still reproduces at HEAD `89a542e` (testnet-0005, 2026-11-10).\n\nLedger side is correct — `validateAndAddLeaseForceSettle` (`ledger.go:1968-1978`) refunds the full `pending.Amount` and a correctly-built block is accepted. But the node client still builds the block wrong: `forceSettleLease` (`node/node.go:1901-1955`, line 1934) uses `Balance: oldXUSD + lease.Cost` (base cost only) and never sums `lease.Renewals[].Cost`.\n\nAfter any renewal the node's own ledger rejects its own block: `balance mismatch: expected 10000000, got 9998666`.","created_at":"2026-11-10T10:30:13+00:00"},{"id":3135,"source":"github","source_ref":"6815858504","author":"Rizky792","team":false,"body":"Executed end-to-end confirmation of the automatic-tick path for this issue — supporting evidence, not a new report.\n\nHEAD 89a542e (xe-node), local only, no live net, no real funds. Setup: real in-process ledger + local statechain genesis with sys.timekeepers (threshold 1) + two real libp2p hosts (consumer node + separate timekeeper peer, attestations via the production gatherAttestations path) + real gossipsub. The force-settle block was built by the real forceSettleLease, triggered by the real settleLoop (10s tick). 3/3 full runs PASS.\n\nResults, renewed lease (base 40,000 + renew 40,000, escrow 80,000, provider never settles, past expiry + 1h grace + 25m gap):\n- Every settleLoop tick: node-built force-settle REJECTED — 'Failed to add lease_force_settle: balance mismatch: expected 100000000, got 99960000'. 9 distinct rejections across the 3 runs, no backoff or already-tried marker. Pending escrow stayed 80,000 locked, consumer XUSD stayed 99,920,000, lease stayed Accepted.\n- Control, SDK-style full-escrow block for the same lease: ACCEPTED, lease unfulfilled, consumer XUSD back to 100,000,000 (full 80,000 refund).\n- Control, no renewal (base-only lease): node-built force-settle ACCEPTED via the real node path, full 40,000 refund. The defect is specific to renewed leases.\n- Archive executed (not inferred): advanced to expiry + 365 days + 1h and ran the real tryArchiveExpiredLeases — pending escrow deleted, lease Expired, consumer XUSD still 99,920,000. The 80,000 never came back. Note: the archive log line says 'burned 40000' (Cost+Stake) while the deleted pending was 80,000.\n\nWhy this adds to #155: this issue's PoC replicates the client-built block; this is the same defect executed through the automatic settleLoop path, including the attestation gate that a no-timekeeper repro never reaches (without a configured timekeeper the block fails attestation validation before the balance check).\n\nContext, written honestly: bounty ticket XE-1869 (same automatic path, executed PoC) was closed as a duplicate of XE-0102, and XE-2901 (bounty desk, still NEW) describes the same mechanism with a static PoC only. I am not filing a new bounty ticket — this comment only adds executed proof of the automatic path to the open issue. The fix in #173 (compute the refund from the full pending escrow) is exactly what this confirms is needed: build the force-settle block from leaseSettleAmount(lease) / LeaseTotalEmission (base + renewals) for both Balance and Amount, as settleLease already does.","created_at":"2026-11-12T05:50:35+00:00"}]}