3

My understanding is that the Transaction-Payment Pallet prioritizes transactions based on tip, weight and length of the transaction. ChargeTransactionPayment::get_priority uses this data to give priority to a transaction.

Question:

If I want to change the priority of certain transactions.

  1. Do I need to make the modification in the Transaction-Payment-Pallet?
  2. Create another SignedExtension?

If I can create another Signed Extension, does it matter what order inside SignedExtra is in? For example, do I need to place this SignedExtension after Transaction-Payment-Pallet SignedExtension to prevent an overwrite from Transaction-Payment-Pallet?

1 Answer 1

2

The default Substrate transaction queue uses the TaggedTransactionQueue Runtime API to query the runtime about the validity and priority of queued transactions.

Under the hood, this is usually implemented in the runtime as

    impl tx_pool_api::runtime_api::TaggedTransactionQueue<Block> for Runtime {
        fn validate_transaction(
            source: TransactionSource,
            tx: <Block as BlockT>::Extrinsic,
            block_hash: <Block as BlockT>::Hash,
        ) -> TransactionValidity {
            Executive::validate_transaction(source, tx, block_hash)
        }
    }

The TransactionValidity is a Result<ValidTransaction, _>, where a ValidTransaction` has a field

priority: TransactionPriority // = u64

Under the hood, Executive::validate_transaction uses the CheckedExtrinsic::validate function, which in turn invokes the SignedExtension::validate function.

In order to plug into this part of Substrate, you should create an alternative SignedExtension with a custom validate function that returns a suitable TransactionValidity.

5
  • Thanks for this insight! I am kinda surprised that an alternative UncheckedExtrinsic is preferred over implementing a SignedExtension. Do you know why we would avoid using a SignedExtension?
    – Yatusabes
    Sep 11, 2022 at 4:33
  • 1
    Actually, SignedExtension is possibly better. It uses the same mechanism but looks easier to plug in.
    – rob
    Sep 12, 2022 at 17:04
  • 1
    @Yatusabes the answer is correct. If you want to modify the priority, create a new SignedExtension. Order matters
    – NachoPal
    Sep 19, 2022 at 13:30
  • So all reprioritization should be done after the transaction payment pallet? What is the impact on performance when adding a signed extension after the transaction payment pallet vs. modifying the Transaction-Payment-Pallet?
    – Yatusabes
    Sep 27, 2022 at 19:05
  • 1
    I am afraid the only way to answer you question is benchmarking: substrate.stackexchange.com/a/2950/527 To be honest, I think the difference if any is going to be minimal since you'll be applying the same logic in both places. It would be more about what is the overhead of adding a new SignedExtension. My recommendation is not to touch transaction-payment as it will be easier for your code maintenance when upgrading Substrate versions.
    – NachoPal
    Sep 28, 2022 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.