C++ implementation of the Ethereum protocol based on the Erigon architecture.
- About Silkworm
- Obtaining Source Code
- Building on Linux & macOS
- Building on Windows
- Codemap
- Testing Silkworm
- Style Guide
- License
Silkworm is a greenfield C++ implementation of the Ethereum protocol based on the Erigon architecture. It aims to be the fastest Ethereum client while maintaining the high quality and readability of its source code. Silkworm uses libmdbx as the database engine.
Silkworm was conceived as an evolution of the Erigon project, as outlined in its release commentary.
Silkworm is under active development and hasn't reached the alpha phase yet. Hence there have been no releases so far.
To obtain Silkworm source code for the first time:
git clone --recurse-submodules https://github.com/torquem-ch/silkworm.git
cd silkworm
Silkworm uses a few git submodules (some of which have their own submodules). So after you've updated to the latest code with
git pull
update the submodules as well by running
git submodule update --init --recursive
Building Silkworm requires:
- C++20 compiler: GCC >= 10.2.0 or Clang >= 12.0.0
- CMake
- GMP (
sudo apt-get install libgmp3-dev
orbrew install gmp
or https://gmplib.org/manual/Installing-GMP)
Once the prerequisites are installed, bootstrap cmake by running
mkdir build
cd build
cmake ..
(In the future you don't have to run cmake ..
again.)
Then run the build itself
make -j
Note about parallel builds using -j
: if not specified the exact number of parallel tasks, the compiler will spawn as many
as the cores available. That may cause OOM errors if the build is executed on a host with a large number of cores but a relatively
small amount of RAM. To work around this, either specify -jn
where n
is the number of parallel tasks you want to allow or
remove -j
completely. Typically for Silkworm, each compiler job requires 4GB of RAM. So, if your total RAM is 16GB, for example,
then -j4
should be OK, while -j8
is probably not. It also means that you need a machine with at least 4GB RAM to compile Silkworm.
Now you can run the unit tests. There's one for core and one for node.
cmd/test/core_test
cmd/test/node_test
cmd/test/consensus
Note! Windows builds are maintained for compatibility/portability reasons. However, due to the lack of 128-bit integers support by MSVC, execution performance is inferior when compared to Linux builds.
- Install Visual Studio 2019. Community edition is fine.
- Make sure your setup includes CMake support and Windows 10 SDK.
- Install vcpkg.
.\vcpkg\vcpkg install mpir:x64-windows
- Add <VCPKG_ROOT>\installed\x64-windows\include to your
INCLUDE
environment variable. - Add <VCPKG_ROOT>\installed\x64-windows\bin to your
PATH
environment variable. - Install Perl (needed for OpenSSL build process)
- Open Visual Studio and select File -> CMake...
- Browse the folder where you have cloned this repository and select the file CMakeLists.txt
- Let CMake cache generation complete (it may take several minutes)
- Solution explorer shows the project tree.
- To build simply
CTRL+Shift+B
- Binaries are written to
%USERPROFILE%\CMakeBuilds\silkworm\build
If you want to change this path simply editCMakeSettings.json
file.
Note ! Memory compression on Windows 10/11
Windows 10/11 provide a memory compression feature which makes available more RAM than what physically mounted at cost of extra CPU cycles to compress/decompress while accessing data. As MDBX is a memory mapped file this feature may impact overall performances. Is advisable to have memory compression off.
Use the following steps to detect/enable/disable memory compression:
- Open a PowerShell prompt with Admin privileges
- Run
Get-MMAgent
(check whether memory compression is enabled) - To disable memory compression :
Disable-MMAgent -mc
and reboot - To enable memory compression :
Enable-MMAgent -mc
and reboot
Apart from the submodules and some auxiliary directories, Silkworm contains the following components:
core
Thecore
library contains the bulk of the Ethereum protocol logic as described by the Yellow Paper. Code withincore
is compatible with WebAssembly and may not use C++ exceptions.node
Thenode
library contains database, staged sync, and other logic necessary for functioning as an Ethereum node. Thenode
library depends on thecore
library.cmd
The source code of Silkworm executable binaries.
Note : at current state of development Silkworm can't actually "sync" the chain like Erigon does. What instead does is a one-pass loop over all implemented stages to process all blocks which are already in the database. Due to that you NEED a primed database from Erigon.
You can try run Silkworm to test the stages implemented so far. To do that you need to obtain a primed database by Erigon (strictly from stable
branch) by forcing it to stop before stage Senders.
On Linux build Erigon and
export STOP_BEFORE_STAGE="Senders"
./build/bin/erigon --datadir <path-where-to-store-data>
On Windows build Erigon and
$env:STOP_BEFORE_STAGE="Senders"
./build/bin/erigon.exe --datadir <path-where-to-store-data>
After any of those steps (wait for completion) launch Silkworm and point it to the same data directory you've used for Erigon
cmd/silkworm --datadir <same-datadir-path-used-for-erigon>
We use the standard C++20 programming language. We adhere to Google's C++ Style Guide with the following differences:
- C++20 rather than C++17.
snake_case()
for function names.- .cpp & .hpp file extensions for C++; .c & .h are reserved for C.
using namespace foo
is allowed inside .cpp files, but not inside headers.- Exceptions are allowed outside of the
core
library. - User-defined literals are allowed.
- Maximum line length is 120, indentation is 4 spaces – see .clang-format.
- Use
#pragma once
in the headers instead of the classic#ifndef
guards.
Silkworm is licensed under the terms of the Apache license. See LICENSE for more information.