I am wondering how nodes discover other nodes
Nodes learn about other nodes through:
- DNS seeds (which run crawlers that maintain databases of network nodes)
- From their peers (nodes gossip IP addresses of other nodes to each other)
- From their own database of nodes (which is fed by the above two mechanisms)
- From a hardcoded list built-in to the client, as a final fall back.
and miners
Miners are just nodes like all others; there is nothing special about them in this regard.
basically, who to broadcast received transactions and blocks to.
To clarify:
- Nodes make connections to other nodes; this is what needs to be discovered. Every node makes a few random connections to other nodes, not to everyone in the network.
- Nodes broadcast transactions and blocks (and IP addresses of other nodes) to these peers, not to everyone.
Eventually everyone will hear about every block, and most transactions, because everyone is connected to one another.
I'm assuming that when a new node or miner wants to be discovered, it broadcasts to all known nodes informing them that its a new node or miner.
It just rumors its IP address to its peers. Those peers will put the node's IP address in their peer database, and gossip it further to their peers. Over time, more and more nodes will learn about it.
Then the node puts the node or miner on a list of IP addresses, to broadcast transactions and blocks accordingly.
Nodes only ever communicate with their own peers (typically 8-10 outgoing connections, up to a few 100 incoming ones), but they can maintain databases of IP addresses with 10s of thousands of nodes. Most of those will never be connected with, but may be rumoured to others.