Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Test.Ouroboros.Network.Diffusion.Node.ChainDB
Synopsis
- data ChainDB block m = ChainDB {
- cdbIndexVar :: TVar m (Map (ChainHash block) [block])
- cdbLongestChainVar :: TVar m (Chain block)
- newtype SelectChain block = SelectChain {
- getSelectedChain :: Chain block
- newChainDB :: MonadSTM m => m (ChainDB block m)
- addBlock :: (MonadSTM m, HasFullHeader block) => block -> ChainDB block m -> STM m ()
- getBlockPointSet :: (MonadSTM m, HasHeader block) => ChainDB block m -> STM m (Set (Point block))
Documentation
ChainDB is an in memory store of all fetched (downloaded) blocks.
This type holds an index mapping previous hashes to their blocks (i.e. if a block A has prevHash H then the entry "H -> [A]" exists in the map) and the current version of the longest chain.
Used to simulate real world ChainDB, it offers the invariant that
cdbLongestChainVar
is always the longest known chain of downloaded blocks.
Whenever a node generates a new block it gets added here, and whenever it gets
a block via block fetch it gets added here as well. Everytime addBlock
is
called the possibly new longest chain gets computed, since the API is atomic
we can guarantee that in each moment ChainDB has the current longest chain.
This type is used in diffusion simulation.
Constructors
ChainDB | |
Fields
|
newtype SelectChain block Source #
Chain selection as a Monoid
.
Constructors
SelectChain | |
Fields
|
Instances
HasHeader block => Monoid (SelectChain block) Source # | |
Defined in Test.Ouroboros.Network.Diffusion.Node.ChainDB Methods mempty :: SelectChain block Source # mappend :: SelectChain block -> SelectChain block -> SelectChain block Source # mconcat :: [SelectChain block] -> SelectChain block Source # | |
HasHeader block => Semigroup (SelectChain block) Source # | |
Defined in Test.Ouroboros.Network.Diffusion.Node.ChainDB Methods (<>) :: SelectChain block -> SelectChain block -> SelectChain block Source # sconcat :: NonEmpty (SelectChain block) -> SelectChain block Source # stimes :: Integral b => b -> SelectChain block -> SelectChain block Source # |
newChainDB :: MonadSTM m => m (ChainDB block m) Source #
Constructs a new ChainDB, the index has only 1 value which is the
GenesisHash
but this hash does not map to any block.
addBlock :: (MonadSTM m, HasFullHeader block) => block -> ChainDB block m -> STM m () Source #
Adds a block to ChainDB.
This function also recomputes the longest chain with the new block information.
getBlockPointSet :: (MonadSTM m, HasHeader block) => ChainDB block m -> STM m (Set (Point block)) Source #
Constructs the block Point set of all downloaded blocks