Pages:
Author

Topic: [Guide] Solo mine testnet bitcoins with bfgminer, Bitcoin Core, and a CPU/GPU (Read 980 times)

legendary
Activity: 2842
Merit: 7333
Crypto Swap Exchange
Why doesn't Bitcoin Core sync with the testnet?



Without any additional detail, i only can assume something wrong with your internet connection. Anyway, for this Bitcoin Core problem i suggest you to create new thread on Bitcoin Technical Support while following this format [READ BEFORE POSTING] Tech Support Help Request Format.
legendary
Activity: 2898
Merit: 1041
Why doesn't Bitcoin Core sync with the testnet?



hero member
Activity: 882
Merit: 5814
not your keys, not your coins!
I just catched an instance where the last block was 20 minutes ago and bfgminer never adjusted the difficulty setting from its '125M' value.
It sounds like this could be the reason it doesn't mine any blocks: if it never knows the difficulty is low, it won't find a block at low difficulty.
From your screenshot:
Quote
125M (894.7T)
I'm starting to think difficulty=1 doesn't mean it takes picoseconds to mine a block:
Minimum difficulty of 1.0 on testnet is equal to difficulty of 0.5 on mainnet.
At difficulty 1, that is around 7 Mhashes per second.
That would explain why ASICs still beat any CPU miner as it would take me about a second, while it takes the ASICs a fraction of a millisecond.
You may be up to something. I don't know why, but I assumed that difficulty=1 meant the hash just had to be smaller than 2256-1.
This is where I was wrong:
The highest possible target (difficulty 1) is defined as 0x1d00ffff

The average time to find a block can be approximated by calculating:

Code:
time = difficulty * 2**32 / hashrate
The expected number of hashes we need to calculate to find a block with difficulty D is therefore

D * 2**256 / (0xffff * 2**208)
Actually, if we use this formula, it appears that with difficulty=1, you need on average 4295032833 or ~4.3GH to find a valid one. So on a 7MH/s machine, that's 613 seconds or 10 minutes. Impossible.. Grin

Code:
>>> 1 * 2**32 / 7000000
613.5667565714285

But on the other hand, it can't be right since people here did succeed with CPUs. What if the article is outdated / wrong?

If we work with the figure of 7MH for 1 valid hash, it would mean the minimum network hashrate must have always been over 11.6kH/s; otherwise it wouldn't be possible to mine a block in 10 minutes (11,600*600 ≈ 7,000,000). That seems realistic for 2009. According to the blockchain [1], it was in the single-digit Megahash range all the way back in 2009.

Do we know @ETFbitcoin 's hash rate?

[1] https://www.coinwarz.com/mining/bitcoin/hashrate-chart/2009



Quickly using the same formula for a single Compac F, it becomes clear it has much better chances:
Code:
>>> 1 * 2**32 / 300e9
0.014316557653333332

Code:
>>> 4.3e9 / 300e9 # hashes needed on average / hashrate of compac f
0.014333333333333333
With just 300GH/s and difficulty=1, it only takes it 0.0143s to go through those 7 million hashes.
This would also mean that the formula expecting @LoyceV's CPU to take on average 10 minutes, is correct.
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
I just catched an instance where the last block was 20 minutes ago and bfgminer never adjusted the difficulty setting from its '125M' value.
It sounds like this could be the reason it doesn't mine any blocks: if it never knows the difficulty is low, it won't find a block at low difficulty.
From your screenshot:
Quote
125M (894.7T)
I'm starting to think difficulty=1 doesn't mean it takes picoseconds to mine a block:
Minimum difficulty of 1.0 on testnet is equal to difficulty of 0.5 on mainnet.
At difficulty 1, that is around 7 Mhashes per second.
That would explain why ASICs still beat any CPU miner as it would take me about a second, while it takes the ASICs a fraction of a millisecond.
hero member
Activity: 882
Merit: 5814
not your keys, not your coins!
One thing I just realized is that in the screenshot, the I value (BTC per hour) is set to a question mark. So maybe it did quickly submit a block candidate and was waiting to see if it got accepted by the network? Can you post a log screenshot of what it looks like when bfgminer finds a valid block (whether it is accepted by the network or not - you mention 2 stale blocks)?
What exactly do you mean by log? I checked my Bitcoin Core log and found out older log was wiped. After quick search, Bitcoin Core has config called shrinkdebugfile which enabled by default with 10MB limit. And few days ago i perform reindex which wipe everything from last years.
With log, I mean the bfgminer log output as shown here.



I am wondering whether it logs / shows whether it found a block at diff 1 here.
Trying to work out whether the software even realizes that 20 minutes have passed, reduces the difficulty to 1, hashes a block candidate and tries to submit it or whether this all doesn't even happen.

Even just seeing how a successfully mined block is shown in this log, would help, since I can only reference my experience with cgminer whose output looks very different.
hero member
Activity: 882
Merit: 5814
not your keys, not your coins!
After almost 4 days, i managed to mine 4 blocks. But due to relative slow internet connection, 2 of them become stale. Overall it's good experience and i got about ~0.05 tBTC, which probably will be used to try few different OPCODES on scripting or simply donate it to tBTC faucet.

On a side note, on 3rd day i tried to mine only with 1 thread CPU since the goal to mine block with difficulty 1. But when i shutdown my PC, i got this error message with >100K occurrence. Quick search on google shows it's due continuous CPU usage for long time, although i'm not 100% sure it's due to bfgminer.

Code:
kernel: rcu: INFO: rcu_preempt detected expedited stalls on CPUs/tasks: { P93622 } 116803 jiffies s: 7173 root: 0x1/.
kernel: rcu: blocking rcu_node structures (internal RCU debug): l=1:0-15:0x0/T
Did you monitor your CPU miner a bit? I just catched an instance where the last block was 20 minutes ago and bfgminer never adjusted the difficulty setting from its '125M' value. Does it take a bit longer to adjust or what is the cause? Or is it just not reflected in the user interface? I expected it to drop to 1 as soon as the 20 minute mark passed, even if it may not end up being first at submitting something to the network. But it simply didn't budge.



This is Loyce's machine with 7 threads hashing and 1 core free to submit a block quickly.



One thing I just realized is that in the screenshot, the I value (BTC per hour) is set to a question mark. So maybe it did quickly submit a block candidate and was waiting to see if it got accepted by the network? Can you post a log screenshot of what it looks like when bfgminer finds a valid block (whether it is accepted by the network or not - you mention 2 stale blocks)?
legendary
Activity: 2842
Merit: 7333
Crypto Swap Exchange
Who decides on those 20 minutes anyway?

This is good question. On Bitcoin Wiki, 20 minutes only mentioned since early 2013[1]. But afterwards i found out Gavin Andresen propose this[2] and create pull request some time later[3].

I checked the last 2 days, and to my surprise only 115 blocks per day get mined.

Mining difficulty on testnet keep rising which discourage some people to perform mining, where people with CPU/GPU only expect to earn tBTC from 1 difficulty after 20 minutes.

I'm surprised because the total block height is much higher than for Bitcoin.

Probably because now we have separate testing network dedicated for newer Bitcoin feature (e.g. signet and segnet) and in past people attempt to attack/stress Bitcoin testnet by mining with tons of ASIC.



[1] https://en.bitcoin.it/w/index.php?title=Testnet&oldid=35502
[2] https://bitcointalksearch.org/topic/m.627957
[3] https://github.com/bitcoin/bitcoin/pull/686
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
Rough numbers: At 300GH/s and difficulty of 1, I should in theory mine one valid block in 3ps (picoseconds), meanwhile at 6MH/s it would take 166ns (nanoseconds).
However, in a difficulty=1 scenario, the difference of 165997ps should make no difference at all. Network latency to other nodes will probably be in the single to double-digit ms range. For reference: 1ms (which is a really good network latency) are a million ns.
Who decides on those 20 minutes anyway? In Bitcoin, there's no need for exact timestamps. Is this different in testnet?
I checked a few of the latest testnet blocks, and found times between blocks of:
2418404 > 2418405: 20 minutes and 3 seconds.
2418410 > 2418411: 20 minutes and 5 seconds.
2418407 > 2418408: 20 minutes and 8 seconds.

