<p>Simply, NANO uses UDP for blocks which are usually (certainly mostly, but always??) lower than the <strong>theoretical</strong> size limit of a UDP packet, 65 KB. In Bitcoin's case, transactions ≠ blocks. It's surely inefficient to transfer long data (Bitcoin blocks can be up to 4 megabytes - theoretically) using UDP, and that's also how other services choose between them. Besides, even if blocks were a few kilobytes, packet drop will cause miners to lose A LOT, as a few seconds delay is significant.</p>

<p>If the data is small, you can just send one packet (which is usually much lower than 65 KB). Otherwise, using TCP, handshake, keepalive things are not expensive.</p>

<p>Trivia: In Satoshi's client, there were no additional error correction codes in the protocol. Satoshi trusted TCP error correction.</p>

CC BY-SA 4.0
2018-09-13T17:41:13.630Z
Block is bitcoin is 1 mb. sure, it won't fit into one UDP datagram, and even if it did, at 65KB, it is still subject to fragmentation. However, it makes no sense to not allow the transaction themselves to be UDP based
user2584960
CC BY-SA 4.0
2018-09-13T15:11:18.143Z
2018-09-13T15:11:18.143Z
MCCCS
<p>There are several Reliable UDP implementations available by now, so requirements like packet loss recovery and statefulness can be addressed. One example is the UDT library developed by the University of Chicago: <a href="http://udt.sourceforge.net/" rel="nofollow noreferrer">http://udt.sourceforge.net/</a></p>

<p>We've developed a protocol named SRT (Secure Reliable Transport), initially based on UDT and extended by adding bi-directional data transfer and encryption to the mix. Although it's optimized for real-time data like video, it's content independent by design: <a href="https://github.com/Haivision/srt" rel="nofollow noreferrer">https://github.com/Haivision/srt</a></p>

<p>In video use cases, we are seeing dramatically increased bandwidth utilization numbers using UDP over TCP (e.g. RTMP), especially relevant for longer distance communication. I do believe it does make sense to evaluate UDP based alternatives for data transfer between nodes in order to increase network efficiency.</p>

CC BY-SA 4.0
2018-09-27T18:59:57.023Z
do you have contact info I can reach you at - I would like to discuss.
user2584960
CC BY-SA 4.0
2018-09-25T14:17:45.973Z
2018-09-25T14:17:45.973Z
heidabyr
<p>UDP is not very useful in Bitcoin. It is largely a unidirectional communication structure, whereas Bitcoin relies on bidirectional communication. When a node connects to another node, there is saved state for those nodes (nodes keep track of things that they have sent to other nodes and of things they have received from other nodes) and there is back and forth communication (e.g. send <code>inv</code>, receive <code>getdata</code> response, and send the data). UDP is not useful for that, but TCP is.</p>

<p>Furthermore, UDP exposes the nodes to the unreliability of the networks. The packet loss rate is not 0 (and cannot be 0), so using UDP results in a lot of extra data being sent due to packet loss. This is because blocks and transactions cannot be missing any bytes whatsoever. Otherwise they will be invalid. With TCP, if a packet is dropped, TCP will handle the resending of the data. But with UDP that needs to be handled at the application layer and it just gets complicated since figuring out what has been dropped requires bidirectional communication which is not easily done with UDP.</p>

<p>So overall, UDP is not useful for Bitcoin. It does not support bidirectional communication and it does not guarantee delivery of packets. Both of those things are necessary for Bitcoin's P2P protocol to work, so UDP can't be used. TCP is does both of those things at the protocol level, so it is used.</p>

CC BY-SA 4.0
2018-09-13T17:40:15.500Z
This is incorrect. First of all UDP is not a unidirectional communication. UDP is connectionless, however statefulness can be implemented at the application layer, which BITCOIN already does. see their p2p system. Like I said, the loss of the packet isnt an issue as the whole idea of a p2p network is so that its tolerant to packet loss. So what if a node didn't get a transaction, just ask for it again. Your answer is not very helpful. sorry.
user2584960
CC BY-SA 4.0
2018-09-13T21:22:29.967Z
I also cringed a bit at the unidirectional claim, but it's not entirely untrue: that's why NAT traversal is an issue for UDP where it isn't one for TCP.   It is the case the statefulness can be and is implemented in the application but the statefulness of TCP itself is really modest compared to the general statefulness of the protocol. As my answer pointed out: it would be totally reasonable for each bitcoin node to have a TCP connection up with most of the other reachable nodes. The state costs for the TCP itself aren't that substantial. The bitcoin protocol state is another matter...
G. Maxwell
CC BY-SA 4.0
2018-09-13T14:25:25.240Z
2018-09-13T14:25:25.240Z
Ava Chow
<p>The Bitcoin system doesn't have just one network protocol:   Any way of obtaining the blocks is equally valid-- blocks over freenet, over satellite broadcast, over the P2P network, all work just as well and are used in practice.  UDP is used with bitcoin too, by the <a href="https://bitcoin.stackexchange.com/questions/56485/can-someone-please-explain-fibre-to-me-like-im-5-and-why-is-it-useful">Fibre protocol</a>.</p>

