Skip to content

Commit

Permalink
Move Ticked to top-level module
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Jul 1, 2020
1 parent d224db4 commit 86f60f7
Show file tree
Hide file tree
Showing 43 changed files with 118 additions and 84 deletions.
Expand Up @@ -47,6 +47,7 @@ import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Dual
import Ouroboros.Consensus.Protocol.PBFT
import Ouroboros.Consensus.Ticked

import Ouroboros.Consensus.Byron.Crypto.DSIGN
import Ouroboros.Consensus.Byron.Ledger
Expand Down Expand Up @@ -240,9 +241,9 @@ forgeDualByronBlock cfg forgeState curBlockNo tickedLedger txs isLeader =
(castForgeState forgeState)
curBlockNo
(Ticked {
tickedSlotNo = curSlotNo
, tickedLedgerState = dualLedgerStateMain $
tickedLedgerState tickedLedger
tickedSlotNo = curSlotNo
, tickedState = dualLedgerStateMain $
tickedState tickedLedger
})
(map dualGenTxMain txs)
isLeader
Expand All @@ -251,8 +252,8 @@ forgeDualByronBlock cfg forgeState curBlockNo tickedLedger txs isLeader =
aux = forgeByronSpecBlock
curSlotNo
curBlockNo
(dualLedgerStateAux $ tickedLedgerState tickedLedger)
(dualLedgerStateAux $ tickedState tickedLedger)
(map dualGenTxAux txs)
(bridgeToSpecKey
(dualLedgerStateBridge $ tickedLedgerState tickedLedger)
(dualLedgerStateBridge $ tickedState tickedLedger)
(hashVerKey . deriveVerKeyDSIGN . pbftSignKey $ isLeader))
Expand Up @@ -45,6 +45,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.Protocol.PBFT
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.TypeFamilyWrappers

import Ouroboros.Consensus.Byron.Ledger
Expand Down Expand Up @@ -275,7 +276,7 @@ instance TxGen DualByronBlock where
-> m [GenTx DualByronBlock]
go acc 0 _ = return (reverse acc)
go acc n st = do
mTx <- hedgehogAdapter $ genTx cfg (tickedLedgerState st)
mTx <- hedgehogAdapter $ genTx cfg (tickedState st)
case mTx of
Nothing -> return (reverse acc)
Just tx ->
Expand Down
Expand Up @@ -33,6 +33,7 @@ import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Protocol.PBFT
import Ouroboros.Consensus.Ticked

import Ouroboros.Consensus.Byron.Crypto.DSIGN
import Ouroboros.Consensus.Byron.Ledger.Block
Expand Down Expand Up @@ -189,7 +190,7 @@ forgeRegularBlock cfg _forgeState curNo tickedLedger txs isLeader =
proof = CC.Block.mkProof body

prevHeaderHash :: CC.Block.HeaderHash
prevHeaderHash = case ledgerTipHash (tickedLedgerState tickedLedger) of
prevHeaderHash = case ledgerTipHash (tickedState tickedLedger) of
GenesisHash -> error
"the first block on the Byron chain must be an EBB"
BlockHash (ByronHash h) -> h
Expand Down
Expand Up @@ -65,6 +65,7 @@ import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.CommonProtocolParams
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Ticked

import Ouroboros.Consensus.Byron.Ledger.Block
import Ouroboros.Consensus.Byron.Ledger.Conversions
Expand Down
Expand Up @@ -66,6 +66,7 @@ import qualified Cardano.Chain.ValidationMode as CC

import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Condense

import Ouroboros.Consensus.Byron.Ledger.Block
Expand Down
Expand Up @@ -31,6 +31,7 @@ import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.CommonProtocolParams
import Ouroboros.Consensus.Ticked

import Ouroboros.Consensus.ByronSpec.Ledger.Accessors
import Ouroboros.Consensus.ByronSpec.Ledger.Block
Expand Down
Expand Up @@ -15,8 +15,8 @@ import GHC.Generics (Generic)

import Cardano.Prelude (AllowThunk (..), NoUnexpectedThunks)

import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ticked

import Ouroboros.Consensus.ByronSpec.Ledger.Block
import Ouroboros.Consensus.ByronSpec.Ledger.GenTx
Expand Down
Expand Up @@ -40,6 +40,7 @@ import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Time

import qualified Shelley.Spec.Ledger.BaseTypes as SL
Expand Down
Expand Up @@ -23,6 +23,7 @@ import Cardano.Crypto.Hash (HashAlgorithm)
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ticked

