In this exercise, you will implement a simple peer-to-peer network that functions as a distributed chat room. The key features include:
- Command Line Interface: The chat client runs as a command-line program.
- Peer Connection: Upon startup, the client requests the IP address and port of an existing peer. If the peer is not found, it starts its own network.
- Client Details: The client prints its IP address and port for incoming connections.
- Messaging: The client prompts the user for text strings. When a string is typed, it is broadcast to all connected clients.
- Message Handling: The system ensures that messages are printed at all clients without revealing the sender's information.
This exercise extends the previous chat system into a distributed ledger with the following features:
- Ledger Management: Each client maintains a ledger that tracks accounts and balances.
- Transactions: Clients can make transactions, and all peers update their ledgers accordingly.
- Eventual Consistency: The system ensures that if all clients stop sending transactions, all ledgers will eventually converge to the same state.
- Peer Connections: Clients connect to a list of peers and forward transactions to maintain ledger consistency.
Enhance the ledger system with signed transactions:
- Signed Transactions: Transactions are now signed with RSA keys, ensuring only account owners can authorize transactions.
- Validation: Transactions are validated based on their signature and non-negative amounts.
- RSA Integration: Encode and decode RSA public keys for transaction processing.
Modify the system to achieve total order for transactions:
- Sequencer Role: A designated sequencer establishes the order of transactions.
- Block Creation: The sequencer creates blocks containing transaction IDs and signs them.
- Order Enforcement: Clients process transactions based on the sequencer's block order.
Implement a proof-of-stake based blockchain with total order:
- Genesis Block: Includes special public keys with initial balances.
- Proof-of-Stake: A tree-based blockchain where block creation is based on the stake (account balance).
- Transaction Fees: Implement transaction fees and rewards for block creators.
- Testing: Validate the system's performance, including handling invalid transactions, rollbacks, and resistance to malicious peers.