net: Make p2p recv buffer timeout 20 minutes for all peers #20651

pull jnewbery wants to merge 1 commits into bitcoin:master from jnewbery:2020-12-recv-buffer-timeout changing 1 files +1 −1
  1. jnewbery commented at 1:25 pm on December 14, 2020: member

    The timeout interval for the send and recv buffers was changed from 90 minutes to 20 minutes in commit f1920e86 in 2013, except for peers that did not support the pong message (where the recv buffer timeout remained at 90 minutes). A few observations:

    • for peers that support BIP 31 (pong messages), this recv buffer timeout is almost redundant with the ping timeout. We send a ping message every two minutes, and set a timeout of twenty minutes to receive the pong response. If the recv buffer was really timing out, then the pong response would also time out.
    • BIP 31 is supported by all nodes of p2p version 60000 and higher, and has been in widespread use since 2013. I’d be very surprised if there are many nodes on the network that don’t support pong messages.
    • The recv buffer timeout is not specified in any p2p BIP. We’re free to set it at any value we want.
    • A peer that doesn’t support BIP 31 and hasn’t sent any message to us at all in 90 minutes is unlikely to be useful for us, and is more likely to be evicted AttemptToEvictConnection() since it’ll have the worst possible ping time and isn’t providing blocks/transactions.

    Therefore, we remove this check, and set the recv buffer timeout to 20 minutes for all peers. This removes the final p2p version dependent logic from the net layer, so all p2p version data can move into the net_processing layer.

    Alternative approaches:

    • Set the recv buffer timeout to 90 minutes for all peers. This almost wouldn’t be a behaviour change at all (pre-BIP 31 peers would still have the same recv buffer timeout, and we can’t ever reach a recv buffer timeout higher than 21 minutes for post-BIP31 peers, because the pong timeout would be hit first).
    • Stop supporting peers that don’t support BIP 31. BIP 31 has been in use since 2012, and implementing it is trivial.
  2. [net] Make p2p recv buffer timeout 20 minutes for all peers
    The timeout interval for the send and recv buffers was changed from 90
    minutes to 20 minutes in commit f1920e86 in 2013, except for peers that
    did not support the pong message (where the recv buffer timeout remained
    at 90 minutes). A few observations:
    
    - for peers that support BIP 31 (pong messages), this recv buffer
      timeout is almost redundant with the ping timeout. We send a ping
      message every two minutes, and set a timeout of twenty minutes to
      receive the pong response. If the recv buffer was really timing out,
      then the pong response would also time out.
    - BIP 31 is supported by all nodes of p2p version 60000 and higher, and
      has been in widespread use since 2013. I'd be very surprised if there
      are many nodes on the network that don't support pong messages.
    - The recv buffer timeout is not specified in any p2p BIP. We're free to
      set it at any value we want.
    - A peer that doesn't support BIP 31 and hasn't sent any message to us
      at all in 90 minutes is unlikely to be useful for us, and is more likely
      to be evicted AttemptToEvictConnection() since it'll have the worst
      possible ping time and isn't providing blocks/transactions.
    
    Therefore, we remove this check, and sent the recv buffer timeout to 20
    minutes for all peers. This removes the final p2p version dependent
    logic from the net layer, so all p2p version data can move into the
    net_processing layer.
    
    Alternative approaches:
    
    - Set the recv buffer timeout to 90 minutes for all peers. This almost
      wouldn't be a behaviour change at all (pre-BIP 31 peers would still
      have the same recv buffer timeout, and we can't ever reach a recv buffer
      timeout higher than 21 minutes for post-BIP31 peers, because the pong
      timeout would be hit first).
    - Stop supporting peers that don't support BIP 31. BIP 31 has been in
      use since 2012, and implementing it is trivial.
    ea36a453e3
  3. fanquake added the label P2P on Dec 14, 2020
  4. MarcoFalke commented at 2:47 pm on December 14, 2020: member
    review ACK ea36a453e3d06657679459e1168347648fa7c5c0
  5. promag commented at 4:33 pm on December 14, 2020: member

    Code review ACK ea36a453e3d06657679459e1168347648fa7c5c0.

    nit, commit is from 2014.

  6. jnewbery commented at 5:21 pm on December 14, 2020: member

    nit, commit is from 2014.

    Good catch. I’ll update the commit message if I need to retouch this PR.

  7. practicalswift commented at 8:31 pm on December 14, 2020: contributor

    Concept ACK

    While touch the timeout handling, consider moving these log messages to BCLog::NET:

    0$ git grep 'LogPrintf(.*socket.*timeout:'
    1src/net.cpp:            LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
    2src/net.cpp:            LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
    

    These two are among the least informative unconditional log messages we currently have, and they are both peer triggerable (in low volume luckily) :)

  8. jnewbery commented at 10:50 am on December 15, 2020: member

    While touch the timeout handling, consider moving these log messages

    I’d prefer to leave that for a future PR to keep this one focused.

  9. jonatack commented at 11:21 am on December 15, 2020: member
    Code review ACK ea36a453e3d06657679459e1168347648fa7c5c0
  10. practicalswift commented at 12:33 pm on December 15, 2020: contributor
    cr ACK ea36a453e3d06657679459e1168347648fa7c5c0: patch looks correct
  11. ajtowns commented at 10:05 pm on December 15, 2020: member

    ACK ea36a453e3d06657679459e1168347648fa7c5c0

    Removes special case for old peers that don’t seem to be around, and 20min timeout vs 90min timeout should be fine for any such peers anyway. Only touches one line of code so hopefully shouldn’t interfere with any other PRs in the works. Don’t think it has any denial-of-service impact; buggy nodes all seem like they’ll announce bip31 compliant version numbers anyway, and people doing deliberate attacks can just do ping/pong to keep the connection open anyway.

  12. sipa commented at 10:14 pm on December 15, 2020: member

    utACK ea36a453e3d06657679459e1168347648fa7c5c0

    I don’t see any downsides to simplifying this.

  13. sdaftuar commented at 7:27 pm on December 16, 2020: member

    Only downside I could think of is if there’s some (old) wallet software someone might be using, where this change could cause more frequent disconnects?

    Presumably such software would have had to deal with the 90 minute timeout anyway though, so changing it to 20 minutes seems unlikely to be a fundamental problem.

    Concept ACK.

  14. MarcoFalke merged this on Dec 16, 2020
  15. MarcoFalke closed this on Dec 16, 2020

  16. jnewbery deleted the branch on Dec 16, 2020
  17. sidhujag referenced this in commit 61f7e7f506 on Dec 17, 2020
  18. DrahtBot locked this on Feb 15, 2022

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: 2024-07-03 10:13 UTC

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