Provides the system context for the consensus algorithm and deals with the actual content of blocks. Responsible primarily for the creation of new blocks (populated with transactions from TransactionPool
) and for content validation of proposed blocks (verifying transaction results).
Currently a single instance per virtual chain per node.
TransactionPool
- Uses it to populate transactions in proposed blocks and validate ordering of others' proposed blocks.VirtualMachine
- Uses it to execute transactions and generate receipts and state diffs.StateStorage
- Queries the merkle root of the state for writing in proposed blocks and validating others' proposed ones.- Passive towards
ConsensusAlgo
and just provides services to it upon request.
- Initialize the configuration.
Returns a sorted list of nodes (public keys) that participate in the approval committee for the ordering of a given block height. Called by consensus algo.
- The current list of nodes (per block height) is managed by the configuration.
- If the size of requested committee is larger than total nodes, select all nodes as the committee.
- Order the nodes based on the weighted random sorting algorithm (reputation is taken into account here).
Returns a sorted list of nodes (public keys) that participate in the approval committee for the execution validation of a given block height. Called by consensus algo.
- The current list of nodes (per block height) is managed by the configuration.
- If the size of requested committee is larger than total nodes, select all nodes as the committee.
- Order the nodes based on the weighted random sorting algorithm (reputation is taken into account here).
Performed by consensus leader only, upon request from consensus algo to perform the ordering phase of the consensus during a live round.
- Get pending transactions by calling
TransactionPool.GetTransactionsForOrdering
.- If there are too little transactions to append (minimal block according to a configurable amount):
- Wait configurable time (eg. 0.5 sec) and retry once.
- If no transactions continue with an empty block (number of transactions is 0).
- If there are too little transactions to append (minimal block according to a configurable amount):
- Current protocol version (
0x1
). - Current virtual chain.
- Block height is given.
- Hash pointer to the previous (latest) Transactions block is given.
- 64b unix timestamp.
- The merkle root hash of the transactions in the block.
- Placeholder: metadata - holds reputation / algorithm data.
- Hash of the block metadata.
Performed by the leader only, upon request from consensus algo to perform the execution phase of the consensus during a live round.
- The Transactions block for this block height should be cached from previous call to
RequestNewTransactionsBlock
. --> - Execute the ordered transactions set by calling
VirtualMachine.ProcessTransactionSet
creating receipts and state diff.
- Current protocol version (
0x1
). - Current virtual chain.
- Block height is given.
- Hash pointer to the previous (latest) Results block is given.
- 64b unix timestamp.
- The merkle root hash of the transaction receipts in the block.
- The hash of the state diff in the block.
- Hash pointer to the Transactions block of the same height.
- Merkle root of the state prior to the block execution, retrieved by calling
StateStorage.GetStateHash
. - Transaction id bloom filter (see block format for structure).
- Transaction timestamp bloom filter (see block format for structure).
Validates another node's proposed block. Performed upon request from consensus algo when receiving a proposal during a live consensus round.
- Check protocol version.
- Check virtual chain.
- Check block height is the next of the previous block's height.
- Check hash pointer indeed points to previous block.
- Check timestamp is within configurable allowed jitter of system timestamp, and later than previous block.
- Check transaction merkle root hash.
- Check metadata hash.
- Call
TransactionPool.ValidateTransactionsForOrdering
to validate pre order checks, expiration and no duplication.
Validates another node's proposed block. Performed upon request from consensus algo when receiving a proposal during a live consensus round.
- Check protocol version.
- Check virtual chain.
- Check block height is the next of the previous block's height.
- Check hash pointer indeed points to previous block.
- Check timestamp is within configurable allowed jitter of system timestamp, and later than previous block.
- Check transaction receipts merkle root hash.
- Check the hash of the state diff in the block.
- Check hash pointer to the Transactions block of the same height.
- Check merkle root of the state prior to the block execution, retrieved by calling
StateStorage.GetStateHash
. - Check transaction id bloom filter (see block format for structure).
- Check transaction timestamp bloom filter (see block format for structure).
- Execute the ordered transactions set by calling
VirtualMachine.ProcessTransactionSet
creating receipts and state diff. - Compare the receipts merkle root hash to the one in the block.
- Compare the state diff hash to the one in the block (supports only deterministic execution).