-
Notifications
You must be signed in to change notification settings - Fork 24
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!
@@ -178,6 +178,7 @@ load :: | |||
( LedgerDbSerialiseConstraints blk | |||
, CanStowLedgerTables (LedgerState blk) | |||
, LedgerSupportsProtocol blk | |||
, V2.CanUpgradeLedgerTables (LedgerState blk) |
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.
LedgerSupportsV2LedgerDB
@@ -226,6 +227,7 @@ store :: | |||
( LedgerDbSerialiseConstraints blk | |||
, CanStowLedgerTables (LedgerState blk) | |||
, LedgerSupportsProtocol blk | |||
, V2.CanUpgradeLedgerTables (LedgerState blk) |
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.
LedgerSupportsV2LedgerDB
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
if (nsToIndex $ Telescope.tip hs0) /= (nsToIndex $ Telescope.tip hs1) | ||
then extendTables (hmap (const (K ())) $ Telescope.tip hs1) | ||
else id) | ||
$ vs |
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.
Calling Telescope.tip
on hs1
twice
@@ -106,6 +107,7 @@ class ( LedgerSupportsProtocol blk | |||
, ShowProxy (BlockQuery blk) | |||
, ShowProxy (TxId (GenTx blk)) | |||
, (forall fp. ShowQuery (BlockQuery blk fp)) | |||
, V2.LedgerSupportsV2LedgerDB blk |
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.
The V2.
prefix might be dropped, since the constraint name already includes V2
. This also applies to the same qualified imports in the other modules in this PR
-- * Snapshots | ||
, CanUpgradeLedgerTables (..) |
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.
CanUpgradeLedgerTables
is not part of snapshots
@@ -104,10 +116,10 @@ newInMemoryLedgerTablesHandle someFS@(SomeHasFS hasFS) l = do | |||
, readAll = do | |||
hs <- readTVarIO tv | |||
guardClosed hs pure | |||
, pushDiffs = \(!diffs) -> | |||
, pushDiffs = \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.
, pushDiffs = \st0 (!diffs) -> | |
, pushDiffs = \st0 !diffs -> |
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 looks wrong, passing in the same state twice?
@@ -81,7 +81,7 @@ data LedgerTablesHandle m l = LedgerTablesHandle { | |||
-- | Costly read all operation, not to be used in Consensus but only in | |||
-- snapshot-converter executable. | |||
, readAll :: !(m (LedgerTables l ValuesMK)) | |||
, pushDiffs :: !(LedgerTables l DiffMK -> m ()) | |||
, pushDiffs :: !(forall mk. l mk -> l DiffMK -> m ()) |
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 would benefit from some docs explaining about how the two ledger state should be related
@@ -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 |
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.
Slightly long line
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.