Repatriate residual stake and locks on lease termination#2709
Conversation
🛡️ AI Review — Skeptic (security review)VERDICT: VULNERABLE LOW scrutiny: l0r1s has repo write permission, a 2018 account, substantial contribution history, and no Gittensor allowlist match found; branch is fix-lease-handoff -> devnet-ready. No Findings
Prior-comment reconciliation
ConclusionThe PR still allows 📜 Previous run (superseded)
# 🔍 AI Review — Auditor (domain review) has not yet run on this PR. |
|
🔄 AI review updated — Skeptic: VULNERABLE |
|
|
||
| // Move any lease coldkey lock to the beneficiary-controlled hotkey without | ||
| // assigning ownership of the generated lease hotkey to the beneficiary. | ||
| Self::move_lease_lock_to_beneficiary_hotkey(&lease, &hotkey)?; |
There was a problem hiding this comment.
[MEDIUM] Lease termination can still commit a partial handoff on lock conflict
terminate_lease is not wrapped in #[transactional] or with_transaction, but this call mutates lock rows via do_move_lock before later fallible calls. In the conflict case covered by the new test, repatriate_lease_coldkey_alpha can still return LockHotkeyMismatch after this mutation and after owner/aggregate updates, leaving the lease in storage while the subnet owner and lock state have already changed. Make the whole termination path storage-transactional, or preflight every fallible lock/proxy/currency operation before the first mutation.
|
🔄 AI review updated — Skeptic: VULNERABLE |
| Self::move_lease_lock_to_beneficiary_hotkey(&lease, &hotkey)?; | ||
|
|
||
| // Transfer ownership to the beneficiary | ||
| SubnetOwner::<T>::insert(lease.netuid, lease.beneficiary.clone()); |
There was a problem hiding this comment.
Should we also re-point Owner[lease.hotkey] to the beneficiary? Otherwise, emissions land on a non-controllable account (lease.coldkey). Or maybe we need to de-register it at all.
Repatriate residual stake and locks on lease termination
Closes #2663.
Problem
do_terminate_leasehanded subnet ownership to the beneficiary but left theaccumulated owner-cut alpha and lock state on the lease's derived coldkey
(
blake2_256("leasing/coldkey", lease_id)). That coldkey has no private key andthe beneficiary proxy can't extract stake, so every fixed-end lease termination
permanently stranded the owner emissions accrued during the lease.
Change
Before tearing down the lease coldkey, termination now:
conviction earned during the lease (
do_move_lock(..., preserve_conviction));(
reassign_subnet_owner_lock_aggregates, extracted so it's shared with theexisting owner-change path);
transfer_full_lock_to_coldkey);SubnetUidToLeaseId;dec_providers, then sweeps theunreserved proxy deposit to the beneficiary, so the keyless coldkey is reaped
cleanly with no dangling account, refcount, or stranded funds.
Post-condition: no alpha, lock, or ownership rows remain under the lease coldkey.