This project is a distributed cryptocurrency mining simulation using shared memory, semaphores, and signals for synchronization. It includes:
- A network of miners competing to solve a cryptographic function.
- A monitor process that oversees the network and logs results.
- Mechanisms to detect and remove dishonest miners.
✅ Shared memory and semaphores for process synchronization.
✅ Secure handling of system signals (SIGINT, SIGUSR2) to prevent crashes.
✅ Efficient round-based mining with thread management.
✅ Timeouts to prevent deadlocks.
✅ Detection and removal of dishonest miners.
- Blocks SIGINT signals while initializing shared memory and semaphores.
- Creates or accesses existing shared memory.
- Sets up message queues for communication (execution continues even if unavailable).
- Allocates memory for thread management and mining parameters.
- Blocks SIGUSR2 and SIGINT during cycles to ensure predictable behavior.
- Each miner adds its PID to the network and starts mining.
- The process enters a suspended state (
sigsuspend
) awaiting SIGUSR2. - All miners compete to solve the same hash function.
- A losing miner may still find the correct solution before its threads cancel.
- 🛑 Solution: Introduced semaphores instead of signals to ensure stability.
- The winning miner signals the others.
- Miners follow an ordered execution:
- Winner waits for losers to copy the block.
- Losers wait for the winner to generate a new block.
- Semaphores include a 3-second timeout to prevent deadlocks.
- All miners must complete the round to maintain network integrity.
- Blocks are stored in a linked list, allocating memory per round.
- Miners log completed blocks into a file.
- The monitor process only joins if at least one miner is active.
- Miners send blocks after the monitor joins to prevent message queue overload.
- Parent process filters blocks, while the child process writes them to a file.
- Failed blocks are recorded but retried in the next round.
- Detects pirate miners who attempt to manipulate the network:
- Using an incorrect hash function.
- Attempting fake mining computations.
- Since over 50% of votes can corrupt the blockchain, the winner terminates dishonest miners who vote against a valid solution.
- ✅ Meets all project requirements, including the voting system and monitoring.
- ✅ Extensive testing: Over 90% execution success rate, even with pirate miner attacks.
- ✅ Memory management validated with Valgrind (no leaks or segmentation faults).
- ❗ Potential improvements:
- More robust failure handling.
- Prevent deadlocks if a process crashes while holding a semaphore.
This project is a simplified cryptocurrency mining simulation with:
- Robust synchronization mechanisms.
- Secure handling of fraudulent miners.
- Strong error management and logging.
While it’s not perfect, it effectively balances performance, security, and stability in a multi-process mining environment. 🚀
- Linux-based system (recommended)
- GCC compiler
make
- Basic knowledge of C programming
make
./miner
./monitor
This project is licensed under the MIT License.
Feel free to open issues or submit pull requests to improve this project! 🚀