๐ช Instances
pallet-commitment supports multiple independent instances within the same runtime.
This is achieved through the generic instance parameter on its configuration trait:
pallet_commitment::Config<I> where I: 'static
where I requires a marker-struct that identifies a particular Commitment instance.
Each instance has its own:
- storage
- configuration
- balance plugin
- reserve hold reason
- freeze reason
- limits
- accounting behavior
This allows multiple commitment engines to coexist inside one runtime without sharing state.
๐งฉ Why Use Multiple Instances?โ
Most runtimes only need one Commitment instance.
Multiple consumer pallets can safely share it.
Example:
Staking
\
Governance ----> Commitment
/
Lending
All pallets reuse the same commitment engine while keeping their own commitment reasons and digest semantics.
Sometimes, however, different protocols require completely different commitment behavior.
For example:
| Protocol | Requirement |
|---|---|
| Native Staking | Share-based lazy accounting |
| Prediction Markets | Fixed settlement model |
| Treasury Escrow | No variants |
| Managed Vaults | Different scalars configuration |
Rather than forcing one configuration to fit every protocol, each protocol can use its own Commitment instance.
โ๏ธ How It Worksโ
Instead of:
impl pallet_commitment::Config for Runtime { ... }
define multiple instances:
pub struct NativeStake;
pub struct Markets;
pub struct Treasury;
impl pallet_commitment::Config<NativeStake> for Runtime { ... }
impl pallet_commitment::Config<Markets> for Runtime { ... }
impl pallet_commitment::Config<Treasury> for Runtime { ... }
Each becomes an independent commitment engine.
NativeStake != Markets != Treasury
They do not share storage or configuration.
๐๏ธ Independent Configurationโ
Every instance may choose its own configuration.
For example:
BalanceFamilyBalanceContextAssetPositionMaxCommitsMaxIndexEntriesEmitEvents
One instance may support pools while another disables them entirely.
One may use share-based accounting while another uses a completely different Lazy Balance plugin.
๐๏ธ Separate Storageโ
Every instance owns its own storage namespace.
For example:
CommitMap<NativeStake> โ CommitMap<Markets>
The same applies to every storage item:
CommitMapDigestMapEntryMapIndexMapPoolMapReasonValueAssetToIssueAssetToReap
Commitments created in one instance are completely isolated from every other instance.
๐ซ When NOT to Use Instancesโ
Do not create multiple instances simply because multiple pallets use Commitment.
If all consumer pallets can share:
- the same accounting model
- the same balance plugin
- the same limits
- the same commitment behavior
then a single Commitment instance is the recommended architecture.
Different consumer pallets can still define:
- different commitment reasons
- different digest meanings
- different variants
without requiring separate instances.
โ When to Use Instancesโ
Create multiple instances only when the question is:
"Should these protocols behave as different commitment engines?"
If the answer is yes, use multiple instances.
Otherwise, share one instance across all consumer pallets.
๐ In One Sentenceโ
Commitment instances allow multiple independent commitment engines to coexist within the same runtime, each with its own storage, configuration, and accounting model.
๐ Next Stepโ
The next section covers benchmarking and weight generation for commitment operations.
๐ Advanced -> Weights