haskoin-node-0.8.0: Haskoin Node P2P library for Bitcoin and Bitcoin Cash

CopyrightNo rights reserved
LicenseUNLICENSE
Maintainerxenog@protonmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Haskoin.Node.Chain.Logic

Contents

Description

State and code for block header synchronization.

Synopsis

Documentation

dataVersion :: Word32 Source #

Version of the database.

data ChainState p Source #

Mutable state for the header chain process.

Constructors

ChainState 

Fields

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.

Constructors

ChainReader 

Fields

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.

isSynced :: (MonadChainLogic a p m, MonadIO m) => m Bool Source #

Return True if the chain has ever been considered synced. it will always return True, even if the chain gets out of sync for any reason.

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