<!-- XE-0583 · [High] PR #147 (XE-0022 fix) is fix-incomplete: unwinding a consumer lease_open deletes the shared lease record, orphans the provider's lease_accept and makes the provider's fork unresolvable · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0583>. The page is the record; this is the same page for reading.*

XE-0583 · Bounty

# \[High\] PR #147 (XE-0022 fix) is fix-incomplete: unwinding a consumer lease\_open deletes the shared lease record, orphans the provider's lease\_accept and makes the provider's fork unresolvable

Closed · duplicate
—
web
filed 2026-11-05 04:15 UTC
by xe:79bd7409

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Consensus

Duplicate of
:   [XE-0002](https://bounty.xe.network/XE-0002) accepted

Tracked
:   internally

Updated
:   2026-11-14 22:52 UTC

Told
:   2026-11-14 22:52 UTC

### Patches

None linked.

### History

- [209781](https://bounty.xe.network/log/209781) 2026-11-14 22:52 UTC reply.sent
- [44408](https://bounty.xe.network/log/44408) 2026-11-08 20:32 UTC proposal.adopted
- [44407](https://bounty.xe.network/log/44407) 2026-11-08 20:32 UTC ticket.status new → closed
- [27890](https://bounty.xe.network/log/27890) 2026-11-08 11:08 UTC proposal.adopted
- [27889](https://bounty.xe.network/log/27889) 2026-11-08 11:08 UTC proposal.adopted
- [27888](https://bounty.xe.network/log/27888) 2026-11-08 11:08 UTC ticket.facts
- [27887](https://bounty.xe.network/log/27887) 2026-11-08 11:08 UTC proposal.adopted
- [27886](https://bounty.xe.network/log/27886) 2026-11-08 11:08 UTC ticket.facts
- [27885](https://bounty.xe.network/log/27885) 2026-11-08 11:08 UTC proposal.adopted
- [27884](https://bounty.xe.network/log/27884) 2026-11-08 11:08 UTC ticket.facts
- [27883](https://bounty.xe.network/log/27883) 2026-11-08 11:08 UTC proposal.adopted
- [27703](https://bounty.xe.network/log/27703) 2026-11-08 11:08 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-0583) · [JSON](https://bounty.xe.network/v1/tickets/XE-0583) · [markdown](https://bounty.xe.network/XE-0583.md)

### Report

# PR #147 (the fix for XE-0022) is fix-incomplete: unwinding a consumer-side `lease_open` permanently deletes the shared lease record, orphans the provider's `lease_accept`, and makes the provider's own fork unresolvable

## Summary

PR #147 removes the "cannot unwind descendant" refusal in `swapBlockLocked` / `planRollbackFrom`, allowing lease-family blocks to be unwound during conflict resolution. That is the intended remedy for **XE-0022** (`core/ledger: swap cannot unwind lease and multisig descendants, permanently stalling the account on a contested send`).

The new path has a cross-account side effect that PR #147 does not handle: unwinding a consumer's `lease_open` block **deletes the shared lease record** from the store. The provider's `lease_accept` lives on the *provider's* chain, so it is not a descendant on the consumer's chain and is not unwound — it survives as an **orphan**, permanently referencing a lease that no longer exists.

Three consequences, all reproduced deterministically:

1. **The provider can never settle the lease it accepted.** `validateAndAddLeaseSettle` looks the lease up in the record store and fails: `lease not found: <hash>`. The re-accept path is also closed (`CommitBlock: lease state conflict: lease <hash> not found`), so the orphan is **permanent and unrepairable**.
2. **Any later fork on the provider's chain at or below the accept is unresolvable.** `SwapBlock` fails deterministically with `undo: lease <hash> not found while reversing lease_accept`. Every candidate winner at that fork point requires unwinding the same orphaned accept, so no candidate can ever be promoted. Worse, the error contains the substring `not found`, so `core.IsRetryableError` returns `true` and the failed-promotion quarantine at `core/quorum.go:328` (`errors.Is(err, ErrWinnerFullValidation) && !IsRetryableError(err)`) never triggers — the stale-conflict sweep retries the same impossible promotion indefinitely instead of substituting a different candidate.
3. **Live-vs-restart reputation divergence.** The live node reports `leases_accepted_as_provider: 1` and `leases_accepted_as_consumer: 1`; a node rebuilt from the same store reports **zero for both**, because `rebuildReputation` derives `EventLeaseAccepted` solely from lease *records*.

The failure is **order-dependent**: if the provider resolves their own fork first, the accept unwind restores the lease to `LeaseCreated` and no orphan remains (T8). The bad order — consumer forks first, provider forks later — is the natural race.

This is a **fix-incomplete residual on XE-0022**, framed the same way as **XE-0570** (a gap left by an accepted fix PR), not a duplicate of XE-0022 itself.

## Affected component and versions

- `xeprotocol/xe`, `master` @ `02e9641` **with the PR #147 diff applied** (PR head `ba4a167`).
- PR #147 diff: 2 source hunks — `core/ledger.go` (`swapBlockLocked` descendant allow-list) and `core/rollback.go` (`planRollbackFrom` descendant allow-list), plus the new test `core/swap_lease_descendant_test.go`.
- Code paths: `core/rollback.go` (`buildBlockUndo`, `priorLease`), `core/ledger.go` (`swapBlockLocked`, `validateAndAddLeaseAccept`, `validateAndAddLeaseSettle`, `rebuildReputation`), `store/badger_store.go` (`applyUndoTxn`).

## Relation to existing reports (dedup)

- **XE-0022** (`accepted` / `likely-valid` / `high`, area `consensus`, reporter 13, GitHub issue #43) is the **home ticket** for PR #147. Its body states that `buildUndo` "already knows how to reverse lease descendants". PR #147 is that fix. This report is the residual the fix does not address.
- **XE-0135** (reporter 43, GitHub issue #226) and its fix PR **#227 / #232** address *stale store reads inside a single cascade*: they make `priorLease`, `escrowPendingOf`, `priorLeasePopRenewal` and `xusdBalanceOnChain` consult the in-flight `cascadeBuild` overlay instead of the store. That is **not** this defect. Here the lease record was deleted by an **earlier, completed** cascade, so the second cascade's overlay has no entry for that lease; `cb.lookupLease` falls through to the store and returns `nil`, and the same fatal error fires. The #227 diff changes the *source of the lookup*, not the handling of a missing lease, so the residual survives it. The failure modes are also different: #227 is about stale values corrupting balance math, this is about a *permanently absent* record making a fork unresolvable.
- **XE-0137** (reporter 44\) is a pending-send destination race in the same function family (supply inflation) — unrelated mechanism.
- **XE-0570** (reporter 210, mine) is the precedent for filing a *fix-incomplete residual* rather than re-reporting the parent ticket.
- Desk scan: all **199** public tickets were searched for `147`, `lease_accept`, `lease accept`, `orphan`, `not found while reversing`, `swapblock`, `reputation`, `descendant`, `unwind`, `priorLease`, `missing lease`, `lease record`, `fork`, `conflict`, `lease_settle`, `settle`, `force_settle`, `multisig`, `rebuild`, `restart`. **No ticket** mentions the orphaned accept, the `not found while reversing` error, `deleteLeaseHash`, `priorLease`, cross-account lease destruction, or the live/restart reputation divergence.

## Root cause

### 1\. Unwinding `lease_open` deletes a **global** lease record

`core/rollback.go:222-225`:

```
case BlockLease:
    deletePendingID = b.Hash
    deleteLeaseHash = b.Hash
```

`core/rollback.go:315` puts it in the undo as `DeleteLeaseHash`, and `store/badger_store.go:1101-1104` physically removes it:

```
if u.DeleteLeaseHash != "" {
    if err := txn.Delete(prefixedKey(prefixLease, u.DeleteLeaseHash)); err != nil {
```

The lease record is **shared state** between two accounts (consumer and provider), but the unwind is driven by the **consumer's** chain only. The provider's `lease_accept` is not on the consumer's chain, so it is not in the unwind set and is left behind. Note that `applyUndoTxn` never deletes the block record itself (`prefixBlock`), so the `lease_open` **block** survives while the lease **record** does not — the two halves of the lease state diverge. The harness confirms this split directly:

```
post-swap lease record: DELETED | lease_open block record present=true (needed to re-validate lease_accept: core/ledger.go:1615)
```

That split is what keeps the orphan alive rather than making it self-evident: `validateAndAddLeaseAccept` resolves the lease **block** (`core/ledger.go:1615`), which still exists, while everything that depends on the lease **record** fails.

### 2\. The orphaned `lease_accept` cannot be unwound, and cannot be settled

`core/rollback.go:226-228` (unwinding an accept) and `core/rollback.go:255` (the fatal check):

```
case BlockLeaseAccept:
    restoreLease = l.priorLease(b.Source, LeaseCreated)
...
if (b.Type == BlockLeaseAccept || ...) && restoreLease == nil {
    return nil, nil, fmt.Errorf("undo: lease %s not found while reversing %s", shortHash(b.Source), b.Type)
}
```

`priorLease` (`core/rollback.go:89`) reads the lease from the store; the record is gone, so it returns `nil` and the unwind aborts. `core/ledger.go:2995` wraps that as `ErrWinnerFullValidation`.

Settling is blocked too — `core/ledger.go:2125-2134` resolves the lease through the same record store (`lease not found: <hash>`), and `core/ledger.go:2186-2192` additionally requires the escrow pending send, which the unwind already deleted. Re-accepting is blocked by the store CAS (`lease state conflict: lease <hash> not found`). The provider's chain therefore keeps a block whose referenced lease no longer exists, with no way to settle, re-accept, or unwind it.

### 3\. Reputation is derived from lease records only

`core/ledger.go:607-683` (`rebuildReputation`) enumerates `GetAllLeases()` and emits `EventLeaseAccepted` per lease record (`core/ledger.go:627`). With the record deleted, a restarted node loses the accept event entirely — for **both** the provider (`leases_accepted_as_provider`) and the consumer (`leases_accepted_as_consumer`), while the live node still counts both.

## Reproduction

Deterministic PoC harness: `cmd/pocdiff` (scenarios `T1`–`T10`), run against `master` \+ the PR #147 diff. No network, no wall-clock dependence (fake clock via `core.Now`), fixed base time `time.Unix(1700000000,0)` and shared keys so MemStore and BadgerStore runs produce identical hashes.

```
go run ./cmd/pocdiff/
```

Actors: `keys[0]` \= consumer, `keys[1]` \= provider, `keys[2]` \= timekeeper / third party.

| Scenario | What it does | Result |
| --- | --- | --- |
| T1 | consumer opens lease, provider accepts, consumer forks at the `lease_open` and the swap unwinds it | lease record **DELETED**, provider accept **still present** |
| T2 | same, with a renewal in between | lease record **DELETED**, escrow pending dropped |
| T3 | provider forks at its own accept (before the consumer forks) | lease restored to `created`, **no orphan** |
| T4 | provider unwinds its own settle | parity, no orphan |
| T5 | **consumer forks first, then the provider forks** | provider fork **UNRESOLVABLE** |
| T6 | provider tries to settle the orphaned lease | `lease not found` |
| T7 | provider forks at a block *after* the accept | swap succeeds, but the accept stays orphaned forever |
| T8 | **reverse order** (provider forks first, consumer second) | no orphan, no later failure |
| T9 | classifies the fatal unwind error | `errors.Is(ErrWinnerFullValidation)=true`, `IsRetryableError=true` |
| T10 | provider tries to re-accept the orphaned lease | `CommitBlock: lease state conflict: lease <hash> not found` — orphan is unrepairable |

### T5 — the provider's fork becomes unresolvable

```
steps: lease: ok | accept: ok | lease state=accepted stake=0 renewals=0 |
       conflict-send: ok | swap-lease-away: ok |
       post-swap lease record: DELETED |
       provider chain len=2 accept_present=true prov_xusd=10000000 |
       provider-conflict-send: ok |
       provider-swap: ERR SwapBlock: winner failed full validation: build undo for 39c9bda27f3a...:
                       undo: lease 3251a1454bfd... not found while reversing lease_accept
```

Full error:

```
SwapBlock: winner failed full validation: build undo for 39c9bda27f3a...: undo: lease 3251a1454bfd... not found while reversing lease_accept
```

### T9 — the failure is deterministic but misclassified as retryable

```
classification: errors.Is(ErrWinnerFullValidation)=true IsRetryableError=true
```

`core/retryable.go:13` lists the bare substring `"not found"` as a retryable pattern, so `core/quorum.go:328`

```
if errors.Is(err, ErrWinnerFullValidation) && !IsRetryableError(err) {
    qm.failedPromotions[...] = Now()
```

never records the failure. The stale-conflict sweep (`core/quorum.go:528-573`) therefore re-promotes the same impossible candidate on every cycle, instead of quarantining it and substituting a promotable one. Because **every** candidate at that fork point needs the same accept unwind, the conflict is never resolved and the provider's account stays conflicted (new blocks are rejected with `account has unresolved conflict — block rejected pending resolution`, `core/ledger.go:817`).

### T1/T2 — live vs restart divergence

Live node:

```
rep 6c99ab87024b {"version":2,"leases_accepted_as_provider":1,...}
rep 98dcb595e34a {"version":2,"leases_accepted_as_consumer":1,...}
```

Node rebuilt from the same store (same balances, same delegated weight, same account keys):

```
(no reputation block at all for either account)
```

### Layer results (store independence)

The harness runs every scenario three ways:

- **Layer 1 — MemStore vs BadgerStore**, same sequence, comparing per-step accept/reject and the final state: **0 divergences across all 18 scenarios**. The defect is therefore *not* a test-store artifact; production nodes run `BadgerStore` (`MemStore` is used only by `cmd/fuzzsim`, `cmd/poc*` and tests).
- **Layer 2 — store-level edge conditions**: 6 pre-existing divergences (mem silent-ok vs badger error). These are latent/unreachable in the current tree and are **not** part of this report.
- **Layer 3 — live in-memory state vs state rebuilt from the store**: 7 divergences (T1, T2, T5, T6, T7, T9, T10) — all of them the reputation divergence described above. Balances, delegated weight and account keys are identical in every scenario.

## Impact

- **Cross-account state destruction.** One account's conflict resolution unilaterally deletes another account's lease state. The provider's chain is left containing a block that references a lease which exists nowhere in the store — the chain is no longer self-consistent with the lease store, and the block cannot be settled, re-accepted, or unwound.
- **Permanent account stall (the XE-0022 impact class, reintroduced for `lease_accept`).** Any later conflict on the provider's chain at or below the orphaned accept can never be resolved. The failure is deterministic, and the retryable misclassification prevents the substitute-candidate mechanism from ever engaging.
- **Node-state divergence.** A node that keeps running reports a lease acceptance that a node restarted over the same store does not. Any consumer of the reputation API sees different answers before and after a restart. (Reputation does **not** feed finalization eligibility — `core/repeligibility.go` uses the `sys.representatives` allow-list — so this is an inconsistency, not a fork.)
- **Dead revenue for the provider.** The lease escrow is returned to the consumer by the unwind, so the provider is left with an accepted-but-unsettleable lease and can never collect the lease revenue.
- **The provider's chain is no longer replayable from genesis on a node that lacks the unwound `lease_open` block.** `validateAndAddLeaseAccept` requires the lease block record (`core/ledger.go:1615`, failing with `source lease block not found` at `core/ledger.go:1619-1620`). On the node that performed the unwind the block record survives, but on a node that only ever receives the provider's chain, the `lease_open` block is no longer part of any chain — the provider's `lease_accept` cannot be re-validated. This last point is derived from the code path rather than separately reproduced in the harness, and is listed here as a risk to investigate rather than as a demonstrated outcome.

## Honest bounds (what is *not* claimed)

- **No supply inflation.** The XUSD census is conserved across every stage (`total_xusd=20000000` at funded / after-accept / after-renew / after-swap): the escrow is refunded to the consumer, it is not destroyed. The settle path additionally refuses without the escrow pending record (`no escrow pending to burn for lease`), so the provider cannot convert the orphan into emission.
- **No double-accept.** The store CAS rejects a second accept for the same lease (`lease state conflict: lease <hash> not found`).
- **No stake-burn claim.** `LeaseStakeDivisor` is `const uint64(0)` in `master` (`core/ledger.go:116`), so the provider stake is always 0 and no stake can be burned.
- **Not a consensus fork.** Balances, delegated weight, account keys and keysets are identical live vs rebuilt. The fork-level impact is the *unresolvable conflict* on the provider's account, not divergent ledger state.
- **Precondition.** The trigger requires a lease that has been accepted, a contested block on the consumer's chain at or below the `lease_open`, and a later contested block on the provider's chain at or below the `lease_accept`. No special privileges are needed — any account can fork its own chain — but it is a compound race rather than a single transaction.
- **The fresh-node replayability consequence above is code-path analysis, not a reproduced result.** Everything else in this report is reproduced by the harness.

## Suggested fix direction

1. **Do not delete a lease record while another account's chain still references it.** In `buildBlockUndo` / `applyUndoTxn`, a `lease_open` unwind should not physically remove the lease record when a `lease_accept` for that lease exists on another account's chain; instead it should demote the lease back to `LeaseCreated` and re-anchor the escrow, leaving the provider's accept valid.
2. **Make the unwind of a `lease_accept` tolerant of a missing lease record.** `priorLease` should reconstruct the prior lease state from the chain (`lease_open` block \+ the accept's own undo data) when the record is absent, rather than aborting with a fatal error. The abort is what turns a recoverable state inconsistency into a permanently unresolvable conflict.
3. **Make the orphan detectable.** If a lease record is missing while a `lease_accept` referencing it remains on-chain, the provider's chain should be flagged/quarantined rather than silently accepted.
4. **Fix the error classification.** `core.IsRetryableError` matching the bare substring `"not found"` makes deterministic "lease not found" failures look transient; that is what prevents `core/quorum.go:328` from quarantining the impossible promotion and substituting a different candidate.
5. **Derive reputation accept events from the chain, not only from lease records**, so the live and rebuilt views agree (or make the rebuild reproduce the live events exactly).

## Artifacts

- Harness: `cmd/pocdiff` (master \+ PR #147 diff), scenarios `S1`–`S8` and `T1`–`T10`; `cmd/pocdiff/lease_unwind.go` holds the lease-descendant scenarios.
- Run log: `pocdiff_pr147_output.txt` (T5 error string, T9 classification, T1/T2 live-vs-rebuilt reputation dumps).
- PR diff used: `pr147.diff` (2 hunks: `core/ledger.go`, `core/rollback.go`).
- Base commit: `master` @ `02e9641`; PR head: `ba4a167`.

### Thread

**XE desk**team2026-11-14 22:52 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-0002, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-0583 and says what differs; it is read like any other.
