Skip to content

MuhtasimTanmoy/chain-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Experimental Blockchain in Rust [WIP]

A blockchain implementation written for educational purpose in the Rust programming language that is in the experimental alpha stage. The project's main objective is to enhance understanding of Rust programming language fundamentals and best practices by constructing a system that involves distributed and peer-to-peer networking.

This is all very much work-in-progress research code. There are a lot of rough edges, some of the code is in need of some cleanup, and the packaging/configuration/ documentation doesn't exist that much.

Quickstart

## First create a wallet
cargo run createwallet

Output:
success: address 3JGDNu6Pnuench1hoXyibBemfYjGT8RHRS


## Print the addresses in wallet
cargo run listaddresses

addresses: 
3JGDNu6Pnuench1hoXyibBemfYjGT8RHRS


## Create the chain
## first user will have the coinbase transaction, and genesis block will store that
cargo run create 3JGDNu6Pnuench1hoXyibBemfYjGT8RHRS

Output:
Success


## Print the chain
cargo run printchain

Sample output in analysis.md


## Get balance of the user
cargo run getbalance 3JGDNu6Pnuench1hoXyibBemfYjGT8RHRS
Balance of '3JGDNu6Pnuench1hoXyibBemfYjGT8RHRS'; 100 


## Send money to from one user to another
cargo run send 3JGDNu6Pnuench1hoXyibBemfYjGT8RHRS  36M6fHwAame68se5hhqG1j2kXRujFCDQhN 10

Features

The project's functionality is currently limited, and the following tasks are on the to-do list to improve it. Feel free to give any idea/ suggestions on improvement.

  • Create working chain of blocks
  • Save blocks on SQLite database
  • Set up command line interface
  • Set up transaction
  • Set up genesis block, coinbase transaction
  • Set up wallet
  • Implement naive Proof of work mining
  • Send transaction from one account to another with hash of public key as address
  • Add signature for input access control at the time of making a transaction
  • Send transaction signed with private key
  • Use merkle hash for calculating block fingerprint
  • Optimize transaction access from a particular block, currently traverses the complete chain which is inefficient
  • Add networking layer for communication between clients
  • Add a caching layer
  • Restructure the project to use different crates for each functionality
  • Add specification for communication protocol
  • Look at transport medium, grpc?
  • Add a separate client to interact with the full node

Docs

Concepts

Two base primitives in the blockchain system

  1. Transaction
  2. Block

Nodes collect new transactions into a block, hash them into a hash tree (merkle root hash), and scan through nonce values to make the block's hash satisfy proof-of-work requirements.

When a miner solves the proof-of-work, it broadcasts the block to network nodes and if the block is valid it is added to the blockchain. The first transaction in the block is the coinbase transaction that creates a new coin owned by the creator of the block.

A node is responsible for processing, validating, and relaying the block and its transactions. A node is distinct on the network from miners and wallets.

There will be three types of node

  • Central Node
    • Other nodes connect to it, it sends data to others
  • Miner Node
    • Gathers transactions in memory pool and after reaching a threshold mine a new block and broadcast to the network
  • Wallet Node
    • Send coins between wallets, like SPV Node

Nodes will communicate with each other with following types of messages

  • BlockMessage
    • Passing block info from one node another after successful mining
  • GetMessage
    • One node requesting block info from another node
  • DataRequestMessage
    • Requests three types of data
      • Block
      • Data
      • Transaction
  • InventoryMessage
    • Sent in reply to a “getblocks” message or “mempool” message. Refer: link
  • TxMessage
    • Sent after successful mining
  • VersionMessage
    • Nodes version transfer message

References

About

Experimental Blockchain Node built from scratch in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published