Define ss58 prefix inside the runtime (#7810)

* Add SS58Prefix type to the frame_system config trait

* Remove unused chain_id runtime interface
This commit is contained in:
Alexander Theißen
2020-12-30 23:07:37 +01:00
committed by GitHub
parent bd48ff310d
commit ec2c70396e
67 changed files with 85 additions and 25 deletions
@@ -16,6 +16,7 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42;
}
impl system::Config for Test {
@@ -40,6 +41,7 @@ impl system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
}
impl Config for Test {
@@ -136,6 +136,7 @@ parameter_types! {
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
}
// Configure FRAME pallets to include in runtime.
@@ -185,6 +186,8 @@ impl frame_system::Config for Runtime {
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
}
impl pallet_aura::Config for Runtime {
+2
View File
@@ -176,6 +176,7 @@ parameter_types! {
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
pub const SS58Prefix: u8 = 42;
}
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
@@ -202,6 +203,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
type SS58Prefix = SS58Prefix;
}
impl pallet_utility::Config for Runtime {
+1
View File
@@ -952,6 +952,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -42,6 +42,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -66,6 +66,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_timestamp::Config for Test {
@@ -164,6 +164,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl_outer_origin! {
+1
View File
@@ -438,6 +438,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -86,6 +86,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
@@ -77,6 +77,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
@@ -78,6 +78,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = Module<Test>;
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
@@ -94,6 +94,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl Config for Test {
+1
View File
@@ -82,6 +82,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -996,6 +996,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl Config<Instance1> for Test {
type Origin = Origin;
+1
View File
@@ -130,6 +130,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_balances::Config for Test {
type MaxLocks = ();
+1
View File
@@ -113,6 +113,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
@@ -1099,6 +1099,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -57,6 +57,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
@@ -76,6 +76,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
type Extrinsic = TestXt<Call<Test>, ()>;
@@ -59,6 +59,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -764,6 +764,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -618,6 +618,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
type Balance = u64;
+1
View File
@@ -100,6 +100,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
+1
View File
@@ -63,6 +63,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -130,6 +130,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -69,6 +69,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -321,6 +321,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
ord_parameter_types! {
pub const One: u64 = 1;
@@ -63,6 +63,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl Config for Test {
+1
View File
@@ -80,6 +80,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -283,6 +283,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -472,6 +472,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
ord_parameter_types! {
@@ -63,6 +63,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = (Balances,);
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
+1
View File
@@ -116,6 +116,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -82,6 +82,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -180,6 +180,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
type System = frame_system::Module<Test>;
+1
View File
@@ -78,6 +78,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -837,6 +837,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl logger::Config for Test {
type Event = ();
+1
View File
@@ -68,6 +68,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_balances::Config for Test {
@@ -67,6 +67,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = Balances;
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
+1
View File
@@ -218,6 +218,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_timestamp::Config for Test {
+1
View File
@@ -78,6 +78,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type AccountData = pallet_balances::AccountData<u64>;
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_balances::Config for Test {
@@ -65,6 +65,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = (Balances,);
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
+1
View File
@@ -166,6 +166,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
+1
View File
@@ -139,6 +139,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
// Implement the logger module's `Config` on the Test runtime.
@@ -364,6 +364,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -226,6 +226,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -218,6 +218,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -259,6 +259,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -165,6 +165,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
frame_support::construct_runtime!(
@@ -141,6 +141,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_test::Trait for Runtime {
+1
View File
@@ -87,6 +87,7 @@ impl system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl module::Config for Runtime {
@@ -72,6 +72,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl crate::Config for Test {}
+14
View File
@@ -257,6 +257,13 @@ pub trait Config: 'static + Eq + Clone {
type OnKilledAccount: OnKilledAccount<Self::AccountId>;
type SystemWeightInfo: WeightInfo;
/// The designated SS85 prefix of this chain.
///
/// This replaces the "ss58Format" property declared in the chain spec. Reason is
/// that the runtime should know about the prefix in order to make use of it as
/// an identifier of the chain.
type SS58Prefix: Get<u8>;
}
pub type DigestOf<T> = generic::Digest<<T as Config>::Hash>;
@@ -516,6 +523,13 @@ decl_module! {
/// The weight configuration (limits & base values) for each class of extrinsics and block.
const BlockWeights: limits::BlockWeights = T::BlockWeights::get();
/// The designated SS85 prefix of this chain.
///
/// This replaces the "ss58Format" property declared in the chain spec. Reason is
/// that the runtime should know about the prefix in order to make use of it as
/// an identifier of the chain.
const SS58Prefix: u8 = T::SS58Prefix::get();
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if !UpgradedToU32RefCount::get() {
Account::<T>::translate::<(T::Index, u8, T::AccountData), _>(|_key, (nonce, rc, data)|
+1
View File
@@ -117,6 +117,7 @@ impl Config for Test {
type OnNewAccount = ();
type OnKilledAccount = RecordKilled;
type SystemWeightInfo = ();
type SS58Prefix = ();
}
pub type System = Module<Test>;
+1
View File
@@ -335,6 +335,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const MinimumPeriod: u64 = 5;
+8 -7
View File
@@ -81,6 +81,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -292,28 +293,28 @@ fn slash_tip_works() {
System::set_block_number(1);
Balances::make_free_balance_be(&Treasury::account_id(), 101);
assert_eq!(Treasury::pot(), 100);
assert_eq!(Balances::reserved_balance(0), 0);
assert_eq!(Balances::free_balance(0), 100);
assert_ok!(TipsModTestInst::report_awesome(Origin::signed(0), b"awesome.dot".to_vec(), 3));
assert_eq!(Balances::reserved_balance(0), 12);
assert_eq!(Balances::free_balance(0), 88);
let h = tip_hash();
assert_eq!(last_event(), RawEvent::NewTip(h));
// can't remove from any origin
assert_noop!(
TipsModTestInst::slash_tip(Origin::signed(0), h.clone()),
BadOrigin,
);
// can remove from root.
assert_ok!(TipsModTestInst::slash_tip(Origin::root(), h.clone()));
assert_eq!(last_event(), RawEvent::TipSlashed(h, 0, 12));
// tipper slashed
assert_eq!(Balances::reserved_balance(0), 0);
assert_eq!(Balances::free_balance(0), 88);
@@ -662,6 +662,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
+1
View File
@@ -80,6 +80,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -118,6 +118,7 @@ impl frame_system::Config for Test {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -433,6 +433,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
parameter_types! {
pub const MaxLocks: u32 = 10;
@@ -170,9 +170,6 @@ pub trait Externalities: ExtensionStore {
value: Option<Vec<u8>>,
);
/// Get the identity of the chain.
fn chain_id(&self) -> u64;
/// Get the trie root of the current storage map.
///
/// This will also update all child storage keys in the top-level storage map.
-5
View File
@@ -388,11 +388,6 @@ pub trait Trie {
/// Interface that provides miscellaneous functions for communicating between the runtime and the node.
#[runtime_interface]
pub trait Misc {
/// The current relay chain identifier.
fn chain_id(&self) -> u64 {
sp_externalities::Externalities::chain_id(*self)
}
/// Print a number.
fn print_num(val: u64) {
log::debug!(target: "runtime", "{}", val);
@@ -263,8 +263,6 @@ impl Externalities for BasicExternalities {
crate::ext::StorageAppend::new(current).append(value);
}
fn chain_id(&self) -> u64 { 42 }
fn storage_root(&mut self) -> Vec<u8> {
let mut top = self.inner.top.clone();
let prefixed_keys: Vec<_> = self.inner.children_default.iter().map(|(_k, v)| {
@@ -507,10 +507,6 @@ where
StorageAppend::new(current_value).append(value);
}
fn chain_id(&self) -> u64 {
42
}
fn storage_root(&mut self) -> Vec<u8> {
let _guard = guard();
if let Some(ref root) = self.storage_transaction_cache.transaction_storage_root {
@@ -156,8 +156,6 @@ impl<'a, H: Hasher, B: 'a + Backend<H>> Externalities for ReadOnlyExternalities<
unimplemented!("storage_append is not supported in ReadOnlyExternalities")
}
fn chain_id(&self) -> u64 { 42 }
fn storage_root(&mut self) -> Vec<u8> {
unimplemented!("storage_root is not supported in ReadOnlyExternalities")
}
@@ -143,8 +143,6 @@ impl Externalities for AsyncExternalities {
panic!("`storage_append`: should not be used in async externalities!")
}
fn chain_id(&self) -> u64 { 42 }
fn storage_root(&mut self) -> Vec<u8> {
panic!("`storage_root`: should not be used in async externalities!")
}
+1
View File
@@ -462,6 +462,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
}
impl pallet_timestamp::Config for Runtime {