In this article, we will dive into the source code of Ethereum. Most Blockchain app developers will not go this deep. But if you do, you will gain some unique knowledge and stand out from your peers.
Introduction to Geth
The Ethereum Blockchain is a network of computers called nodes.
Each node runs a software called an Ethereum client . The most used client is called Geth, and this is its Github repo.
Most of the code is in Golang. There are many code modules, but only a few are important.
Geth modules
The accounts module is for wallet management.
The cmd module is the CLI of Geth. And if you go in this file, it’s what is executed when you start the CLI . Especially this function:
func main() {
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
This can be a fun to follow the rabbit hole and follow the execution path from there .
Then there is the consensus module, where you have the mining algorithm ethhash .
Then there is the core module, which manages the data structure of the Blockchains, like blocks, transactions. And that also has the Ethereum Virtual Machine or EVM, which executes the smart contract. That’s one of the most interesting part of the code.
Then there is eth, a module to keep the local Blockchain synced with the rest of the network.
Then there is ethdb, the database where the Ethereum Blockchain is stored, which uses a key value db used by google called LevelDB .
Then there is the miner module, for mining Ethereum. It makes use of the ethhash mining algorithm in the consensus module.
Then there is p2p, a low-level networking library to exchange data between nodes. Then there is the params module, where you have various configuration. For example there is the block number for the different forks.
Then we have rpc, which handles all the interfaces of geth, such as the json rpc API, the web socket API and the IPC API, a very fast way to interact with a GETH client if you are on the same machine.
And then there is the tests folder, which are integration tests to make sure that the implementation of geth respects the specification of the Ethereum protocol.
And you will notice that Solidity is not part of Geth, it’s a separate repo.
Conclusion
If you want to keep digging, feel free to explore the codebase of Geth.
And there are also other implementations in other languages, like in Javascript.
And you can also checkout the different implementations of Ethereum 2.0, like Prism.
That’s it for today!
Leave a Reply