import qualified Shelley.Spec.Ledger.LedgerState as SL
import qualified Shelley.Spec.Ledger.STS.Ledger as STS
Expand Down Expand Up @@ -77,7 +78,7 @@ genTx
-> TickedLedgerState (ShelleyBlock (TPraosMockCrypto h))
-> Gen.GenEnv h
-> Gen (GenTx (ShelleyBlock (TPraosMockCrypto h)))
genTx _cfg Ticked { tickedSlotNo, tickedLedgerState } genEnv =
genTx _cfg Ticked { tickedSlotNo, tickedState } genEnv =
mkShelleyTx <$> Gen.genTx
genEnv
ledgerEnv
Expand All @@ -91,7 +92,7 @@ genTx _cfg Ticked { tickedSlotNo, tickedLedgerState } genEnv =
-- that point.
isSimpleTx (SL._body -> txb) =
(Seq.null $ SL._certs txb)
ShelleyLedgerState { shelleyState } = tickedLedgerState
ShelleyLedgerState { shelleyState } = tickedState

epochState :: CSL.EpochState h
epochState = SL.nesEs shelleyState
Expand Down
Expand Up @@ -22,6 +22,7 @@ import qualified Data.Sequence.Strict as Seq
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ticked

import qualified Shelley.Spec.Ledger.BlockChain as SL
import qualified Shelley.Spec.Ledger.Keys as SL
Expand Down Expand Up @@ -71,7 +72,7 @@ forgeShelleyBlock cfg forgeState curNo tickedLedger txs isLeader =
toShelleyPrevHash
. castHash
. ledgerTipHash
. tickedLedgerState
. tickedState
$ tickedLedger

