Proof of Work (PoW) describes a consensus mechanism that requires a significant amount of computing effort from a network of devices, commonly known as mining. In a typical PoW system, miners compete to solve cryptographic puzzles, where the goal is to find a specific nonce value using the SHA-256 algorithm. This process is computationally intensive and requires significant energy expenditure, as miners must repeatedly hash different nonce values until the correct one is found. However, the energy consumed in this process could be directed towards more meaningful computational tasks. Machine learning models can be trained to solve real-world problems, and their integration into blockchain could enhance the system’s overall utility. This approach can also mitigate the issue of resource wastage associated with traditional PoW mechanisms.
In this project, we have implemented machine learning algorithms to select miners in the Ethereum network. By considering accuracy as a key parameter, we ensure that miners are chosen based on their contribution to solving practical problems. This not only promotes fairer competition but also aligns the computational efforts of miners with meaningful tasks, thereby enhancing the overall efficiency and utility of the blockchain system.
We have implemented a multi-node configuration of Ethereum by incorporating the Efficient Proof of Learning (EPoL) consensus mechanism. Specifically, we focused on the ethash files and used the Go programming language to develop our new consensus algorithm, EPoL. In this new approach, we replaced the code of the PoW consensus mechanism with our implementation, which involves training datasets using machine learning algorithms.
Download Ethereum files from the official website and replace the consensus
folder in go/src/consensus
with the one given in this repository.
Create a folder ethereum
(as a workspace) and subfolders nodes
in the home directory where the Ethereum files downloaded must be present. We create four node folders for a four-node setup.
mkdir ethereum
cd ethereum
mkdir node1 node2 node3 node4
Compile the Ethereum code by running the command below inside a terminal opened in the go/src/ethereum/go-ethereum
folder and then copy the geth
executable file from the go/bin
folder into the ethereum
(workspace) folder.
go install -v ./cmd/geth
Nodes must be initialized with a unique account hash and authentication (password), functioning as participants in the system. These nodes are connected to their respective accounts. To achieve this, we used "geth," an executable file generated, which facilitates the creation and running of Ethereum nodes. Write down the public key of each node.
sudo ./geth --datadir ~/ethereum/node1 account new
sudo ./geth --datadir ~/ethereum/node2 account new
sudo ./geth --datadir ~/ethereum/node3 account new
sudo ./geth --datadir ~/ethereum/node4 account new
Create a special file called a genesis file in a simple JSON format to initialize the blockchain. This file is created using "puppeth," a tool that helps manage private Ethereum networks. The genesis file includes the hash of the accounts and acts as an initializer for the blockchain. This file is linked to all nodes.
Initialize the nodes with the genesis file.
sudo ./geth --datadir ~/ethereum/node1 init genesis.json
sudo ./geth --datadir ~/ethereum/node2 init genesis.json
sudo ./geth --datadir ~/ethereum/node3 init genesis.json
sudo ./geth --datadir ~/ethereum/node4 init genesis.json
Generate a "boot node" to aid in the effective communication of nodes.
sudo bootnode -genkey boot.key
Run the bootnode with the generated bootkey, which must be running in the background to help nodes stay connected in the network.
sudo bootnode -nodekey boot.key
# Example: enode://6d20dc312a4c9262a7251a68dc539db0557123309c6aae8b34bad9b1ee0afc1bf36d3be604ebec067ad7f962ec745fc2749bfcba868a01ce616542f22bafea58@127.0.0.1:0?discport=30301
With all preparations complete, start the blockchain on each terminal representing each node, with each node using its communication channel (port). This process ensures our modified blockchain with the EPoL consensus mechanism starts up successfully. Run each of the following in separate terminals.
sudo ./geth --allow-insecure-unlock --datadir ~/ethereum/node1/ --syncmode 'full' --port 30311 --rpc --rpcaddr 'localhost' --rpcport 8501 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://<bootnode_enode>@127.0.0.1:0?discport=30301' --networkid 1515 --gasprice '1' --mine console
sudo ./geth --allow-insecure-unlock --datadir ~/ethereum/node2/ --syncmode 'full' --port 30312 --rpc --rpcaddr 'localhost' --rpcport 8502 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://<bootnode_enode>@127.0.0.1:0?discport=30301' --networkid 1515 --gasprice '1' --mine console
sudo ./geth --allow-insecure-unlock --datadir ~/ethereum/node3/ --syncmode 'full' --port 30313 --rpc --rpcaddr 'localhost' --rpcport 8503 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://<bootnode_enode>@127.0.0.1:0?discport=30301' --networkid 1515 --gasprice '1' --mine console
sudo ./geth --allow-insecure-unlock --datadir ~/ethereum/node4/ --syncmode 'full' --port 30314 --rpc --rpcaddr 'localhost' --rpcport 8504 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://<bootnode_enode>@127.0.0.1:0?discport=30301' --networkid 1515 --gasprice '1' --mine console
The Geth console will be active for each node, allowing you to interact with the Ethereum network.