Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust P2P Blockchain Sync

A minimal peer-to-peer node built in Rust using libp2p, demonstrating a simple blockchain sync over a custom protocol.

This is a work in progress.

This implementation ensures that each node maintains an in-memory copy of the blockchain, and they are connected using QUIC to exchange sync messages. The nodes are then converged to the same block height and hash, without any consensus logic (WIP)

Build

git clone https://github.com/ali-usama/rust-p2p-sync.git
cd rust-p2p-sync
cargo build --release

Run Demo

We'll start with three nodes on localhost with unique ports, each using QUIC over UDP.

# Node A — seed node, creates 5 demo blocks
RUST_LOG=info ./target/release/rust-p2p-sync \
  --listen-addr /ip4/127.0.0.1/udp/9001/quic-v1 \
  --n-blocks 5

# Node B — connects to A and syncs
RUST_LOG=info ./target/release/rust-p2p-sync \
  --listen-addr /ip4/127.0.0.1/udp/9002/quic-v1 \
  --peer-addr /ip4/127.0.0.1/udp/9001/quic-v1

# Node C — also connects to A
RUST_LOG=info ./target/release/rust-p2p-sync \
  --listen-addr /ip4/127.0.0.1/udp/9003/quic-v1 \
  --peer-addr /ip4/127.0.0.1/udp/9001/quic-v1

Expected Output

  • Each node logs Connected to <PeerId> and Received request/response event...
  • Nodes B and C fetch five blocks from A
  • All nodes converge to the same block height and hash

About

A minimal P2P node built in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages