Ejemplo n.º 1
0
    def run_test(self):
        node = self.nodes[0]  # convenience reference to the node
        node.generatetoaddress(
            1,
            node.get_deterministic_priv_key().address)  # Get node out of IBD

        self.log.info('Test max locator size')
        block_count = node.getblockcount()
        for msg in [msg_getheaders(), msg_getblocks()]:
            self.log.info(
                'Wait for disconnect when sending {} hashes in locator'.format(
                    MAX_LOCATOR_SZ + 1))
            node.add_p2p_connection(P2PInterface())
            msg.locator.vHave = [
                int(node.getblockhash(i - 1), 16)
                for i in range(block_count, block_count -
                               (MAX_LOCATOR_SZ + 1), -1)
            ]
            node.p2p.send_message(msg)
            node.p2p.wait_for_disconnect()
            node.disconnect_p2ps()

            self.log.info(
                'Wait for response when sending {} hashes in locator'.format(
                    MAX_LOCATOR_SZ))
            node.add_p2p_connection(P2PInterface())
            msg.locator.vHave = [
                int(node.getblockhash(i - 1), 16)
                for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)
            ]
            node.p2p.send_message(msg)
            if type(msg) == msg_getheaders:
                node.p2p.wait_for_header(int(node.getbestblockhash(), 16))
            else:
                node.p2p.wait_for_block(int(node.getbestblockhash(), 16))
Ejemplo n.º 2
0
    def run_test(self):
        node = self.nodes[0]
        node.add_p2p_connection(P2PInterface())
        chaintip = node.getbestblockhash()

        # Mine some blocks and invalidate them
        blocks = node.generatetoaddress(
            3,
            node.get_deterministic_priv_key().address)
        assert_equal(blocks[-1], node.getbestblockhash())
        node.invalidateblock(blocks[0])
        assert_equal(chaintip, node.getbestblockhash())

        # Clear any old messages
        with p2p_lock:
            node.p2p.last_message.pop("block", None)
            node.p2p.last_message.pop("cmpctblock", None)
            node.p2p.last_message.pop("headers", None)

        # Requests for the invalidated block and it's decendants should fail.
        # Not doing so is a potential DoS vector.
        for b in blocks:
            block_hash = int(b, 16)

            # Currently, the implementation for getblocks skips blocks which
            # are not on the currently active chain. This is the only logged
            # indication of such.
            with node.assert_debug_log(expected_msgs=["getblocks -1 to"]):
                msg = msg_getblocks()
                msg.locator.vHave = [block_hash]
                node.p2p.send_message(msg)
                node.p2p.sync_with_ping()

            with node.assert_debug_log(expected_msgs=[
                    "ignoring request from peer=0 for old block that isn't in the main chain"
            ]):
                msg = msg_getdata()
                msg.inv.append(CInv(MSG_BLOCK, block_hash))
                node.p2p.send_message(msg)
                node.p2p.sync_with_ping()

            with node.assert_debug_log(expected_msgs=[
                    "ignoring request from peer=0 for old block that isn't in the main chain"
            ]):
                msg = msg_getdata()
                msg.inv.append(CInv(MSG_CMPCT_BLOCK, block_hash))
                node.p2p.send_message(msg)
                node.p2p.sync_with_ping()

            with node.assert_debug_log(expected_msgs=[
                    "ignoring request from peer=0 for old block header that isn't in the main chain"
            ]):
                msg = msg_getheaders()
                msg.hashstop = block_hash
                node.p2p.send_message(msg)
                node.p2p.sync_with_ping()
    def run_test(self):
        node = self.nodes[0]  # convenience reference to the node
        node.generate(1)  # Get node out of IBD

        self.log.info('Test max locator size')
        block_count = node.getblockcount()
        for msg in [msg_getheaders(), msg_getblocks()]:
            self.log.info('Wait for disconnect when sending {} hashes in locator'.format(MAX_LOCATOR_SZ + 1))
            node.add_p2p_connection(P2PInterface())
            msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ + 1), -1)]
            node.p2p.send_message(msg)
            node.p2p.wait_for_disconnect()
            node.disconnect_p2ps()

            self.log.info('Wait for response when sending {} hashes in locator'.format(MAX_LOCATOR_SZ))
            node.add_p2p_connection(P2PInterface())
            msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)]
            node.p2p.send_message(msg)
            if type(msg) == msg_getheaders:
                node.p2p.wait_for_header(int(node.getbestblockhash(), 16))
            else:
                node.p2p.wait_for_block(int(node.getbestblockhash(), 16))
Ejemplo n.º 4
0
 def send_getblocks(self, locator):
     getblocks_message = msg_getblocks()
     getblocks_message.locator.vHave = locator
     self.send_message(getblocks_message)