Questions tagged [frame]
Questions about Substrate's framework for developing custom runtime logic.
52
questions
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 ...
5
votes
0
answers
31
views
Are Offences ever pruned?
In our runtime we have a custom implementation of offence reporting. I want to write an adapter for grandpa equivocation offences (implementing the ReportOffence trait), and have been using the ...
1
vote
2
answers
66
views
How we can implement Governance in a chain?
I need to implement governance on my chain.
Do we have any references which guide me in development?
1
vote
1
answer
45
views
Pallet Fails to Build Because of `std` Macros
I am currently facing this Error:
Using rustc version: rustc 1.62.0-nightly (e85edd9a8 2022-04-28)
Compiling frame-support v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=...
0
votes
2
answers
51
views
How to execute an ELF binary after a successful transaction
I am working on figuring out an efficient way to run an ELF binary after successful transaction. I also want to pass arguments along the execution.
Example: /bin/ping 1.1.1.1
OCW might be a solution, ...
1
vote
1
answer
16
views
How to Implement sp_core:Encode?
I've copied Kulupu's difficulty pallet and tried to build my node after connecting the pallet. The decl_storage! macro in that pallet looks like this:
decl_storage! {
trait Store for Module<T: ...
4
votes
2
answers
46
views
How to change the number of heap pages
We are running into an allocator memory error where the number of heap pages appears to be insufficient to run a transaction on our validator (substrate-node).
This is the error in question:
2022-04-...
0
votes
1
answer
27
views
Question about Raw Origin in Frame System Pallet
Inside mod pallet {}, there is code for RawOrigin, which is
pub enum RawOrigin<AccountId> {
Root,
Signed(AccountId),
None,
}
I don't know how we can use this AccountId type ...
6
votes
2
answers
159
views
Scalability beyond Asynchronous Backing
With the release of Asynchronous Backing, a good performance increase is expected (lower block time, increased block weight).
Which further efforts are being undertaken with regards to Polkadot ...
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> ...
0
votes
2
answers
48
views
Manually implement `Default` for `AccountId`
I am creating a parachain with a custom pallet, where i have this set up in storage:
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type NeuronMetadataOf<...
5
votes
1
answer
63
views
Why is there no `Default` implementation for `T::AccountId`?
Starting with version 9.17 and greater I started getting these errors for the custom pallets I've made. Could I please get a pointer in resolving this issue? Example output from compiler:
#[derive(...
1
vote
1
answer
23
views
Transaction fails with account from an extension but OK with local account
I'm trying to figure out why my pallet UI produces wrong signatures when using Polkadot.js extension.
UI is similar to https://polkadot.js.org/apps/#/signing: it calculates the signature over data ...
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 ...
2
votes
1
answer
34
views
Why do frame calls take a `Vec` parameter instead of `BoundedVec`?
I saw that some of the calls in frame take Vec as a parameter. I haven't found a call that takes BoundedVec, but my impression was that I should basically always use BoundedVec over Vec?
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<_,...
0
votes
1
answer
24
views
Storing BTreeMap and Vec gives error
New substrate version requires derive MaxEncodedLen
I have a following storage:
#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = &...
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,...
12
votes
2
answers
61
views
What are some good use cases for anonymous proxies?
There are some good conceptual explainers on what anonymous proxies are, yet it's not clear to me which use cases they serve best.
What are some problems that using anonymous proxies would solve? What ...
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 ...
2
votes
1
answer
31
views
How to create an escrow account without runtime upgrade
I'd like to create an account that is only usable through the root origin like the treasury account. It should be possible to transfer funds to it, but sending from it should only be possible through ...
7
votes
2
answers
64
views
What are the differences between using declarative and attribute macros in FRAME?
What's the main difference (besides the code) between using the decl_storage! macro rule and using the [pallet::storage] macro?
I've seen pretty much everyone using macro rules, but on the latest ...
3
votes
1
answer
16
views
Why does pallet-election-phragmen have a Balance field in it's Genesis Config?
Why does pallet-election-phragmen have a Balance field here?
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub members: Vec<(T::AccountId, BalanceOf<T>)&...
1
vote
1
answer
28
views
Query on polkadot-apps chain-state cuts of string. Text-overflow?
Im trying to store a public key in a StorageValue, but when i try to consult it on polkadot-js chain-state, the string gets cut off in the following manner:
KeyStart...KeyEnd
The value being put in ...
2
votes
1
answer
32
views
How can I configure genesis state for my pallet's tests without hardcoding it?
I've been writing tests for pallet-kitties and have configured the genesis state inside my mock runtime by setting the storage items for two kitties (one Male and one Female) and their owners (with ...
10
votes
1
answer
59
views
When to use `BoundedVec` vs. `WeakBoundedVec` vs. `Vec`?
Are there any guiding principles that can be applied to decide whether to use Substrate's BoundedVec, WeakBoundedVec, or Vec in a runtime?
Is it a general rule of thumb to use the bounded variant ...
1
vote
1
answer
23
views
Problem running assert_last_event in tests.rs
As the title suggests, I've been trying to call assert_last_event on the tests.rs class without success. The problem first happened when developing the kitties tutorial and after several toolchain ...
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
...
3
votes
1
answer
37
views
Why is `DispatchResultWithPostInfo` expected?
The compiler: expected DispatchResultWithPostInfo
It found: ) -> DispatchResult {
I want to use DispatchResult and do not understand what the problem is.
Additional context:
#[frame_support::...
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,
...
1
vote
1
answer
36
views
Slashing and rewarding funds
I am trying to understand slashing and rewarding funds from the recipe example.
https://substrate.recipes/currency-imbalances.html
For slashing funds it doesn't require initialization with <...
1
vote
3
answers
57
views
Substrate compatible crate for handling RSA encryption
Im working on a project where i want to store encrypted data on-chain and later reveal that data. For this process im thinking of using a trusted off-chain worker to act as a "key-manager". ...
1
vote
1
answer
31
views
Basics > Runtime > FRAME > Substrate FRAME Pallets
as a learner and beginner, I have 2 questions about the FRAME Pallets and especially to that overview:
https://docs.substrate.io/v3/runtime/frame/--> Substrate FRAME PALLETS:
The highlighted ...
4
votes
3
answers
56
views
Basics > Runtime > FRAME > Modules (Runtime, System) / Difference?
I am a curious learner and on my way of understanding the core principles of the Substrate universe + going through the tutorials on substrate.io.
As far as I understood is: there exists a Core ...
2
votes
1
answer
38
views
When to use `compact` on extrinsic arguments?
I keep seeing #[pallet::compact] on some extrinsic arguments like here on the pallet-assets/mint definition:
pub fn mint(
origin: OriginFor<T>,
#[pallet::compact] id: T::...
2
votes
1
answer
22
views
testing pallet with ensure_root
I have written tests.rs and mock.rs
everything is working except a function which has checks for root
pub fn create_something(
origin: OriginFor<T>,
org: T::Hash
) -> ...
7
votes
1
answer
97
views
How to fix `parity_scale_codec::MaxEncodedLen` is not implemented for `T`?
When building my pallet, I run into the error:
error[E0277]: the trait bound `T: parity_scale_codec::MaxEncodedLen` is not satisfied
--> pallets/template/src/lib.rs:42:15
|
42 | #[pallet::...
0
votes
1
answer
17
views
Mocking Time - `hidden_include::traits::Time` cannot be made into an object
I am working on testing my pallet.
in my mock.rs:
impl pallet_x::Config for Test {
type Event = Event;
type Time = Time<Moment = u64>;
}
when running cargo test I am getting this error:
...
2
votes
2
answers
56
views
How do treasury accounts compare to end user accounts in FRAME?
I would like to understand how treasury accounts are created and used under the hood. How do they compare to end user accounts? Are they also just an AccountId to AccountInfo map in storage?
1
vote
1
answer
29
views
What is a runtime as a data structure?
After a runtime is complete and all the macros are expanded, what kind of data structure is the runtime?
e.g.
Is the Runtime a struct? If so, what are some of the fields? I want to be able to build a ...
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 ...
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 ...
4
votes
2
answers
38
views
What means `PhantomData<T>` in a pallet?
I see that some pallets wrap phantom data:
pub struct Pallet<T>(PhantomData<T>);
and others not:
pub struct Pallet<T>(_);
Why is it there?
Do I need this in my pallet as well?
3
votes
1
answer
26
views
Difference between ReservableCurrency and NamedReservableCurrency?
The docs on the traits ReservableCurrency and NamedReservableCurrency currency are the same, although they clearly have subtle differences between them. When should someone use ReservableCurrency vs ...
5
votes
2
answers
46
views
How are Events aggregated
I noticed that every pallet (that i've checked) that has any events uses the following line in the pallets config trait:
type Event: From<Event<Self, I>> + IsType<<Self as ...
5
votes
1
answer
33
views
Which data to put in a Pallet Event?
In other blockchains I practiced extreme frugality with event data, since it is expensive.
For example only putting an ID into an event which can then be looked up with lookup(ID) -> ...
1
vote
1
answer
27
views
pallet module in frame_support_procedural crate
Im looking into some of the procedural macros used, namely the #[pallet] attribute to declare a pallet that is recognised by construct_runtime!. However, I cannot find the source code for the pallet ...
1
vote
2
answers
28
views
When should I use `ConstU32` to declare a constant value for my pallet?
There seems to be different approaches to declaring constants for a pallet's runtime implementation.
A common approach for example is:
// In pallet/example/src/lib.rs
#[pallet::config]
pub trait ...
4
votes
2
answers
55
views
Is it possible to use format! in Substrate runtime?
From the link, It seems format! can work in Substrate runtime.
let hello_world = sp_std::fmt::format!("Hello,{}","world");
I want to have a variable hello_world and use it for ...
4
votes
1
answer
36
views
How Does FRAME Account Data Work?
The FRAME system for runtime development defines an AccountData type, which is coupled with data from the Balances Pallet in the Polkadot runtime. What other types of data could be tracked using this ...