-
Notifications
You must be signed in to change notification settings - Fork 86
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
The HardFork protocol combinator #1175
Conversation
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/ChainState.hs
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/ChainState.hs
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/ChainState.hs
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/ChainState.hs
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/OuroborosTag.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/OuroborosTag.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/OuroborosTag.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/Ouroboros/Consensus/Protocol/HardFork/OuroborosTag.hs
Outdated
Show resolved
Hide resolved
|
||
-- Rewind chain state | ||
|
||
rewindChainState (HardForkCfg cfgP1 cfgP2) cstate mSlotNo = |
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 rewind window might be too large (P2 might restrict the window, but if we have a snapshot, we could rollback anyway). Think about whether we could tighten this (related: dropSnapshotIfNeeded
).
d6675c5
to
dc5587a
Compare
Will need rebasing on #1227 . |
This still uses
but actually the hard fork combinator should use a concrete type for blocks and for headers, which adds the necessary envelope. This isn't implemented yet, but we did discuss the binary format: Binary format for the hard fork combinatorThe binary format used for one ledger (say, Byron) should not have to take into Nonetheless, hard forks -- points in the block chain where we switch over from One option is to hope that by a stroke of luck, the binary formats of the Note that such an envelope must be anticipated from the start. We cannot Unfortunately, of course, the current Byron chain does not include this Very concretely, the decoder for a Byron block is fromCBORABlockOrBoundary
:: EpochSlots -> Decoder s (ABlockOrBoundary ByteSpan)
fromCBORABlockOrBoundary epochSlots = do
enforceSize "Block" 2
fromCBOR @Word >>= \case
0 -> ABOBBoundary <$> fromCBORABoundaryBlock
1 -> ABOBBlock <$> fromCBORABlock epochSlots
t -> cborError $ DecoderErrorUnknownTag "Block" (fromIntegral t) and for a Byron header fromCBORABlockOrBoundaryHdr :: CC.EpochSlots
-> Decoder s (ABlockOrBoundaryHdr ByteSpan)
fromCBORABlockOrBoundaryHdr epochSlots = do
enforceSize "ABlockOrBoundaryHdr" 2
fromCBOR @Word >>= \case
0 -> ABOBBoundaryHdr <$> CC.fromCBORABoundaryHeader
1 -> ABOBBlockHdr <$> CC.fromCBORAHeader epochSlots
t -> error $ "Unknown tag in encoded HeaderOrBoundary" <> show t That is, both consist of a CBOR 2-tuple, with either 0 or 1 in the first This makes the hard fork envelope entirely backwards compatible with the Byron |
dc5587a
to
dae59b3
Compare
This only introduces the protocol combinator, not yet the ledger integration. We might still end up tweaking this a bit. Co-authored-by: Rupert Horlick <rupert.horlick@iohk.io>
This design currently assumes the |
We might have to rethink the |
After discussing this with @dnadales , useful to be very explicit: the hard fork combinator _must be |
Sketching out what the header should look like: data HardForkHeader before after =
BeforeHeader (Header before)
| BoundaryHeader (HeaderHash before) (Header after)
| AfterHeader (Header after) The data HardForkHeaderHash before after =
BeforeHeaderHash (HeaderHash before)
| AfterHeaderHash (HeaderHash after)
type instance HeaderHash (HardForkHeader before after) =
HardForkHeaderHash before after
instance HasHeader (HardForkHeader before after) where
blockPrevHash (BoundaryHeader finalBefore hdr) =
case blockPrevHash hdr of
BlockHash _ -> error "invariant violation"
GenesisHash -> BlockHash (BeforeHeaderHash finalBefore)
blockPrevHash (AfterHeader hdr) =
case blockPrevHash hdr of
GenesisHash -> error "invariant violation"
BlockHash b -> BlockHash (AfterHeaderHash b) (and exactly the same for blocks). |
The Shelley ledger will need to be updated so that the prev hash it uses is something like this: data PrevHash crypto
-- | The first Shelley block
--
-- For a Shelley only chain, the hash here would be the hash of the genesis config.
-- For a Byron/Shelley chain, the hash here would be the hash of the final Byron block.
Genesis !(HashHeader crypto)
-- | Any subsequent block
| Block !(HashHeader crypto)` |
Change of plan re Shelley. See IntersectMBO/cardano-ledger#1266 (comment) . |
2003: Hard-fork compatible `BlockchainTime` r=edsko a=edsko Closes #1637 Closes #1205 (opened #2002 for the remaining work). Depends on #1989 This finally unblocks the further development of the hard fork combinator at #1175 . Co-authored-by: Edsko de Vries <edsko@well-typed.com> Co-authored-by: Thomas Winant <thomas@well-typed.com>
2003: Hard-fork compatible `BlockchainTime` r=edsko a=edsko Closes #1637 Closes #1205 (opened #2002 for the remaining work). Depends on #1989 This finally unblocks the further development of the hard fork combinator at #1175 . Co-authored-by: Edsko de Vries <edsko@well-typed.com> Co-authored-by: Thomas Winant <thomas@well-typed.com>
2003: Hard-fork compatible `BlockchainTime` r=edsko a=edsko Closes #1637 Closes #1205 (opened #2002 for the remaining work). Depends on #1989 This finally unblocks the further development of the hard fork combinator at #1175 . Co-authored-by: Edsko de Vries <edsko@well-typed.com> Co-authored-by: Thomas Winant <thomas@well-typed.com>
2003: Hard-fork compatible `BlockchainTime` r=edsko a=edsko Closes #1637 Closes #1205 (opened #2002 for the remaining work). Depends on #1989 This finally unblocks the further development of the hard fork combinator at #1175 . Co-authored-by: Edsko de Vries <edsko@well-typed.com> Co-authored-by: Thomas Winant <thomas@well-typed.com>
Obsoleted by #2034. |
2003: Hard-fork compatible `BlockchainTime` r=edsko a=edsko Closes #1637 Closes #1205 (opened #2002 for the remaining work). Depends on #1989 This finally unblocks the further development of the hard fork combinator at #1175 . Co-authored-by: Edsko de Vries <edsko@well-typed.com> Co-authored-by: Thomas Winant <thomas@well-typed.com>
This only introduces the protocol combinator, not yet the ledger
integration. We might still end up tweaking this a bit.
Co-authored-by: Rupert Horlick rupert.horlick@iohk.io