Distributed Blockchain Synchronization
University Projects #Distributed Computing#Python

Overview#

A distributed computing application that builds and validates a blockchain by requesting blocks from peers. This application was built in Python and uses Sockets to send requests and receive responses from peers.

View the project on GitHub.

Key Achievements#

  • Implemented GOSSIP protocol for peer discovery
  • Built consensus mechanism that correctly identifies and syncs to longest chain
  • Handled out-of-order block delivery through storage and reordering
  • Maintained synchronization through periodic consensus (every 2 minutes)
  • Responded to peer requests including BLOCK, CONSENSUS, STATS_REPLY, and GOSSIP_REPLY

Implementation#

Network#

  • Implemented sockets to perform peer-to-peer communication
  • Build GOSSIP protocol for peer discovery
  • Handled peer timeout (1 minute inactivity) and removal
  • Maintained peer list through keep-alive messages (every 30 seconds)

Consensus#

  • Requested STATS from all known peers to determine chain heights
  • Identified longest chain using max(height,hash) comparison
  • Broke longest chain ties by counting peers reporting the same (height, hash)
  • Requestd blocks round-robin from all peers with longest chain

Block Validation#

  • Validated nonce length (max 40 characters)
  • Verified message count (max 10 per block)
  • Checked message length (max 20 characters per message)
  • Confirmed hash follows predefined rules

Protocol Details#

Joining Network#

  1. Send GOSSIP to 3 random peers
  2. Reply to unknown GOSSIP IDs via GOSSIP_REPLY
  3. Start keep-alive timer to timeout peers that don’t GOSSIP_REPLY within 1 minute
  4. Begin consensus process

Local Block Synchronization#

  1. Request STATS from all known peers
  2. Wait for STAT_REPLYs
  3. Identify longest chain and which peers have it
  4. Request blocks round-robin from peers with longest chain
  5. Validate blocks and add blocks to local chain
  6. Handle ANNOUNCEMENTs of newly mined blocks via block validation

Network Block Synchronization#

  1. Perform consensus on local chain before sending STATS_REPLY to peers
  2. Do consensus every 2 minutes to ensure local chain synchronized with network chain

Technologies#

Python, Sockets, GOSSIP Protocol, Consensus Algorithms, Distributed Systems

← Back to Projects