<p>As far the common Bitcoin P2P protocol goes UDP is not an especially good fit for most operations that it performs.  Bitcoin needs to reliably send messages far larger than an IP packet, like transactions and blocks. Although the internet is "reliable" packet loss rates of 1-3% are common. This means that any application needing to communicate large messages with UDP must implement packetization, retransmission, reordering, etc-- the same things that TCP already implements for us.  Many applications that have 'rolled their own TCP' in userspace have ended up with exploitable bugs in them, so it isn't something that should be done without good cause. </p>

<p>UDP also has the issue of NAT traversal:  Getting bidirectional communication across a NAT with UDP is not a simple matter. Crossing anything more complicated than a full cone nat requires considerable amounts of special code but without it there will be a many hosts that just can't talk to other peers with UDP.</p>

<p>You mention connectionlessness allowing you relay to a random host in the network, but in Bitcoin P2P we make use of the consistent relationship between nodes to make the network more reliable and efficient. Nodes have an idea what their peers already know and can avoid sending them redundant data. Nodes also know which peers have been fastest in sending them blocks in the past and handle them specially. Likewise, even if the protocol is connectionless there are costs to processing messages from peers by prioritizing handling messages from existing peers, Bitcoin reduces the impact of some kinds of DOS attack. Handling larger than one-packet messages, retransmissions, etc. also mean that even with a connectionless transport there still needs to be some kind of persistent state.</p>

<p>But an if implementation did want to randomly connect to send a message it could, at an extra cost is a couple round trips for the handshake. Or not even  that: there are only about 10,000 reachable nodes in the P2P network, there wouldn't be much of a challenge in holding open a mostly idle TCP connection to each and ever one of them if all the state retained were just the TCP state. So for that point the use of UDP would at best just be an optimization for something that could already be done but isn't done. I think it would be more interesting to demonstrate the usefulness of having all those connections first, before worrying about optimizing it.</p>

<p>So why might UDP transport be useful to the Bitcoin P2P protocol?</p>

<ul>
<li><p>To get lowest latency block transfer possible there must be <em>no</em> round trips even in the face of packet loss which precludes TCP and which is why Fibre uses UDP. But to get no round trips the protocol must be able to handle loss without retransmission and to get low latency a block must be decodable with a minimum amount of data received. This requires very sophisticated error correction techniques which are an evolving area and haven't become mature enough yet to consider mainstreaming them. The latency benefits of fibre also exist so long as a small number of hosts are using it, since it does the heavy lifting of taking blocks all around the world.  Round trips don't cause much harm on low latency links. And this latency concern only applies to block relay.</p></li>
<li><p>Unlike TCP, UDP requires some amount of NAT traversal handling to simply get bidirectional communication working. But combined with full nat traversal handling UDP is often able to establish communication between hosts which are both behind different NATs.  This could be helpful for the Bitcoin P2P network since most hosts are unreachable behind a nat. So, ironically, one of UDP's challenges is also one of its uses. However, to connect hosts which are both behind a net the assistance of a third party non-natted host is required along with even more NAT traversal code.  Considering the complexity of traversal improving Bitcoin's support for TCP port mapping (e.g. implementing NAT-PMP) would probably be a better return on investment right now.</p></li>
<li><p>Use of UDP would allow for "worst than best effort" traffic handling. For low priority "bulk traffic" like syncing the blockchain it would be nice if the traffic carefully shaped itself to avoid interfering with other traffic on the network. Alternative congestion control algorithims like <a href="https://en.wikipedia.org/wiki/LEDBAT" rel="noreferrer">LEDBAT</a> make it possible to transfer low priority data with minimal impact. But since TCP stacks don't yet commonly support these congestion control approaches, applications that want them currently need to implement their own transports. For Bitcoin it would be ideal if we could just flip a socket option and turn  LEDBAT on and off on existing connections (e.g. when the peer is requesting historical blocks or in the future when something like Fibre is being used by the node to relay new blocks) but that isn't an option yet.</p></li>
</ul>

<p>[These last two reasons are the reasons that Bittorrent usually uses UDP]</p>

CC BY-SA 4.0
2018-09-13T17:50:45.033Z
@g-maxwell Great answer. What do you think about the following: If its for a PoS system in which certain validators can process transactions only. Instead of relying on TCP block propagation, do you think it would be useful to have those validators accept UDP transaction requests so that we can get transactions validated faster? In other words, do you see any disadvantage to use TCP for block propagation (large data) and UDP for single transaction request so that the nodes do not need to establish TCP connection.
user2584960
CC BY-SA 4.0
2018-09-13T18:02:29.093Z
Why do transactions need to propagate fast? That premise is generally in conflict with privacy.
Pieter Wuille
CC BY-SA 4.0
2018-09-13T19:37:59.860Z
Because if we want real adoption for crypto two things need to happen: stable currency and confirmation time. We can solve stablility via pegging and that leaves us with confirmation time. In order to achieve 2-3 second confirmation time we need faster relay mechnism than propagation.
user2584960
CC BY-SA 4.0
2018-09-13T19:53:55.840Z
Bitcoin achieves subsecond most of the network propagation time for small blocks... there is no need to use anything other than TCP for that.  But 2-3 second true confirmation time is pushing with the laws of physics for an actually decentralized network that spans earth and is probably not practically possible with real networks. Sometimes though not often whole continents are mostly severed from each other for minutes.
G. Maxwell
CC BY-SA 4.0
2018-09-13T22:56:39.850Z
If you can put the whole POW vs Pos argument aside I actually have a working prototype that has run a real test net in a geographically dislocated setting where I achieved (my team) a 6-7 second true confirmation. This is not including transaction submission time of course. So to ask the question here Greg: would UDP transaction submission be a good idea in my setting? Appreciate your insight as you are well respected in my book.
user2584960
CC BY-SA 4.0
2018-09-13T15:15:06.290Z
2018-09-13T15:24:13.127Z
2018-09-13T15:24:13.127Z
G. Maxwell
<p>Bitcoin uses TCP for P2P but why is UDP not used?  Modern day internet has relatively low packet loss rate so UDP is reliable. Even if some packets are dropped the peers can always request for the blocks. With TCP, the network is rather staticly constructed whereas with UDP you can construct a random graph each time a block is propagated as UDP is connectionless.</p>
<p>NANO uses UDP and I think it’s a good approach. I’m just curious as to if I’m missing something. Bootstrapping can obviously be done using TCP.</p>

<peers><peer-discovery><tcp>
Why doesn’t Bitcoin use UDP to do Blockpropagation?
user2584960
# Why doesn’t Bitcoin use UDP to do Blockpropagation?

(Asked by: username_0 on 2018-09-13)

Bitcoin uses TCP for P2P but why is UDP not used? Modern day internet has relatively low packet loss rate so UDP is reliable. Even if some packets are dropped the peers can always request for the blocks. With TCP, the network is rather staticly constructed whereas with UDP you can construct a random graph each time a block is propagated as UDP is connectionless.

NANO uses UDP and I think it’s a good approach. I’m just curious as to if I’m missing something. Bootstrapping can obviously be done using TCP.

**Tags:** peers, peer-discovery, tcp


---

## 4 answers

### Answer by username_4 on 2018-09-13. Score: 25 | Accepted answer

The Bitcoin system doesn't have just one network protocol: Any way of obtaining the blocks is equally valid-- blocks over freenet, over satellite broadcast, over the P2P network, all work just as well and are used in practice. UDP is used with bitcoin too, by the [Fibre protocol](https://bitcoin.stackexchange.com/questions/56485/can-someone-please-explain-fibre-to-me-like-im-5-and-why-is-it-useful).

As far the common Bitcoin P2P protocol goes UDP is not an especially good fit for most operations that it performs. Bitcoin needs to reliably send messages far larger than an IP packet, like transactions and blocks. Although the internet is "reliable" packet loss rates of 1-3% are common. This means that any application needing to communicate large messages with UDP must implement packetization, retransmission, reordering, etc-- the same things that TCP already implements for us. Many applications that have 'rolled their own TCP' in userspace have ended up with exploitable bugs in them, so it isn't something that should be done without good cause.

