There is a overlap with this submit and others however I will attempt to straight right a few issues right here.
Why do we have now two kinds of connections, outgoing and incoming?
To threat stating the apparent generally our node will make a request to hook up with one other node (outbound) while different instances a node will make a request to hook up with our node (inbound). In a wholesome peer to look (P2P) protocol you’ll be able to’t actually keep away from having each outgoing and incoming requests. The extent to which outbound and inbound connections are handled otherwise by your full node is a extra fascinating query. These Bitcoin Core PR evaluation membership notes (June eighth 2022) on inbound block-relay-only connections acknowledged:
As soon as the connection is established, the connection is essentially symmetric (the protocol works the identical in each instructions), though we deal with outbound friends with some choice.
In case you are involved about malicious full nodes you might need some trusted or semi trusted full nodes you select to hook up with (outbound) while presumably all inbound connection requests are from nodes you already know little or no about.
Are outgoing connections those the place we notify of recent blocks/transactions, whereas incoming connections are those the place they notify us of recent blocks/transactions?
No, each outbound and inbound connections can notify your node of recent blocks and transactions and vice versa. That PR evaluation membership I referred to does focus on block-relay-only friends which is the place you determine to solely relay blocks to sure friends and never transactions, IP addresses. Inbound connections may point out they do not need to obtain transactions and so forth.
After we do the preliminary synchronization (IBD) or utterly randomly need to ask a couple of block or transaction or one thing third, is it achieved with outgoing connections or incoming connections?
Each. If we aren’t conscious of any friends/connections (ie we have now no connections in any respect) in the beginning of IBD we’d must make the most of DNS seeds to study of potential friends.
edit: Because of lightlike for stating this remark within the Bitcoin Core code on IBD often solely being achieved with outbound friends
If we have no outbound
friends, or if we aren’t downloading any blocks from such friends, then
permit block downloads from this peer, too. We favor downloading
blocks from outbound friends to keep away from placing undue load on (say) some
residence person who’s simply making outbound connections to the community, however
if our solely supply of the newest blocks is from an inbound peer, we
must be sure you ultimately obtain it (and never simply wait
indefinitely for an outbound peer to have it).