Skip to content

feat: add per-account flags to block receiving TAO, Alpha, and locked Alpha#2746

Open
ppolewicz wants to merge 488 commits into
mainfrom
feat/block_receiving_transfers
Open

feat: add per-account flags to block receiving TAO, Alpha, and locked Alpha#2746
ppolewicz wants to merge 488 commits into
mainfrom
feat/block_receiving_transfers

Conversation

@ppolewicz

@ppolewicz ppolewicz commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements issue #2730: adds the ability for a destination address to block incoming transfers of TAO, staked Alpha, and locked Alpha.

What was added

  • 3 new storage maps in pallet-subtensor:

    • BlockReceivingTao<T> — per-account flag to block incoming TAO transfers (only cross-coldkey paths)
    • BlockReceivingAlpha<T> — per-account flag to block incoming staked-Alpha transfers (user-facing entry points only; internal system re-staking is unaffected)
    • BlockReceivingLockedAlpha<T> — per-account flag to block incoming locked-Alpha transfers
  • 3 new extrinsics (call indices 139 / 140 / 141):

    • set_block_receiving_tao(enabled: bool)
    • set_block_receiving_alpha(enabled: bool)
    • set_block_receiving_locked_alpha(enabled: bool)

    Each extrinsic uses insert when enabling (saves storage only when true) and remove when disabling (frees storage), which avoids keeping default-false entries in state.

  • 3 new error variants:

    • ReceivingTaoBlocked
    • ReceivingAlphaBlocked
    • ReceivingLockedAlphaBlocked
  • 3 new events:

    • BlockReceivingTaoSet { account, enabled }
    • BlockReceivingAlphaSet { account, enabled }
    • BlockReceivingLockedAlphaSet { account, enabled }
  • Enforcement in existing transfer paths:

    • transition_stake_internal (cross-coldkey TAO transfer) checks BlockReceivingTao — hoisted before any mutations (guard-first pattern)
    • transition_stake_internal (cross-coldkey Alpha re-stake) checks BlockReceivingAlpha — hoisted before any mutations
    • transition_stake_internal same-subnet branch checks BlockReceivingAlpha for cross-coldkey transfers
    • do_add_stake (user-facing stake entry point) checks BlockReceivingAlpha
    • transfer_lock checks BlockReceivingLockedAlpha
  • Weight benchmarks added for all three new extrinsics (set_block_receiving_tao, set_block_receiving_alpha, set_block_receiving_locked_alpha).

  • 10 unit tests in pallets/subtensor/src/tests/block_receiving.rs covering set/clear, blocking, and allow-after-clear for each flag, plus a new test covering the same-subnet cross-coldkey Alpha block path.

Fixes applied (code review)

  • R-1: Hoisted TAO and Alpha block checks before unstake_from_subnet mutation in transition_stake_internal so all guards fire pre-mutation.
  • R-2: Added BlockReceivingAlpha check in the same-subnet branch of transition_stake_internal so same-subnet cross-coldkey transfers are also blocked.
  • R-4: Added #[benchmark] entries for the three new extrinsics so CI can generate accurate weights.
  • R-5: Corrected set_block_receiving_tao docstring to reflect the narrowed check scope (cross-coldkey TAO transfer only).
  • R-6: Added test_block_receiving_alpha_prevents_same_subnet_transfer to cover the R-2 fix.

Test plan

  • cargo fmt -p pallet-subtensor — no formatting issues
  • cargo clippy -p pallet-subtensor --tests — no errors
  • cargo test -p pallet-subtensor block_receiving — 10/10 tests pass

l0r1s and others added 30 commits May 9, 2026 19:30
@camfairchild

Copy link
Copy Markdown
Contributor

cACK

… Alpha

Implements issue #2730. Adds three new storage maps (BlockReceivingTao,
BlockReceivingAlpha, BlockReceivingLockedAlpha), three new extrinsics
(call_index 139/140/141), and enforces the flags in transfer_tao,
stake_into_subnet, and transfer_lock. Includes 9 unit tests.
… path, add benchmarks

- R-1: Move TAO and Alpha block checks before unstake_from_subnet mutation in
  transition_stake_internal so all guards fire pre-mutation (guard-first pattern).
- R-2: Add BlockReceivingAlpha check in the same-subnet branch of
  transition_stake_internal so same-subnet cross-coldkey transfers are also blocked.
- R-5: Correct set_block_receiving_tao docstring to reflect the narrowed check scope.
- R-4: Add guesstimated #[benchmark] entries for the three new extrinsics so CD can
  generate accurate weights later.
- R-6: Add test_block_receiving_alpha_prevents_same_subnet_transfer to cover R-2.
…x coldkey swap migration

- Rename BlockReceivingAlpha → ReceivingAlphaEnabled with inverted (opt-in) semantics:
  cross-coldkey Alpha transfers are blocked by default; coldkeys must call
  set_receiving_alpha_enabled(true) to receive Alpha from other coldkeys.
- Remove BlockReceivingAlpha check from validate_add_stake so self-staking always works.
- Add pallet getter functions: get_receiving_alpha_enabled, get_block_receiving_tao,
  get_block_receiving_locked_alpha.
- Add three precompile view functions to StakingPrecompileV2:
  isReceivingTaoBlocked, isReceivingAlphaEnabled, isReceivingLockedAlphaBlocked.
- R-1: Migrate all three BlockReceiving flags during coldkey swap (take+insert pattern).
- R-5: Document intentional bypass of ReceivingAlphaEnabled in buy_alpha order path.
- R-6: Add tests covering cross-subnet and same-subnet alpha-blocked-by-default paths.
@ppolewicz ppolewicz force-pushed the feat/block_receiving_transfers branch from 8b4f7ca to ed882df Compare June 17, 2026 15:40
@github-actions

Copy link
Copy Markdown
Contributor

eco-tests changed — indexer review required

This PR modifies files under eco-tests/. and may affect downstream indexing.
cc @evgeny-s — please review manually

Changed files
  • eco-tests/Cargo.toml
  • eco-tests/src/helpers.rs
  • eco-tests/src/lib.rs
  • eco-tests/src/mock.rs
  • eco-tests/src/tests_taocom_indexer.rs

@github-actions github-actions Bot requested a review from evgeny-s June 17, 2026 15:40
…in tests

The two cross-coldkey transfer tests in chain-extensions now require
ReceivingAlphaEnabled=true for the destination coldkey to succeed, matching
the new opt-in semantics of the alpha-transfer flag.
…rStakeFrom test

The staking_precompile_v2_transfer_stake_from_consumes_allowance_and_moves_stake
test performs a cross-coldkey stake transfer to the spender account, which now
requires ReceivingAlphaEnabled=true under the new opt-in alpha-transfer semantics.
…er_stake test

The test_transfer_stake_fees_alpha test performs a cross-coldkey stake transfer,
which now requires ReceivingAlphaEnabled=true for the destination coldkey under
the new opt-in alpha-transfer semantics.
…sferStake

Cross-coldkey stake transfers now require the destination coldkey to have
ReceivingAlphaEnabled=true. Add setReceivingAlphaEnabled utility and call it
in the TypeScript E2E tests before each cross-coldkey transferStake call.
Biome requires the chained method calls on a single line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.