UDP also has the issue of NAT traversal: Getting bidirectional communication across a NAT with UDP is not a simple matter. Crossing anything more complicated than a full cone nat requires considerable amounts of special code but without it there will be a many hosts that just can't talk to other peers with UDP.

You mention connectionlessness allowing you relay to a random host in the network, but in Bitcoin P2P we make use of the consistent relationship between nodes to make the network more reliable and efficient. Nodes have an idea what their peers already know and can avoid sending them redundant data. Nodes also know which peers have been fastest in sending them blocks in the past and handle them specially. Likewise, even if the protocol is connectionless there are costs to processing messages from peers by prioritizing handling messages from existing peers, Bitcoin reduces the impact of some kinds of DOS attack. Handling larger than one-packet messages, retransmissions, etc. also mean that even with a connectionless transport there still needs to be some kind of persistent state.

But an if implementation did want to randomly connect to send a message it could, at an extra cost is a couple round trips for the handshake. Or not even that: there are only about 10,000 reachable nodes in the P2P network, there wouldn't be much of a challenge in holding open a mostly idle TCP connection to each and ever one of them if all the state retained were just the TCP state. So for that point the use of UDP would at best just be an optimization for something that could already be done but isn't done. I think it would be more interesting to demonstrate the usefulness of having all those connections first, before worrying about optimizing it.

So why might UDP transport be useful to the Bitcoin P2P protocol?