I checked the last 2 days, and to my surprise only 115 blocks per day get mined. I'm surprised because the total block height is much higher than for Bitcoin. I'm also surprised that several people here have mined several blocks per day at difficulty 1, which means that only a few dozen people can do that per day. I'd expect much more people to be mining testnet.
hero member
Activity: 882
Merit: 5814
not your keys, not your coins!
did you try to mine tBTC on a month without any result?
I killed it after a week. I started it again (this morning), and gave n0nce access. Let's see if I missed something.
Rough numbers: At 300GH/s and difficulty of 1, I should in theory mine one valid block in 3ps (picoseconds), meanwhile at 6MH/s it would take 166ns (nanoseconds).
However, in a difficulty=1 scenario, the difference of 165997ps should make no difference at all. Network latency to other nodes will probably be in the single to double-digit ms range. For reference: 1ms (which is a really good network latency) are a million ns.

There is a chance that your CPU is overloaded with all cores mining and no core ready to push that packet out to the network asap. Another idea would be making sure that this old CPU miner code doesn't wait for e.g. a whole set of nonce values before returning a valid block or something silly like that. It should return as soon as a block meets the difficulty, but I wouldn't rule out that it waits longer for whatever (legacy?) reason.

I will definitely have a look at your bfgminer config and the bfgminer code, too.
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
did you try to mine tBTC on a month without any result?
I killed it after a week. I started it again (this morning), and gave n0nce access. Let's see if I missed something.
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
I'm mining Testnet now! It's CPU only, on a server. Let's see if it catches a block.
It's been 4 days, and at 6.33Mh/s, I haven't found a single block. Maybe I did something wrong, or maybe CPU mining is still too slow even when the difficulty is 1. Either way, I gave up for now, and killed the miner. It seems like a waste of CPU. I'll keep Bitcoin Core Testnet running for a while.
member
Activity: 129
Merit: 16
hey OP, this works:

Code:
git clone https://bitbucket.org/ckolivas/hashfast
cd hashfast/
./autogen.sh
CFLAGS="-O2 -Wall -march=native -I/opt/rocm-5.4.1/opencl/include/" LDFLAGS="-L/opt/rocm-5.4.1/opencl/lib/" ./configure --enable-opencl
make
./cgminer -o -u -p

...for cgminer usage on AMD GPU - valid 22 december 2022
member
Activity: 129
Merit: 16
Also, I've noticed that bfgminer isn't creating proof with more than 8 zeros.

Is there a way to modify so it creates proof with more than 8 zeros?

example:

Proof: 0000000074f7267c7ed96843de88967a43728be514fee31a6b5dc623bb688291
Target: 00000000000000000007f5900000000000000000000000000000000000000000
TrgVal? no (false positive; hash > target)


I looked in bfgminer/miner.c but couldn't manage to change anything to create 19 leading zero proof
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
Thanks for the tutorial, I'm mining Testnet now! It's CPU only, on a server. Let's see if it catches a block.

The only problem I ran into was at this step:
Code:
./autogen.sh
The error came down to this:
Code:
fatal: unable to connect to github.com:
And the solution was easy:
Code:
git config --global url."https://".insteadOf git://
newbie
Activity: 4
Merit: 0
In particular, you're disabling getwork and stratum connectivity:

Thank you, but I did that deliberately. I was pointed to this thread from  https://bitcointalksearch.org/topic/what-is-a-good-reference-for-a-getblocktemplate-based-solo-miner-5418942 entitled What is a good reference for a getblocktemplate based solo miner. Hence I was expecting bfgminer could serve that purpose, which does not seem to be the case. But on the other hand it appears that cpuminer might serve the purpose.
hero member
Activity: 952
Merit: 938

I tried to repeat the procedure, but I ran into some issues.

~snip~

You're running bfgminer with different options than what I wrote here. Check those first.

In particular, you're disabling getwork and stratum connectivity:

Quote
--no-stratum                    Disable Stratum detection
--no-getwork                    Disable getwork support
Try running it without those options
newbie
Activity: 4
Merit: 0

I tried to repeat the procedure, but I ran into some issues.

Note that MYUSER, MYPASS and MYADDR are replaced by their actual values when running the below commands
I'm able to access the node using
Code:
bitcoin-cli -rpcuser=MYUSER -rpcpassword=MYPASS  -rpcport=5000 -rpcconnect=MY.NODE.IP.NR getblocktemplate '{"rules": ["segwit"], "capabilities": ["coinbasetxn", "workid", "coinbase/append"]}'|grep coinbaseo
  "coinbaseaux": {
  "coinbasevalue": 3041246,

So it seem to be able to connect, but if I try with bfgminer
 
Code:
$ ./bfgminer --text-only --no-getwork --no-stratum -S cpu:auto -o http://MY.NODE.IP.NR:5000 -u MYUSER -p MYPASS  --generate-to MYADDR  --coinbase-sig "bfgminer test"

 [2022-11-25 14:45:14] Started bfgminer 5.5.0-34-g866fd36f
 [2022-11-25 14:45:14] Probing for an alive pool
 [2022-11-25 14:45:14] Pool 0 slow/down or URL or credentials invalid
 [2022-11-25 14:45:15] No servers were found that could be used to get work from.
 [2022-11-25 14:45:15] Please check the details from the list below of the servers you have input
 [2022-11-25 14:45:15] Most likely you have input the wrong URL, forgotten to add a port, or have not set up workers
 [2022-11-25 14:45:15] Pool: 0  URL: http://MY.NODE.IP.NR:5000  User: MYUSER  Password: MYPASS

While I'm running the above command I observe the following on the console of my node:
Code:
2022-11-25T13:49:59Z ThreadRPCServer method=getblocktemplate user=MYUSER

Running on the node itself it seem to connect:
Code:
./bfgminer --no-local-bitcoin --text-only --no-getwork --no-stratum -S cpu:auto -o http://MY.NODE.IP.NR:5000 -u MYUSER -p MYPASS  --generate-to MYADDR  --coinbase-sig "bfgminer test"

 [2022-11-25 15:10:16] Started bfgminer 5.5.0-34-g866fd36f
 [2022-11-25 15:10:16] No devices detected!
 [2022-11-25 15:10:16] Waiting for devices
 [2022-11-25 15:10:16] Probing for an alive pool
 [2022-11-25 15:10:16] Network difficulty changed to 66M (472.5T)
 [2022-11-25 15:10:16] Pool 0 http://MY.NODE.IP.NR:5000 alive
 [2022-11-25 15:10:16] Long-polling activated for http://MY.NODE.IP.NR:5000 (getblocktemplate)
20s:  0.0 avg:  0.0 u:  0.0  h/s | A:0 R:0+0(none) HW:0/none
 [2022-11-25 15:11:38] Longpoll from pool 0 detected new block
20s:  0.0 avg:  0.0 u:  0.0  h/s | A:0 R:0+0(none) HW:0/none
 [2022-11-25 15:17:16] Longpoll from pool 0 detected new block
20s:  0.0 avg:  0.0 u:  0.0  h/s | A:0 R:0+0(none) HW:0/noneone
 [2022-11-25 15:25:48] Longpoll from pool 0 detected new block
20s:  0.0 avg:  0.0 u:  0.0  h/s | A:0 R:0+0(none) HW:0/none

Also running cpuminer from the remote computer on the LAN seem to work

Code:
$ ./minerd -a sha256d -o http://MY.NODE.IP.NR:5000  -u MYUSER -p MYPASS --coinbase-addr MYADDR --no-getwork --no-stratum --no-redirect
[2022-11-25 15:18:35] Binding thread 0 to cpu 0
[2022-11-25 15:18:35] 4 miner threads started, using 'sha256d' algorithm.
[2022-11-25 15:18:35] Binding thread 1 to cpu 1
[2022-11-25 15:18:35] Binding thread 3 to cpu 3
[2022-11-25 15:18:35] Binding thread 2 to cpu 2
[2022-11-25 15:18:35] Long-polling activated for http://MY.NODE.IP.NR:5000
[2022-11-25 15:18:35] thread 0: 2097152 hashes, 6732 khash/s
[2022-11-25 15:18:35] thread 1: 2097152 hashes, 6732 khash/s
[2022-11-25 15:18:35] thread 2: 2097152 hashes, 6730 khash/s
[2022-11-25 15:18:35] thread 3: 2097152 hashes, 6730 khash/s
[2022-11-25 15:19:35] LONGPOLL pushed new work
[2022-11-25 15:19:35] thread 0: 401725792 hashes, 6729 khash/s
[2022-11-25 15:19:35] thread 3: 401732512 hashes, 6730 khash/s
[2022-11-25 15:19:35] thread 2: 401754024 hashes, 6730 khash/s
[2022-11-25 15:19:35] thread 1: 401665288 hashes, 6728 khash/s
[2022-11-25 15:20:35] thread 3: 403777896 hashes, 6731 khash/s
[2022-11-25 15:20:35] thread 1: 403706232 hashes, 6729 khash/s
[2022-11-25 15:20:35] thread 2: 403799288 hashes, 6731 khash/s
[2022-11-25 15:20:35] LONGPOLL pushed new work
[2022-11-25 15:20:35] thread 3: 78352 hashes, 7178 khash/s
[2022-11-25 15:20:35] thread 0: 403740032 hashes, 6728 khash/s
[2022-11-25 15:20:35] thread 2: 70736 hashes, 6729 khash/s
[2022-11-25 15:20:35] thread 1: 52128 hashes, 4724 khash/s
[2022-11-25 15:21:03] LONGPOLL pushed new work
[2022-11-25 15:21:03] thread 3: 187733520 hashes, 6731 khash/s
...

Does this mean that cpuminer is working as expected while bfgminer does not. I will leave it running for a few days and see if I'm able to solve a block on the test network.
legendary
Activity: 2842
Merit: 7333
Crypto Swap Exchange
After almost 4 days, i managed to mine 4 blocks. But due to relative slow internet connection, 2 of them become stale. Overall it's good experience and i got about ~0.05 tBTC, which probably will be used to try few different OPCODES on scripting or simply donate it to tBTC faucet.

On a side note, on 3rd day i tried to mine only with 1 thread CPU since the goal to mine block with difficulty 1. But when i shutdown my PC, i got this error message with >100K occurrence. Quick search on google shows it's due continuous CPU usage for long time, although i'm not 100% sure it's due to bfgminer.

Code:
kernel: rcu: INFO: rcu_preempt detected expedited stalls on CPUs/tasks: { P93622 } 116803 jiffies s: 7173 root: 0x1/.
kernel: rcu: blocking rcu_node structures (internal RCU debug): l=1:0-15:0x0/T
hero member
Activity: 952
Merit: 938
You really should mention that by design the Testnet coins have ZERO monetary value. Purchase and sale of them is strongly discouraged as Testnet and its coins are for testing software -- not making money... Mining them and holding them is also pretty pointless because the Testnet chain is periodically forked to render previously mined Testnet coins unusable.

After a development project is over it is expected that all Testnet coins mined during testing are to be donated back to the Faucets.

Yeah, I didn't mention it because I thought that was well known for the people reading the Development & Technical Discussion forum. It's basically for people that don't want to depend on faucets to test their projects. Once you know how to do it you can mine some testnet bitcoin for yourself overnight, even if there's no faucets available.

But you're right, it might be worth noting it for people that come here from the outside through a search or a link. Yes, testnet bitcoins are only useful for testing, they don't have any other value, and they can even disappear at any time. That's also why I didn't mention any kind of security for the wallet, because it doesn't matter.
legendary
Activity: 3612
Merit: 2506
Evil beware: We have waffles!
You really should mention that by design the Testnet coins have ZERO monetary value. Purchase and sale of them is strongly discouraged as Testnet and its coins are for testing software -- not making money... Mining them and holding them is also pretty pointless because the Testnet chain is periodically forked to render previously mined Testnet coins unusable.

After a development project is over it is expected that all Testnet coins mined during testing are to be donated back to the Faucets.
Pages:
Jump to: