-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: utxo-hd-main
Are you sure you want to change the base?
Conversation
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shelley instance is trivial
...oros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Ledger.hs
Outdated
Show resolved
Hide resolved
5f97360
to
88b224f
Compare
pushDiffs newtbs diffs | ||
newst = forgetLedgerTables st' | ||
|
||
pushDiffs newtbs st' st' |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay!
LedgerTables | ||
$ ValuesMK | ||
$ ( | ||
if (nsToIndex $ Telescope.tip hs0) /= (nsToIndex $ Telescope.tip hs1) |
There was a problem hiding this comment.
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
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Ledger.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Node/Run.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/InMemory.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/InMemory.hs
Outdated
Show resolved
Hide resolved
...boros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/LedgerSeq.hs
Outdated
Show resolved
Hide resolved
...boros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2/LedgerSeq.hs
Show resolved
Hide resolved
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Ledger.hs
Outdated
Show resolved
Hide resolved
88b224f
to
62fa65a
Compare
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.