Skip to content

P10->P11 migration into Rust block state#1635

Open
allanbrondum wants to merge 1 commit into
ar/psr-91-implement-migration-of-rust-block-state-and-block-statefrom
ar/psr-90-haskell-side-migration-implementation_2
Open

P10->P11 migration into Rust block state#1635
allanbrondum wants to merge 1 commit into
ar/psr-91-implement-migration-of-rust-block-state-and-block-statefrom
ar/psr-90-haskell-side-migration-implementation_2

Conversation

@allanbrondum

@allanbrondum allanbrondum commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Purpose

Implement migration of the Rust block state from P10 to P11 on the Haskell side.

Changes

The P10 PLT state is loaded by Rust and then migrated to P11 by Rust also.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

ProtocolLevelTokensNone :: (PltStateVersionFor pv ~ 'PLTStateNone) => ProtocolLevelTokensForStateVersion pv
ProtocolLevelTokensV0 :: (PltStateVersionFor pv ~ 'PLTStateV0) => (HashedBufferedRef' ProtocolLevelTokensHash ProtocolLevelTokens) -> ProtocolLevelTokensForStateVersion pv
ProtocolLevelTokensV1 :: (PltStateVersionFor pv ~ 'PLTStateV1) => RustBS.ForeignPLTBlockStatePtr pv -> ProtocolLevelTokensForStateVersion pv
data ProtocolLevelTokensForPV (pv :: ProtocolVersion) where

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just renamed and reformatted

Comment on lines +513 to +523
-- Migrate from Haskell to Rust, by reloading the PLT state from the blob store and into Rust and then
-- migrate the newly loaded state in the Rust block state implementation.
let oldBlobRefMaybe = getHBRRefIfBlobbed oldPLTsRef
let oldBlobRef =
maybe
(error "Haskell maintained PLT state to migrate from does not have blob reference set")
id
oldBlobRefMaybe
(oldState :: ForeignPLTBlockStatePtr (MPV m)) <- lift $ loadDirect (coerce oldBlobRef)
ProtocolLevelTokensV1 <$> RustBS.migrate oldState
migrateProtocolLevelTokensForPV migration (ProtocolLevelTokensV1 oldState) =

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual migration logic

@allanbrondum allanbrondum changed the title Migration of Rust block state P10->P11 migration into Rust block state Apr 23, 2026
Comment on lines +515 to +520
let oldBlobRefMaybe = getHBRRefIfBlobbed oldPLTsRef
let oldBlobRef =
maybe
(error "Haskell maintained PLT state to migrate from does not have blob reference set")
id
oldBlobRefMaybe

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let oldBlobRefMaybe = getHBRRefIfBlobbed oldPLTsRef
let oldBlobRef =
maybe
(error "Haskell maintained PLT state to migrate from does not have blob reference set")
id
oldBlobRefMaybe
(_, oldBlobRef) <- lift $ refFlush oldPLTsRef

Comment on lines +1077 to +1084
-- | Get the 'BlobRef' if the value in the reference is stored in the blob store. Else
-- 'Nothing' is returned.
getBRRefIfBlobbed ::
BufferedRef a -> Maybe (BlobRef a)
getBRRefIfBlobbed (BRBlobbed ref) = Just ref
getBRRefIfBlobbed (BRMemory _ _) = Nothing
getBRRefIfBlobbed (BRBoth ref _) = Just ref

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using refFlush

Comment on lines +1702 to +1707
-- | Get the 'BlobRef' if value in the reference is stored in the blob store. Else
-- 'Nothing' is returned.
getHBRRefIfBlobbed ::
HashedBufferedRef' h a -> Maybe (BlobRef a)
getHBRRefIfBlobbed (HashedBufferedRef br _) = getBRRefIfBlobbed br

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using refFlush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants