src.mining

Functionality for mining new blocks.

Functions

Classes

Miner(proto, reward_pubkey) Management of a background process that mines for new blocks.
class src.mining.Miner(proto, reward_pubkey)

Management of a background process that mines for new blocks.

The miner process is forked for each new proof of work that needs to be performed. The completed block is sent back JSON-serialized through a pipe that is opened for that purpose. When that pipe is closed by the parent process prematurely, the proof of work process knows it is no longer needed and exits.

To start the mining process, start_mining needs to be called once. After that, the mining will happen automatically, with the mined block switching every time the chainbuilder finds a new primary block chain.

To stop the mining process, there is the shutdown method. Once stopped, mining cannot be resumed (except by creating a new Miner).

Variables:
  • proto (Protocol) – The protocol where newly mined blocks will be sent to.
  • chainbuilder (ChainBuilder) – The chain builder used by start_mining to find the primary chain.
  • _cur_miner_pipes (Optional[List[int]]) – Pipes where worker processes will write their results to.
  • _cur_miner_pids (List[int]) – Process ids of our worker processes.
  • reward_pubkey (Signing) – The public key to which mining fees and block rewards should be sent to.
shutdown()

Stop all mining.

start_mining()

Start mining on a new block.