Skip to content

Commit c8947d6

Browse files
fix: re-inserts some entries lost in the early permission0 days (#121)
Some entries in the accumulation storage were lost in the early permission0 days. This migration patch re-inserts them, resuming the accumulation and distribution of tokens. Closes CHAIN-115
2 parents e1f5dab + a77ab0f commit c8947d6

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

pallets/permission0/src/migrations.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
pub mod v4 {
2+
use num_traits::Zero;
23
use polkadot_sdk::{
34
frame_support::{migrations::VersionedMigration, traits::UncheckedOnRuntimeUpgrade},
5+
sp_tracing::warn,
46
sp_weights::Weight,
57
};
68

7-
use crate::{Config, Pallet};
9+
use crate::{Config, EmissionAllocation, Pallet, PermissionScope};
810

911
pub type Migration<T, W> = VersionedMigration<3, 4, MigrateToV6<T>, Pallet<T>, W>;
1012
pub struct MigrateToV6<T>(core::marker::PhantomData<T>);
@@ -83,9 +85,37 @@ pub mod v4 {
8385
let _ = old_storage::PermissionsByGrantor::<T>::clear(u32::MAX, None);
8486
let _ = old_storage::PermissionsByGrantee::<T>::clear(u32::MAX, None);
8587

86-
for (id, contract) in old_storage::Permissions::<T>::iter() {
88+
for (pid, contract) in old_storage::Permissions::<T>::iter() {
89+
if let PermissionScope::Emission(scope) = &contract.scope {
90+
if let EmissionAllocation::Streams(streams) = &scope.allocation {
91+
for stream in streams.keys() {
92+
if !crate::AccumulatedStreamAmounts::<T>::contains_key((
93+
&contract.grantor,
94+
&stream,
95+
&pid,
96+
)) {
97+
warn!(
98+
"inserting accumulated stream value for broken contract: {pid}, stream: {stream}"
99+
);
100+
crate::AccumulatedStreamAmounts::<T>::set(
101+
(&contract.grantor, &stream, &pid),
102+
Some(Zero::zero()),
103+
);
104+
}
105+
}
106+
}
107+
}
108+
109+
crate::PermissionsByDelegator::<T>::mutate(&contract.grantor, |pids| {
110+
let _ = pids.try_push(pid);
111+
});
112+
113+
crate::PermissionsByRecipient::<T>::mutate(&contract.grantee, |pids| {
114+
let _ = pids.try_push(pid);
115+
});
116+
87117
crate::Permissions::<T>::set(
88-
id,
118+
pid,
89119
Some(crate::PermissionContract {
90120
delegator: contract.grantor,
91121
recipient: contract.grantee,

0 commit comments

Comments
 (0)