Skip to content

Commit 41fe308

Browse files
JuaniRioslrazovic
andauthored
⬆️ Release 0.7.6 (#355)
* Storage migration * chore: fmt * feat: bump transaction_version --------- Co-authored-by: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com>
1 parent f120272 commit 41fe308

File tree

4 files changed

+170
-70
lines changed

4 files changed

+170
-70
lines changed
+156-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,159 @@
11
//! A module that is responsible for migration of storage.
2-
use frame_support::traits::StorageVersion;
3-
2+
use super::*;
3+
use frame_support::{
4+
pallet_prelude::*,
5+
traits::{tokens::Balance as BalanceT, StorageVersion},
6+
};
7+
use serde::{Deserialize, Serialize};
48
/// The current storage version
5-
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);
9+
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
610
pub const LOG: &str = "runtime::funding::migration";
11+
use frame_support::traits::OnRuntimeUpgrade;
12+
13+
pub mod v3tov4 {
14+
use super::*;
15+
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
16+
pub struct OldProjectDetails<
17+
AccountId,
18+
Did,
19+
BlockNumber,
20+
Price: FixedPointNumber,
21+
Balance: BalanceT,
22+
EvaluationRoundInfo,
23+
> {
24+
pub issuer_account: AccountId,
25+
pub issuer_did: Did,
26+
/// Whether the project is frozen, so no `metadata` changes are allowed.
27+
pub is_frozen: bool,
28+
/// The price in USD per token decided after the Auction Round
29+
pub weighted_average_price: Option<Price>,
30+
/// The current status of the project
31+
pub status: OldProjectStatus,
32+
/// When the different project phases start and end
33+
pub phase_transition_points: PhaseTransitionPoints<BlockNumber>,
34+
/// Fundraising target amount in USD (6 decimals)
35+
pub fundraising_target_usd: Balance,
36+
/// The amount of Contribution Tokens that have not yet been sold
37+
pub remaining_contribution_tokens: Balance,
38+
/// Funding reached amount in USD (6 decimals)
39+
pub funding_amount_reached_usd: Balance,
40+
/// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing
41+
pub evaluation_round_info: EvaluationRoundInfo,
42+
/// If the auction was oversubscribed, how much USD was raised across all winning bids
43+
pub usd_bid_on_oversubscription: Option<Balance>,
44+
/// When the Funding Round ends
45+
pub funding_end_block: Option<BlockNumber>,
46+
/// ParaId of project
47+
pub parachain_id: Option<ParaId>,
48+
/// Migration readiness check
49+
pub migration_readiness_check: Option<MigrationReadinessCheck>,
50+
/// HRMP Channel status
51+
pub hrmp_channel_status: HRMPChannelStatus,
52+
}
53+
54+
#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
55+
pub struct MigrationReadinessCheck {
56+
pub holding_check: (xcm::v3::QueryId, CheckOutcome),
57+
pub pallet_check: (xcm::v3::QueryId, CheckOutcome),
58+
}
59+
60+
impl MigrationReadinessCheck {
61+
pub fn is_ready(&self) -> bool {
62+
self.holding_check.1 == CheckOutcome::Passed(None) &&
63+
matches!(self.pallet_check.1, CheckOutcome::Passed(Some(_)))
64+
}
65+
}
66+
67+
pub type PalletIndex = u8;
68+
#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
69+
pub enum CheckOutcome {
70+
AwaitingResponse,
71+
Passed(Option<PalletIndex>),
72+
Failed,
73+
}
74+
75+
#[derive(
76+
Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize,
77+
)]
78+
pub enum OldProjectStatus {
79+
#[default]
80+
Application,
81+
EvaluationRound,
82+
AuctionInitializePeriod,
83+
AuctionOpening,
84+
AuctionClosing,
85+
CalculatingWAP,
86+
CommunityRound,
87+
RemainderRound,
88+
FundingFailed,
89+
AwaitingProjectDecision,
90+
FundingSuccessful,
91+
ReadyToStartMigration,
92+
MigrationCompleted,
93+
}
94+
95+
type OldProjectDetailsOf<T> =
96+
OldProjectDetails<AccountIdOf<T>, Did, BlockNumberFor<T>, PriceOf<T>, BalanceOf<T>, EvaluationRoundInfoOf<T>>;
97+
98+
pub struct UncheckedMigrationToV4<T: Config>(PhantomData<T>);
99+
impl<T: Config> OnRuntimeUpgrade for UncheckedMigrationToV4<T> {
100+
fn on_runtime_upgrade() -> frame_support::weights::Weight {
101+
let mut items = 0;
102+
let mut translate = |_key, item: OldProjectDetailsOf<T>| -> Option<ProjectDetailsOf<T>> {
103+
items += 1;
104+
let new_status = match item.status {
105+
OldProjectStatus::Application => ProjectStatus::Application,
106+
OldProjectStatus::EvaluationRound => ProjectStatus::EvaluationRound,
107+
OldProjectStatus::AuctionInitializePeriod => ProjectStatus::AuctionInitializePeriod,
108+
OldProjectStatus::AuctionOpening => ProjectStatus::AuctionOpening,
109+
OldProjectStatus::AuctionClosing => ProjectStatus::AuctionClosing,
110+
OldProjectStatus::CalculatingWAP => ProjectStatus::CalculatingWAP,
111+
OldProjectStatus::CommunityRound => ProjectStatus::CommunityRound,
112+
OldProjectStatus::RemainderRound => ProjectStatus::RemainderRound,
113+
OldProjectStatus::FundingFailed => ProjectStatus::FundingFailed,
114+
OldProjectStatus::AwaitingProjectDecision => ProjectStatus::AwaitingProjectDecision,
115+
OldProjectStatus::FundingSuccessful => {
116+
debug_assert!(item.funding_end_block.is_none(), "Settlement shouldn't have started yet");
117+
ProjectStatus::FundingSuccessful
118+
},
119+
120+
OldProjectStatus::ReadyToStartMigration => {
121+
debug_assert!(false, "No project should be in this state when upgrading to v4");
122+
ProjectStatus::CTMigrationStarted
123+
},
124+
OldProjectStatus::MigrationCompleted => {
125+
debug_assert!(false, "No project should be in this state when upgrading to v4");
126+
ProjectStatus::CTMigrationFinished
127+
},
128+
};
129+
Some(ProjectDetailsOf::<T> {
130+
issuer_account: item.issuer_account,
131+
issuer_did: item.issuer_did,
132+
is_frozen: item.is_frozen,
133+
weighted_average_price: item.weighted_average_price,
134+
status: new_status,
135+
phase_transition_points: item.phase_transition_points,
136+
fundraising_target_usd: item.fundraising_target_usd,
137+
remaining_contribution_tokens: item.remaining_contribution_tokens,
138+
funding_amount_reached_usd: item.funding_amount_reached_usd,
139+
evaluation_round_info: item.evaluation_round_info,
140+
usd_bid_on_oversubscription: item.usd_bid_on_oversubscription,
141+
funding_end_block: item.funding_end_block,
142+
migration_type: None,
143+
})
144+
};
145+
146+
crate::ProjectsDetails::<T>::translate(|key, object: OldProjectDetailsOf<T>| translate(key, object));
147+
148+
T::DbWeight::get().reads_writes(items, items)
149+
}
150+
}
151+
152+
pub type MigrationToV4<T> = frame_support::migrations::VersionedMigration<
153+
3,
154+
4,
155+
UncheckedMigrationToV4<T>,
156+
crate::Pallet<T>,
157+
<T as frame_system::Config>::DbWeight,
158+
>;
159+
}