mkBhBody toSign = SL.BHBody {
Expand Down
Expand Up @@ -75,6 +75,7 @@ import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.CommonProtocolParams
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Versioned

import qualified Control.State.Transition as STS
Expand Down Expand Up @@ -198,7 +199,7 @@ instance TPraosCrypto c
applyLedgerBlock cfg
blk
Ticked {
tickedLedgerState = ShelleyLedgerState {
tickedState = ShelleyLedgerState {
history
, shelleyState = oldShelleyState
}
Expand Down
Expand Up @@ -33,6 +33,7 @@ import Ouroboros.Network.Block (unwrapCBORinCBOR, wrapCBORinCBOR)

import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Condense

import qualified Shelley.Spec.Ledger.API as SL
Expand Down
Expand Up @@ -57,8 +57,8 @@ import Cardano.Prelude (Natural, NoUnexpectedThunks (..))
import Cardano.Slotting.EpochInfo

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Condense

import Control.State.Transition.Extended (applySTS)
Expand Down
Expand Up @@ -89,6 +89,7 @@ import Ouroboros.Consensus.Mock.Ledger.Address
import Ouroboros.Consensus.Mock.Ledger.State
import qualified Ouroboros.Consensus.Mock.Ledger.UTxO as Mock
import Ouroboros.Consensus.Protocol.Abstract (SecurityParam)
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util ((.:))
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Consensus.Util.Orphans ()
Expand Down
Expand Up @@ -21,6 +21,7 @@ import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Mock.Ledger.Block
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked

-- | Construct the protocol specific part of the block
--
Expand Down Expand Up @@ -60,7 +61,7 @@ forgeSimple ForgeExt { forgeExt } cfg forgeState curBlock tickedLedger txs proof

stdHeader :: SimpleStdHeader c ext
stdHeader = SimpleStdHeader {
simplePrev = ledgerTipHash (tickedLedgerState tickedLedger)
simplePrev = ledgerTipHash (tickedState tickedLedger)
, simpleSlotNo = curSlot
, simpleBlockNo = curBlock
, simpleBodyHash = hash body
Expand Down
Expand Up @@ -65,11 +65,11 @@ import Cardano.Prelude (NoUnexpectedThunks (..), fromMaybe)
import Cardano.Slotting.EpochInfo

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Mock.Ledger.Stake
import Ouroboros.Consensus.NodeId (CoreNodeId (..))
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Protocol.Signed
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Condense

{-------------------------------------------------------------------------------
Expand Down
Expand Up @@ -92,6 +92,7 @@ import Ouroboros.Consensus.Node.Tracers
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.NodeKernel as NodeKernel
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Consensus.Util.Orphans ()
Expand Down Expand Up @@ -771,7 +772,7 @@ runThreadNetwork systemTime ThreadNetworkArgs
where
EpochNo x = currentEpoch
EpochSize y = epochSize0
let p = ledgerTipPoint' (Proxy @blk) $ tickedLedgerState tickedLdgSt
let p = ledgerTipPoint' (Proxy @blk) $ tickedState tickedLdgSt

let needEBB = inFirstEra && NotOrigin ebbSlot > pointSlot p
case mbForgeEbbEnv <* guard needEBB of
Expand Down
Expand Up @@ -96,6 +96,7 @@ import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Protocol.BFT
import Ouroboros.Consensus.Protocol.MockChainSel
import Ouroboros.Consensus.Protocol.Signed
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Consensus.Util.Orphans ()

Expand Down
1 change: 1 addition & 0 deletions ouroboros-consensus/ouroboros-consensus.cabal
Expand Up @@ -143,6 +143,7 @@ library
Ouroboros.Consensus.Protocol.PBFT.State
Ouroboros.Consensus.Protocol.PBFT.State.HeaderHashBytes
Ouroboros.Consensus.Protocol.Signed
Ouroboros.Consensus.Ticked
Ouroboros.Consensus.TypeFamilyWrappers
Ouroboros.Consensus.Util
Ouroboros.Consensus.Util.AnchoredFragment
Expand Down
Expand Up @@ -64,6 +64,7 @@ import Ouroboros.Consensus.Node.Serialisation
import Ouroboros.Consensus.Protocol.Abstract
import qualified Ouroboros.Consensus.Storage.ChainDB.Init as InitChainDB
import Ouroboros.Consensus.Storage.ChainDB.Serialisation
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.TypeFamilyWrappers

import Ouroboros.Consensus.HardFork.Abstract
Expand Down
Expand Up @@ -19,6 +19,7 @@ import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Consensus.Util.SOP

Expand All @@ -33,14 +34,14 @@ instance (CanHardFork xs, All CanForge xs) => CanForge (HardForkBlock xs) where
type ExtraForgeState (HardForkBlock xs) = PerEraExtraForgeState xs

forgeBlock cfg forgeState bno
Ticked { tickedSlotNo, tickedLedgerState }
Ticked { tickedSlotNo, tickedState }
txs isLeader =
-- First establish the 'IsLeader' and the 'LedgerState' are from the
-- same era. As we have passed the ledger view of the ticked ledger to
-- obtain the 'IsLeader' value, it __must__ be from the same era.
case State.match
(getOneEraIsLeader isLeader)
(getHardForkLedgerState tickedLedgerState) of
(getHardForkLedgerState tickedState) of
Left _mismatch ->
error "IsLeader from different era than the TickedLedgerState"
Right matched ->
Expand All @@ -57,7 +58,7 @@ instance (CanHardFork xs, All CanForge xs) => CanForge (HardForkBlock xs) where
ei :: EpochInfo Identity
ei = State.epochInfoLedger
(configLedger cfg)
(getHardForkLedgerState tickedLedgerState)
(getHardForkLedgerState tickedState)

-- | Unwraps all the layers needed for SOP and call 'forgeBlock'.
matchedForgeBlock
Expand Down
Expand Up @@ -38,6 +38,7 @@ import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.TypeFamilyWrappers

import Ouroboros.Consensus.HardFork.Combinator.Abstract
Expand Down
Expand Up @@ -33,6 +33,7 @@ import Cardano.Prelude (NoUnexpectedThunks)

import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.TypeFamilyWrappers

import Ouroboros.Consensus.HardFork.Combinator.Abstract
Expand Down
Expand Up @@ -32,8 +32,8 @@ import GHC.Generics (Generic)
import Cardano.Prelude (NoUnexpectedThunks)

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Consensus.Util ((..:), (.:))
import Ouroboros.Consensus.Util.SOP
Expand Down
Expand Up @@ -68,8 +68,8 @@ import Cardano.Prelude (NoUnexpectedThunks)

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Abstract (Ticked)
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Ticked
import qualified Ouroboros.Consensus.Util.CBOR as Util.CBOR

{-------------------------------------------------------------------------------
Expand Down
Expand Up @@ -42,6 +42,7 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Type
import Ouroboros.Consensus.Block.Abstract
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.Basics
import Ouroboros.Consensus.Ticked
import Ouroboros.Consensus.Util (repeatedly, repeatedlyM)

{-------------------------------------------------------------------------------
Expand Down

0 comments on commit 86f60f7

Please sign in to comment.