Type Definition frame_system::pallet::StorageQueue
source · pub type StorageQueue<T: Config> = StorageValue<_GeneratedPrefixForStorageStorageQueue<T>, BoundedVec<(BlockNumberFor<T>, Option<u32>, Vec<(Option<T::AccountId>, EncodedTx)>), StorageQueueLimit>, ValueQuery>;
Expand description
Storage queue is used for storing transactions in blockchain itself.
Main reason for that storage entry is fact that upon VER block N
execution it is
required to fetch & executed transactions from previous block (N-1
) but due to origin
substrate design blocks & extrinsics are stored in rocksDB database that is not accessible
from runtime part of the node (see Substrate architecture) what makes it impossible to properly implement block
execution logic. As an solution blockchain runtime storage was selected as buffer for txs
waiting for execution. Main advantage of such approach is fact that storage state is public
so its impossible to manipulate data stored in there. Storage queue is implemented as double
buffered queue - to solve problem of rare occasions where due to different reasons some txs
that were included in block N
are not able to be executed in a following block N+1
(good
example is new session hook/event that by design consumes whole block capacity).
Overhead
Its worth to notice that storage queue adds only single storage write, as list of all txs is stored as single value (encoded list of txs) maped to single key (block number)
Storage Qeueue interaction
There are two ways to interact with storage queue:
- enqueuing new txs using
Pallet::enqueue_txs
inherent - poping txs from the queue using
Pallet::pop_txs
that is exposed throught RuntimeApi call
Storage type is StorageValue
with value type BoundedVec < (BlockNumberFor < T >, Option < u32 >, Vec < (Option < T :: AccountId >, EncodedTx) >), StorageQueueLimit, >
.