Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solo-mining Sugarchain with multiple computer

First of all, make sure you have a full node running and fully synced All machines need to be connected to the same local network (e.g same wi-fi)

Node configuration

On the computer with the full node, find the local IP address: On MacOS/Linux you can use

ifconfig

And should return something like

en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	ether e4:ce:8f:0e:33:c4 
	inet6 fe80::404:8467:3244:a799%en1 prefixlen 64 secured scopeid 0x7 
	inet 192.168.178.107 netmask 0xffffff00 broadcast 192.168.178.255
	inet6 2001:7e8:c8de:2000:c40:7f55:b1ca:4fbe prefixlen 64 autoconf secured 
	inet6 2001:7e8:c8de:2000:bc3c:2b79:8478:693b prefixlen 64 autoconf temporary 
	nd6 options=201<PERFORMNUD,DAD>
	media: autoselect
	status: active

What we need is our IP address as well as the CIDR notation of it

The important part is the line with inet

inet 192.168.178.107 netmask 0xffffff00 broadcast 192.168.178.255

With that, we will be able to calculate the CIDR address for the sugarchainf.conf So in my case, the IP of the full node is 192.168.178.107 The netmask is 0xffffff00 in https://www.subnetonline.com/pages/subnet-calculators/dec-to-hex-calculator.php enter your netmask Calculating the mask and copy the subnet mask, in my case it's 255.255.255.0

Now on https://www.subnet-calculator.com/cidr.php enter your IP and your mask Calculating the CIDR and copy the net CIDR notation, in my case it's 192.168.178.0/24

Now open your sugarchain.conf file and modify as follow

server=1
rpcbind=192.168.178.107
rpcuser=user
rpcpassword=pass
rpcallowip=127.0.0.1
rpcallowip=192.168.178.0/24

notice the rpcbind is the full node IP and the last rpcallowip is our IP in CIDR notation, this will allow anyone in our local network to connect to our node.

Miner

Now on any computer connected to the same network, just run the miner using the node IP For example with sugarmaker (don't forget to change the options accordingly to your own configuration)

 ./sugarmaker -o http://192.168.178.107:34229 -u user -p pass --coinbase-addr=sugar1q3hjg38ygedjz96e7vyvsju36q2muke439t3237 -t1

With remote server

If you have some remote computer like a VPS and you want to make them mine on your computer, you would need to Remote Port Forward through SSH.

To connect to SSH

ssh -R localhost:31337:192.168.178.107:34229 IP_SERVER

Note that I used the IP from rpcbind in localhost:31337:192.168.178.107:34229, so make sure to replace it with the one of your sugarchain.conf

To mine on your server

./sugarmaker -o http://localhost:31337 -u user -p pass --coinbase-addr=sugar1q3hjg38ygedjz96e7vyvsju36q2muke439t3237 -t1

Don't forget to change the options accordingly to your own configuration

Note if you mine with multiple device

To add some randomness on your block generation, and to avoid duplicate works (same miner with the same template with the same nonce would produce the same hash), it's advice to have a different coinbase-addr for each of your miner

Happy mining :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment