Skip to content

Block download can stall after call to InvalidateBlock() #5806

Closed

Description

@sdaftuar

I observed that block propagation didn't work as I expected in testing with InvalidateBlock.

Let's say we have two nodes connected and synced. Then we use one to mine 20 blocks and sync the nodes. Then we invalidate the first of those blocks via rpc call to each node.

If we then mine 19 blocks on that same node that generated the initial 20, those blocks won't all propagate to the other node (the first 16 will make it, because of the call to getdata on processing each inv, which occurs until we've maxed out the number of blocks in flight to that peer). A specific test that fails is pasted below.

I believe what is happening is that the CNodeState variable pindexBestKnownBlock is stuck pointing at an invalid but more-work chain, and consequently the block download logic believes it doesn't have a peer from which to download the blocks on the new headers chain.

I'm not sure what the best way to fix this is, maybe we could clear the pindexBestKnownBlock variables if they're pointing to now-invalid blocks before returning from InvalidateBlock, or perhaps we could check the validity of pindexBestKnownBlock when we are comparing it in UpdateBlockAvailability? Both those approaches do appear to fix this test, but I'm not quite familiar enough with this logic to know whether either of those potential solutions makes sense.

#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

#
# Test invalidateblock
#

from test_framework import BitcoinTestFramework
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from util import *
import os
import shutil

class InvalidateBlockTest(BitcoinTestFramework):

    def setup_network(self):
        self.nodes = []
        self.nodes.append(start_node(0, self.options.tmpdir, ['-debug', '-whitelist=127.0.0.1']))
        self.nodes.append(start_node(1, self.options.tmpdir, ['-debug', '-whitelist=127.0.0.1']))
        connect_nodes(self.nodes[1], 0)
        self.is_network_split = False
        self.sync_all()

    def run_test(self):
        self.nodes[0].setgenerate(True, 1) # Leave IBD
        self.sync_all()

        cnt = self.nodes[0].getblockcount()

        node1blocks = self.nodes[1].setgenerate(True, 18)

        self.sync_all()
        if (self.nodes[0].getblockcount() != cnt + 18):
            raise AssertionError("Failed to sync initial blocks")

        self.nodes[0].invalidateblock(node1blocks[0])
        self.nodes[1].invalidateblock(node1blocks[0])

        if (self.nodes[0].getblockcount() != cnt):
            raise AssertionError("Failed to invalidate initial blocks")

        self.nodes[1].setgenerate(True, 17)

        print "All blocks generated, trying to sync"
        self.sync_all()
        if (self.nodes[0].getblockcount() != cnt + 17):
            raise AssertionError("Failed to sync shorter but valid chain")

if __name__ == '__main__':
    InvalidateBlockTest().main()

Activity

  1. domob1812 commented on Sep 11, 2016

    @domob1812
    Contributor

    See also #8698, which seems to be caused by the same underlying issue.

  2. added a commit that references this issue on Nov 4, 2019
    df117c8
  3. added a commit that references this issue on Dec 15, 2019
    24227b2
  4. locked as resolved and limited conversation to collaborators on Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions