2

Suppose a node receives the same "inv" message from many peers.

  1. Will the node send "getheaders" requests to all the peers or only one of them?

  2. Does the node keep a timer for getting the "headers" response from the peers? How big is the timer?

  3. Suppose the node sends "getheaders" requests to only one of its peers and the timer expires. How many other peers does the node then send "getheaders" requests to? Does the node store a map data structure map<"inv", peer id from which the inv is received> to do this?

satya
  • 161
  • 5
  • Are you asking about Bitcoin Core (and which version?), or nodes in general? This is all local policy that each node/implementation can decide for itself. – Pieter Wuille Jul 22 '21 at 00:24
  • @PieterWuille I'm asking about how Bitcoin Core (the latest version) implements it, and if there is a general node policy laid out somewhere that many implementations use. – satya Jul 22 '21 at 01:31

1 Answers1

3
  1. During IBD, Bitcoin Core will only send getheaders to one peer. After IBD, it will send it to all on connection.
  2. 15 minutes. After that it will disconnect the peer if nothing is received.
  3. As after timeout peers get disconnected, that opens up the slot for "headers requesting peer" to go to another one.
Pieter Wuille
  • 98,249
  • 9
  • 183
  • 287
  • Interesting. Isn't 15 minutes a pretty large timeout to wait? The node waits only for 2 seconds for receiving a response from "getdata", and disconnects the peer if it didn't send "block" within 2 seconds right? – satya Jul 22 '21 at 12:00
  • What about "getdata" message? Does the node send "getdata" to all the peers that sent the corresponding "headers" or only one of them? – satya Jul 22 '21 at 12:12
  • 1
    Bitcoin Core never requests the same block or transaction twice from the same peer. They all have timeouts that are tracked, and reassigned when the timeout expires. – Pieter Wuille Jul 22 '21 at 13:55
  • Got it. I understand that after IBD, if a node gets the same "inv" message from 5 peers, then the node sends the same "getheaders" request to all 5 peers. It makes sense as "getheaders" and "headers" are pretty small messages and don't add too much communication. Suppose the node gets the same "headers" from 5 peers. Will the node send "getdata" request to all 5 peers? Or will the node send "getdata" request to one peer, wait until the timer expires, and then send "getdata" to another peer? – satya Jul 22 '21 at 14:33
  • Sorry, I meant to say: Bitcoin Core never requests the same transaction/block twice simultaneously, even from distinct peers. The existing request has to time out before it is asked elsewhere. – Pieter Wuille Jul 22 '21 at 15:11
  • That's perfect :) Is the timeout for "getdata" also 15 minutes? – satya Jul 22 '21 at 15:12
  • For transactions it is 2 minutes, but we don't disconnect on on timeout; just mark the peer as not having that tx, and asking another. For blocks I don't remember the details. You can look in https://github.com/bitcoin/bitcoin/tree/master/src/txrequest.h for some of the design choices for tx requesting. The block fetching code is spread out over a few places in net_processing.cpp. – Pieter Wuille Jul 22 '21 at 15:24