Questions tagged [storage]

Questions about storing and accessing stored data on a Substrate blockchain.

Filter by
Sorted by
Tagged with
0 votes
1 answer
21 views

Get value *AND KEY* from iter_prefix_values

I have a StorageNMap #[pallet::storage] #[pallet::getter(fn resources)] /// Stores resource info pub type Resources<T: Config> = StorageNMap< _, ( ...
user avatar
1 vote
1 answer
18 views

When querying storage at a particular block, are the values returned those before or after the execution of the extrinsics in that block?

For example: We have a storage item: Counter that is set to 0. An extrinsic increment in block 11 adds 1 to Counter. If we query for the value of Counter at block 11, do we get 0 or 1?
user avatar
  • 113
1 vote
3 answers
22 views

Inserting into a map of vectors

If I have a storage item defined as: pub Foo get(fn foo): map hasher(twox_64_concat) u32 => Vec<T::AccountId>; Do I always need to check if Foo contains the key before deciding to insert or ...
user avatar
  • 217
2 votes
1 answer
28 views

Scale codec: Is there a way to extract an enum's arm's codec index value?

Using scale, an enum can be written like this: #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] pub enum Block { #[codec(index = 101)] V1(BlockV1), } The #[codec(index = 101)], the 101 ...
user avatar
3 votes
2 answers
124 views

How key-values database and Merkle Tree works together on Substrate

I have been looking deep dive into Substrate and trying to understand things behind the hood, especially storage API. I am really keen to explore more in the Merkle abstraction between Storage API and ...
user avatar
0 votes
1 answer
19 views

After genesis has occurred how do I configure new pallet with pre-filled storage?

This question is somewhat similar to this question about configuring for testing but it is for an already live chain. In this scenario a new pallet will be added to an existing chain's runtime. The ...
user avatar
  • 220
0 votes
1 answer
20 views

How to selectively populate state from a snapshot of one chain onto another?

Goal To use a full snapshot at some block height of one chain and selectively pull in select parts of this state. Use cases Migrating state from another chain. Example: A snapshot of only assets ...
user avatar
  • 1,232
1 vote
1 answer
21 views

How can we use struct instead of tuple in pallet storage?

I am working on a pallet in which there is storage in which I am using a tuple. Can we use a struct instead of a tuple in the storage of pallet? if yes is there any reference to how we can use it?
user avatar
2 votes
0 answers
69 views

Accessing On-Chain Data In an Off-Chain Worker

I am looking to aggregate On-Chain data in an Off-Chain Worker, e.g. summing transaction fees included in blocks from the last 24 hrs. This is listed as one of the main use cases for Off-Chain Workers....
user avatar
  • 21
0 votes
1 answer
14 views

getReadProof for specific event

I want to generate a StorageProof for a specific event that is stored in storage. I have found System_Events but this returns me all events of a block, instead of a specific one. I stumbled on ...
user avatar
2 votes
1 answer
30 views

How does `#[codec(mel_bound())]` work?

When declaring types, with generic parameters, to be stored in runtime storage, it’s common to see this pattern #[derive(Encode, Decode, MaxEncodedLen, TypeInfo)] pub struct MyItem<TypeA, TypeB> ...
user avatar
  • 411
2 votes
1 answer
26 views

Get all runtime storage `Orders` values from the client

1 the runtime storage order type as follow: // Order storage #[pallet::storage] #[pallet::getter(fn order)] pub type Orders<T: Config<I>, I: 'static = ()> = StorageMap< ...
user avatar
1 vote
1 answer
30 views

Verify storage entry with getReadProof

I'm currently trying to prove a storage entry by verifying the output of getReadProof but am not really sure how to do this. For some context: I want to query a parachains header from the relay chains ...
user avatar
2 votes
0 answers
29 views

upgrade runtime, the stored data has changed

No custom data migration logic for this pallet. but the data retrieved by the chain state has changed. here is code logic. #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, ...
user avatar
2 votes
1 answer
37 views

Do repeated reads of the same storage value add to the total weight?

