$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');
// 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
///////////////////////////////////////////////////////////////////////////////
* 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]
$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.
*/
*/
private $bufferInstance = NULL;
+ /**
+ * An array for initialized producers
+ */
+ private $producersInitialized = array();
+
/**
* Stacker name for incoming queue
*/
*/
const STACKER_NAME_OUT_QUEUE = 'out_queue';
+ /**
+ * Maximum number of producers (2: test and real)
+ */
+ const MAX_PRODUCERS = 2;
+
/**
* Protected constructor
*
* 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
}
}
// 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;
// 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();
}
--- /dev/null
+<?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]
+?>
*/
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();
}
/**
$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.
*/
}
* 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
*
* @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;
}
}
--- /dev/null
+<?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]
+?>
-Subproject commit f1483fbeae4881d349f9b9558340d1d56b0aab78
+Subproject commit 5146bb541d7f55ff75a71f677f7538281c4b73b6