1

If use gethcommand,then the node starts to sync with Ethereum Mainnet by default.If usegeth --testnet --networkid 3 --datadir <testnetdatapath>,then the node will connect to Ropsten.

How does this connection established? What are the steps executing at that time? Connecting to Blockchain,downloading genesis,downloading other blocks? How this functionality is achieved?

1

For syncing purposes, it doesn't matter whether it's the mainnet or a test net like Ropsten. This is how the process would somewhat proceed:

  1. Your Geth client will look for peers in the network. It uses ÐΞV's p2p network protocol for discovering and connecting to peers. Read more here, it's a repo of documents, so you might want to read relevant markdown files. During initialization, the concept of bootnodes comes in handy. Read more on how peers are discovered here in the ethereum wiki.

  2. Depending on your sync mode, your node will fetch (and validate) blocks from other peers in the network. At this point of time, your eth.syncing parameter will return true. When the syncing is complete, it means your node is up-to-date with other nodes in the network and you're technically aware of the most recent state of the Ethereum Virtual Machine and you can even mine the new transactions, or just validate them.

  3. From the launch, the Geth node also has JSON-RPC server running.

  4. Once the syncing is complete, your node will additionally be able to broadcast, and/or listen to broadcasts of new transactions in the network.

UPDATE:

I forgot to mention point 0, which @Ishmael has mentioned in his answer, that the genesis block is 'hardcoded' in the source code itself.

0

Geth has in their source code the genesis blocks and the bootnodes of the networks they support: mainnet, rinkeby, ropsten, etc.

At the beginning geth will connect to bootnodes and request new peers. Once connected to new peers it will start downloading blocks and verify they are descendant of the genesis block in the source code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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