Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
dev::eth::BlockQueue Class Reference

A queue of blocks. More...

#include <BlockQueue.h>

Inheritance diagram for dev::eth::BlockQueue:
[legend]
Collaboration diagram for dev::eth::BlockQueue:
[legend]

Classes

struct  UnverifiedBlock
 

Public Member Functions

 BlockQueue ()
 
 ~BlockQueue ()
 
void setChain (BlockChain const &_bc)
 
ImportResult import (bytesConstRef _block, bool _isOurs=false)
 Import a block into the queue. More...
 
void tick ()
 Notes that time has moved on and some blocks that used to be "in the future" may no be valid. More...
 
void drain (std::vector< VerifiedBlock > &o_out, unsigned _max)
 Grabs at most _max of the blocks that are ready, giving them in the correct order for insertion into the chain. More...
 
bool doneDrain (h256s const &_knownBad=h256s())
 Must be called after a drain() call. More...
 
void noteReady (h256 const &_b)
 Notify the queue that the chain has changed and a new block has attained 'ready' status (i.e. is in the chain). More...
 
void retryAllUnknown ()
 Force a retry of all the blocks with unknown parents. More...
 
std::pair< unsigned, unsigned > items () const
 Get information on the items queued. More...
 
void clear ()
 Clear everything. More...
 
void stop ()
 Stop all activity, leaves the class in limbo, waiting for destruction. More...
 
h256 firstUnknown () const
 Return first block with an unknown parent. More...
 
BlockQueueStatus status () const
 Get some infomration on the current status. More...
 
QueueStatus blockStatus (h256 const &_h) const
 Get some infomration on the given block's status regarding us. More...
 
template<class T >
Handler onReady (T const &_t)
 
template<class T >
Handler onRoomAvailable (T const &_t)
 
template<class T >
void setOnBad (T const &_t)
 
bool knownFull () const
 
bool unknownFull () const
 
u256 difficulty () const
 
bool isActive () const
 

Private Member Functions

void noteReady_WITH_LOCK (h256 const &_b)
 
bool invariants () const override
 Reimplement to specify the invariants. More...
 
void verifierBody ()
 
void collectUnknownBad_WITH_BOTH_LOCKS (h256 const &_bad)
 
void updateBad_WITH_LOCK (h256 const &_bad)
 
void drainVerified_WITH_BOTH_LOCKS ()
 
std::size_t knownSize () const
 
std::size_t knownCount () const
 
std::size_t unknownSize () const
 
std::size_t unknownCount () const
 

Private Attributes

BlockChain const * m_bc
 The blockchain into which our imports go. More...
 
boost::shared_mutex m_lock
 General lock for the sets, m_future and m_unknown. More...
 
h256Hash m_drainingSet
 All blocks being imported. More...
 
h256Hash m_readySet
 All blocks ready for chain import. More...
 
h256Hash m_unknownSet
 Set of all blocks whose parents are not ready/in-chain. More...
 
SizedBlockMap< h256m_unknown
 For blocks that have an unknown parent; we map their parent hash to the block stuff, and insert once the block appears. More...
 
h256Hash m_knownBad
 Set of blocks that we know will never be valid. More...
 
SizedBlockMap< time_t > m_future
 Set of blocks that are not yet valid. Ordered by timestamp. More...
 
Signal m_onReady
 Called when a subsequent call to import blocks will return a non-empty container. Be nice and exit fast. More...
 
Signal m_onRoomAvailable
 Called when space for new blocks becomes availabe after a drain. Be nice and exit fast. More...
 
Mutex m_verification
 Mutex that allows writing to m_verified, m_verifying and m_unverified. More...
 
std::condition_variable m_moreToVerify
 Signaled when m_unverified has a new entry. More...
 
SizedBlockQueue< VerifiedBlockm_verified
 List of blocks, in correct order, verified and ready for chain-import. More...
 
SizedBlockQueue< VerifiedBlockm_verifying
 List of blocks being verified; as long as the block component (bytes) is empty, it's not finished. More...
 
SizedBlockQueue< UnverifiedBlockm_unverified
 List of <block hash, parent hash, block data> in correct order, ready for verification. More...
 
std::vector< std::thread > m_verifiers
 Threads who only verify. More...
 
std::atomic< bool > m_deleting = {false}
 Exit condition for verifiers. More...
 
std::function< void(Exception &)> m_onBad
 Called if we have a block that doesn't verify. More...
 
u256 m_difficulty
 Total difficulty of blocks in the queue. More...
 
u256 m_drainingDifficulty
 Total difficulty of blocks in draining. More...
 

Detailed Description

A queue of blocks.

Sits between network or other I/O and the BlockChain. Sorts them ready for blockchain insertion (with the BlockChain::sync() method).

Definition at line 225 of file BlockQueue.h.

Constructor & Destructor Documentation

BlockQueue::BlockQueue ( )

Definition at line 47 of file BlockQueue.cpp.

Here is the call graph for this function:

BlockQueue::~BlockQueue ( )

Definition at line 58 of file BlockQueue.cpp.

Here is the call graph for this function:

Member Function Documentation

QueueStatus BlockQueue::blockStatus ( h256 const &  _h) const

Get some infomration on the given block's status regarding us.

Definition at line 386 of file BlockQueue.cpp.

Here is the caller graph for this function:

void BlockQueue::clear ( )

Clear everything.

Definition at line 74 of file BlockQueue.cpp.

Here is the caller graph for this function:

void BlockQueue::collectUnknownBad_WITH_BOTH_LOCKS ( h256 const &  _bad)
private

Definition at line 317 of file BlockQueue.cpp.

u256 BlockQueue::difficulty ( ) const

Definition at line 529 of file BlockQueue.cpp.

Here is the caller graph for this function:

bool BlockQueue::doneDrain ( h256s const &  _knownBad = h256s())

Must be called after a drain() call.

Notes that the drained blocks have been imported into the blockchain, so we can forget about them.

Returns
true iff there are additional blocks ready to be processed.

Definition at line 333 of file BlockQueue.cpp.

Here is the caller graph for this function:

void BlockQueue::drain ( std::vector< VerifiedBlock > &  o_out,
unsigned  _max 
)

Grabs at most _max of the blocks that are ready, giving them in the correct order for insertion into the chain.

Don't forget to call doneDrain() once you're done importing.

Definition at line 433 of file BlockQueue.cpp.

Here is the caller graph for this function:

void BlockQueue::drainVerified_WITH_BOTH_LOCKS ( )
private

Definition at line 160 of file BlockQueue.cpp.

Here is the call graph for this function:

h256 dev::eth::BlockQueue::firstUnknown ( ) const
inline

Return first block with an unknown parent.

Definition at line 263 of file BlockQueue.h.

Here is the caller graph for this function:

ImportResult BlockQueue::import ( bytesConstRef  _block,
bool  _isOurs = false 
)

Import a block into the queue.

Definition at line 175 of file BlockQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool BlockQueue::invariants ( ) const
overrideprivatevirtual

Reimplement to specify the invariants.

Implements dev::HasInvariants.

Definition at line 460 of file BlockQueue.cpp.

bool BlockQueue::isActive ( ) const

Definition at line 535 of file BlockQueue.cpp.

std::pair<unsigned, unsigned> dev::eth::BlockQueue::items ( ) const
inline

Get information on the items queued.

Definition at line 254 of file BlockQueue.h.

Here is the call graph for this function:

Here is the caller graph for this function:

std::size_t BlockQueue::knownCount ( ) const
private

Definition at line 412 of file BlockQueue.cpp.

bool BlockQueue::knownFull ( ) const

Definition at line 401 of file BlockQueue.cpp.

std::size_t BlockQueue::knownSize ( ) const
private

Definition at line 407 of file BlockQueue.cpp.

void dev::eth::BlockQueue::noteReady ( h256 const &  _b)
inline

Notify the queue that the chain has changed and a new block has attained 'ready' status (i.e. is in the chain).

Definition at line 248 of file BlockQueue.h.

void BlockQueue::noteReady_WITH_LOCK ( h256 const &  _b)
private

Definition at line 472 of file BlockQueue.cpp.

template<class T >
Handler dev::eth::BlockQueue::onReady ( T const &  _t)
inline

Definition at line 271 of file BlockQueue.h.

Here is the caller graph for this function:

template<class T >
Handler dev::eth::BlockQueue::onRoomAvailable ( T const &  _t)
inline

Definition at line 272 of file BlockQueue.h.

Here is the caller graph for this function:

void BlockQueue::retryAllUnknown ( )

Force a retry of all the blocks with unknown parents.

Definition at line 496 of file BlockQueue.cpp.

void dev::eth::BlockQueue::setChain ( BlockChain const &  _bc)
inline

Definition at line 231 of file BlockQueue.h.

Here is the caller graph for this function:

template<class T >
void dev::eth::BlockQueue::setOnBad ( T const &  _t)
inline

Definition at line 274 of file BlockQueue.h.

Here is the caller graph for this function:

BlockQueueStatus BlockQueue::status ( ) const

Get some infomration on the current status.

Definition at line 378 of file BlockQueue.cpp.

Here is the caller graph for this function:

