Exemplo n.º 1
0
    def __test_getblocks(self, node0, block_count):
        block1 = self.chain.next_block(block_count)
        block_count += 1
        self.log.info(f"block1 hash: {block1.hash}")

        self.__send_blocking_validation_block(block1, node0)

        receivedBlock = False

        def on_block(conn, message):
            nonlocal receivedBlock
            message.block.calc_sha256()
            if message.block.sha256 == block1.sha256:
                receivedBlock = True
        node0.on_block = on_block
        node0.send_message(msg_getblocks())

        block2 = self.chain.next_block(block_count)
        block_count += 1
        self.log.info(f"block2 hash: {block2.hash}")

        self.__send_blocking_validation_waiting_block(block2, node0)

        def wait_for_log():
            line_text = "Blocks that were received before getblocks message"
            for line in open(glob.glob(self.options.tmpdir + "/node0" + "/regtest/bitcoind.log")[0]):
                if line_text in line:
                    self.log.info("Found line: %s", line)
                    return True
            return False
        wait_until(wait_for_log)

        # remove block validating status to finish validation
        self.nodes[0].waitaftervalidatingblock(block1.hash, "remove")

        def wait_for_getblocks_reply():
            return receivedBlock
        wait_until(wait_for_getblocks_reply)

        # remove block validating status to finish validation
        self.nodes[0].waitaftervalidatingblock(block2.hash, "remove")

        # wait till validation of block finishes
        node0.sync_with_ping()

        return block_count
Exemplo n.º 2
0
    def __test_getblocks(self, node0, block_count):
        block1 = self.chain.next_block(block_count)
        block_count += 1
        self.log.info(f"block1 hash: {block1.hash}")

        self.__send_blocking_validation_block(block1, node0)

        receivedBlock = False

        def on_block(conn, message):
            nonlocal receivedBlock
            message.block.calc_sha256()
            if message.block.sha256 == block1.sha256:
                receivedBlock = True

        node0.on_block = on_block
        node0.send_message(msg_getblocks())

        block2 = self.chain.next_block(block_count)
        block_count += 1
        self.log.info(f"block2 hash: {block2.hash}")

        self.__send_blocking_validation_waiting_block(block2, node0)

        wait_until(lambda: check_for_log_msg(
            self, "Blocks that were received before getblocks message",
            "/node0"))

        # remove block validating status to finish validation
        self.nodes[0].waitaftervalidatingblock(block1.hash, "remove")

        def wait_for_getblocks_reply():
            return receivedBlock

        wait_until(wait_for_getblocks_reply)

        # remove block validating status to finish validation
        self.nodes[0].waitaftervalidatingblock(block2.hash, "remove")

        # wait till validation of block finishes
        node0.sync_with_ping()

        return block_count
Exemplo n.º 3
0
 def send_getblocks(self, locator):
     getblocks_message = msg_getblocks()
     getblocks_message.locator.vHave = locator
     self.send_message(getblocks_message)
Exemplo n.º 4
0
 def send_getblocks(self, locator):
     getblocks_message = msg_getblocks()
     getblocks_message.locator.vHave = locator
     self.send_message(getblocks_message)