]> git.mxchange.org Git - hub.git/commitdiff
Added real genesis block producer (not funtional).
authorRoland Haeder <roland@mxchange.org>
Thu, 21 May 2015 01:38:50 +0000 (03:38 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 21 May 2015 01:38:50 +0000 (03:38 +0200)
Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/config.php
application/hub/interfaces/miner/class_MinerHelper.php
application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php
application/hub/main/miner/class_BaseHubMiner.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/producer/class_BaseProducer.php
application/hub/main/producer/miner/blocks/class_MinerRealGenesisBlockProducer.php [new file with mode: 0644]
application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php
application/hub/main/states/miner/booting/class_MinerBootingState.php
application/hub/main/tasks/miner/block_producer/class_MinerRealGenesisBlockProducerTask.php [new file with mode: 0644]
core

index 9f26d4909b6de7e18496db3492f6f489801bf97c..67a51950604e1b1e462ca7e739a9db2b400e685c 100644 (file)
@@ -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
 ///////////////////////////////////////////////////////////////////////////////
index 18e1b651ec6db9ee5ba412542654ab9bc17d02c0..30e6b870b6fe685ecdefdfe8bd2333e81eb44224 100644 (file)
@@ -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]
index 742b40be42e2781e7aa3628d05c43dade2f865bc..aaa30dbf1c2332663f1ccb2b9333345461951303 100644 (file)
@@ -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.
                 */
index 8bbc29fa67bbcf7afde4d69c581c90794ce5a88b..ecdfaa459c8c636a3f4865d98e4b405dff01e54a 100644 (file)
@@ -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
        }
 }
 
index 1de50c8643384e758c4aa1f77f8aa1018e3c7df1..c1d8f059a17781c9d5d1c8b31b963fbccf46227d 100644 (file)
@@ -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;
index 26dcb91b31d1d528844cfd32a96fa02868ac4ee7..8ac4cdfa13439cb832b7ee908bef428631d36bc1 100644 (file)
@@ -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 (file)
index 0000000..18f3998
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * A MinerRealGenesisBlock producer class
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 8d5aedce0ecd741c822f2c5780ec5c2e8c701886..b710328bf32575e2d51839256ba298c6eb9f78ca 100644 (file)
@@ -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.
                 */
        }
index 476cd4968b9d2feaa4a4dc9d13fdab3885392ed7..a30e8a641a7930923f220f24225b83326c2e7a8c 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 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 (file)
index 0000000..e52e2c2
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * A RealGenesisBlockProducer task for miners
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 f1483fbeae4881d349f9b9558340d1d56b0aab78..5146bb541d7f55ff75a71f677f7538281c4b73b6 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit f1483fbeae4881d349f9b9558340d1d56b0aab78
+Subproject commit 5146bb541d7f55ff75a71f677f7538281c4b73b6