Note: All links to the code are based on a fixed revision, so we can link line numbers. Code might have changed by now, nonetheless use these revisions when doing updates to this document.
- the app was configured and started
- all services registered
- the discovery protocol discovered some nodes
- the peermanager successfully connected a node
- established an encrypted multiplexed session
- we are waiting for ingress data in the peer connection
geth sets up a full Node: cmd/geth/main.go#L187
which registers an instance of the eth.Ethereum service with that Node: cmd/geth/main.go#L211
The eth.Ethereum service contains a ProtocolManager, which includes one SubProtocol for every supported protocol version: eth/handler.go#L134
Each of the SubProtocols is setup with a Run method that calls the ProtocolManager's handle() method: eth/handler.go#L144
And the Run method of each SubProtocol gets called when geth starts the Node: cmd/geth/main.go#L188 node/node.go#L142 node/node.go#L206 p2p/server.go#L406 p2p/server.go#L542 p2p/server.go#L742 p2p/peer.go#L150 p2p/peer.go#L303
which loops infinitely, handling incoming messages from the connected peer: eth/handler.go#L311
handleMsg() reads the msg from the peer: eth/handler.go#L324
which in our case is a NewBlockMsg, so the block data is decoded and scheduled for import: eth/handler.go#L629
The block fetcher will then try to import the new block: eth/fetcher/fetcher.go#L313
If the block header validates correctly it is propagated to the node's peers: eth/fetcher/fetcher.go#L672
processed: eth/fetcher/fetcher.go#L684 core/blockchain.go#L959
and if that results in a valid state, it's committed to the database: core/blockchain.go#L971
and written to the chain: core/blockchain.go#L984
What
geth
command line options were used? I am writing up a more detailed walkthrough.