Skip to content

Commit 498642d

Browse files
chore: final migrations tweaks (#118)
We are getting ready for the mainnet release on July 7th. This change finishes the name porting logic converting agent names to complying namespace names, by lowering and removing whitespace from the names.
1 parent 5d79e22 commit 498642d

File tree

7 files changed

+8
-229
lines changed

7 files changed

+8
-229
lines changed

pallets/governance/src/migrations.rs

Lines changed: 1 addition & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use polkadot_sdk::frame_support::{
55

66
use crate::{Config, Pallet};
77

8-
pub mod v3 {
8+
pub mod v5 {
99
use pallet_permission0_api::{CuratorPermissions, Permission0CuratorApi, PermissionDuration};
1010
use polkadot_sdk::{
1111
frame_system::RawOrigin,
@@ -159,175 +159,3 @@ pub mod v3 {
159159
}
160160
}
161161
}
162-
163-
pub mod v4 {
164-
use pallet_permission0_api::{CuratorPermissions, Permission0CuratorApi, PermissionDuration};
165-
use polkadot_sdk::{
166-
frame_system::RawOrigin,
167-
sp_tracing::{info, warn},
168-
};
169-
170-
use super::*;
171-
172-
pub type Migration<T, W> = VersionedMigration<3, 4, MigrateToV4<T>, Pallet<T>, W>;
173-
pub struct MigrateToV4<T>(core::marker::PhantomData<T>);
174-
175-
mod old_storage {
176-
use polkadot_sdk::frame_support::{storage_alias, Identity};
177-
178-
use crate::AccountIdOf;
179-
180-
#[storage_alias]
181-
pub type Curators<T: crate::Config> =
182-
StorageMap<crate::Pallet<T>, Identity, AccountIdOf<T>, ()>;
183-
}
184-
185-
impl<T: Config> UncheckedOnRuntimeUpgrade for MigrateToV4<T> {
186-
fn on_runtime_upgrade() -> Weight {
187-
for (curator, _) in old_storage::Curators::<T>::iter() {
188-
let res = <<T as Config>::Permission0>::grant_curator_permission(
189-
RawOrigin::Root.into(),
190-
curator.clone(),
191-
CuratorPermissions::all(),
192-
None,
193-
PermissionDuration::Indefinite,
194-
pallet_permission0_api::RevocationTerms::RevocableByGrantor,
195-
);
196-
197-
match res {
198-
Ok(perm_id) => info!("migrated curator {curator:?} to permission0: {perm_id}"),
199-
Err(err) => {
200-
warn!("Could not migrate curator {curator:?} to permission0: {err:?}");
201-
}
202-
}
203-
}
204-
205-
Weight::zero()
206-
}
207-
}
208-
}
209-
210-
pub mod v5 {
211-
use crate::proposal::{GlobalParamsData, ProposalData};
212-
213-
use super::*;
214-
215-
pub type Migration<T, W> = VersionedMigration<4, 5, MigrateToV5<T>, Pallet<T>, W>;
216-
pub struct MigrateToV5<T>(core::marker::PhantomData<T>);
217-
218-
mod old_storage {
219-
use codec::{Decode, Encode, MaxEncodedLen};
220-
use polkadot_sdk::{
221-
frame_support::{storage_alias, DebugNoBound, Identity},
222-
polkadot_sdk_frame::prelude::BlockNumberFor,
223-
sp_core::ConstU32,
224-
sp_runtime::{BoundedVec, Percent},
225-
};
226-
use scale_info::TypeInfo;
227-
228-
use crate::{
229-
proposal::{ProposalId, ProposalStatus},
230-
AccountIdOf, BalanceOf,
231-
};
232-
233-
#[derive(Clone, DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen)]
234-
#[scale_info(skip_type_params(T))]
235-
pub struct Proposal<T: crate::Config> {
236-
pub id: ProposalId,
237-
pub proposer: AccountIdOf<T>,
238-
pub expiration_block: BlockNumberFor<T>,
239-
pub data: ProposalData<T>,
240-
pub status: ProposalStatus<T>,
241-
pub metadata: BoundedVec<u8, ConstU32<256>>,
242-
pub proposal_cost: BalanceOf<T>,
243-
pub creation_block: BlockNumberFor<T>,
244-
}
245-
246-
#[derive(Clone, DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen, PartialEq, Eq)]
247-
#[scale_info(skip_type_params(T))]
248-
pub enum ProposalData<T: crate::Config> {
249-
GlobalParams(GlobalParamsData<T>),
250-
GlobalCustom,
251-
Emission {
252-
recycling_percentage: Percent,
253-
treasury_percentage: Percent,
254-
incentives_ratio: Percent,
255-
},
256-
TransferDaoTreasury {
257-
account: AccountIdOf<T>,
258-
amount: BalanceOf<T>,
259-
},
260-
}
261-
262-
#[derive(Clone, DebugNoBound, TypeInfo, Decode, Encode, MaxEncodedLen, PartialEq, Eq)]
263-
#[scale_info(skip_type_params(T))]
264-
pub struct GlobalParamsData<T: crate::Config> {
265-
pub min_name_length: u16,
266-
pub max_name_length: u16,
267-
pub max_allowed_agents: u16,
268-
pub min_weight_control_fee: u8,
269-
pub min_staking_fee: u8,
270-
pub dividends_participation_weight: Percent,
271-
pub proposal_cost: BalanceOf<T>,
272-
}
273-
274-
#[storage_alias]
275-
pub type Proposals<T: crate::Config> =
276-
StorageMap<crate::Pallet<T>, Identity, ProposalId, Proposal<T>>;
277-
}
278-
279-
impl<T: Config> UncheckedOnRuntimeUpgrade for MigrateToV5<T> {
280-
fn on_runtime_upgrade() -> Weight {
281-
for (id, proposal) in old_storage::Proposals::iter() {
282-
let new_data = match proposal.data {
283-
old_storage::ProposalData::GlobalParams(old_storage::GlobalParamsData {
284-
min_name_length,
285-
max_name_length,
286-
min_weight_control_fee,
287-
min_staking_fee,
288-
dividends_participation_weight,
289-
proposal_cost,
290-
..
291-
}) => ProposalData::GlobalParams(GlobalParamsData {
292-
min_name_length,
293-
max_name_length,
294-
min_weight_control_fee,
295-
min_staking_fee,
296-
dividends_participation_weight,
297-
namespace_pricing_config:
298-
<T as pallet_torus0::Config>::DefaultNamespacePricingConfig::get(),
299-
proposal_cost,
300-
}),
301-
old_storage::ProposalData::GlobalCustom => ProposalData::GlobalCustom,
302-
old_storage::ProposalData::Emission {
303-
recycling_percentage,
304-
treasury_percentage,
305-
incentives_ratio,
306-
} => ProposalData::Emission {
307-
recycling_percentage,
308-
treasury_percentage,
309-
incentives_ratio,
310-
},
311-
old_storage::ProposalData::TransferDaoTreasury { account, amount } => {
312-
ProposalData::TransferDaoTreasury { account, amount }
313-
}
314-
};
315-
316-
let new_proposal = crate::proposal::Proposal {
317-
id: proposal.id,
318-
proposer: proposal.proposer,
319-
expiration_block: proposal.expiration_block,
320-
data: new_data,
321-
status: proposal.status,
322-
metadata: proposal.metadata,
323-
proposal_cost: proposal.proposal_cost,
324-
creation_block: proposal.creation_block,
325-
};
326-
327-
crate::Proposals::<T>::set(id, Some(new_proposal));
328-
}
329-
330-
Weight::zero()
331-
}
332-
}
333-
}

pallets/governance/src/proposal.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -548,16 +548,12 @@ fn create_unrewarded_proposal<T: crate::Config>(
548548
) {
549549
let mut reward_votes_for = BoundedBTreeMap::new();
550550
for (key, value) in votes_for {
551-
reward_votes_for
552-
.try_insert(key, value)
553-
.expect("this wont exceed u32::MAX");
551+
let _ = reward_votes_for.try_insert(key, value);
554552
}
555553

556554
let mut reward_votes_against: AccountStakes<T> = BoundedBTreeMap::new();
557555
for (key, value) in votes_against {
558-
reward_votes_against
559-
.try_insert(key, value)
560-
.expect("this probably wont exceed u32::MAX");
556+
let _ = reward_votes_against.try_insert(key, value);
561557
}
562558

563559
UnrewardedProposals::<T>::insert(
@@ -634,9 +630,7 @@ pub fn tick_proposal_rewards<T: crate::Config>(block_number: BlockNumberFor<T>)
634630
.chain(unrewarded_proposal.votes_against.into_iter())
635631
{
636632
let curr_stake = *account_stakes.get(&acc_id).unwrap_or(&0u128);
637-
account_stakes
638-
.try_insert(acc_id, curr_stake.saturating_add(stake))
639-
.expect("infallible");
633+
let _ = account_stakes.try_insert(acc_id, curr_stake.saturating_add(stake));
640634
}
641635

642636
match get_reward_allocation::<T>(&governance_config, n) {
Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1 @@
1-
pub mod v2 {
2-
use polkadot_sdk::{
3-
frame_support::{migrations::VersionedMigration, traits::UncheckedOnRuntimeUpgrade},
4-
sp_weights::Weight,
5-
};
61

7-
use crate::{Config, Pallet};
8-
9-
pub type Migration<T, W> = VersionedMigration<1, 2, MigrateToV2<T>, Pallet<T>, W>;
10-
pub struct MigrateToV2<T>(core::marker::PhantomData<T>);
11-
12-
impl<T: Config> UncheckedOnRuntimeUpgrade for MigrateToV2<T> {
13-
fn on_runtime_upgrade() -> Weight {
14-
Weight::zero()
15-
}
16-
}
17-
}
18-
19-
pub mod v3 {
20-
use polkadot_sdk::{
21-
frame_support::{migrations::VersionedMigration, traits::UncheckedOnRuntimeUpgrade},
22-
sp_weights::Weight,
23-
};
24-
25-
use crate::{Config, Pallet};
26-
27-
pub type Migration<T, W> = VersionedMigration<2, 3, MigrateToV3<T>, Pallet<T>, W>;
28-
pub struct MigrateToV3<T>(core::marker::PhantomData<T>);
29-
30-
impl<T: Config> UncheckedOnRuntimeUpgrade for MigrateToV3<T> {
31-
fn on_runtime_upgrade() -> Weight {
32-
Weight::zero()
33-
}
34-
}
35-
}

pallets/torus0/api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct NamespacePath(NamespacePathInner);
7979
impl NamespacePath {
8080
/// The root agent namespace entry.
8181
pub fn agent_root() -> NamespacePath {
82-
NamespacePath(b"agent".to_vec().try_into().unwrap())
82+
NamespacePath(NamespacePathInner::truncate_from(b"agent".to_vec()))
8383
}
8484

8585
/// Create a new root agent namespace path from the agent name

pallets/torus0/src/migrations.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ pub mod v5 {
111111
let _ = storage::NamespaceCount::<T>::clear(u32::MAX, None);
112112

113113
let path = NamespacePath::agent_root();
114+
#[allow(deprecated)]
114115
if let Err(err) =
115-
crate::namespace::create_namespace::<T>(NamespaceOwnership::System, path)
116+
crate::namespace::create_namespace0::<T>(NamespaceOwnership::System, path, false)
116117
{
117118
error!("failed to create root agent namespace: {err:?}");
118119
return Weight::default();
@@ -127,11 +128,7 @@ pub mod v5 {
127128
continue;
128129
};
129130

130-
let agent_name = if cfg!(feature = "testnet") {
131-
agent_name.to_ascii_lowercase().replace(' ', "-")
132-
} else {
133-
agent_name.into()
134-
};
131+
let agent_name = agent_name.trim().to_ascii_lowercase().replace(' ', "-");
135132

136133
let Ok(bounded_name) = agent_name.as_bytes().to_vec().try_into() else {
137134
error!("cannot lower case agent {agent_name:?}");

runtime/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ pub type SignedPayload = sp_runtime::generic::SignedPayload<RuntimeCall, SignedE
8484
///
8585
/// This can be a tuple of types, each implementing `OnRuntimeUpgrade`.
8686
type Migrations = (
87-
pallet_governance::migrations::v3::Migration<Runtime, RocksDbWeight>,
88-
pallet_governance::migrations::v4::Migration<Runtime, RocksDbWeight>,
8987
pallet_governance::migrations::v5::Migration<Runtime, RocksDbWeight>,
90-
pallet_permission0::migrations::v2::Migration<Runtime, RocksDbWeight>,
91-
pallet_permission0::migrations::v3::Migration<Runtime, RocksDbWeight>,
9288
pallet_emission0::migrations::v2::Migration<Runtime, RocksDbWeight>,
9389
pallet_torus0::migrations::v4::Migration<Runtime, RocksDbWeight>,
9490
pallet_torus0::migrations::v5::Migration<Runtime, RocksDbWeight>,

xtask/src/run.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ pub(super) fn run(mut r: flags::Run) {
7878
ops::key_insert_cmd(&path, &chain_spec, &account.suri, "aura");
7979
ops::key_insert_cmd(&path, &chain_spec, &account.suri, "gran");
8080

81-
dbg!(&chain_spec);
82-
8381
let _run = ops::run_node(&path, &chain_spec, &node, &r.bootnodes, r.isolated)
8482
.spawn()
8583
.unwrap()

0 commit comments

Comments
 (0)