void BlockQueue::stop ( )

Stop all activity, leaves the class in limbo, waiting for destruction.

Definition at line 63 of file BlockQueue.cpp.

void BlockQueue::tick ( )

Notes that time has moved on and some blocks that used to be "in the future" may no be valid.

Definition at line 350 of file BlockQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::size_t BlockQueue::unknownCount ( ) const
private

Definition at line 428 of file BlockQueue.cpp.

bool BlockQueue::unknownFull ( ) const

Definition at line 417 of file BlockQueue.cpp.

std::size_t BlockQueue::unknownSize ( ) const
private

Definition at line 423 of file BlockQueue.cpp.

void BlockQueue::updateBad_WITH_LOCK ( h256 const &  _bad)
private

Definition at line 267 of file BlockQueue.cpp.

Here is the call graph for this function:

void BlockQueue::verifierBody ( )
private

Definition at line 91 of file BlockQueue.cpp.

Here is the call graph for this function:

Member Data Documentation

BlockChain const* dev::eth::BlockQueue::m_bc
private

The blockchain into which our imports go.

Definition at line 303 of file BlockQueue.h.

std::atomic<bool> dev::eth::BlockQueue::m_deleting = {false}
private

Exit condition for verifiers.

Definition at line 322 of file BlockQueue.h.

u256 dev::eth::BlockQueue::m_difficulty
private

Total difficulty of blocks in the queue.

Definition at line 325 of file BlockQueue.h.

u256 dev::eth::BlockQueue::m_drainingDifficulty
private

Total difficulty of blocks in draining.

Definition at line 326 of file BlockQueue.h.

h256Hash dev::eth::BlockQueue::m_drainingSet
private

All blocks being imported.

Definition at line 306 of file BlockQueue.h.

SizedBlockMap<time_t> dev::eth::BlockQueue::m_future
private

Set of blocks that are not yet valid. Ordered by timestamp.

Definition at line 311 of file BlockQueue.h.

h256Hash dev::eth::BlockQueue::m_knownBad
private

Set of blocks that we know will never be valid.

Definition at line 310 of file BlockQueue.h.

boost::shared_mutex dev::eth::BlockQueue::m_lock
mutableprivate

General lock for the sets, m_future and m_unknown.

Definition at line 305 of file BlockQueue.h.

std::condition_variable dev::eth::BlockQueue::m_moreToVerify
private

Signaled when m_unverified has a new entry.

Definition at line 316 of file BlockQueue.h.

std::function<void(Exception&)> dev::eth::BlockQueue::m_onBad
private

Called if we have a block that doesn't verify.

Definition at line 324 of file BlockQueue.h.

Signal dev::eth::BlockQueue::m_onReady
private

Called when a subsequent call to import blocks will return a non-empty container. Be nice and exit fast.

Definition at line 312 of file BlockQueue.h.

Signal dev::eth::BlockQueue::m_onRoomAvailable
private

Called when space for new blocks becomes availabe after a drain. Be nice and exit fast.

Definition at line 313 of file BlockQueue.h.

h256Hash dev::eth::BlockQueue::m_readySet
private

All blocks ready for chain import.

Definition at line 307 of file BlockQueue.h.

SizedBlockMap<h256> dev::eth::BlockQueue::m_unknown
private

For blocks that have an unknown parent; we map their parent hash to the block stuff, and insert once the block appears.

Definition at line 309 of file BlockQueue.h.

h256Hash dev::eth::BlockQueue::m_unknownSet
private

Set of all blocks whose parents are not ready/in-chain.

Definition at line 308 of file BlockQueue.h.

SizedBlockQueue<UnverifiedBlock> dev::eth::BlockQueue::m_unverified
private

List of <block hash, parent hash, block data> in correct order, ready for verification.

Definition at line 319 of file BlockQueue.h.

Mutex dev::eth::BlockQueue::m_verification
mutableprivate

Mutex that allows writing to m_verified, m_verifying and m_unverified.

Definition at line 315 of file BlockQueue.h.

SizedBlockQueue<VerifiedBlock> dev::eth::BlockQueue::m_verified
private

List of blocks, in correct order, verified and ready for chain-import.

Definition at line 317 of file BlockQueue.h.

std::vector<std::thread> dev::eth::BlockQueue::m_verifiers
private

Threads who only verify.

Definition at line 321 of file BlockQueue.h.

SizedBlockQueue<VerifiedBlock> dev::eth::BlockQueue::m_verifying
private

List of blocks being verified; as long as the block component (bytes) is empty, it's not finished.

Definition at line 318 of file BlockQueue.h.


The documentation for this class was generated from the following files: