Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement migrate accountV3toV4 #1300

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ initialPrePreCooldownQueue target =
}

-- | Migrate a cooldown queue unchanged.
migrateCooldownQueue :: forall m t av. (SupportMigration m t) => CooldownQueue av -> t m (CooldownQueue av)
migrateCooldownQueue :: forall m t av1 av2. (SupportMigration m t, AVSupportsFlexibleCooldown av2) => CooldownQueue av1 -> t m (CooldownQueue av2)
migrateCooldownQueue EmptyCooldownQueue = return EmptyCooldownQueue
migrateCooldownQueue (CooldownQueue queueRef) =
CooldownQueue <$> migrateEagerBufferedRef return queueRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,32 @@ migratePersistentAccountStakeEnduringV2toV3 PersistentAccountStakeEnduringDelega
liftStakedBalanceStateTT $ retainDelegator paseDelegatorId oldStake newTarget
return $!! (newDelegatorInfo, emptyCooldownQueue)

-- | Migrate PersistentAccountStakeEnduring from AccountV3 to AccountV4. There
-- are no pending changes to take care of in V3, only the BakerInfoExV1 data
-- type needs to be migrated by setting the new `_bieIsSuspended` flag to
-- false.
migratePersistentAccountStakeEnduringV3toV4 ::
(SupportMigration m t, AccountMigration 'AccountV4 (t m)) =>
PersistentAccountStakeEnduring 'AccountV3 ->
-- | Returns the new 'PersistentAccountStakeEnduring' and 'CooldownQueue'.
t m (PersistentAccountStakeEnduring 'AccountV4)
migratePersistentAccountStakeEnduringV3toV4 PersistentAccountStakeEnduringNone =
return PersistentAccountStakeEnduringNone
migratePersistentAccountStakeEnduringV3toV4 PersistentAccountStakeEnduringBaker{..} = do
newBakerInfo <- migrateReference (return . (\BakerInfoExV1{..} -> BakerInfoExV1{_bieIsSuspended = CTrue False, ..})) paseBakerInfo
return
PersistentAccountStakeEnduringBaker
{ paseBakerInfo = newBakerInfo,
paseBakerPendingChange = NoChange,
..
}
migratePersistentAccountStakeEnduringV3toV4 PersistentAccountStakeEnduringDelegator{..} =
return $!
PersistentAccountStakeEnduringDelegator
{ paseDelegatorPendingChange = NoChange,
..
}

-- | This relies on the fact that the 'AccountV2' hashing of 'AccountStake' is independent of the
-- staked amount.
instance (MonadBlobStore m) => MHashableTo m (AccountStakeHash 'AccountV2) (PersistentAccountStakeEnduring 'AccountV2) where
Expand Down Expand Up @@ -1968,6 +1994,34 @@ migrateEnduringDataV2toV3 ed = do
paedStake
paedStakeCooldown

migrateEnduringDataV3toV4 ::
(SupportMigration m t, AccountMigration 'AccountV4 (t m), MonadLogger (t m)) =>
-- | Current enduring data
PersistentAccountEnduringData 'AccountV3 ->
-- | New enduring data.
t m (PersistentAccountEnduringData 'AccountV4)
migrateEnduringDataV3toV4 ed = do
logEvent GlobalState LLTrace "Migrating persisting data"
paedPersistingData <- migrateEagerBufferedRef return (paedPersistingData ed)
paedEncryptedAmount <- forM (paedEncryptedAmount ed) $ \e -> do
logEvent GlobalState LLTrace "Migrating encrypted amount"
migrateReference migratePersistentEncryptedAmount e
paedReleaseSchedule <- forM (paedReleaseSchedule ed) $ \(oldRSRef, lockedAmt) -> do
logEvent GlobalState LLTrace "Migrating release schedule"
newRSRef <- migrateReference migrateAccountReleaseSchedule oldRSRef
return (newRSRef, lockedAmt)
logEvent GlobalState LLTrace "Migrating stake"
paedStake <- migratePersistentAccountStakeEnduringV3toV4 (paedStake ed)
logEvent GlobalState LLTrace "Migrating cooldown queue"
paedStakeCooldown <- migrateCooldownQueue (paedStakeCooldown ed)
logEvent GlobalState LLTrace "Reconstructing account enduring data"
makeAccountEnduringDataAV4
paedPersistingData
paedEncryptedAmount
paedReleaseSchedule
paedStake
paedStakeCooldown

-- | Migration for 'PersistentAccountEnduringData'. Only supports 'AccountV3'.
-- The data is unchanged in the migration.
migrateEnduringDataV3toV3 ::
Expand Down Expand Up @@ -2081,11 +2135,21 @@ migrateV3ToV3 acc = do
migrateV3ToV4 ::
( MonadBlobStore m,
MonadBlobStore (t m),
MonadTrans t
AccountMigration 'AccountV4 (t m),
MonadTrans t,
MonadLogger (t m)
) =>
PersistentAccount 'AccountV3 ->
t m (PersistentAccount 'AccountV4)
migrateV3ToV4 _acc = error "TODO(drsk) github #1221. implement migrateV3ToV4"
migrateV3ToV4 acc = do
(accountEnduringData) <- migrateEagerBufferedRef migrateEnduringDataV3toV4 (accountEnduringData acc)
return $!
PersistentAccount
{ accountNonce = accountNonce acc,
accountAmount = accountAmount acc,
accountStakedAmount = accountStakedAmount acc,
..
}

-- | A trivial migration from account version 4 to account version 4.
-- In particular the data is retained as-is.
Expand Down
Loading