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

Translate tables if needed when pushing diffs in V2 #1360

Open
wants to merge 2 commits into
base: utxo-hd-main
Choose a base branch
from

Conversation

jasagredo
Copy link
Contributor

The new function upgradeTables (local to the V2 implementation) will be used when pushing diffs, giving it the current tip and the new tip with diffs (as returned by the ledger rules). If can then choose to eject all txouts to the new tip index (performing translations) then reinjecting them. This should only be called when we are crossing an era boundary.

atomically
$ modifyTVar tv
(\r -> guardClosed r (LedgerTablesHandleOpen . flip (ltliftA2 (\(ValuesMK vals) (DiffMK d) -> ValuesMK (Diff.applyDiff vals d))) diffs))
(\r -> guardClosed r (LedgerTablesHandleOpen . flip (ltliftA2 (\(ValuesMK vals) (DiffMK d) -> ValuesMK (Diff.applyDiff vals d))) (projectLedgerTables diffs) . upgradeTables st0 diffs))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the place where upgradeTables is used.

@@ -1110,6 +1112,44 @@ class ( Show (HardForkTxOut xs)
default txOutEjections :: CanHardFork xs => NP (K (NS WrapTxOut xs) -.-> WrapTxOut) xs
txOutEjections = composeTxOutTranslations $ ipTranslateTxOut hardForkEraTranslation

instance (CanHardFork xs, HasHardForkTxOut xs) => CanUpgradeLedgerTables (LedgerState (HardForkBlock xs)) where
upgradeTables
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where we define it for the HardForkBlock (so for Cardano)

@@ -527,3 +528,6 @@ decodeByronResult :: BlockQuery ByronBlock fp result
-> forall s. Decoder s result
decodeByronResult query = case query of
GetUpdateInterfaceState -> fromByronCBOR

instance V2.CanUpgradeLedgerTables (LedgerState ByronBlock) where
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Byron instance is trivial

@@ -754,3 +755,6 @@ decodeShelleyLedgerState = decodeVersion [
, shelleyLedgerTransition
, shelleyLedgerTables = emptyLedgerTables
}

instance V2.CanUpgradeLedgerTables (LedgerState (ShelleyBlock proto era)) where
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shelley instance is trivial

@jasagredo jasagredo force-pushed the utxo-hd-txout-fwd-3 branch from 5f97360 to 88b224f Compare January 17, 2025 12:01
pushDiffs newtbs diffs
newst = forgetLedgerTables st'

pushDiffs newtbs st' st'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is wrong. It should be st st'

Copy link
Contributor

@jorisdral jorisdral left a comment

Choose a reason for hiding this comment

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

Looks okay!

ouroboros-consensus-cardano/app/snapshot-converter.hs Outdated Show resolved Hide resolved
ouroboros-consensus-cardano/app/snapshot-converter.hs Outdated Show resolved Hide resolved
LedgerTables
$ ValuesMK
$ (
if (nsToIndex $ Telescope.tip hs0) /= (nsToIndex $ Telescope.tip hs1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can write something more direct by recursing on both telescopes. Or maybe something like this already exists, like matchTelescope.

It's maybe not a super important optimisation to apply, what do you think? We'll be calling this function every time we push diffs

@jasagredo jasagredo force-pushed the utxo-hd-txout-fwd-3 branch from 88b224f to 62fa65a Compare January 20, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants