Dengjianping / yt-chain

a toy of block chain written by rust and CUDA
MIT License
3 stars 1 forks source link
actix-web blockchain cuda graphql rust sled

yt-chain

Build Status

yt-chain is just a toy of blockchain inspired by this article Learn Blockchains by Building One. Originally, that's python based project, so I want to use rust to implement a one, and giving some improvements to the rust based one.

Platforms supported

Stacks

Requirements

  1. Linux platform.
  2. Latest stable/nightly rust.
    • If you want to run this project on raspberry pi, use nightly rust, and uncomment line 39, 40 in file Cargo.toml to enable "nightly" feature of sled, due to the bug 32-bit ARM compatibility.
  3. CUDA installed(at least 8.0, and device is capable of compute capability at least 3.5).
    • This is for accelerating mining blocks, there're some implemented encryption algorithms like sha256/384/512. It's optional, if you don't use GPU to mine blocks.
  4. CMake(at least 3.8).

Build && Run

CPU mining mode

If you want cpu to mine the block, use following command to build the project

cargo run --release
GPU mining mode

But if you want to try GPU(CUDA) to mine blocks, run the coming command.

cargo run --features "cuda" --release

These mining algorithms are optimized, no bank conflicts, aligned accessing global memory, close to 100% occupancy. I tested it on my device(Jetson TX2), which is a pascal featured embedded device. It only has 256 CUDA cores, runs 2048 × 2 threads at a time.

If you compile the project on desktop computer(equipped GTX series graphic card), it will run much faster than this device. Such as GTX-1080/GTX-2080 device, having 2560 CUDA cores, in theory, it should be 10x faster than my testing device at least, and the memory bandwidth is much bigger than Jetson TX2.

Calculate 2048×100 elements at a time

Algorithm Time cost on kernel(cuda function)
sha256 1.50ms
sha384 3.83ms
sha512 3.92ms

Usage

There're some APIs created for operate the server.

Mining.

mining

Get the whole blockchain.

chains

Transaction.

transaction

Before this operation, start a another node server.

Register a node

register

Consensus.

consensus