Copyright | No rights reserved |
---|---|
License | UNLICENSE |
Maintainer | xenog@protonmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
State and code for block header synchronization.
Synopsis
- dataVersion :: Word32
- data ChainDataVersionKey = ChainDataVersionKey
- data ChainState p = ChainState {}
- newtype BlockHeaderKey = BlockHeaderKey BlockHash
- data BestBlockKey = BestBlockKey
- type MonadChainLogic a p m = (BlockHeaders m, MonadReader (ChainReader a p) m)
- data ChainReader a p = ChainReader {
- myReader :: !a
- myChainDB :: !DB
- chainState :: !(TVar (ChainState p))
- initChainDB :: (MonadChainLogic a p m, MonadUnliftIO m) => Network -> m ()
- purgeChainDB :: (MonadChainLogic a p m, MonadUnliftIO m) => m ()
- importHeaders :: (MonadIO m, BlockHeaders m) => Network -> [BlockHeader] -> m (Either PeerException Bool)
- notifySynced :: (MonadIO m, MonadChainLogic a p m) => m Bool
- nextPeer :: (MonadIO m, MonadChainLogic a p m) => m (Maybe p)
- syncHeaders :: (Eq p, MonadChainLogic a p m, MonadIO m) => BlockNode -> p -> m GetHeaders
- setLastReceived :: (MonadChainLogic a p m, MonadIO m) => m ()
- addPeer :: (Eq p, MonadIO m, MonadChainLogic a p m) => p -> m ()
- getSyncingPeer :: (MonadChainLogic a p m, MonadIO m) => m (Maybe p)
- setSyncingPeer :: (MonadChainLogic a p m, MonadIO m) => p -> m ()
- isSynced :: (MonadChainLogic a p m, MonadIO m) => m Bool
- setSynced :: (MonadChainLogic a p m, MonadIO m) => m ()
- finishPeer :: (Eq p, MonadIO m, MonadChainLogic a p m) => p -> m ()
- lastMessage :: (MonadChainLogic a p m, MonadIO m) => m (Maybe (p, UTCTime))
Documentation
dataVersion :: Word32 Source #
Version of the database.
data ChainDataVersionKey Source #
Database key for version.
Instances
newtype BlockHeaderKey Source #
Key for block header in database.
Instances
Eq BlockHeaderKey Source # | |
Defined in Network.Haskoin.Node.Chain.Logic (==) :: BlockHeaderKey -> BlockHeaderKey -> Bool # (/=) :: BlockHeaderKey -> BlockHeaderKey -> Bool # | |
Show BlockHeaderKey Source # | |
Defined in Network.Haskoin.Node.Chain.Logic showsPrec :: Int -> BlockHeaderKey -> ShowS # show :: BlockHeaderKey -> String # showList :: [BlockHeaderKey] -> ShowS # | |
Serialize BlockHeaderKey Source # | |
Defined in Network.Haskoin.Node.Chain.Logic put :: Putter BlockHeaderKey # get :: Get BlockHeaderKey # | |
KeyValue BlockHeaderKey BlockNode Source # | |
Defined in Network.Haskoin.Node.Chain.Logic |
data BestBlockKey Source #
Key for best block in database.
Instances
Eq BestBlockKey Source # | |
Defined in Network.Haskoin.Node.Chain.Logic (==) :: BestBlockKey -> BestBlockKey -> Bool # (/=) :: BestBlockKey -> BestBlockKey -> Bool # | |
Show BestBlockKey Source # | |
Defined in Network.Haskoin.Node.Chain.Logic showsPrec :: Int -> BestBlockKey -> ShowS # show :: BestBlockKey -> String # showList :: [BestBlockKey] -> ShowS # | |
Serialize BestBlockKey Source # | |
Defined in Network.Haskoin.Node.Chain.Logic put :: Putter BestBlockKey # get :: Get BestBlockKey # | |
KeyValue BestBlockKey BlockNode Source # | |
Defined in Network.Haskoin.Node.Chain.Logic |
type MonadChainLogic a p m = (BlockHeaders m, MonadReader (ChainReader a p) m) Source #
Type alias for monad commonly used in this module.
data ChainReader a p Source #
Reader for header synchronization code.
ChainReader | |
|
initChainDB :: (MonadChainLogic a p m, MonadUnliftIO m) => Network -> m () Source #
Initialize header database. If version is different from current, the database is purged of conflicting elements first.
purgeChainDB :: (MonadChainLogic a p m, MonadUnliftIO m) => m () Source #
Purge database of elements having keys that may conflict with those used in this module.
importHeaders :: (MonadIO m, BlockHeaders m) => Network -> [BlockHeader] -> m (Either PeerException Bool) Source #
Import a bunch of continuous headers. Returns True
if the number of
headers is 2000, which means that there are possibly more headers to sync
from whatever peer delivered these.
notifySynced :: (MonadIO m, MonadChainLogic a p m) => m Bool Source #
Check if best block header is in sync with the rest of the block chain by
comparing the best block with the current time, verifying that there are no
peers in the queue to be synced, and no peer is being synced at the moment.
This function will only return True
once. It should be used to decide
whether to notify other processes that the header chain has been synced. The
state of the chain will be flipped to synced when this function returns
True
.
nextPeer :: (MonadIO m, MonadChainLogic a p m) => m (Maybe p) Source #
Get next peer to sync against from the queue.
syncHeaders :: (Eq p, MonadChainLogic a p m, MonadIO m) => BlockNode -> p -> m GetHeaders Source #
Set a syncing peer and generate a GetHeaders
data structure with a block
locator to send to that peer for syncing.
setLastReceived :: (MonadChainLogic a p m, MonadIO m) => m () Source #
Set the time of last received data to now if a syncing peer is active.
addPeer :: (Eq p, MonadIO m, MonadChainLogic a p m) => p -> m () Source #
Add a new peer to the queue of peers to sync against.
getSyncingPeer :: (MonadChainLogic a p m, MonadIO m) => m (Maybe p) Source #
Get syncing peer if there is one.
setSyncingPeer :: (MonadChainLogic a p m, MonadIO m) => p -> m () Source #
Set syncing peer to the pone provided.
setSynced :: (MonadChainLogic a p m, MonadIO m) => m () Source #
Set chain as synced.
finishPeer :: (Eq p, MonadIO m, MonadChainLogic a p m) => p -> m () Source #
Remove a peer from the queue of peers to sync and unset the syncing peer if it is set to the provided value.
lastMessage :: (MonadChainLogic a p m, MonadIO m) => m (Maybe (p, UTCTime)) Source #
Return the syncing peer and time of last communication received, if any.
Orphan instances
(Monad m, MonadIO m, MonadReader (ChainReader a p) m) => BlockHeaders m Source # | |
addBlockHeader :: BlockNode -> m () # getBlockHeader :: BlockHash -> m (Maybe BlockNode) # getBestBlockHeader :: m BlockNode # setBestBlockHeader :: BlockNode -> m () # addBlockHeaders :: [BlockNode] -> m () # |