pallets/linear-release/src/tests.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ fn check_vesting_status_for_multi_schedule_account() {
125125
assert_eq!(Balances::balance_on_hold(&MockRuntimeHoldReason::Reason, &2), 20 * ED);
126126
assert_ok!(Vesting::vested_transfer(Some(4).into(), 2, sched1, MockRuntimeHoldReason::Reason));
127127
assert_eq!(Balances::balance_on_hold(&MockRuntimeHoldReason::Reason, &2), 29 * ED); // Why 29 and not 30? Because sched1 is already unlocking.
128-
// Free balance is the one set in Genesis inside the Balances pallet
129-
// + the one from the vested transfer.
130-
// BUT NOT the one in sched0, since the vesting will start at block #10.
128+
// Free balance is the one set in Genesis inside the Balances pallet
129+
// + the one from the vested transfer.
130+
// BUT NOT the one in sched0, since the vesting will start at block #10.
131131
let balance = Balances::balance(&2);
132132
assert_eq!(balance, ED * (2));
133133
// The most recently added schedule exists.
@@ -193,7 +193,7 @@ fn unvested_balance_should_not_transfer() {
193193
ExtBuilder::default().existential_deposit(10).build().execute_with(|| {
194194
let user1_free_balance = Balances::free_balance(1);
195195
assert_eq!(user1_free_balance, 50); // Account 1 has free balance
196-
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
196+
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
197197
assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5)); // Account 1 cannot send more than vested amount...
198198
assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 56), TokenError::FundsUnavailable);
199199
});
@@ -205,13 +205,13 @@ fn vested_balance_should_transfer() {
205205
assert_eq!(System::block_number(), 1);
206206
let user1_free_balance = Balances::free_balance(1);
207207
assert_eq!(user1_free_balance, 50); // Account 1 has free balance
208-
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
208+
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
209209
assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5));
210210
assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 45), TokenError::Frozen); // Account 1 free balance - ED is < 45
211211
assert_ok!(Vesting::vest(Some(1).into(), MockRuntimeHoldReason::Reason));
212212
let user1_free_balance = Balances::free_balance(1);
213213
assert_eq!(user1_free_balance, 55); // Account 1 has free balance
214-
// Account 1 has vested 1 unit at block 1 (plus 50 unvested)
214+
// Account 1 has vested 1 unit at block 1 (plus 50 unvested)
215215
assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 45)); // After the vest it can now send the 45 UNIT
216216
});
217217
}
@@ -259,7 +259,7 @@ fn vested_balance_should_transfer_using_vest_other() {
259259
ExtBuilder::default().existential_deposit(10).build().execute_with(|| {
260260
let user1_free_balance = Balances::free_balance(1);
261261
assert_eq!(user1_free_balance, 50); // Account 1 has free balance
262-
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
262+
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
263263
assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5));
264264
assert_ok!(Vesting::vest_other(Some(2).into(), 1, MockRuntimeHoldReason::Reason));
265265
assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55 - 10));
@@ -317,7 +317,7 @@ fn extra_balance_should_transfer() {
317317

318318
// Account 2 has no units vested at block 1, but gained 100
319319
assert_ok!(Balances::transfer_allow_death(Some(2).into(), 3, 100 - 10)); // Account 2 can send extra
320-
// units gained
320+
// units gained
321321
});
322322
}
323323