I have an extrinsic with multiple calls to other pallet functions. As it calls other internal functions, more than one of them access the same storage value (either an actual StorageValue or the same ...
user avatar
  • 411
3 votes
1 answer
38 views

How to create an iterator for a child storage trie?

I have a Storage Map which I am using to to store structs and a Storage Value to use for indexing this: #[pallet::storage] #[pallet::getter(fn consequences)] /// Storage map holding basic Consequence ...
user avatar
2 votes
1 answer
42 views

How to test a local keystore?

I'm trying to add a test case for my function which is extracting key from the local Keystore. This is how I'm creating an instance of a local Keystore and setting a key inside it in my test ...
user avatar
0 votes
1 answer
24 views

Runtime API to collect values in StorageMap

I'm trying to retrieve all values in my StorageMap defined as such in my pallet: #[pallet::storage] #[pallet::getter(fn submitted_tasks)] pub type SubmittedTasks<T: Config> = StorageMap<_,...
user avatar
3 votes
1 answer
42 views

Are there ways to suppress blockchain growth rate (in terms of storage)?

So during my testing I found out that with just 1 node running, on an npos consensus, my chain grew from 110 Mb to 990 Mb within two days. Is this expected? Are there strategies for controlling the ...
user avatar
2 votes
1 answer
37 views

How to use `IterableStorageMap`

So currently, I need to iterate over the StorageMap defined like this: pub(super) type Report<T: Config> = StorageMap<_, Blake2_128Concat, (T::AccountId, HealthRound), Reports<T::AccountId,...
user avatar
12 votes
1 answer
44 views

Multiple remove_all calls in same block

I stumbled upon an unexpected behavior when doing storage migration. Problem Description I want to clean-up a large DoubleStorageMap in multiple steps. And that works just fine, however I also want to ...
user avatar
  • 123
4 votes
1 answer
45 views

BTreeMap storage type

I would like to store a large amount of sorted integers, they should be traversable with efficient get and insert. If I can iterate over a storage map, could you let me know how? Or is there a ...
user avatar
3 votes
2 answers
104 views

Storage Migration Guide Using #[pallet::storage]

I am new to both substrate and rust so trying to educate myself. I've the read documentation for both and am now going through the various tutorials and guides. I'm currently on the Basic Storage ...
user avatar
0 votes
1 answer
44 views

Definition of storage map for stored items

In the tutorial of learning substrate, a storage map for stored items is defined as follows, in which the symbol => appears, but this specification is not in the standard syntax of rust. How to ...
user avatar
  • 3
2 votes
1 answer
32 views

Migrating to new code base

We have a prototype of substrate-based blockchain running with few nodes. After some time running and testing we came up with new version of code-base, which consists of the same runtime, pallets and ...
user avatar
3 votes
2 answers
49 views

When should I use #[pallet::generate_store(pub(super) trait Store)]

I'm fiddling with substrate's #[pallet::generate_store(pub(super) trait Store)] https://docs.substrate.io/v3/runtime/macros/#palletpallet Documentation says Generates the Store trait if the attribute ...
user avatar
  • 237
4 votes
1 answer
34 views

Issue with #[pallet::generate_storage_info]

I was digging into substrate's storage_info macro https://docs.substrate.io/v3/runtime/macros/#palletgenerate_storage_info. To get hands dirty checked code from https://github.com/yourarj/substrate-...
user avatar
  • 237
4 votes
1 answer
31 views

Complexity of StorageDoubleMap::remove_prefix

The official documentation of StorageMaps states An implementation of a map with a two keys. It provides an important ability to efficiently remove all entries that have a common first key. https://...
user avatar
3 votes
2 answers
48 views

How to build prefixed key for rocksdb

I would like to know how can the key for the state System Events storage can be built for a given block hash/height
user avatar
6 votes
2 answers
52 views

What's the overhead associated with the `#[transactional]` macro?

Substrate has a macro, #[transactional], to ensure that any modifications to storage are not persisted in case of an error during execution. I imagine there's some sort of caching done before ...
user avatar
  • 140
9 votes
1 answer
69 views

How to manually remove storage items using Sudo?

I'm trying to remove a storage item on the relay chain, specifically a futureCode entry for a parachain. I've seen that there's an extrinsic I can call system.killStorage(keys), however I have some ...
user avatar
2 votes
3 answers
44 views

Query node for full history of an account's extrinsic/transaction records

I'm trying to get transaction history (ie. transfers) using just the account id. From my understanding the only way this can be done is if you go through every single block and look up the transaction ...
user avatar
  • 21
5 votes
2 answers
65 views

How to check if StorageMap is empty

I have created a simple storage map as follows and I just want to check if it's empty or not. I am comparing it with rust HashMaps, it has the is_empty() method to check. I intend to use this in the ...
user avatar
  • 349
4 votes
1 answer
35 views

How i define a 1 to N relation in storage?

i'm trying to define a 1 to N storage relation in my pallet. I have a Resource (owned by an account ) which will be linked to N Use structs ( kind of a set ) - Account #1 --> Resource #A ...
user avatar
4 votes
3 answers
74 views

Smart contract to IPFS communication

Assuming I was a smart contract deployed in a Parachain EVM wanting to cross out to IPFS to save or read data, what is the best way of achieving this in a decentralised way. For example, doing this ...
user avatar
  • 123
8 votes
2 answers
67 views

How to use bounded vector for storage

I'm trying to use BoundedVec from frame_support for one of my storage items like this, pub(super) type Payloads<T: Config> = StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec<Payload>,...
user avatar
6 votes
1 answer
56 views

Generating a Storage Key when making an RPC request

I'm trying to make an RPC call to a Substrate node, but I can't generate a proper Storage Key. The Module and Method parts are fine, the problem is the Twox64Concat part. The sp_core::twox_64 of value ...
user avatar
7 votes
3 answers
60 views

How to limit the number of values by prefix in StorageDoubleMap?

Say I have a StorageDoubleMap that stores Data structs for each user and ContextId #[pallet::storage] pub type Info<T: Config> = StorageDoubleMap< _, Blake2_128Concat, ...
user avatar
  • 411
1 vote
1 answer
29 views

Should I do storage migration after remove fields from storage struct type?

I have a map storage, which stores structures. I've just removed a field from the structure, should I write storage migration codes for that? Could substrate work with existing values without a ...
user avatar
2 votes
1 answer
29 views

How to store a list of allowable assets for a pallet extrinsic?

I want to write a function which a user can call with an asset id and the amount of which it wants to deposit. I need to check if said asset id is within a list of allowable assets, which can change ...
user avatar
  • 411
2 votes
1 answer
31 views

Is it safe to delete elements when iterating through a storage map in Substrate?

In my pallet, I have a StorageDoubleMap called MyDoubleMap. I want to delete all the kv pairs under key1. So I may write the code like below: for (key2, _value) in MyDoubleMap::<T>::iter_prefix(...
user avatar
  • 464
6 votes
1 answer
77 views

How expensive is it to access storage items?

How expensive are storage reads and writes? Does the cost depend on the size of the item?
user avatar
1 vote
1 answer
42 views

Forked Parity pallet, didn't migrate storage, deployed to chain. How to clear original storage from the live chain?

We started a chain using pallet_collator_selection and later forked it. Both the original and the forked pallet use the LastAuthoredBlock StorageItem. We did not execute a storage migration from the ...
user avatar
1 vote
1 answer
29 views

Reclaim used space of a removed StorageItem on a live chain

I am changing the collator_selection pallet by removing the LastAuthoredBlock StorageItem and adding an unrelated one, so although the chain is live, no data migration is needed. What happens with the ...
user avatar
7 votes
1 answer
50 views

How can I check whether a specific storage item was already accessed in the current block?

Inside a FRAME runtime I want to check whether a specific storage item was already read in the current block. Reason is to determine the impact of storage accesses across the extrinsics of a block ...
user avatar
3 votes
1 answer
40 views

Storage definition syntax

#[pallet::storage] pub(super) type ProofMapping<T: Config> = StorageMap<_, Blake2_128Concat, Vec<u8>, (T::AccountId, T::BlockNumber), ValueQuery >; What does the syntax used to ...
user avatar
4 votes
1 answer
32 views

Where can I find the code that defines what StorageKind the Offchain Index uses by default?

I see the OffchainIndex interface defined here: pub trait OffchainIndex { /// Write a key value pair to the Offchain DB database in a buffered fashion. fn set(&mut self, key: &[u8], ...
user avatar
  • 2,870
1 vote
1 answer
21 views

How to merge incoming data with existing data?

Let's say I have a struct called MyStruct and it looks like this. pub struct MyStruct<> { pub name: Vec<u8>, pub email: Option<Vec<u8>>, pub username: Option<Vec&...
user avatar
  • 497
3 votes
2 answers
56 views

Can I return a custom value from an extrinsic call

Looking at the docs, it seems I can only return custom weights in dispatchables I want to be able to create data in storage then return the ID, because we will be calling the chain from a UI/Dapp I am ...
user avatar
4 votes
1 answer
27 views

Is the full Merkle Trie copied in every block along with updates?

In the example given here: Does each block save a copy of a Storage item? Is the Merkle Trie copied to every block or is it the "diff" of the Merkle Trie that is updated on the new block? ...
user avatar
  • 2,870