Skip to content

Commit 6727830

Browse files
authored
Merge pull request #3480 from autonomys/fix-unlock-failure
Fix unlock failure due to missing share price
2 parents dae2c45 + 07ca4eb commit 6727830

File tree

6 files changed

+476
-38
lines changed

6 files changed

+476
-38
lines changed

crates/pallet-domains/src/benchmarking.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,16 @@ mod benchmarks {
759759
do_finalize_domain_epoch_staking::<T>(domain_id)
760760
.expect("finalize domain staking should success");
761761

762+
let current_domain_epoch_index = DomainStakingSummary::<T>::get(domain_id)
763+
.expect("domain must initialized")
764+
.current_epoch_index;
762765
Withdrawals::<T>::try_mutate(operator_id, nominator.clone(), |maybe_withdrawal| {
763766
let withdrawal = maybe_withdrawal.as_mut().unwrap();
764-
do_convert_previous_epoch_withdrawal::<T>(operator_id, withdrawal)?;
767+
do_convert_previous_epoch_withdrawal::<T>(
768+
operator_id,
769+
withdrawal,
770+
current_domain_epoch_index,
771+
)?;
765772
assert_eq!(withdrawal.withdrawals.len() as u32, w);
766773
Ok::<(), StakingError>(())
767774
})

crates/pallet-domains/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ mod pallet {
754754
#[pallet::storage]
755755
pub type SkipBalanceChecks<T> = StorageValue<_, BTreeSet<DomainId>, ValueQuery>;
756756

757+
/// TODO: remove after all "missing-share-price" withdrawal is unlocked on Taurus
758+
/// Storage that hold a domain epoch, for epoch that happen before it, the share price may
759+
/// be missing due to https://github.com/autonomys/subspace/issues/3459, in this case, we
760+
/// use the current share price as the default.
761+
#[pallet::storage]
762+
pub type AllowedDefaultSharePriceEpoch<T> = StorageValue<_, DomainEpoch, OptionQuery>;
763+
757764
#[derive(TypeInfo, Encode, Decode, PalletError, Debug, PartialEq)]
758765
pub enum BundleError {
759766
/// Can not find the operator for given operator id.

crates/pallet-domains/src/migrations.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ pub struct VersionUncheckedMigrateV3ToV4<T>(sp_std::marker::PhantomData<T>);
2525
impl<T: Config> UncheckedOnRuntimeUpgrade for VersionUncheckedMigrateV3ToV4<T> {
2626
fn on_runtime_upgrade() -> Weight {
2727
domain_balance_check_migration_migration::migrate_domain_balance_check::<T>()
28+
.saturating_add(
29+
domain_balance_check_migration_migration::migrate_domain_share_price_check::<T>(),
30+
)
2831
}
2932
}
3033

3134
mod domain_balance_check_migration_migration {
3235
use super::{BTreeSet, Config};
33-
use crate::SkipBalanceChecks;
36+
use crate::staking::DomainEpoch;
37+
use crate::{AllowedDefaultSharePriceEpoch, DomainStakingSummary, SkipBalanceChecks};
3438
use frame_support::pallet_prelude::Weight;
3539
use sp_core::Get;
3640
use sp_domains::DomainId;
@@ -41,4 +45,16 @@ mod domain_balance_check_migration_migration {
4145
SkipBalanceChecks::<T>::put(list);
4246
T::DbWeight::get().reads_writes(0, 1)
4347
}
48+
49+
pub(super) fn migrate_domain_share_price_check<T: Config>() -> Weight {
50+
// 1 read and 1 write
51+
let domain_id = DomainId::new(0);
52+
if let Some(staking_summary) = DomainStakingSummary::<T>::get(domain_id) {
53+
AllowedDefaultSharePriceEpoch::<T>::put(DomainEpoch::from((
54+
domain_id,
55+
staking_summary.current_epoch_index,
56+
)));
57+
}
58+
T::DbWeight::get().reads_writes(1, 1)
59+
}
4460
}

0 commit comments

Comments
 (0)