Syncing of chains with different height depends on "connection direction" #5113

issue domob1812 opened this issue on October 21, 2014
  1. domob1812 commented at 7:09 AM on October 21, 2014: contributor

    Experimenting with a private -regtest network, I found the following behaviour that seems wrong: I've got two nodes, A and B. They are initially disconnected and A has a chain of height 210 while B has one of height 220 - they are forked at block 200. Now I want to connect the nodes and expect that A switches to B's longer chain.

    When I connect A to B (addnode call on A), this is precisely what happens. However, when I connect B to A (addnode called on B), both keep their chains. This seems very odd to me. I seem to recall that "a few days ago" both alternatives resulted in the nodes syncing to the same chain. (And can try to find out more about this / give more details if necessary.)

  2. sipa commented at 7:17 AM on October 21, 2014: member

    In which code version do you observe this?

  3. domob1812 commented at 7:22 AM on October 21, 2014: contributor

    Current Git header: 64ffc995d685cf8a53ef868572e835ce42269ec6

    My code contains also private commits, but they only touch the qa/rpc-tests folder.

  4. domob1812 referenced this in commit 2290ed01bc on Oct 24, 2014
  5. domob1812 cross-referenced this on Oct 24, 2014 from issue Add the ability for network splits to the Python test framework. by domob1812
  6. gavinandresen referenced this in commit e401a2c557 on Oct 24, 2014
  7. morcos commented at 1:43 AM on October 27, 2014: member

    I ran into this problem as well. The below code demonstrates it by hanging at sync_blocks. If you switch which node connects to which it tends to change whether it works or not. I also noticed that if you use sync_all it sometimes fails syncing the mempools after syncing the blocks. I'm not familar enough with the headers first code, but I think the issue is caused by which peer does a getheaders from the other. This is run from the current master.

    #!/usr/bin/env python
    
    from test_framework import BitcoinTestFramework
    from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
    from util import *
    import time
    
    class SyncDir(BitcoinTestFramework):
        def setup_network(self):
            self.nodes = []
            self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
            self.nodes.append(start_node(1, self.options.tmpdir, ["-debug"]))
            connect_nodes(self.nodes[1], 0)
            print("Nodes connected")
            self.is_network_split = False
            self.sync_all()
            random_transaction(self.nodes, Decimal("0.001"), Decimal("0.0001"), 0, 0)
            print ("One tx sent")
            self.nodes[0].setgenerate(True,1)
            print ("Block mined")
            self.sync_all()
            print ("Chains synced")
            stop_node(self.nodes[0],0)
            print ("Node stopped")
            self.nodes[0] = start_node(3, self.options.tmpdir,["-debug"])
            print ("New node created")
            connect_nodes(self.nodes[0], 1)  #connect the new node
            #connect_nodes(self.nodes[1], 3)  #connect the new node
            print ("New node connected....")
            #self.sync_all()
            sync_blocks(self.nodes)
            print ("New node synced")
    
        def run_test(self):
            print ("Running test")
    
    if __name__ == '__main__':
        SyncDir().main()
    
  8. TheBlueMatt commented at 1:58 AM on October 27, 2014: contributor

    I believe this is a dup/very related to #5138.

  9. domob1812 commented at 6:04 AM on October 27, 2014: contributor

    Regarding the sync_all problem: I ran into this myself recently as well. In my case, the problem is that the blocks are synced but the mempools are not. This happens (for me) when transactions are put back into the mempool after reorganising - it seems those are not broadcasted to the nodes that always were on the longer chain.

    Since I introduced sync_all, should I propose another patch? sync_all could be modified to be configurable about what should be synced (blocks and/or mempool), either with an optional argument or with a new member variable. join_network would then only sync blocks and not the mempools. Sounds like a good idea? Or should such a change be introduced only together with actual tests that need the fixed behaviour?

  10. gavinandresen cross-referenced this on Oct 28, 2014 from issue Introduce preferred download peers by sipa
  11. laanwj added the label Bug on Jan 8, 2015
  12. laanwj added the label Priority High on Jan 8, 2015
  13. laanwj commented at 1:25 PM on January 8, 2015: member

    Should be fixed by #5157

  14. laanwj closed this on Jan 8, 2015

  15. MarcoFalke cross-referenced this on Aug 27, 2019 from issue test: Establish only one connection between nodes in rpc_invalidateblock by MarcoFalke
  16. laanwj referenced this in commit cd737214ce on Sep 16, 2019
  17. sidhujag referenced this in commit f9a3ff0065 on Sep 16, 2019
  18. MarcoFalke cross-referenced this on Sep 17, 2019 from issue test: Remove connect_nodes_bi by MarcoFalke
  19. MarcoFalke referenced this in commit 59c138d2f1 on Sep 18, 2019
  20. random-zebra cross-referenced this on Mar 30, 2020 from issue [Tests][Refactor] Remove connect_nodes_bi by random-zebra
  21. random-zebra referenced this in commit 46585f7b62 on Mar 31, 2020
  22. reddink referenced this in commit 0c8bc1b50c on May 27, 2020
  23. bitcoin locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:55 UTC