Giter Site home page Giter Site logo

racytech / silkworm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from erigontech/silkworm

0.0 0.0 0.0 93.5 MB

C++ implementation of the Ethereum protocol

License: Apache License 2.0

Shell 0.01% C++ 99.66% Python 0.10% C 0.11% Makefile 0.01% CMake 0.13%

silkworm's Introduction

Silkworm - C++ Ethereum Execution Client

C++ implementation of the Ethereum Execution Layer (EL) protocol based on the Erigon Thorax architecture.

CircleCI macOS Windows CodeCov GitHub semver

Table of Contents

About Silkworm

Silkworm is a greenfield C++ implementation of the Ethereum protocol based on the Erigon Thorax 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.

Obtaining Source Code

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 on Linux & macOS

Building Silkworm requires:

  • C++20 compiler: GCC >= 11.2.0 or Clang >= 12.0.0
  • CMake
  • Tools for gmplib: sudo apt-get install -y m4 texinfo bison

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

or Ethereum Consensus Tests

cmd/test/consensus

Building on Windows

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 edit CMakeSettings.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

Codemap

Apart from the submodules and some auxiliary directories, Silkworm contains the following components:

  • cmd
    The source code of Silkworm executable binaries.
  • silkworm/core
    This module contains the heart of the Ethereum protocol logic as described by the Yellow Paper. Source code within core is compatible with WebAssembly and cannot use C++ exceptions.
  • silkworm/node
    This module contains the database, the staged sync and other logic necessary to function as an Ethereum node. This module depends on the core module.
  • silkworm/sentry
    This module implements the networking and protocol stacks for Sentry component for an Ethereum node based on Erigon Thorax architecture. This module depends on both the core and node modules.
  • silkworm/wasm
    This module allows the core the run on WebAssembly. This module depends on both the core and node modules.

Testing Silkworm

Note: at current state of development Silkworm can't actually sync the chain like Erigon does.

You can try to run Silkworm to test just the sync on the pre-Merge Ethereum chain. In order to do that you need to:

  • run an instance of Erigon Sentry component from devel branch
  • set the environment variable STOP_AT_BLOCK to a value < 15'537'351 (e.g. STOP_AT_BLOCK=15000000)

Linux and macOS

Erigon Sentry

git clone --recurse-submodules https://github.com/ledgerwatch/erigon.git
cd erigon
git checkout devel
make sentry
./build/bin/sentry

Silkworm

export STOP_AT_BLOCK=15000000
./cmd/silkworm

Windows

Erigon Sentry

git clone --recurse-submodules https://github.com/ledgerwatch/erigon.git
cd erigon
git checkout devel
make sentry
./build/bin/sentry.exe

Silkworm

$env:STOP_AT_BLOCK=15000000
./cmd/silkworm.exe

Use Conan as Package Manager

Silkworm uses Hunter as package manager, but will soon switch to Conan (https://conan.io/).

Install Conan using:

pip3 install --user conan==1.58.0 chardet

and add its binary to PATH:

export "PATH=$HOME/Library/Python/3.9/bin:$PATH"

To use Conan at this experimental stage add the -DCONAN_PACKAGE_MANAGER option set to ON, and the Conan profile with the -DCONAN_PROFILE option, with the name of the profile to use.

Example:

cmake .. -DCONAN_PACKAGE_MANAGER=ON -DCONAN_PROFILE=linux_gcc_11_release

You can find all available conan profiles inside the cmake/profiles folder.

The conan packages could also be pre-installed using conan install:

conan install --install-folder=build/conan --build=missing --profile=cmake/profiles/macos_arm_clang_13_debug .

Style Guide

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 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.

License

Silkworm is licensed under the terms of the Apache license. See LICENSE for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.