Pipelines

Block Creation

This module takes care of all the logic related to block creation.

The logic is encapsulated in the BlockPipeline class, while the sequence of actions to do on transactions is specified in the create_pipeline function.

class bigchaindb.pipelines.block.BlockPipeline[source]

This class encapsulates the logic to create blocks.

Note

Methods of this class will be executed in different processes.

filter_tx(tx)[source]

Filter a transaction.

Parameters:tx (dict) – the transaction to process.
Returns:The transaction if assigned to the current node, None otherwise.
Return type:dict
validate_tx(tx)[source]

Validate a transaction.

Also checks if the transaction already exists in the blockchain. If it does, or it’s invalid, it’s deleted from the backlog immediately.

Parameters:tx (dict) – the transaction to validate.
Returns:The transaction if valid, None otherwise.
Return type:Transaction
create(tx, timeout=False)[source]

Create a block.

This method accumulates transactions to put in a block and outputs a block when one of the following conditions is true: - the size limit of the block has been reached, or - a timeout happened.

Parameters:
  • tx (Transaction) – the transaction to validate, might be None if a timeout happens.
  • timeout (bool) – True if a timeout happened (Default: False).
Returns:

The block, if a block is ready, or None.

Return type:

Block

write(block)[source]

Write the block to the Database.

Parameters:block (Block) – the block of transactions to write to the database.
Returns:The Block.
Return type:Block
delete_tx(block)[source]

Delete transactions.

Parameters:block (Block) – the block containg the transactions to delete.
Returns:The block.
Return type:Block
bigchaindb.pipelines.block.tx_collector()[source]

A helper to deduplicate transactions

bigchaindb.pipelines.block.create_pipeline()[source]

Create and return the pipeline of operations to be distributed on different processes.

bigchaindb.pipelines.block.start()[source]

Create, start, and return the block pipeline.

Block Voting

This module takes care of all the logic related to block voting.

The logic is encapsulated in the Vote class, while the sequence of actions to do on transactions is specified in the create_pipeline function.

class bigchaindb.pipelines.vote.Vote[source]

This class encapsulates the logic to vote on blocks.

Note

Methods of this class will be executed in different processes.

ungroup(block_id, transactions)[source]

Given a block, ungroup the transactions in it.

Parameters:
  • block_id (str) – the id of the block in progress.
  • transactions (list(dict)) – transactions of the block in progress.
Returns:

None if the block has been already voted, an iterator that yields a transaction, block id, and the total number of transactions contained in the block otherwise.

validate_tx(tx_dict, block_id, num_tx)[source]
Validate a transaction. Transaction must also not be in any VALID
block.
Parameters:
  • tx_dict (dict) – the transaction to validate
  • block_id (str) – the id of block containing the transaction
  • num_tx (int) – the total number of transactions to process
Returns:

Three values are returned, the validity of the transaction, block_id, num_tx.

vote(tx_validity, block_id, num_tx)[source]

Collect the validity of transactions and cast a vote when ready.

Parameters:
  • tx_validity (bool) – the validity of the transaction
  • block_id (str) – the id of block containing the transaction
  • num_tx (int) – the total number of transactions to process
Returns:

None, or a vote if a decision has been reached.

write_vote(vote, num_tx)[source]

Write vote to the database.

Parameters:vote – the vote to write.
bigchaindb.pipelines.vote.create_pipeline()[source]

Create and return the pipeline of operations to be distributed on different processes.

bigchaindb.pipelines.vote.get_changefeed()[source]

Create and return ordered changefeed of blocks starting from last voted block

bigchaindb.pipelines.vote.start()[source]

Create, start, and return the block pipeline.

Block Status

This module takes care of all the logic related to block status.

Specifically, what happens when a block becomes invalid. The logic is encapsulated in the Election class, while the sequence of actions is specified in create_pipeline.

class bigchaindb.pipelines.election.Election(events_queue=None)[source]

Election class.

check_for_quorum(next_vote)[source]

Checks if block has enough invalid votes to make a decision

Parameters:next_vote – The next vote.
requeue_transactions(invalid_block)[source]

Liquidates transactions from invalid blocks so they can be processed again

Stale Transaction Monitoring

This module monitors for stale transactions.

It reassigns transactions which have been assigned a node but remain in the backlog past a certain amount of time.

class bigchaindb.pipelines.stale.StaleTransactionMonitor(timeout=5, backlog_reassign_delay=None)[source]

This class encapsulates the logic for re-assigning stale transactions.

Note

Methods of this class will be executed in different processes.

check_transactions()[source]

Poll backlog for stale transactions

Returns:txs to be re assigned
Return type:txs (list)
reassign_transactions(tx)[source]

Put tx back in backlog with new assignee

Returns:transaction
bigchaindb.pipelines.stale.create_pipeline(timeout=5, backlog_reassign_delay=5)[source]

Create and return the pipeline of operations to be distributed on different processes.

bigchaindb.pipelines.stale.start(timeout=5, backlog_reassign_delay=None)[source]

Create, start, and return the block pipeline.