* To get lowest latency block transfer possible there must be *no* round trips even in the face of packet loss which precludes TCP and which is why Fibre uses UDP. But to get no round trips the protocol must be able to handle loss without retransmission and to get low latency a block must be decodable with a minimum amount of data received. This requires very sophisticated error correction techniques which are an evolving area and haven't become mature enough yet to consider mainstreaming them. The latency benefits of fibre also exist so long as a small number of hosts are using it, since it does the heavy lifting of taking blocks all around the world. Round trips don't cause much harm on low latency links. And this latency concern only applies to block relay.
* Unlike TCP, UDP requires some amount of NAT traversal handling to simply get bidirectional communication working. But combined with full nat traversal handling UDP is often able to establish communication between hosts which are both behind different NATs. This could be helpful for the Bitcoin P2P network since most hosts are unreachable behind a nat. So, ironically, one of UDP's challenges is also one of its uses. However, to connect hosts which are both behind a net the assistance of a third party non-natted host is required along with even more NAT traversal code. Considering the complexity of traversal improving Bitcoin's support for TCP port mapping (e.g. implementing NAT-PMP) would probably be a better return on investment right now.
* Use of UDP would allow for "worst than best effort" traffic handling. For low priority "bulk traffic" like syncing the blockchain it would be nice if the traffic carefully shaped itself to avoid interfering with other traffic on the network. Alternative congestion control algorithims like [LEDBAT](https://en.wikipedia.org/wiki/LEDBAT) make it possible to transfer low priority data with minimal impact. But since TCP stacks don't yet commonly support these congestion control approaches, applications that want them currently need to implement their own transports. For Bitcoin it would be ideal if we could just flip a socket option and turn LEDBAT on and off on existing connections (e.g. when the peer is requesting historical blocks or in the future when something like Fibre is being used by the node to relay new blocks) but that isn't an option yet.

[These last two reasons are the reasons that Bittorrent usually uses UDP]

> **Comments:**
> **username_0**: @g-username_4 Great answer. What do you think about the following: If its for a PoS system in which certain validators can process transactions only. Instead of relying on TCP block propagation, do you think it would be useful to have those validators accept UDP transaction requests so that we can get transactions validated faster? In other words, do you see any disadvantage to use TCP for block propagation (large data) and UDP for single transaction request so that the nodes do not need to establish TCP connection.  
> **username_5**: Why do transactions need to propagate fast? That premise is generally in conflict with privacy.  
> **username_0**: Because if we want real adoption for crypto two things need to happen: stable currency and confirmation time. We can solve stablility via pegging and that leaves us with confirmation time. In order to achieve 2-3 second confirmation time we need faster relay mechnism than propagation.  
> **username_4**: Bitcoin achieves subsecond most of the network propagation time for small blocks... there is no need to use anything other than TCP for that.  But 2-3 second true confirmation time is pushing with the laws of physics for an actually decentralized network that spans earth and is probably not practically possible with real networks. Sometimes though not often whole continents are mostly severed from each other for minutes.  
> **username_0**: If you can put the whole POW vs Pos argument aside I actually have a working prototype that has run a real test net in a geographically dislocated setting where I achieved (my team) a 6-7 second true confirmation. This is not including transaction submission time of course. So to ask the question here Greg: would UDP transaction submission be a good idea in my setting? Appreciate your insight as you are well respected in my book.  

---

### Answer by username_1 on 2018-09-13. Score: 1

Simply, NANO uses UDP for blocks which are usually (certainly mostly, but always??) lower than the **theoretical** size limit of a UDP packet, 65 KB. In Bitcoin's case, transactions ≠ blocks. It's surely inefficient to transfer long data (Bitcoin blocks can be up to 4 megabytes - theoretically) using UDP, and that's also how other services choose between them. Besides, even if blocks were a few kilobytes, packet drop will cause miners to lose A LOT, as a few seconds delay is significant.

If the data is small, you can just send one packet (which is usually much lower than 65 KB). Otherwise, using TCP, handshake, keepalive things are not expensive.

Trivia: In Satoshi's client, there were no additional error correction codes in the protocol. Satoshi trusted TCP error correction.

> **Comments:**
> **username_0**: Block is bitcoin is 1 mb. sure, it won't fit into one UDP datagram, and even if it did, at 65KB, it is still subject to fragmentation. However, it makes no sense to not allow the transaction themselves to be UDP based  

---

### Answer by username_2 on 2018-09-25. Score: 0

There are several Reliable UDP implementations available by now, so requirements like packet loss recovery and statefulness can be addressed. One example is the UDT library developed by the University of Chicago: <http://udt.sourceforge.net/>

We've developed a protocol named SRT (Secure Reliable Transport), initially based on UDT and extended by adding bi-directional data transfer and encryption to the mix. Although it's optimized for real-time data like video, it's content independent by design: <https://github.com/Haivision/srt>

In video use cases, we are seeing dramatically increased bandwidth utilization numbers using UDP over TCP (e.g. RTMP), especially relevant for longer distance communication. I do believe it does make sense to evaluate UDP based alternatives for data transfer between nodes in order to increase network efficiency.

> **Comments:**
> **username_0**: do you have contact info I can reach you at - I would like to discuss.  

---

### Answer by username_3 on 2018-09-13. Score: 0

UDP is not very useful in Bitcoin. It is largely a unidirectional communication structure, whereas Bitcoin relies on bidirectional communication. When a node connects to another node, there is saved state for those nodes (nodes keep track of things that they have sent to other nodes and of things they have received from other nodes) and there is back and forth communication (e.g. send `inv`, receive `getdata` response, and send the data). UDP is not useful for that, but TCP is.

Furthermore, UDP exposes the nodes to the unreliability of the networks. The packet loss rate is not 0 (and cannot be 0), so using UDP results in a lot of extra data being sent due to packet loss. This is because blocks and transactions cannot be missing any bytes whatsoever. Otherwise they will be invalid. With TCP, if a packet is dropped, TCP will handle the resending of the data. But with UDP that needs to be handled at the application layer and it just gets complicated since figuring out what has been dropped requires bidirectional communication which is not easily done with UDP.

So overall, UDP is not useful for Bitcoin. It does not support bidirectional communication and it does not guarantee delivery of packets. Both of those things are necessary for Bitcoin's P2P protocol to work, so UDP can't be used. TCP is does both of those things at the protocol level, so it is used.

> **Comments:**
> **username_0**: This is incorrect. First of all UDP is not a unidirectional communication. UDP is connectionless, however statefulness can be implemented at the application layer, which BITCOIN already does. see their p2p system. Like I said, the loss of the packet isnt an issue as the whole idea of a p2p network is so that its tolerant to packet loss. So what if a node didn't get a transaction, just ask for it again. Your answer is not very helpful. sorry.  
> **username_4**: I also cringed a bit at the unidirectional claim, but it's not entirely untrue: that's why NAT traversal is an issue for UDP where it isn't one for TCP.   It is the case the statefulness can be and is implemented in the application but the statefulness of TCP itself is really modest compared to the general statefulness of the protocol. As my answer pointed out: it would be totally reasonable for each bitcoin node to have a TCP connection up with most of the other reachable nodes. The state costs for the TCP itself aren't that substantial. The bitcoin protocol state is another matter...  

---

