Pages:
Author

Topic: [Guide] Solo mine testnet bitcoins with cgminer, Bitcoin Core, and a Compac F - page 3. (Read 1387 times)

hero member
Activity: 1008
Merit: 960
And you can of course write something into the coinbase of the block you found, just add this option to the config file:

Code:
--btc-sig      Set signature to add to coinbase when solo mining (optional)

Do you know format of (such as HEX or plain text) or have example of working ? I tried using search feature, but GitHub doesn't enable such feature on forked repository.

It's a simple text argument, the same as the btc-address argument you have to give in the config file. Just add another line with that.

Just try it out, that's the whole point of the testnet  Grin
hero member
Activity: 1008
Merit: 960
~snip~
That's great to know! I wasn't aware of this rule. Will spin a Compac F up to mine some testnet BTC, then.. Cheesy
I've never hit a solo block, so this should be a pretty cool experience.

That was the motivation for me to do this in the first place  Grin

A couple of things you might want to do:

Keep the log of your first block:

Code:
sudo /home/user/bitcoin_testnet/cgminer/cgminer -c /home/user/bitcoin_testnet/mine_testnet.conf 2>> /home/user/bitcoin_testnet/my_first_block_log.txt

And you can of course write something into the coinbase of the block you found, just add this option to the config file:

Code:
--btc-sig      Set signature to add to coinbase when solo mining (optional)
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
--snip--

But apparently testnet3 resets diff to 1 at some blocks, as those are the ones I hit:

Code:
Accepted Diff 1/1 GSF 0
Not at some blocks, but after 20 minutes since last block mined. That might be why you mine more block than @NotATether expected.
That's great to know! I wasn't aware of this rule. Will spin a Compac F up to mine some testnet BTC, then.. Cheesy
I've never hit a solo block, so this should be a pretty cool experience.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
Thanks for writing this guide. Although people who currently don't have ASIC better use Signet or Regtest, unless they also want to try their luck with solo mining on Bitcoin mainnet.

--snip--

But apparently testnet3 resets diff to 1 at some blocks, as those are the ones I hit:

Code:
Accepted Diff 1/1 GSF 0

Not at some blocks, but after 20 minutes since last block mined. That might be why you mine more block than @NotATether expected.
jr. member
Activity: 51
Merit: 20
Nicely detailed guide!
hero member
Activity: 1008
Merit: 960
A few blocks overnight? That means the testnet difficulty is extremely low. Exactly what was the testnet difficulty when you wrote this guide?

I'm sure this will help a bunch of people who are setting up testnet bitcoin mining farms.

The difficulty was in the millions:

Code:
Network diff set to 76.6M

But apparently testnet3 resets diff to 1 at some blocks, as those are the ones I hit:

Code:
Accepted Diff 1/1 GSF 0
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
A few blocks overnight? That means the testnet difficulty is extremely low. Exactly what was the testnet difficulty when you wrote this guide?

I'm sure this will help a bunch of people who are setting up testnet bitcoin mining farms.
hero member
Activity: 1008
Merit: 960
If you need some testnet bitcoins, you can easily get them by solo mining. Some other guides I've found in the web are outdated, so I made this one to work with the latest software/hardware.

You'll need:
  • Latest version of Bitcoin Core(v23.0 at the time of writing)
  • Special build of cgminer that allows solo mining, available from https://github.com/cmmodtools/cgminer with a small update from this guide.
  • Ideally an ASIC miner. You can use any miner that works with cgminer, even the USB miner from GekkoScience, the Compac F:

To make things simple, for this guide I am going to assume you have two computers, one running a Compac F miner and another one running Bitcoin core. It shouldn't matter if you're running both on the same computer or if you have a different miner.

Step 1: Install and run Bitcoin Core

We're going to use the folder ~/bitcoin_testnet to save everything so that it's easy to remove once you're done and to keep things simple. You can of course use a different path if you want.

Inside ~/bitcoin_testnet create a folder called data:

Code:
mkdir -p ~/bitcoin_testnet/data

Download the Bitcoin Core for your platform into ~/bitcoin_testnet/ and extract it there.

Now let's prepare the configuration file. Create a text file named bitcoin_testnet.conf in ~/bitcoin_testnet/ and put these content in it:

Code:
testnet=1
txindex=1
server=1
[test]
rpcport=5000
rpcallowip=YOUR_MINER_IP
rpcuser=YOUR_RPC_USER
rpcpassword=YOUR_RPC_PASSWORD
rpcbind=0.0.0.0

The thing that you need to understand here is that you're setting up the Bitcoin node to run in testnet, and you're defining an RPC port(5000 in this case, can be anything), user and password, and whitelisting a specific IP to connect to your node(YOUR_MINER_IP). You'll need these details and your Bitcoin node IP later when connecting from cgminer.

You can now start running your Bitcoin node by doing the following(make sure to change user to your actual user:

Code:
/home/user/bitcoin_testnet/bitcoin-23.0/bin/bitcoind -conf=/home/user/bitcoin_testnet/bitcoin_testnet.conf -datadir=/home/user/bitcoin_testnet/data

If you want, you can keep this running in the background with screen:

Code:
screen -dm -S bitcoin_testnet /home/user/bitcoin_testnet/bitcoin-23.0/bin/bitcoind -conf=/home/user/bitcoin_testnet/bitcoin_testnet.conf -datadir=/home/user/bitcoin_testnet/data

You can then see what's happening with:

Code:
screen -r bitcoin_testnet

To detach the screen, simply press Ctrl-A and then Ctrl-D. You'll be back in the console, and the command will continue running in the background.

Step 2: Install and run cgminer

We're going to use an updated repo of cgminer, this one has the latest changes from kano so that we can use the Compac F, plus some fixes that allow solo mining. Of course you might want to change the options to match your environment or miner.

Code:
cd ~/bitcoin_testnet/
git clone https://github.com/cmmodtools/cgminer
cd cgminer
./autogen.sh
CFLAGS="-O2 -Wall -march=native -fcommon" ./configure --enable-gecko
make

Now, in theory we should be ready, but we need one extra change. Open the file cgminer.c with your favorite text editor and change this line:

Code:
if (opt_btc_address[0] != '1') {

To this:

Code:
if (opt_btc_address[0] != '1' && opt_btc_address[0] != 'm' && opt_btc_address[0] != 'n'  ) {

Basically we need to also consider the first symbol of the testnet address, which is either n or m. OK, now run make again:
Code:
make

And now cgminer is compiled and ready. Let's create the configuration file:

Create a text file named ~/bitcoin_testnet/cgminer_testnet.conf with these contents:

Code:
{
"pools" : [
        {
                "url" : "http://YOUR_BITCOIN_CORE_IP:5000",
                "user" : "YOUR_RPC_USER",
                "pass" : "YOUR_RPC_PASSWORD"
        }
],

"btc-address": "YOUR_TESTNET_BTC_ADDRESS",

"gekko-compacf-freq" : "400",
"gekko-compacf-detect" : true,
"gekko-start-freq" : "300",
"gekko-mine2" : true,
"gekko-tune2" : "60",

"suggest-diff" : "442",
"failover-only" : true,
}

If you don't have a testnet btc address yet, note that Bitcoin Core now doesn't generate a wallet by default any more so you will need to create one. You can read about it in createwallet. Then you should be able to getnewaddress. Make sure to use the legacy format as that's what cgminer is expecting. You address should start with n or m.

Alternatively, you can simply use the GUI. To open the GUI, first stop the bitcoind process (Ctrl-C) and then run bitcoin-qt instead. There you'll be able to easily create wallets and generate addresses by clicking around.

And now you can simply run cgminer like this:

Code:
sudo /home/user/bitcoin_testnet/cgminer/cgminer -c /home/user/bitcoin_testnet/mine_testnet.conf

You can of course also run it in the background with screen, or run this at startup, etc. It will depend on your particular setup. If you're on a pi for example, you could create a bash shell executable (~/start_mining.sh) with that code and then simply add this to /etc/rc.local:

Code:
su - pi -c "screen -dm -S cgminer ~/start_mining.sh"

That's just one example, you can choose to run it however you prefer.

There it is, it should now say:

Code:
Solo mining to valid address: YOUR_TESTNET_BTC_ADDRESS

If you leave it overnight you should hit a few blocks with the Compac F USB miner.

Happy testnet solo mining!  Grin
Pages:
Jump to: