From: Roland Haeder Date: Thu, 21 May 2015 01:38:50 +0000 (+0200) Subject: Added real genesis block producer (not funtional). X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=58c8089a80a885128553f9a79786c613017a00c7;p=hub.git Added real genesis block producer (not funtional). Signed-off-by: Roland Haeder --- diff --git a/application/hub/config.php b/application/hub/config.php index 9f26d4909..67a519506 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -972,13 +972,25 @@ $cfg->setConfigEntry('task_miner_block_fetcher_max_runs', 0); $cfg->setConfigEntry('miner_test_genesis_block_producer_task_class', 'MinerTestGenesisBlockProducerTask'); // CFG: TASK-MINER-TEST-GENESIS-BLOCK-PRODUCER-STARTUP-DELAY -$cfg->setConfigEntry('task_miner_test_genesis_block_producer_startup_delay', 500); +$cfg->setConfigEntry('task_miner_test_genesis_block_producer_startup_delay', 1000); // CFG: TASK-MINER-TEST-GENESIS-BLOCK-PRODUCER-INTERVAL-DELAY -$cfg->setConfigEntry('task_miner_test_genesis_block_producer_interval_delay', 1000*60*60); +$cfg->setConfigEntry('task_miner_test_genesis_block_producer_interval_delay', 10000); // CFG: TASK-MINER-TEST-GENESIC-BLOCK-PRODUCER-MAX-RUNS -$cfg->setConfigEntry('task_miner_test_genesis_block_producer_max_runs', 1); +$cfg->setConfigEntry('task_miner_test_genesis_block_producer_max_runs', 0); + +// CFG: MINER-REAL-GENESIS-BLOCK-PRODUCER-TASK-CLASS +$cfg->setConfigEntry('miner_real_genesis_block_producer_task_class', 'MinerRealGenesisBlockProducerTask'); + +// CFG: TASK-MINER-REAL-GENESIS-BLOCK-PRODUCER-STARTUP-DELAY +$cfg->setConfigEntry('task_miner_real_genesis_block_producer_startup_delay', 500); + +// CFG: TASK-MINER-REAL-GENESIS-BLOCK-PRODUCER-INTERVAL-DELAY +$cfg->setConfigEntry('task_miner_real_genesis_block_producer_interval_delay', 10000); + +// CFG: TASK-MINER-REAL-GENESIC-BLOCK-PRODUCER-MAX-RUNS +$cfg->setConfigEntry('task_miner_real_genesis_block_producer_max_runs', 0); // CFG: MINER_NODE-COMMUNICATOR-TASK-CLASS $cfg->setConfigEntry('miner_node_communicator_task_class', 'MinerNodeCommunicatorTask'); @@ -995,12 +1007,18 @@ $cfg->setConfigEntry('task_miner_node_communicator_max_runs', 0); // CFG: MINER-TEST-GENESIS-BLOCK-PRODUCER-CLASS $cfg->setConfigEntry('miner_test_genesis_block_producer_class', 'MinerTestGenesisBlockProducer'); +// CFG: MINER-REAL-GENESIS-BLOCK-PRODUCER-CLASS +$cfg->setConfigEntry('miner_real_genesis_block_producer_class', 'MinerRealGenesisBlockProducer'); + // CFG: MINER-NODE-COMMUNICATOR-CLASS $cfg->setConfigEntry('miner_node_communicator_class', 'MinerNodeCommunicator'); // CFG: MINER-TEST-HASH-BLOCK-CLASS $cfg->setConfigEntry('miner_test_hash_block_class', 'HashBlock'); +// CFG: MINER-REAL-HASH-BLOCK-CLASS +$cfg->setConfigEntry('miner_real_hash_block_class', 'HashBlock'); + /////////////////////////////////////////////////////////////////////////////// // Cruncher configuration /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/interfaces/miner/class_MinerHelper.php b/application/hub/interfaces/miner/class_MinerHelper.php index 18e1b651e..30e6b870b 100644 --- a/application/hub/interfaces/miner/class_MinerHelper.php +++ b/application/hub/interfaces/miner/class_MinerHelper.php @@ -84,9 +84,10 @@ interface MinerHelper extends FrameworkInterface { * Changes the state to 'booting' and shall be called after the block * producer has been initialized. * + * @param $producerInstance An instance of a BlockProducer class * @return void */ - function blockProducerHasInitialized (); + function blockProducerHasInitialized (BlockProducer $producerInstance); } // [EOF] diff --git a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php index 742b40be4..aaa30dbf1 100644 --- a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php @@ -79,7 +79,14 @@ class MinerTaskHandlerInitializerFilter extends BaseMinerFilter implements Filte $handlerInstance->registerTask('miner_test_genesis_block_producer', $taskInstance); /* - * 3) A task for communicating into the locally running 'hub' node. + * 3) A task for generating a real "genesis" block. @TODO Define how a + * real "genesis" block is generated + */ + $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_real_genesis_block_producer_task_class'); + $handlerInstance->registerTask('miner_real_genesis_block_producer', $taskInstance); + + /* + * 4) A task for communicating into the locally running 'hub' node. * This rask will check for new blocks on the mining network and * tries to claim found blocks. */ diff --git a/application/hub/main/miner/class_BaseHubMiner.php b/application/hub/main/miner/class_BaseHubMiner.php index 8bbc29fa6..ecdfaa459 100644 --- a/application/hub/main/miner/class_BaseHubMiner.php +++ b/application/hub/main/miner/class_BaseHubMiner.php @@ -37,6 +37,11 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable { */ private $bufferInstance = NULL; + /** + * An array for initialized producers + */ + private $producersInitialized = array(); + /** * Stacker name for incoming queue */ @@ -47,6 +52,11 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable { */ const STACKER_NAME_OUT_QUEUE = 'out_queue'; + /** + * Maximum number of producers (2: test and real) + */ + const MAX_PRODUCERS = 2; + /** * Protected constructor * @@ -212,14 +222,21 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable { * Changes the state to 'booting' and shall be called after the block * producer has been initialized. * + * @param $producerInstance An instance of a BlockProducer class * @return void */ - public function blockProducerHasInitialized () { + public function blockProducerHasInitialized (BlockProducer $producerInstance) { // Make sure the state is correct ('init') $this->getStateInstance()->validateMinerStateIsInit(); - // Change it to 'booting' - MinerStateFactory::createMinerStateInstanceByName('booting'); + // Mark given producer as initialized + $this->producersInitialized[$producerInstance->__toString()] = TRUE; + + // Has all producers been initialized? + if (count($this->producersInitialized) == self::MAX_PRODUCERS) { + // Change it to 'booting' + MinerStateFactory::createMinerStateInstanceByName('booting'); + } // END - if } } diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 1de50c864..c1d8f059a 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -1410,7 +1410,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Is 'claim_reward' the message type? if (in_array('claim_reward', $decodedDataArray[self::PACKAGE_CONTENT_TAGS])) { /* - * Then don't feed this message to the miner as this causes and + * Then don't feed this message to the miner as this causes an * endless loop of mining. */ return; diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php index 26dcb91b3..8ac4cdfa1 100644 --- a/application/hub/main/producer/class_BaseProducer.php +++ b/application/hub/main/producer/class_BaseProducer.php @@ -55,6 +55,12 @@ abstract class BaseProducer extends BaseFrameworkSystem { // Initialize all producers $this->initProducer(); + // Get miner instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Change state to next state + $minerInstance->blockProducerHasInitialized($this); + // Initialize work queue (out-going, produced items) $this->initWorkQueue(); } diff --git a/application/hub/main/producer/miner/blocks/class_MinerRealGenesisBlockProducer.php b/application/hub/main/producer/miner/blocks/class_MinerRealGenesisBlockProducer.php new file mode 100644 index 000000000..18f399853 --- /dev/null +++ b/application/hub/main/producer/miner/blocks/class_MinerRealGenesisBlockProducer.php @@ -0,0 +1,94 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class MinerRealGenesisBlockProducer extends BaseBlockProducer implements BlockProducer, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $producerInstance An instance of a Producer class + */ + public final static function createMinerRealGenesisBlockProducer () { + // Get new instance + $producerInstance = new MinerRealGenesisBlockProducer(); + + // Get a (minable) hash block instance + $minableInstance = ObjectFactory::createObjectByConfiguredName('miner_real_hash_block_class'); + + // Set it here + $producerInstance->setMinableInstance($minableInstance); + + // Return the prepared instance + return $producerInstance; + } + + /** + * Initializes the producer. This method satisfies the abstract BaseProducer + * class. + * + * @return void + * @todo ~10% done + */ + protected function initProducer () { + $this->partialStub('Please implement this method.'); + } + + /** + * Initializes the executor, whatever it does. + * + * @return void + * @todo 0% done + */ + public function initExecutor (Stateable $stateInstance) { + $this->partialStub('Please implement this method.'); + } + + /** + * Prepares the produces of some test units and pushes them onto the queue + * + * @param $stateInstance An instance of a Stateable instance + * @return void + * @todo ~5% done + */ + public function prepareBlockProduction (Stateable $stateInstance) { + // The state must be 'booting' + $stateInstance->validateMinerStateIsBooting(); + + /* + * Now that the miner is booting a genesis block for real mining can be + * created. + */ + } +} + +// [EOF] +?> diff --git a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php index 8d5aedce0..b710328bf 100644 --- a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php +++ b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php @@ -60,12 +60,6 @@ class MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockPr */ protected function initProducer () { $this->partialStub('Please implement this method.'); - - // As last step, change the state of the miner, get the miner first - $minerInstance = Registry::getRegistry()->getInstance('miner'); - - // Change state to next state - $minerInstance->blockProducerHasInitialized(); } /** @@ -90,8 +84,8 @@ class MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockPr $stateInstance->validateMinerStateIsBooting(); /* - * Now that the miner is booting a genesis block for testing purposes - * can be created. The "real" genesis block will be created differently + * Now that the miner is booting a "genesis" block for testing purposes + * can be created. The real "genesis" block will be created differently * to this. */ } diff --git a/application/hub/main/states/miner/booting/class_MinerBootingState.php b/application/hub/main/states/miner/booting/class_MinerBootingState.php index 476cd4968..a30e8a641 100644 --- a/application/hub/main/states/miner/booting/class_MinerBootingState.php +++ b/application/hub/main/states/miner/booting/class_MinerBootingState.php @@ -22,6 +22,11 @@ * along with this program. If not, see . */ class MinerBootingState extends BaseMinerState implements Stateable { + /** + * Array of booted producers + */ + private $bootedProducer = array(); + /** * Protected constructor * @@ -58,11 +63,20 @@ class MinerBootingState extends BaseMinerState implements Stateable { * @return void */ public function executeState (Executor $executorInstance) { + // Has this executor (producer) run? + if (isset($this->bootedProducer[$executorInstance->__toString()])) { + // Then silently skip this + return; + } // END - if + // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Calling prepareBlockProduction() on ' . $executorInstance->__toString() . ' ...'); // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there $executorInstance->prepareBlockProduction($this); + + // Mark producer as booted + $this->bootedProducer[$executorInstance->__toString()] = TRUE; } } diff --git a/application/hub/main/tasks/miner/block_producer/class_MinerRealGenesisBlockProducerTask.php b/application/hub/main/tasks/miner/block_producer/class_MinerRealGenesisBlockProducerTask.php new file mode 100644 index 000000000..e52e2c2e6 --- /dev/null +++ b/application/hub/main/tasks/miner/block_producer/class_MinerRealGenesisBlockProducerTask.php @@ -0,0 +1,80 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class MinerRealGenesisBlockProducerTask extends BaseTask implements Taskable, Visitable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $taskInstance An instance of a Taskable/Visitable class + */ + public final static function createMinerRealGenesisBlockProducerTask () { + // Get new instance + $taskInstance = new MinerRealGenesisBlockProducerTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + */ + public function executeTask () { + // Get the producer instance + $producerInstance = ProducerFactory::createProducerInstance('miner_real_genesis_block_producer_class', 'real_unit'); + + // Get the current miner state from registry + $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance(); + + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString()); + + // We can now invoke that state instance and pass our producer instance for generating some test units + $stateInstance->executeState($producerInstance); + } +} + +// [EOF] +?> diff --git a/core b/core index f1483fbea..5146bb541 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit f1483fbeae4881d349f9b9558340d1d56b0aab78 +Subproject commit 5146bb541d7f55ff75a71f677f7538281c4b73b6