Recycle fees via chain ext with immutable custodial fallback#48
Merged
Conversation
6bb73d5 to
e05a67c
Compare
Wires the AddStakeRecycleV1 chain extension (subtensor PR #2560, function_id=18) into recycle_fees behind an owner-flipped one-way latch. Pre-latch: fees go to an immutable custodial fallback (constructor-only, no setter). Post-latch: fees stake-and-recycle through the chain extension at (staking_hotkey, netuid). Owner flips the latch once subtensor PR #2560 is confirmed live on the deploy network. Auto-probe-on-first-success was rejected: pallet-contracts traps the entire call when a chain extension returns Err(DispatchError) (e.g., unknown function_id pre-#2560 mainnet), so the fallback branch would be unreachable and fees would pile up until the chain extension landed. Owner-flip sidesteps that. Contract: - New storage: staking_hotkey, netuid, chain_ext_enabled (set in constructor; only chain_ext_enabled mutates, via enable_chain_ext). - recycle_fees stays permissionless; branch on chain_ext_enabled — chain ext only or env.transfer to recycle_address. - New enable_chain_ext (owner-only, one-way; reverts if already set). - set_recycle_address removed. - New getters: get_staking_hotkey, get_netuid, get_chain_ext_enabled. - FeesRecycled gains via_chain_ext: bool. - New ChainExtensionLatched event with at_block. Python: - contract_client.py: drop set_recycle_address; add the three getters, enable_chain_ext writer, and a u16 read primitive. - admin.py: drop set-recycle-address; add enable-chain-ext (owner-only, one-way confirm); recycle-fees UX shows pre/post-latch destination. - Metadata regenerated; SubtensorExtension (id=0x1000) wired in env.
d346d26 to
513b26c
Compare
entrius
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires the AddStakeRecycleV1 chain extension (subtensor PR #2560, function_id=18) into
recycle_feesbehind an owner-flipped one-way latch.recycle_address, set once in the constructor — no setter). The off-chain fee-recycler service in alw-utils picks them up and stakes them back to the subnet.(staking_hotkey, netuid). Subtensor stakes-and-burns directly from the contract viaadd_stake_recycle.enable_chain_ext(), exposed asalw admin enable-chain-ext. Reverts if already set; emitsChainExtensionLatched { at_block }once.Why owner-flip and not auto-probe-on-first-success
pallet-contracts traps the entire contract call when a chain extension returns
Err(DispatchError)— which is exactly what subtensor returns for unknown function_ids on networks where PR #2560 hasn't landed yet (mainnet today). An auto-probingrecycle_feeswould revert before reaching its fallback branch, so fees would pile up inaccumulated_feesuntil #2560 lands. Owner-flip sidesteps that entirely.Verified mappings against subtensor PR #2560
0x1000matches subtensor-proxy registration18matchesFunctionId::AddStakeRecycleV1(AccountId, u16, u64)matches(AccountId, NetUid, TaoBalance)— both balance/netuid types arerepr(transparent)newtypes with SCALE-equivalent encodingu64matches encoded alpha amount0= Success matchesOutput::SuccessContract
staking_hotkey,netuid,chain_ext_enabled(constructor-set; onlychain_ext_enabledmutates, viaenable_chain_ext).recycle_feesstays permissionless; branches onchain_ext_enabled— chain ext only orenv.transfertorecycle_address.enable_chain_ext(owner-only, one-way).set_recycle_addressremoved.get_staking_hotkey,get_netuid,get_chain_ext_enabled.FeesRecycledgainsvia_chain_ext: bool; newChainExtensionLatched { at_block }event.Python / CLI
contract_client.py: dropset_recycle_address; add the new getters,enable_chain_extwriter, u16 read primitive.admin.py: dropset-recycle-address; addenable-chain-ext(one-way confirm);recycle-feesUX shows pre/post-latch destination.view.py:alw view contractshows the recycle path (custodial vs chain ext) and the latch target.Companion PR
alw-utils#45 wires
staking_hotkey+netuidinto the contract deployer, restores the off-chain fee-recycler for the pre-latch path, and renames--wallet-name→--owner-hotkey. Hard-blocked on this one.Test plan
cargo contract build --releasecleanpytest tests/passes (387 cases)cd alw-utils/dev-environment && ./down.sh --force && ./up.sh --chains btcbrings up the stack against the rebased deployer./tests/run.sh --chains btc --suite 02passesalw view contractshows pre-latch path with custodial address + latch target rowalw admin recycle-fees(pre-latch) transfers to recycler wallet; recycler service stakes backalw admin enable-chain-extflips latch; second call errors outalw admin recycle-fees(post-latch) routes through chain extension;via_chain_ext = truein event