PHPCoin Docs > Mining > Mining Workflows
This document outlines the complete step-by-step workflows for the different mining processes in PHPCoin.
This section describes the process for the standalone command-line miner, executed via utils/miner.php.
-
Parse Command-Line Arguments & Config: The script launches and reads settings from
miner.confand command-line arguments, with arguments taking precedence.- File:
utils/miner.php
- File:
-
Start Miner Instance(s): Based on the
threadssetting, it uses theForkerclass to create one or more child processes, each with its ownMinerinstance.- File:
utils/miner.php
- File:
-
Fetch Alternative Mining Nodes: Before the loop, it gets a list of other nodes for fallback purposes.
- File:
include/class/Miner.php - Function:
getMiningNodes()
- File:
-
Get Mining Info: At the start of each loop, it requests the current
height,difficulty, and lastblockID from a node.- File:
include/class/Miner.php - Function:
getMiningInfo()
- File:
-
Enter Hashing Sub-Loop: It enters a nested loop, where each iteration is a single hashing attempt.
-
Calculate Elapsed Time: It calculates the seconds passed since the last block's timestamp, adjusted for clock offset.
-
Calculate Argon2id Hash: It computes an Argon2id hash using
password_hash()with specific memory/time costs depending on block height.- File:
include/class/Block.php - Function:
calculateArgonHash()
- File:
-
Calculate Nonce: It derives a nonce from a
sha256hash of the chain ID, miner address, previous block date, elapsed time, and the Argon2id hash.- File:
include/class/Block.php - Function:
calculateNonce()
- File:
-
Calculate Hit & Target: It calculates the numerical
hitand the dynamictargetfor the attempt. Thehitcalculation is scaled byBLOCK_TARGET_MUL(a constant set to1000) for precision.- File:
include/class/Block.php - Functions:
calculateHit(),calculateTarget()
- File:
-
Check for Solution: It checks if
hit > target. -
Check for New Network Block: Every 10 seconds of
elapsedtime, it re-checks the mining info. If the network's block ID has changed, it aborts the current attempt and starts the main loop over.
- Submit to Node(s): Once a block is found, it's submitted to the primary node's API. If that fails, it attempts to submit to the fallback nodes.
- File:
include/class/Miner.php - Function:
sendHash()
- File:
The integrated Node Miner follows the same core hashing loop but with key operational differences.
- Configuration: It uses the
miner_public_keyandminer_private_keyfrom the node's main config file. - Mempool Integration: It gathers pending transactions from the node's local mempool to include in the block.
- Reward Generation: It creates and signs all reward transactions (miner, generator, masternode, etc.) for the new block.
- Local Block Submission: It adds a found block directly to its own local blockchain database.
- Function:
Block->add()
- Function:
- Direct Propagation: It immediately propagates the new block to all connected peers.
- Function:
Propagate::blockToAll('current')
- Function:
- Pre-Mining Checks: It verifies the node is not syncing, has enough peers, and has a sufficient node score before starting.
This section describes how a node processes, verifies, and propagates a block, whether received from a CLI miner via the API or an internal Node Miner.
- CLI Miner: A block is received at the
/mine.php?q=submitHashendpoint. The node performs initial checks: miner version, generator status, node health, peer count, and if the submitted block height is exactly one greater than the current blockchain height.- File:
web/mine.php
- File:
- Node Miner: The block is generated internally; these checks are performed before mining even begins.
- CLI Miner: The node takes the
argon,nonce, and other data from the API request. It then gathers transactions from its own mempool and generates all the necessary reward transactions (miner, generator, masternode, etc.). It signs the complete block with its own generator private key.- File:
web/mine.php
- File:
- Node Miner: This is done before the hashing process begins.
The node calls the mine() method on the newly constructed block object. This is a critical verification step that re-calculates the nonce, hit, and target based on the submitted data to ensure the proof-of-work is valid.
- File:
include/class/Block.php - Function:
mine()
If the mine() validation succeeds, the node calls the add() method. This function:
- Performs final validation checks (e.g., block signature, version code).
- Starts a database transaction.
- Inserts the block record into the
blockstable. - Calls
parse_block()to process and insert every transaction from the block data into thetransactionstable, updating account balances accordingly. - Commits the database transaction.
- File:
include/class/Block.php - Functions:
add(),parse_block()
Once the block is successfully added to the local database, the node immediately propagates it to its peers.
- The
Propagate::blockToAll()method is called. - This method executes a command-line script (
php cli/propagate.php) in a new background process. - The
propagate.phpscript fetches all active peers and sends the new block to each one.
- File:
include/class/Propagate.php - Function:
blockToAll()