P2P: Do not request blocks from peers with fewer blocks than us #1834

pull jgarzik wants to merge 1 commits into bitcoin:master from jgarzik:kickblocks changing 1 files +1 −0
  1. jgarzik commented at 2:35 AM on September 19, 2012: contributor

    If the remote node has a shorter chain, do not waste our special getblocks request on them.

  2. gmaxwell commented at 5:06 AM on September 19, 2012: contributor

    NAK. This potentially breaks the bitcoin distributed algorithm.

    (Ignore checkpoints for a moment.) I mine a long fork with 300,000 diff1 blocks. I feed it to you. You'll now never fetch the much longer real chain from honest nodes. Same problem exists later in the chain too, it's just not trivial to pull off as an attack in that case. May also have some weird effects with forks around the retarget (you can have short competing forks with different difficulties, and because the maximum retarget change is >=2x a lower diff chain could have more blocks, even for a fork only a few blocks long)

  3. jgarzik commented at 5:29 AM on September 19, 2012: contributor

    That case is nigh impossible given checkpoints. You ask to ignore this, to present a theoretical case that does not therefore apply to real world client releases.

    One case obviously can lead to stuck downloads today. The client sends getblocks to a remote peer that we know in advance does not have the data we need. nAskedForBlocks is incremented, preventing further queries, directly and immediately leading to a stuck download.

  4. laanwj commented at 5:43 AM on September 19, 2012: member

    It does seem a bit dangerous to rely on pfrom->nStartingHeight so completely. It's very hard to see what effect this will have in edge cases.

    Couldn't we address the "stuck downloads" problem in another place, ie by detecting stuck downloads actively and requesting from different nodes. After all, even if a node claims to have more blocks, it can still be stuck.

  5. gmaxwell commented at 5:50 AM on September 19, 2012: contributor

    @jgarzik the download happily continues when we get another block from the network in an average of 10 minutes.

    I presented the toy example ignoring checkpoints because its easier to understand. The same exposure exists at retargets where a forks can be created that differ in difficulty by a factor of two, or if a non-majority but high hashpower (e.g. asics before they are widely adopted) attacker used timewarp to mine a fork down to low difficulty starting anywhere after the highest checkpoint.

    I don't think the exposure, even if it is fringe and unexciting is worth avoiding waiting for a block in the rare case that you get a peer which is stuck and behind the chain.

  6. gmaxwell commented at 7:06 AM on September 19, 2012: contributor

    Gah, sorry, I read the title without actually reading the patch. My above concerns aren't an issue here: even in those cases when the real network finds a block again it'll still pull from them, which is adequate and fine.

  7. BitcoinPullTester commented at 1:44 PM on September 20, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/d5d19c74a5f5cbcaad6869dc7d89bd7077b7d175 for binaries and test log.

  8. sipa commented at 12:38 PM on September 21, 2012: member

    Something like this is useful, but it will fail to fetch the new chain in some edge cases (I know, those will be fetched when a successor block is broadcast, but still). Maybe some flexibility, like (nStartingHeight > nBestHeight - 144) is more safe, and will still prevent against the majority of silly getblocks?

  9. P2P: Do not request blocks from peers with fewer blocks than us
    If the remote node has a shorter chain, do not waste our
    special getblocks request on them.
    93dd68e924
  10. jgarzik commented at 5:26 PM on September 24, 2012: contributor

    Updated commit to offset height count by 144.

  11. BitcoinPullTester commented at 4:08 AM on September 25, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/93dd68e924c7cf24b75bfb5b83b1be1cdc27dbdc for binaries and test log.

  12. laanwj commented at 4:28 PM on September 25, 2012: member

    ACK with the 144 offset

  13. sipa commented at 2:06 PM on October 7, 2012: member

    ACK

  14. jgarzik referenced this in commit de2b9459bd on Oct 8, 2012
  15. jgarzik merged this on Oct 8, 2012
  16. jgarzik closed this on Oct 8, 2012

  17. jgarzik deleted the branch on Aug 24, 2014
  18. owlhooter referenced this in commit 21a10057df on Oct 10, 2018
  19. KolbyML referenced this in commit 9d5f5952e0 on Dec 5, 2020
  20. DrahtBot 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-04-20 00:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me