2

I want to access a specific pallet's storage item (for example: a StorageMap or StorageValue) in the function <Runtime as TaggedTransactionQueue<Block>::validate_transaction() (note: this function is found in runtime/src/lib.rs FYI).

Therefore, I am wondering, is it possible to access the value of a pallet's storage item outside of the pallet and in runtime/src/lib.rs (specifically in <Runtime as TaggedTransactionQueue<Block>::validate_transaction()) itself? Thanks

@shawn-tabrizi :)

1 Answer 1

1

Yes that is possible. validate_transaction will be called in the context of some block and in this context you can read the pallet storage items.

While you can read storage items, you also need to ensure that you are staying in certain limits. For example you should not do any kind of storage iteration. The problem with all this is that every node will call validate_transaction before adding a transaction to the tx-pool and also when the transaction is in the pool to check if it is still valid. All these operations are "free" and make it possible to dos your node. So, ensure that you are not doing too many storage reads or doing too many calculations.

8
  • Thank you for your answer. Btw do you know what the function is for reading a specific pallet storage item from the block_hash parameter?
    – aang114
    Dec 3, 2022 at 14:54
  • I don't get your question, sorry. What you mean by "storage item from the block_hash parameter"?
    – bkchr
    Dec 3, 2022 at 20:37
  • Let's say palletX has the storage item: let DummyStorageNumber = StorageValue<_, u64, ValueQuery>. How do I access the value of DummyStorageNumber in <Runtime as TaggedTransactionQueue<Block>>::validate_transaction(source, tx, block_hash)? Thanks
    – aang114
    Dec 4, 2022 at 11:29
  • palletx::DummyStorageNumber::get()
    – bkchr
    Dec 4, 2022 at 19:16
  • I see. Thanks, it works :). Btw could I ask when it is appropriate to use <Runtime as TaggedTransactionQueue<Block>::validate_transaction() and when it is appropriate to use frame_system::Config::BaseCallFilter to filter/validate transactions? Thanks again!
    – aang114
    Dec 6, 2022 at 18:26

Your Answer

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

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