@@ -327,7 +327,7 @@ fn liquid_funds_should_transfer_with_delayed_vesting() {
327327
let user12_free_balance = Balances::free_balance(12);
328328

329329
assert_eq!(user12_free_balance, 1280); // Account 12 has free balance
330-
// Account 12 has liquid funds
330+
// Account 12 has liquid funds
331331
assert_eq!(Vesting::vesting_balance(&12, MockRuntimeHoldReason::Reason), Some(0));
332332

333333
// Account 12 has delayed vesting

runtimes/polimec/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ pub type Migrations = migrations::Unreleased;
157157
/// The runtime migrations per release.
158158
#[allow(missing_docs)]
159159
pub mod migrations {
160+
use crate::Runtime;
161+
160162
/// Unreleased migrations. Add new ones here:
161163
#[allow(unused_parens)]
162-
pub type Unreleased = ();
164+
pub type Unreleased = (pallet_funding::storage_migrations::v3tov4::MigrationToV4<Runtime>);
163165
}
164166

165167
/// Executive: handles dispatch to the various modules.
@@ -205,10 +207,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
205207
spec_name: create_runtime_str!("polimec-mainnet"),
206208
impl_name: create_runtime_str!("polimec-mainnet"),
207209
authoring_version: 1,
208-
spec_version: 0_007_005,
210+
spec_version: 0_007_006,
209211
impl_version: 0,
210212
apis: RUNTIME_API_VERSIONS,
211-
transaction_version: 3,
213+
transaction_version: 4,
212214
state_version: 1,
213215
};
214216

scripts/chopsticks/polimec-testing/polkadot-polimec.yml

-55
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,6 @@ import-storage:
1010
data:
1111
free: "500000000000000"
1212

13-
# account1 - 50k PLMC
14-
- - - "5EoHniZVuKRKNXNtVZzw8Jbc8Qtgy8GN5QKDKSA78HEok7YW"
15-
- providers: 1
16-
data:
17-
free: "500000000000000"
18-
19-
# account2 - 50k PLMC
20-
- - - "5GeXY2mKL4ADz7mDtsuHvNrRky48NqdWb4u8c5Sg9N8s3T1y"
21-
- providers: 1
22-
data:
23-
free: "500000000000000"
24-
25-
# account3 - 50k PLMC
26-
- - - "5EfE8r9uWWMazvyh8tkcuuKSy6PbAZQSqq42CXYwGdvwjpb8"
27-
- providers: 1
28-
data:
29-
free: "500000000000000"
30-
31-
# account4 - 50k PLMC
32-
- - - "5C8ULBGhfaP2nmDcuFbiShQ1hMwWsB7ghbChDKAwdszSWnA5"
33-
- providers: 1
34-
data:
35-
free: "500000000000000"
36-
37-
# account5 - 50k PLMC
38-
- - - "5HGqvcE29nHekDEYND3ZZtobbP4UeCcALFgwEm5YUvroZJr6"
39-
- providers: 1
40-
data:
41-
free: "500000000000000"
42-
43-
# account6 - 50k PLMC
44-
- - - "5CGEmsGTJcYSBCdXvsjDUBxW2dtvte5M8By95gwMwToih37s"
45-
- providers: 1
46-
data:
47-
free: "500000000000000"
48-
49-
# account7 - 50k PLMC
50-
- - - "5GsWm46kXRF7p6ifSQjrdc8HgPbzY4uWgJdQSUcGGDczkDGa"
51-
- providers: 1
52-
data:
53-
free: "500000000000000"
54-
55-
# account8 - 50k PLMC
56-
- - - "5H4AWTrkHN6aaQCv2jn48HVZjGhiCqswt6sPBksFPrrf2FPY"
57-
- providers: 1
58-
data:
59-
free: "500000000000000"
60-
61-
# account9 - 50k PLMC
62-
- - - "5CabLepLT8e6NvJCtzrEZLEBRd1FxKXU72F2NvbYTVf3bNej"
63-
- providers: 1
64-
data:
65-
free: "500000000000000"
66-
67-
6813
ForeignAssets:
6914
Account:
7015
# account0 - 50k DOT, 50k USDT, 50k USDC

0 commit comments

Comments
 (0)