示例#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(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
示例#4
0
    def test_boundary(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)

        boundary = ph.getBoundary(difficulty)

        expected_boundary = (0, 0, 16, 198, 247, 160, 181, 237, 141, 54, 180,
                             199, 243, 73, 56, 88, 54, 33, 250, 252, 139, 0,
                             121, 162, 131, 77, 38, 250, 63, 204, 158, 169)

        self.assertEqual(expected_boundary, boundary)
示例#5
0
 def get_boundary(current_difficulty):
     ph = PoWHelper(kp=config.dev.kp,
                    set_point=config.dev.mining_setpoint_blocktime)
     return ph.getBoundary(current_difficulty)
示例#6
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