-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathlib.rs
More file actions
124 lines (99 loc) · 4.29 KB
/
lib.rs
File metadata and controls
124 lines (99 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// KILT Blockchain – <https://kilt.io>
// Copyright (C) 2025, KILT Foundation
// The KILT Blockchain is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The KILT Blockchain is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// If you feel like getting in touch with us, you can do so at <hello@kilt.io>
//! # Configuration Pallet
//!
//! This pallet allows to change configurations without performing a runtime
//! upgrade.
//!
//! Currently the following configurations are supported:
//!
//! * `CheckAssociatedRelayNumber` of the parachain-system pallet
#![cfg_attr(not(feature = "std"), no_std)]
pub mod configuration;
pub mod default_weights;
#[cfg(any(feature = "mock", test))]
pub mod mock;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
#[cfg(test)]
/// Tests for the configuration pallet
mod tests;
pub use crate::{configuration::Configuration, default_weights::WeightInfo, pallet::*};
#[frame_support::pallet]
// `.expect()` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
// `ref` keyword is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::ref_patterns)]
// The `pallet::event` macro shadows the `deposit_event` definition of `frame_system::Config`.
// This means we cannot avoid shadow reuses anymore, and for new pallets this `allow` clause should only be added at the
// very end of the development cycle of a pallet, and from time to time it should be commented out to catch any issues
// other than the one generated by the `pallet::event` macro.
#[allow(clippy::shadow_reuse)]
// map_err is used over inspect_err in the macro-generated code, and we have to ignore it.
#[allow(clippy::manual_inspect)]
pub mod pallet {
use super::*;
use cumulus_pallet_parachain_system::{CheckAssociatedRelayNumber, RelayNumberStrictlyIncreases};
use frame_support::{
pallet_prelude::*,
traits::{EnsureOriginWithArg, StorageVersion},
};
use frame_system::pallet_prelude::*;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type WeightInfo: WeightInfo;
/// The origin that is allowed to change the configuration
type EnsureOrigin: EnsureOriginWithArg<<Self as frame_system::Config>::RuntimeOrigin, Configuration>;
}
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
/// Stores for the dynamic configuration of the runtime
#[pallet::storage]
pub type ConfigurationStore<T> = StorageValue<_, Configuration, ValueQuery>;
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// The configuration was updated.
ConfigurationUpdate(Configuration),
}
#[pallet::error]
pub enum Error<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the current configuration.
#[pallet::call_index(0)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_configuration())]
pub fn set_configuration(origin: OriginFor<T>, configuration: Configuration) -> DispatchResult {
<T as pallet::Config>::EnsureOrigin::ensure_origin(origin, &configuration)?;
ConfigurationStore::<T>::set(configuration.clone());
Self::deposit_event(Event::<T>::ConfigurationUpdate(configuration));
Ok(())
}
}
impl<T: Config> CheckAssociatedRelayNumber for Pallet<T> {
fn check_associated_relay_number(a: u32, b: u32) {
if ConfigurationStore::<T>::get().relay_block_strictly_increasing {
RelayNumberStrictlyIncreases::check_associated_relay_number(a, b);
}
}
}
}