2

Why do we have two types of connections, outgoing and incoming? What is the purpose of one and the other? Are outgoing connections the ones where we notify of new blocks/transactions, while incoming connections are the ones where they notify us of new blocks/transactions?

When we do the initial synchronization (IBD) or completely randomly want to ask about a block or transaction or something third, is it done with outgoing connections or incoming connections?

1 Answer 1

4

There's a overlap with this post and others but I'll try to directly correct a couple of things here.

Why do we have two types of connections, outgoing and incoming?

To risk stating the obvious sometimes our node will make a request to connect to another node (outbound) whilst other times a node will make a request to connect to our node (inbound). In a healthy peer to peer (P2P) protocol you can't really avoid having both outgoing and incoming requests. The extent to which outbound and inbound connections are treated differently by your full node is a more interesting question. These Bitcoin Core PR review club notes (June 8th 2022) on inbound block-relay-only connections stated:

Once the connection is established, the relationship is largely symmetric (the protocol works the same in both directions), although we treat outbound peers with some preference.

If you are concerned about malicious full nodes you might have some trusted or semi trusted full nodes you choose to connect to (outbound) whilst presumably all inbound connection requests are from nodes you know very little about.

Are outgoing connections the ones where we notify of new blocks/transactions, while incoming connections are the ones where they notify us of new blocks/transactions?

No, both outbound and inbound connections can notify your node of new blocks and transactions and vice versa. That PR review club I referred to does discuss block-relay-only peers which is where you decide to only relay blocks to certain peers and not transactions, IP addresses. Inbound connections can also indicate they don't want to receive transactions etc.

When we do the initial synchronization (IBD) or completely randomly want to ask about a block or transaction or something third, is it done with outgoing connections or incoming connections?

Both. If we aren't aware of any peers/connections (ie we have no connections at all) at the beginning of IBD we might need to utilize DNS seeds to learn of potential peers.

edit: Thanks to lightlike for pointing out this comment in the Bitcoin Core code on IBD usually only being done with outbound peers

If we don't have any outbound peers, or if we aren't downloading any blocks from such peers, then allow block downloads from this peer, too. We prefer downloading blocks from outbound peers to avoid putting undue load on (say) some home user who is just making outbound connections to the network, but if our only source of the latest blocks is from an inbound peer, we have to be sure to eventually download it (and not just wait indefinitely for an outbound peer to have it).

5
  • I see you use the term "outbound" instead of "outgoing" and "inbound" instead of "incoming", are those actually the standard terms used in the Bitcoin world and not "incoming" and "outgoing"?
    – Cosmos
    Dec 17, 2023 at 5:17
  • 2
    @MudjaAdum there are no standards because there is no real standardizing body. Nor should there be. There are commonly used terms but I find there is a great deal of variation and ambiguity. The variations you ask about both seem common usage to me. Dec 17, 2023 at 10:43
  • 1
    IBD is usually only done with outbound peers, only in some rare situations (see github.com/bitcoin/bitcoin/blob/master/src/… for an explanation) inbound peers are used.
    – Lightlike
    Dec 19, 2023 at 1:12
  • A node will generally not get any inbound connections before it is fully synced. @Lightlike: Do I remember correctly that our node will announce new transactions from its own wallet only to outbound connections?
    – Murch
    Dec 19, 2023 at 14:56
  • 1
    @Murch: Yes, we don't actively advertise our address while in IBD, so inbound peers are less likely to happen. But if they do know about our address for some reason, we don't prevent them from connecting. I don't think that we distinguish between in and outbounds when broadcasting wallet transactions.
    – Lightlike
    Dec 19, 2023 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.