示例#1
0
    def test_adaptive_boundary(self):
        ph = PoWHelper()

        parent_difficulty = StringToUInt256("5000")

        current_difficulty = ph.getDifficulty(
            timestamp=105,
            parent_timestamp=100,
            parent_difficulty=parent_difficulty)

        expected_difficulty = StringToUInt256("8125")

        print(parent_difficulty)
        print(expected_difficulty)
        print(current_difficulty)

        self.assertEqual(expected_difficulty, current_difficulty)

        boundary = ph.getBoundary(current_difficulty)

        expected_boundary = StringToUInt256(
            "14251334059977377898285659693376973274248613497309607881779394954820077494"
        )

        self.assertEqual(expected_boundary, boundary)
示例#2
0
def main():
    ph = PoWHelper()
    qm = CustomQMiner()

    input_bytes = [0x03, 0x05, 0x07, 0x09, 0x19]
    difficulty = StringToUInt256("5000")

    for i in range(10):
        boundary = ph.getBoundary(difficulty)

        #       print("difficulty     ", difficulty)
        print("difficulty str ", UInt256ToString(difficulty))
        print("boundary       ", boundary)
        #        print("boundary str   ", UInt256ToString(boundary))

        start = time.time()

        # Set input bytes, nonce
        qm.setInput(input=input_bytes, nonceOffset=0, target=boundary)

        qm.start(thread_count=2)

        while not qm.solutionFound():
            time.sleep(1)

        print("time           ", qm.end - start)
        print("hash           ", qm.solutionHash())
        print()

        # Set a new difficulty
        difficulty = ph.getDifficulty(int(qm.end), int(start), difficulty)
示例#3
0
    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
示例#4
0
    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
示例#5
0
    def get(self,
            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.getBoundary(current_difficulty)
        return current_difficulty, current_target
示例#6
0
    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))
示例#7
0
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
示例#8
0
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
示例#9
0
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,boundary\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

        boundary = ph.getBoundary(difficulty)
        delta = block.blockheader.timestamp - prev_timestamp

        outs = "{},{},{},{},{},{}\n".format(i,
                                            block.blockheader.timestamp,
                                            prev_timestamp,
                                            delta,
                                            UInt256ToString(difficulty),
                                            UInt256ToString(boundary))

        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