Skip to content

Update transaction priority#1955

Merged
sam0x17 merged 8 commits intodevnet-readyfrom
change-transaction-extension2
Aug 21, 2025
Merged

Update transaction priority#1955
sam0x17 merged 8 commits intodevnet-readyfrom
change-transaction-extension2

Conversation

@shamil-gadelshin
Copy link
Collaborator

@shamil-gadelshin shamil-gadelshin commented Aug 15, 2025

This PR changes Subtensor transaction priority algorithm. Here is the current algorithm description.

Transaction Priority

Overview

In Subtensor, transaction priority is determined by custom transaction extensions, which alter or override the default Substrate SDK behavior. Extensions affecting transaction priority are:

  • ChargeTransactionPaymentWrapper (wraps ChargeTransactionPayment)
  • SubtensorTransactionExtension

Substrate SDK combines priorities from all transaction extensions using addition.


1. ChargeTransactionPaymentWrapper

In the Substrate SDK, ChargeTransactionPayment normally calculates transaction priority based on:

  • Tip — an extra fee paid by the sender.
  • Weight — computational complexity of the transaction.
  • Dispatch class — category of the transaction (Normal, Operational, Mandatory).

However, in Subtensor, ChargeTransactionPaymentWrapper overrides this logic.
It replaces the dynamic calculation with a flat priority scale based only on the dispatch class.

Current priority values:

Dispatch Class Priority Value Notes
Normal 1 Standard transactions
Mandatory 1 Rarely used, same as Normal
Operational 10_000_000_000 Reserved for critical system extrinsics (e.g., sudo calls, drand pulses)

2. SubtensorTransactionExtension

This extension introduces special priority rules for certain extrinsics, such as:

  • commit_weights
  • reveal_weights
  • etc.

For these, priority is boosted using a time-sensitive factor:

  1. Retrieve the current block number.
  2. Retrieve the block number from the map LastUpdate.
  3. Calculate the difference between them.
  4. Add this difference to the transaction’s priority.

Additional changes

  • staking transactions have no additional priorities now
  • DRAND extrinsics will get DispatchClass::Operational
  • utility batching extrinsics will have DispatchClass::Normal even if they contain extrinsics with other dispatch classes
  • following extrinsics have their dispatch class changed from Operational to Normal:
    • pallet_registry::set_identity
    • pallet_commitments::set_commitment
    • pallet_subtensor::swap_hotkey
    • pallet_subtensor::register_network
    • pallet_subtensor::set_childen
    • pallet_subtensor::schedule_swap_coldkey
    • pallet_subtensor::schedule_dissove_network
    • pallet_subtensor::register_network_with_identity
    • pallet_subtensor::unstake_all
    • pallet_subtensor::unstake_all_alpha
    • pallet_subtensor::swap_stake
    • pallet_subtensor::swap_stake_limit
    • pallet_subtensor::move_stake
    • pallet_subtensor::transfer_stake
    • pallet_subtensor::try_associate_hotkey
    • pallet_subtensor::start_call
    • pallet_subtensor::associate_evm_key
    • pallet_subtensor::recycle_alpha
    • pallet_subtensor::burn_alpha

The absolute majority of the remaining extrinsics with DispatchClass::Operational have ensure_root or similar origin verification now.

@shamil-gadelshin shamil-gadelshin added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Aug 15, 2025
values_list,
salts_list,
version_keys,
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could possibly be two extensions with one checking for the coldkey swap to invalidate. The other one handles just this priority logic

Copy link
Collaborator

@ppolewicz ppolewicz Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shamil-gadelshin In fact, coldkey swap check should be done in validation, not in transaction extension (in a separate PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the second (priority) extension after the discussion with @ppolewicz

}
DispatchClass::Operational => {
// System calls
10_000_000_000u64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put drand below sudo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a special transaction extension for write_pulse priority. Other extrinsics from drand pallet have sudo origin check.

Copy link
Contributor

@camfairchild camfairchild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment

@ppolewicz
Copy link
Collaborator

Drand pulse submission has to have a check in validation (when inserting into mempool) to see if it's signed by the designated offline worker - if we don't do that then someone can spam these and flood out weight setting, staking, transfers etc

@ppolewicz
Copy link
Collaborator

ppolewicz commented Aug 15, 2025

After a discussion with Shamil, we found out that it should be made slightly simpler and the transaction priority for setting weights should be removed until further notice (due to newly found attack vectors)

EDIT: after an even longer discussion with Vune, it was agreed to remove the priority for setting weights

@shamil-gadelshin
Copy link
Collaborator Author

Last updates:

  • remove weights extrinsics periory
  • new extension for DRAND pulse priority

@camfairchild camfairchild self-requested a review August 21, 2025 16:05
@sam0x17 sam0x17 merged commit e5908ed into devnet-ready Aug 21, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants