Skip to content
Permalink
Browse files

Merge #920

920: Make the StartTime part of RunNode r=Jimbo4350 a=mrBliss

When starting a node, the `nodeStartTime` method can be used to obtain the
start time. This method will return the right time for each block type, and
thus protocol. For example, for real Byron blocks, it will extract it from the
Genesis config. For mock blocks, it will just use some hard-coded dummy date,
since the start time is not important for mock blocks.

Co-authored-by: Thomas Winant <thomas@well-typed.com>
  • Loading branch information...
iohk-bors and mrBliss committed Aug 13, 2019
2 parents e1a81a3 + 3e055c4 commit d69ef321766b33a8d1152b7bfa039717b543f162
@@ -19,6 +19,7 @@ import Ouroboros.Network.Block (BlockNo, ChainHash (..), HeaderHash,
import Ouroboros.Network.BlockFetch (SizeInBytes)

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime (SystemStart)
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Byron
import Ouroboros.Consensus.Mempool
@@ -42,6 +43,10 @@ class (ProtocolLedgerView blk, ApplyTx blk) => RunNode blk where
nodeIsEBB :: blk -> Bool
nodeEpochSize :: Monad m
=> Proxy blk -> EpochNo -> m EpochSize
nodeStartTime :: Proxy blk
-> NodeConfig (BlockProtocol blk)
-> SystemStart


-- Encoders
nodeEncodeBlock :: NodeConfig (BlockProtocol blk) -> blk -> Encoding
@@ -7,11 +7,15 @@ module Ouroboros.Consensus.Node.Run.Byron () where
import Data.Reflection (given)

import qualified Cardano.Chain.Block as Cardano.Block
import Ouroboros.Consensus.Ledger.Byron
import Ouroboros.Consensus.Node.Run.Abstract
import qualified Cardano.Chain.Genesis as Genesis

import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
import Ouroboros.Consensus.Ledger.Byron
import Ouroboros.Consensus.Ledger.Byron.Config
import Ouroboros.Consensus.Ledger.Byron.Forge
import Ouroboros.Consensus.Node.Run.Abstract
import Ouroboros.Consensus.Protocol.ExtNodeConfig
import Ouroboros.Consensus.Protocol.WithEBBs

{-------------------------------------------------------------------------------
RunNode instance
@@ -26,6 +30,15 @@ instance ByronGiven => RunNode (ByronBlockOrEBB ByronConfig) where
Cardano.Block.ABOBBoundary _ -> True
nodeEpochSize = \_ _ -> return 21600 -- TODO #226

-- Extract it from the 'Genesis.Config'
nodeStartTime = const
$ SystemStart
. Genesis.gdStartTime
. Genesis.configGenesisData
. pbftGenesisConfig
. encNodeConfigExt
. unWithEBBNodeConfig

nodeEncodeBlock = const encodeByronBlock
nodeEncodeHeader = const encodeByronHeader
nodeEncodeGenTx = encodeByronGenTx
@@ -6,9 +6,12 @@
module Ouroboros.Consensus.Node.Run.Mock () where

import Codec.Serialise (Serialise, decode, encode)
import Data.Time.Calendar (fromGregorian)
import Data.Time.Clock (UTCTime (..))
import Data.Typeable (Typeable)

import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Mock
import Ouroboros.Consensus.Node.Run.Abstract
@@ -37,6 +40,10 @@ instance ( ProtocolLedgerView (SimpleBlock SimpleMockCrypto ext)
nodeBlockFetchSize = fromIntegral . simpleBlockSize . simpleHeaderStd
nodeIsEBB = const False
nodeEpochSize = \_ _ -> return 21600
nodeStartTime = \_ _ -> SystemStart dummyDate
where
-- This doesn't matter much
dummyDate = UTCTime (fromGregorian 2019 8 13) 0

nodeEncodeBlock = const encode
nodeEncodeHeader = const encode

0 comments on commit d69ef32

Please sign in to comment.
You can’t perform that action at this time.