<!-- XE-13379 · Rolling back a lease_cancel that won over an accept restores the lease to `created`, losing the accept and renewal history · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13379>. The page is the record; this is the same page for reading.*

XE-13379 · Bounty

# Rolling back a lease\_cancel that won over an accept restores the lease to \`created\`, losing the accept and renewal history

Closed · duplicate
—claimed Minor
[xe#533](https://github.com/xeprotocol/xe/issues/533)
filed 2026-11-13 03:33 UTC
by AIRDROP TREASURESS

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   Leasing / ledger

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:51 UTC

Told
:   2026-11-20 00:50 UTC

### Patches

- [xe#535](https://github.com/xeprotocol/xe/pull/535) open by arturbarszcz78
  fix(core/rollback): preserve accept state and renewal history on lease\_cancel rollback (#533)

### History

- [559836](https://bounty.xe.network/log/559836) 2026-11-20 00:51 UTC github.state\_pushed
- [559765](https://bounty.xe.network/log/559765) 2026-11-20 00:51 UTC github.labels
- [559576](https://bounty.xe.network/log/559576) 2026-11-20 00:51 UTC reply.mirrored
- [559033](https://bounty.xe.network/log/559033) 2026-11-20 00:50 UTC proposal.adopted
- [559032](https://bounty.xe.network/log/559032) 2026-11-20 00:50 UTC reply.sent
- [559031](https://bounty.xe.network/log/559031) 2026-11-20 00:50 UTC ticket.status new → closed
- [558105](https://bounty.xe.network/log/558105) 2026-11-20 00:49 UTC proposal.adopted
- [558104](https://bounty.xe.network/log/558104) 2026-11-20 00:49 UTC ticket.facts area
- [558103](https://bounty.xe.network/log/558103) 2026-11-20 00:49 UTC proposal.adopted
- [558102](https://bounty.xe.network/log/558102) 2026-11-20 00:49 UTC ticket.facts
- [558101](https://bounty.xe.network/log/558101) 2026-11-20 00:49 UTC proposal.adopted
- [558100](https://bounty.xe.network/log/558100) 2026-11-20 00:49 UTC ticket.facts

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

### Report

**Suggested tier:** Low

**XE address (reward destination):** 9b663fdac108be34a3b715ef78a9f9bd878af6ef8142f388c6514918e6852dd7

## Summary

`core/rollback.go`, `buildBlockUndo` for `BlockLeaseCancel` always restores the lease to `LeaseCreated` (`priorLease(b.Source, LeaseCreated)`), regardless of the lease's pre-cancel state. But cancel has two possible pre-states: `created`, or `accepted` (cancel wins over a racing accept via `resolveCancelWinsOverAccept`). Undoing a cancel that won over an accept therefore zeroes `StartTime` / `LockedR` / `LockedPayoutCap` / `LockedTWAP` / `Stake`, while keeping `Renewals` and restoring the full escrow.

If the provider then re-accepts, the fresh `PutLease` carries no renewals, so a later settle pays only the base emission and deletes the whole pending escrow. The renewal escrow is destroyed with no corresponding emission.

Related to #391 (same symptom family — renewal escrow destroyed) but a different root cause (`rollback.go` undo-restore, not the cancel refund in `ledger.go`) and a different trigger (fork rollback via quorum conflict resolution, not the pre-finality race). #391's fix (refund `pending.Amount` on cancel) does NOT fix this path.

## Impact

Bounded fund destruction, same order as #391: 517 micro-XUSD (\~$0.0005) per renewal. No theft, no inflation. Requires: fork wins a quorum vote → cancel rolled back → provider re-accepts → provider settles. Reachable in production: `core/quorum.go:321` `confirmConflict` → `swapBlockLocked` (`Ledger.SwapBlock`) undoes the loser block through exactly this `buildBlockUndo` path.

## Steps to reproduce

Unit test against the real ledger code (`github.com/xeprotocol/xe`, testnet-0005):

```
git clone https://github.com/xeprotocol/xe
cd xe
cp round2_ledger_test.go core/
go test ./core -run TestRound2_UndoCancelLosesAcceptedState -v -count=1
```

Note: `round2_ledger_test.go` is NOT in the public repository — the PoC test file is attached to this issue; without it, the XE team cannot run this reproduction.

The test funds consumer \+ provider with 1,000,000 micro-XUSD each, creates a 60 s lease (cost 517 micro-XUSD), provider accepts, consumer renews for another 60 s (escrow 1034), consumer cancels, then `SwapBlock` replaces the cancel with a plain send (fork wins), provider re-accepts, provider settles.

**Expected:** after rollback the lease returns to `accepted` with accept metadata intact; after re-accept renewals \= 1; after settle provider XE emission \= 1034\.
**Actual (reproduced 2026-11-13, verified independently by re-running the PoC):**

```
after cancel: consumer XUSD=999483 (F1: renewal 517 destroyed)
after undo-cancel: state=created settled=false start=0 lockedR=0 renewals=1
after undo-cancel: escrow restored=1034 (base+renewal=1034), total XUSD in system=2000000
after re-accept: state=accepted renewals=0 (was 1 before the rollback)
after settle: provider XE emission=517 (full base+renewal emission would be 1034); total XUSD in system=1998966
--- FAIL: TestRound2_UndoCancelLosesAcceptedState
```

## Root cause

`core/rollback.go`, `buildBlockUndo`, `BlockLeaseCancel` case: `restoreLease = l.priorLease(b.Source, LeaseCreated)` — fixed target state. `priorLease` with target `LeaseCreated` additionally zeroes `Stake`, `StartTime`, `LockedR`, `LockedPayoutCap`, `LockedTWAP`. By contrast, undo of settle/force-settle always restores `accepted` (correct — those only run from `accepted`), undo of accept restores `created` (correct), and undo of renew pops exactly one renewal (correct, verified by control test).

## Suggested fix

Restore the lease to its actual pre-cancel state instead of synthesising one from a fixed target: record the pre-cancel lease snapshot at cancel time (or in the `BlockUndo`, e.g. a `RestoreLease` built from the lease as it stood before the cancel, including `State`, `StartTime`, `Locked*`, `Stake`, `Renewals`). Defense-in-depth: make `validateAndAddLeaseAccept` preserve any existing `Renewals` on re-accept, and/or make `validateAndAddLeaseSettle` reject when `escrow.Amount != lease.Cost + sum(renewal costs)`.

## Controls verified (same PoC file, all PASS)

- Undo of `lease_renew`: escrow back to exactly 517, settle pays base only.
- Undo of `lease_settle`: lease back to `accepted` \+ renewals, escrow 1034, re-settle pays full 1034 XE.
- Force-settle after renew refunds the full pending escrow (consumer 998,966 → 1,000,000).
- Terminal-state guards: renew/cancel/second settle/force-settle after settle, and renew after cancel, all rejected.

[round2\_ledger.txt](https://github.com/user-attachments/files/34781944/round2_ledger.txt)

### Thread

**Joseph Denne**team2026-11-20 00:50 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, 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-13379 and says what differs; it is read like any other.
