def get(measurement, parent_difficulty, dev_config): ph = PoWHelper(kp=dev_config.kp, set_point=dev_config.block_timing_in_seconds) current_difficulty = ph.getDifficulty(measurement=measurement, parent_difficulty=parent_difficulty) current_target = ph.getTarget(current_difficulty) return current_difficulty, current_target
def get(measurement, parent_difficulty): ph = PoWHelper(kp=config.dev.kp, set_point=config.dev.mining_setpoint_blocktime) current_difficulty = ph.getDifficulty(measurement=measurement, parent_difficulty=parent_difficulty) current_target = ph.getTarget(current_difficulty) return current_difficulty, current_target
def test_target_1(self): ph = PoWHelper() difficulty = (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x42, 0x40) target = ph.getTarget(difficulty) expected_target = (169, 158, 204, 63, 250, 38, 77, 131, 162, 121, 0, 139, 252, 250, 33, 54, 88, 56, 73, 243, 199, 180, 54, 141, 237, 181, 160, 247, 198, 16, 0, 0) self.assertEqual(expected_target, target)
def test_adaptive_target(self): ph = PoWHelper() parent_difficulty = StringToUInt256("5000") current_difficulty = ph.getDifficulty( measurement=104, parent_difficulty=parent_difficulty) expected_difficulty = '4644' print(parent_difficulty) print(expected_difficulty) print(current_difficulty) self.assertEqual(expected_difficulty, UInt256ToString(current_difficulty)) target = ph.getTarget(current_difficulty) expected_target = "12766941454368345787240450318120704813017110301439674670851728194227068997120" self.assertEqual(expected_target, UInt256ToString(target))
def main(): persistent_state = State() chain_manager = ChainManager(state=persistent_state) chain_manager.load(GenesisBlock()) ph = PoWHelper() difficulty = StringToUInt256('5000') filename = os.path.expanduser( "~/crypto/qryptonight/modeling/blockdata.csv") with open(filename, 'w') as f: f.write("i,timestamp,prev_timestamp,delta,difficulty,target\n") prev_timestamp = None for i in range(chain_manager.height): block = chain_manager.get_block_by_number(i) if i == 0: prev_timestamp = block.blockheader.timestamp continue target = ph.getTarget(difficulty) delta = block.blockheader.timestamp - prev_timestamp outs = "{},{},{},{},{},{}\n".format(i, block.blockheader.timestamp, prev_timestamp, delta, UInt256ToString(difficulty), UInt256ToString(target)) f.write(outs) difficulty = ph.getDifficulty(block.blockheader.timestamp, prev_timestamp, difficulty) difficulty = StringToUInt256( str(max(2, int(UInt256ToString(difficulty))))) prev_timestamp = block.blockheader.timestamp
difficulty = StringToUInt256('5000') delta = 0 filename = os.path.expanduser("~/crypto/qryptonight/modeling/blockdata.csv") with open(filename, 'w') as f: f.write("i,timestamp,prev_timestamp,delta,difficulty,target\n") prev_timestamp = None for i in range(chain_manager.height): block = chain_manager.get_block_by_number(i) if i == 0: prev_timestamp = block.blockheader.timestamp continue target = ph.getTarget(difficulty) delta = block.blockheader.timestamp - prev_timestamp outs = "{},{},{},{},{},{}\n".format(i, block.blockheader.timestamp, prev_timestamp, delta, UInt256ToString(difficulty), UInt256ToString(target)) f.write(outs) difficulty = ph.getDifficulty(block.blockheader.timestamp, prev_timestamp, difficulty) difficulty = StringToUInt256( str(max(2, int(UInt256ToString(difficulty))))) prev_timestamp = block.blockheader.timestamp
def get_target(current_difficulty): ph = PoWHelper(kp=config.dev.kp, set_point=config.dev.mining_setpoint_blocktime) return ph.getTarget(current_difficulty)
def get_target(current_difficulty, dev_config): ph = PoWHelper(kp=dev_config.kp, set_point=dev_config.block_timing_in_seconds) return ph.getTarget(current_difficulty)