Author

Topic: Bitcoin Core + Solo Mining Program (Read 519 times)

?
Activity: -
Merit: -
February 08, 2025, 06:53:02 PM
#37
Mining is not just computation—it is a game of probability, economics, and efficiency.

Solo mining with Python is an interesting experiment, but Bitcoin does not reward effort; it rewards proof of work. The network does not care how you mine—it only verifies results.

If you are solo mining with low hashrate, you are not competing—you are hoping.
Hope is not a strategy.

The Reality of Solo Mining
   1.   The odds are against you. Even with top-tier hardware, finding a block is unlikely. Without it, it is nearly impossible.
   2.   Python is not optimized for mining. SHA-256 hashing is computationally demanding. Dedicated software and hardware exist for a reason.
   3.   Testnet is your best option. If your goal is to learn, use testnet. If your goal is to mine profitably, reconsider your approach.

A More Practical Approach
   •   If you want to mine solo, use CKPool.
   •   If you want to develop mining software, use C, Rust, or another optimized low-level language.
   •   If you want to earn Bitcoin, there are far more efficient methods than solo mining with inefficient code.

Bitcoin does not adapt to you—you adapt to Bitcoin. Hashrate wins. Probability rules.
Adapt, or be left behind.

Ocoshy
member
Activity: 106
Merit: 160
February 08, 2025, 07:26:02 AM
#36
Quote
Instead people should be calling on and contributing to bitcoin core so that solo mining is a first class supported feature, with good stats so you know its working and can feel excited about it.
Having some stats would be good. But what about using produced shares for real trades? For example: if you have some LN payment, and you use solo mining, you could get your transaction routed with a discount. In this way, small miners would have any incentive to continue solo mining.

Because now, a lot of miners receive real payments from centralized pools. However, usually they "withdraw" their coins, when they earn enough, to make it significantly bigger than fees. And if you are a small miner, then you will get single satoshis, or even millisatoshis in your stats.

Quote
Would you be in favour or against the theoretical idea of a world where every house in the world would be solo mining bitcoin using low budget devices?
Well, it is possible to do that in a trustless way in the current Script. However, it is not connected with the real 80-byte block headers, so you cannot use Merged Mining on top of that. Because here and now, you can use "OP_SIZE 60 OP_LESSTHAN OP_VERIFY 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 OP_CHECKSIG" as described by Garlo Nicon, and you can basically lock any coin into some Proof of Work. And when you pick a different public key, than just the generator, then you can get a Byzantine Generals game, described by Satoshi: https://www.metzdowd.com/pipermail/cryptography/2008-November/014849.html

Then, you can make a simple game, like "N people trying to get a single UTXO". And then, the only problem is that you cannot work simultaneously on the real Bitcoin chain, and on that UTXO, at the same time. However, if future proposals, like OP_CAT would be activated, then it would be possible to also apply Merged Mining there.
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
February 06, 2025, 12:20:31 PM
#35
Instead people should be calling on and contributing to bitcoin core so that solo mining is a first class supported feature, with good stats so you know its working and can feel excited about it.  There is nothing wrong with things like 'solo pools' existing, and I suppose they'd also make good fallbacks for people's local nodes.... but they're not the gold standard the community should be promoting.

This definitely replies to my previous question where I asked you this:

Would you be in favour or against the theoretical idea of a world where every house in the world would be solo mining bitcoin using low budget devices?

It would help the overall network’s decentralisation but it’s true that most people wouldn’t have any profits.

So it’s more for the idealists, isn’t it?

The thing is, solo mining is for those who truly care about bitcoin's longevity.
staff
Activity: 4326
Merit: 8951
February 05, 2025, 09:07:56 PM
#34
~snip
But doesn't this mean that for every block mined by CKPool, one person (or better one miner) receives the block reward on their own?
So, in a sense, it is solo mining, isn't it?

It's absolutely solo mining, but the code of ckpool-solo gives 2% of the block reward to the pool and sends the other 98% to the miner, this is done at the coinbase transaction, completely automatically.

So, you basically have a ready to go system for solo mining, and if you are lucky, you only pay 2% in fees. For comparison, NiceHash also has a 2% fee for mining.

I think it's a great "pool" for solo miners that have home miners (not too loud).

Meh.  So you get the lottery benefit, but not the benefit of contributing significantly to Bitcoin's decenteralization.  And you pay a 2% fee for it.  That's unfortunate.

Instead people should be calling on and contributing to bitcoin core so that solo mining is a first class supported feature, with good stats so you know its working and can feel excited about it.  There is nothing wrong with things like 'solo pools' existing, and I suppose they'd also make good fallbacks for people's local nodes.... but they're not the gold standard the community should be promoting.
hero member
Activity: 1008
Merit: 960
February 05, 2025, 08:55:43 PM
#33
~snip
But doesn't this mean that for every block mined by CKPool, one person (or better one miner) receives the block reward on their own?
So, in a sense, it is solo mining, isn't it?

It's absolutely solo mining, but the code of ckpool-solo gives 2% of the block reward to the pool and sends the other 98% to the miner, this is done at the coinbase transaction, completely automatically.

So, you basically have a ready to go system for solo mining, and if you are lucky, you only pay 2% in fees. For comparison, NiceHash also has a 2% fee for mining.

I think it's a great "pool" for solo miners that have home miners (not too loud).
full member
Activity: 938
Merit: 206
web developer for hire
February 05, 2025, 06:53:04 PM
#32
Say you have some mining device running personally.  How much are you going to make from it?  Some few dollars a month in bitcoin.  What value is that to you?  skip a frappachino or two and spend the money on coins and you'll be better off.
You're competing with pool so probably won't get any sats.

But instead if you solo mine you get a small probability for a life changing amount of Bitcoin.  I think to many people that is much more valuable.
Winning the lottery or finding a block aren't opposite dreams. I'd be surprised if ppl preferred running a solo miner 24-7 against buying a lottery ticket. It's easier to buy a lottery ticket. Solo miner waiting 100k years doesn't make it promising.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
February 05, 2025, 09:12:55 AM
#31
So, in a sense, it is solo mining, isn't it?
It is, indeed, solo mining. That's why it's branded as "solo". You're just connecting to a reliable pool, but it will reward you as a solo-miner, if you find a block.
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
February 05, 2025, 09:07:53 AM
#30
It's completely different. If you solve a block at ckpool.org, you get 98% of the block reward, as if you would if you solo-mined. (2% is the pool's fee)

In nearly every other pool, you're earning bitcoin by providing shares. For example, one common practice is to split the block reward based on how much each miner worked for (based on these shares).

Oh yeah I missed that.
But doesn't this mean that for every block mined by CKPool, one person (or better one miner) receives the block reward on their own?
So, in a sense, it is solo mining, isn't it?
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
February 05, 2025, 09:04:13 AM
#29
So it's not different than mining in any other pool, is it?
It's completely different. If you solve a block at ckpool.org, you get 98% of the block reward, as if you would if you solo-mined. (2% is the pool's fee)

In nearly every other pool, you're earning bitcoin by providing shares. For example, one common practice is to split the block reward based on how much each miner worked for (based on these shares).
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
February 05, 2025, 09:00:53 AM
#28
Those are solo-miners, connecting to pool "solo.ckpool.org". They are most likely mining with ASIC. Every time a block is found by ckpool.org, it's one of the many solo miners, mining at ckpool.org. The benefit of mining there instead of setting up a proper environment yourself, is stability I think.

So it's not different than mining in any other pool, is it?
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
February 05, 2025, 08:57:14 AM
#27
Btw, do we know when was the last time someone solved a block with a regular PC (either via CPU or GPU)?
I highly doubt there's a list of most-recent CPU/GPU mined blocks, and even if there is, there is no way to actually verify they were mined with CPU/GPU.

But searching in mempool.space, I am seeing the CK pool: https://mempool.space/mining/pool/solock and it looks like this pool mined a block 5 days ago. Is this a solo miner?
Those are solo-miners, connecting to pool "solo.ckpool.org". They are most likely mining with ASIC. Every time a block is found by ckpool.org, it's one of the many solo miners, mining at ckpool.org. The benefit of mining there instead of setting up a proper environment yourself, is stability I think.
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
February 05, 2025, 08:52:04 AM
#26
Btw, do we know when was the last time someone solved a block with a regular PC (either via CPU or GPU)?

Has it happened recently?

From time to time (even a couple of years ago) we hear about lucky solo miners using USB ASIC sticks, but I'm specifically asking about lucky CPU/GPU miners.

I am not entirely sure if my answer is correct, so I kindly ask for correction.
But searching in mempool.space, I am seeing the CK pool: https://mempool.space/mining/pool/solock and it looks like this pool mined a block 5 days ago. Is this a solo miner? Judging from the total mined blocks, I don't think so, but on the other hand, could they be a solo miner?
 
sr. member
Activity: 1666
Merit: 310
February 05, 2025, 07:59:13 AM
#25
Btw, do we know when was the last time someone solved a block with a regular PC (either via CPU or GPU)?

Has it happened recently?

From time to time (even a couple of years ago) we hear about lucky solo miners using USB ASIC sticks, but I'm specifically asking about lucky CPU/GPU miners.
sr. member
Activity: 1666
Merit: 310
February 05, 2025, 07:48:19 AM
#24

ccminer performance is not optimal though, it's 5 times slower compared to benchmarks:

https://bizon-tech.com/blog/best-workstations-gpu-for-forensic-password-cracking

ccminer isn't exactly modern, but it seems it was fairly popular when i look at the github and forum discussion page. Although comparing Hashcat SHA-256 with ccminer SHA-256d isn't very good comparison. And FYI, nvidia can run opencl software.
OpenCL is not recommended for Nvidia cards, it has many restrictions compared to CUDA.
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
February 05, 2025, 06:48:16 AM
#23

 while solo mining contributes to the decentralization of Bitcoin (again, if only slightly) and helping to preserve your coins value.


Would you be in favour or against the theoretical idea of a world where every house in the world would be solo mining bitcoin using low budget devices?

It would help the overall network’s decentralisation but it’s true that most people wouldn’t have any profits.

So it’s more for the idealists, isn’t it?
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
February 05, 2025, 04:32:58 AM
#22

ccminer performance is not optimal though, it's 5 times slower compared to benchmarks:

https://bizon-tech.com/blog/best-workstations-gpu-for-forensic-password-cracking

ccminer isn't exactly modern, but it seems it was fairly popular when i look at the github and forum discussion page. Although comparing Hashcat SHA-256 with ccminer SHA-256d isn't very good comparison. And FYI, nvidia can run opencl software.
staff
Activity: 4326
Merit: 8951
February 04, 2025, 08:46:39 PM
#21
OP's coded his own software that's an achievement but he can't use it to mine because it isn't practical. Solo mining's difficult that's why ppl choose mining with pools it's better to find a block & share rewards because solo miners won't find any thing. It's fun to learn mining or coding but OP won't find blocks using solo mining he'll need more hashrate from pools to have any chance of successfully finding blocks.

I disagree strongly.

Say you have some mining device running personally.  How much are you going to make from it?  Some few dollars a month in bitcoin.  What value is that to you?  skip a frappachino or two and spend the money on coins and you'll be better off.

But instead if you solo mine you get a small probability for a life changing amount of Bitcoin.  I think to many people that is much more valuable.

And assuming you already own bitcoins the first option of pooling contributes (if only ever so slightly) to the centralization of Bitcoin, depriving your coins of value... while solo mining contributes to the decentralization of Bitcoin (again, if only slightly) and helping to preserve your coins value.
full member
Activity: 938
Merit: 206
web developer for hire
February 04, 2025, 04:37:25 PM
#20
OP's coded his own software that's an achievement but he can't use it to mine because it isn't practical. Solo mining's difficult that's why ppl choose mining with pools it's better to find a block & share rewards because solo miners won't find any thing. It's fun to learn mining or coding but OP won't find blocks using solo mining he'll need more hashrate from pools to have any chance of successfully finding blocks.
sr. member
Activity: 1666
Merit: 310
February 04, 2025, 07:04:53 AM
#19
ccminer performance is not optimal though, it's 5 times slower compared to benchmarks:

https://bizon-tech.com/blog/best-workstations-gpu-for-forensic-password-cracking
sr. member
Activity: 1666
Merit: 310
February 04, 2025, 05:23:19 AM
#18
Does this program support SHA x86 extensions?
It says it does for Intel Rocket Lake: https://bitcointalksearch.org/topic/m.53865575.

Quote
I'm curious to know if modern x86 CPUs have an SHA-256 ASIC inside, or if it's just microcode (emulating SHA-256 hashing via micro-ops).
They definitely don't have a fully-pipelined ASIC-like engine inside, specifically designed for SHA, but they do improve performance over general purpose instructions.

Quote
It would be interesting if someone could calculate the probability of a modern PC solving a BTC block... must be hundreds or even thousands of years?
Mine performs around 50 MH/s. Plugging that number in the python program above, and you get a 0.034% chance to solve a block within the next 100,000 years.  Grin
I did an SHA-1 benchmark on AIDA64 and my GPU is 8+ times faster compared to the CPU. I assume the SHA-256 perf delta must be roughly the same.

FWIW, you could use also hashcat built-in benchmark.

Is there any modern GPGPU/CUDA miner for SHA-256 hashing

And preferably I'd like the code to stay inside the L2 cache (it's quite big these days) to avoid GDDR bottlenecks. ETH mining required a quite huge DAG file, but BTC mining shouldn't require much VRAM.

AFAIK there's no up-to-date Bitcoin mining software which support CPU or GPU. Old popular software (such as cgminer or bfgminer) doesn't support CUDA either.

I know it's a gamble/long shot, so I don't expect anything really... at best I can expect electrical heating in my room, with a very slim chance of winning the jackpot. Grin

Good luck with that.
I found this one and it works for nVidia/CUDA:

https://github.com/tpruvot/ccminer/releases
https://crazy-mining.org/en/mining/ccminer-how-to-install-and-use-download-and-configure-for-windows/

cgminer/bfgminer only support OpenCL (GCN Radeon).
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
February 04, 2025, 04:03:03 AM
#17
Does this program support SHA x86 extensions?
It says it does for Intel Rocket Lake: https://bitcointalksearch.org/topic/m.53865575.

Quote
I'm curious to know if modern x86 CPUs have an SHA-256 ASIC inside, or if it's just microcode (emulating SHA-256 hashing via micro-ops).
They definitely don't have a fully-pipelined ASIC-like engine inside, specifically designed for SHA, but they do improve performance over general purpose instructions.

Quote
It would be interesting if someone could calculate the probability of a modern PC solving a BTC block... must be hundreds or even thousands of years?
Mine performs around 50 MH/s. Plugging that number in the python program above, and you get a 0.034% chance to solve a block within the next 100,000 years.  Grin
I did an SHA-1 benchmark on AIDA64 and my GPU is 8+ times faster compared to the CPU. I assume the SHA-256 perf delta must be roughly the same.

FWIW, you could use also hashcat built-in benchmark.

Is there any modern GPGPU/CUDA miner for SHA-256 hashing

And preferably I'd like the code to stay inside the L2 cache (it's quite big these days) to avoid GDDR bottlenecks. ETH mining required a quite huge DAG file, but BTC mining shouldn't require much VRAM.

AFAIK there's no up-to-date Bitcoin mining software which support CPU or GPU. Old popular software (such as cgminer or bfgminer) doesn't support CUDA either.

I know it's a gamble/long shot, so I don't expect anything really... at best I can expect electrical heating in my room, with a very slim chance of winning the jackpot. Grin

Good luck with that.
sr. member
Activity: 1666
Merit: 310
February 03, 2025, 06:53:36 PM
#16
Does this program support SHA x86 extensions?
It says it does for Intel Rocket Lake: https://bitcointalksearch.org/topic/m.53865575.

Quote
I'm curious to know if modern x86 CPUs have an SHA-256 ASIC inside, or if it's just microcode (emulating SHA-256 hashing via micro-ops).
They definitely don't have a fully-pipelined ASIC-like engine inside, specifically designed for SHA, but they do improve performance over general purpose instructions.

Quote
It would be interesting if someone could calculate the probability of a modern PC solving a BTC block... must be hundreds or even thousands of years?
Mine performs around 50 MH/s. Plugging that number in the python program above, and you get a 0.034% chance to solve a block within the next 100,000 years.  Grin
I did an SHA-1 benchmark on AIDA64 and my GPU is 8+ times faster compared to the CPU. I assume the SHA-256 perf delta must be roughly the same.

Is there any modern GPGPU/CUDA miner for SHA-256 hashing?

And preferably I'd like the code to stay inside the L2 cache (it's quite big these days) to avoid GDDR bottlenecks. ETH mining required a quite huge DAG file, but BTC mining shouldn't require much VRAM.

I know it's a gamble/long shot, so I don't expect anything really... at best I can expect electrical heating in my room, with a very slim chance of winning the jackpot. Grin
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
January 31, 2025, 03:59:20 AM
#15
Excuse my skepticism, but i find OP behavior is weird. He never make any response to any reply on this thread, but he also create new thread and even duplicate of this thread[1]. Have anyone tried to run OP's code?

[1] https://ninjastic.space/search?author=eric9800
hero member
Activity: 1008
Merit: 960
January 31, 2025, 01:32:51 AM
#14
Nice project.

You can try it at testnet instead of mainnet so that you can actually have a chance of mining a block to verify your code works correctly.

Some time ago I wrote a couple of guides here to solo mine in testnet. You might want to have a look at them to have a working example that you can compare your code with:

[Guide] Solo mine testnet bitcoins with bfgminer, Bitcoin Core, and a CPU/GPU

[Guide] Solo mine testnet bitcoins with cgminer, Bitcoin Core, and a Compac F

Hope it helps!.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
January 30, 2025, 04:10:54 AM
#13
Does this program support SHA x86 extensions?
It says it does for Intel Rocket Lake: https://bitcointalksearch.org/topic/m.53865575.

Quote
I'm curious to know if modern x86 CPUs have an SHA-256 ASIC inside, or if it's just microcode (emulating SHA-256 hashing via micro-ops).
They definitely don't have a fully-pipelined ASIC-like engine inside, specifically designed for SHA, but they do improve performance over general purpose instructions.

Quote
It would be interesting if someone could calculate the probability of a modern PC solving a BTC block... must be hundreds or even thousands of years?
Mine performs around 50 MH/s. Plugging that number in the python program above, and you get a 0.034% chance to solve a block within the next 100,000 years.  Grin
sr. member
Activity: 1666
Merit: 310
January 29, 2025, 06:42:22 PM
#12
It would be greatly helpful if you could review my program and let me know if there are any issues or potential improvements.
Yes, to not use python.  Cheesy

If what you're trying to accomplish is just test your mining program, then you can use testnet4 and see if it's working properly. From a quick glimpse it seems theoretically correct, but there is already optimized mining software for that purpose, like CKpool.

Edit: CKpool with CPU miner software, like cpuminer-opt, as shown below.
Does this program support SHA x86 extensions?

I'm curious to know if modern x86 CPUs have an SHA-256 ASIC inside, or if it's just microcode (emulating SHA-256 hashing via micro-ops).

I couldn't find any info about GPUs, except this one for nVidia and AMD.

It would be interesting if someone could calculate the probability of a modern PC solving a BTC block... must be hundreds or even thousands of years?
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
January 29, 2025, 10:30:17 AM
#11
By the way, do you know a lot of people who solo mine? I know none and I always felt the urge to try it.
It's fun, but it's just gambling. In fact, depending on your equipment, winning the lottery can actually be more profitable than finding a block within several years.

For example, let's take NotFuzzyWarm's numbers. Current target is:
Code:
000000000000000000029a8a0000000000000000000000000000000000000000

To get the probability of finding a block at once (one hash), divide it by 2^256.
Code:
$ echo "ibase=16; $(echo 000000000000000000029a8a0000000000000000000000000000000000000000 | tr 'a-f' 'A-F')" | bc
249381870384321288544767557745710236775970393538166784
$ echo "ibase=16; $(echo ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | tr 'a-f' 'A-F')" | bc
115792089237316195423570985008687907853269984665640564039457584007913129639935
$ echo "scale=50; 249381870384321288544767557745710236775970393538166784 / 115792089237316195423570985008687907853269984665640564039457584007913129639935" | bc
.00000000000000000000000215370386722371405447399827

Therefore, the probability of not finding a block at once, would be 0.99999999999999999999999784629613277628594552600173.

With 150 TH/s, the probability of not finding a block within a second would be:
Code:
0.99999999999999999999999784629613277628594552600173^150000000000000

To calculate this with high precision, you need to make use of special libraries:
Code:
from mpmath import mp

mp.dps = 100 # precision
a = mp.mpf('0.99999999999999999999999784629613277628594552600173') # probability of not finding a block at once
b = 150000000000000 # hashrate


# probability that you won't find a block in one second
result = mp.power(a, b)
print("Probability that you find a block in one second: ", 1-result)

# probability that you won't find a block in one minute
result = mp.power(result, 60)
print("Probability that you find a block in one minute: ", 1-result)

# probability that you won't find a block in one hour
result = mp.power(result, 60)
print("Probability that you find a block in one hour: ", 1-result)

# probability that you won't find a block in one day
result = mp.power(result, 24)
print("Probability that you find a block in one day: ", 1-result)

# probability that you won't find a block in 365 days
result = mp.power(result, 365)
print("Probability that you find a block in 365 days: ", 1-result)

Results:
Code:
$ python script.py 
Probability that you find a block in one second:  0.0000000003230555800313746542651575759752715614541821047547449121224850649399499116300689485485483766011969696
Probability that you find a block in one minute:  0.00000001938333461715659362240752539068268809022908905282234609174506460595343787394574728284894247787867632
Probability that you find a block in one hour:  0.000001162999412016465068516484322398343389488271846415173949033771762598140719659379694685549553920155671
Probability that you find a block in one day:  0.00002791161258291243699820616307956869968979018852187562446262529145259602086639222189814513684159590908
Probability that you find a block in 365 days:  0.0101361601065333352625712188251736971051205876315052582934340097318939980049579694902996727303243481

Those numbers are not totally accurate, of course, because of difficulty adjustments. Given that difficulty is leaning upwards, the probability of mining a block within a year becomes even less than 1% overtime, with the same hashrate.
legendary
Activity: 3892
Merit: 2797
Evil beware: We have waffles!
January 29, 2025, 09:48:09 AM
#10
Hello. What is your equipment, if I may ask?
Mainly Canaan Avalons: A1246 and A1047 and a Nano-3. Also an ancient Bitmain R4 along with Sidehack's Compac-F and Compac-A1.

Since starting in 2014 I've found 10 blocks but all were using PPLNS on Kano's pool. I switched to solo just for 1 final Big Score...
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
January 29, 2025, 03:00:09 AM
#9
That said, I solo mine at Kano.is with 150 THs pointed there. Also, for reference - been doing that for 3 years and still no block. Wink

Hello. What is your equipment, if I may ask?
full member
Activity: 938
Merit: 206
web developer for hire
January 28, 2025, 08:11:31 PM
#8
If you're doing this because you wanted to make a program you've succeeded. It won't have use because solo mining isn't going to bring blocks so who's going to use it ?

I installed Bitcoin Core on my laptop, synchronized it, and successfully ran it. Additionally, I developed a Python program to perform solo mining by connecting to Bitcoin Core via RPC.
legendary
Activity: 3892
Merit: 2797
Evil beware: We have waffles!
January 28, 2025, 04:59:25 PM
#7
You REALLY should ref https://bitcointalksearch.org/topic/bitcoin-mining-intro-rules-of-this-subforum-read-before-posting-2415854 point-3....
Solo mining even with state-of-the-art miners or by renting a massive amount of hash rate has very very VERY long odds against you. Playing at "mining" with a CPU or GPU or even FPGA rigs puts the odds at MAYBE once in the lifetime of the universe.....

I doubt that you can even be able to process 1 share during the 10min average time of blocks being found and new work started.

That said, I solo mine at Kano.is with 150 THs pointed there. Also, for reference - been doing that for 3 years and still no block. Wink
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
January 28, 2025, 03:35:40 PM
#6
It can even be used with a CPU.

Using cpuminer-opt: https://github.com/JayDDee/cpuminer-opt.
Code:
./cpuminer --algo sha256d --coinbase-addr=
--userpass=USER:PASS -o stratum+tcp://192.168.x.y:3333

USER and PASS are credentials of CKpool. CPU miner connects to pool via stratum and receives block templates.

I will try it for fun.
By the way, do you know a lot of people who solo mine? I know none and I always felt the urge to try it.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
January 28, 2025, 02:41:25 PM
#5
Can it be used with small solo mining devices like Mars Lander or
Gekkoscience R909
?
It can even be used with a CPU.

Using cpuminer-opt: https://github.com/JayDDee/cpuminer-opt.
Code:
./cpuminer --algo sha256d --coinbase-addr=
--userpass=USER:PASS -o stratum+tcp://192.168.x.y:3333

USER and PASS are credentials of CKpool. CPU miner connects to pool via stratum and receives block templates.
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
January 28, 2025, 02:16:55 PM
#4
but there is already optimized mining software for that purpose, like CKpool.

Doesn't this require an ASIC to work?
Can it be used with small solo mining devices like Mars Lander or
Gekkoscience R909
?
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
January 28, 2025, 10:46:41 AM
#3
It would be greatly helpful if you could review my program and let me know if there are any issues or potential improvements.
Yes, to not use python.  Cheesy

If what you're trying to accomplish is just test your mining program, then you can use testnet4 and see if it's working properly. From a quick glimpse it seems theoretically correct, but there is already optimized mining software for that purpose, like CKpool.

Edit: CKpool with CPU miner software, like cpuminer-opt, as shown below.
hero member
Activity: 686
Merit: 1360
✔️ CoinJoin Wallet
January 28, 2025, 10:34:18 AM
#2
Please, use code brackets like this:

Code:
#put code here

I will review the code later today, but again, please learn and use proper bbcode tags.
?
Activity: -
Merit: -
January 28, 2025, 02:00:33 AM
#1
I installed Bitcoin Core on my laptop, synchronized it, and successfully ran it. Additionally, I developed a Python program to perform solo mining by connecting to Bitcoin Core via RPC.

In this program, I implemented an algorithm that generates various nonce values and applies them to the mining process. While I am aware that the probability of successfully mining a block is extremely low, I would like to confirm whether my solo mining Python program is technically correct and operates without errors on the actual Bitcoin network.

It would be greatly helpful if you could review my program and let me know if there are any issues or potential improvements. I sincerely appreciate your time and assistance with this request.

Thank you once again, and I look forward to your response.


import hashlib
import requests
import json
import struct
import time
import random

# RPC settings
RPC_USER = "user"
RPC_PASSWORD = "passwd"
RPC_URL = "http://127.0.0.1:8332/"

# User-defined address
MINING_ADDRESS = "your_bitcoin_address"

def is_valid_bitcoin_address(address):
    """Validate the Bitcoin address"""
    try:
        alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
        base58_decoded = 0
        for char in address:
            base58_decoded = base58_decoded * 58 + alphabet.index(char)
        address_bytes = base58_decoded.to_bytes(25, byteorder="big")
        checksum = address_bytes[-4:]
        hash_checksum = hashlib.sha256(hashlib.sha256(address_bytes[:-4]).digest()).digest()[:4]
        return checksum == hash_checksum
    except Exception as e:
        print(f"Address validation failed: {e}")
        return False

# Validate MINING_ADDRESS
if not is_valid_bitcoin_address(MINING_ADDRESS):
    raise ValueError(f"Invalid Bitcoin address: {MINING_ADDRESS}")

def rpc_request(method, params=None):
    """Send an RPC request"""
    payload = json.dumps({"jsonrpc": "2.0", "id": "mining", "method": method, "params": params or []})
    response = requests.post(RPC_URL, auth=(RPC_USER, RPC_PASSWORD), data=payload)
    try:
        response.raise_for_status()
        result = response.json()
        if "result" not in result:
            raise ValueError("The 'result' field is missing in the RPC response.")
        return result["result"]
    except Exception as e:
        print(f"RPC request failed: {e}")
        print(f"Response content: {response.text}")
        raise

def address_to_script_pubkey(address):
    """Convert Bitcoin address to ScriptPubKey"""
    try:
        alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
        base58_decoded = 0
        for char in address:
            base58_decoded = base58_decoded * 58 + alphabet.index(char)
        address_bytes = base58_decoded.to_bytes(25, byteorder="big")
        print(f"Base58 decoding successful: {address_bytes.hex()}")
        pubkey_hash = address_bytes[1:-4]  # Exclude network byte and checksum
        script_pubkey = b"\x76\xa9" + bytes([len(pubkey_hash)]) + pubkey_hash + b"\x88\xac"
        print(f"ScriptPubKey generated successfully: {script_pubkey.hex()}")
        return script_pubkey
    except Exception as e:
        print(f"Address conversion failed: {e}")
        raise

def modify_coinbase_tx(block_template, extra_nonce):
    """Generate a coinbase transaction"""
    coinbase_value = block_template["coinbasevalue"]
    script_pubkey = address_to_script_pubkey(MINING_ADDRESS)
    extra_nonce_script = struct.pack("    script_pubkey = extra_nonce_script + script_pubkey
    coinbase_tx = (
        b"\x01"
        b"\x00"
        b"\x01"
        + b"\x00" * 32
        + b"\xff" * 4
        + b"\x01"
        + struct.pack("        + struct.pack("B", len(script_pubkey))
        + script_pubkey
    )
    return coinbase_tx

def calculate_merkle_root(transactions):
    """Calculate the Merkle root"""
    transaction_hashes = [hashlib.sha256(bytes.fromhex(tx["data"])).digest() for tx in transactions]
    while len(transaction_hashes) > 1:
        if len(transaction_hashes) % 2 == 1:  # Duplicate the last hash if odd
            transaction_hashes.append(transaction_hashes[-1])
        transaction_hashes = [
            hashlib.sha256(transaction_hashes + transaction_hashes[i + 1]).digest()
            for i in range(0, len(transaction_hashes), 2)
        ]
    return transaction_hashes[0][::-1]  # Return little-endian

def calculate_block_hash(header):
    """Generate a block hash by hashing the block header"""
    hash1 = hashlib.sha256(header).digest()
    hash2 = hashlib.sha256(hash1).digest()
    return hash2[::-1]  # Return little-endian

def mine():
    """Mining loop"""
    print("Starting Bitcoin mining...")
    extra_nonce = 0  # Initialize Extra Nonce

    while True:
        try:
            block_template = rpc_request("getblocktemplate", [{"rules": ["segwit"]}])
            previous_block = block_template["previousblockhash"]
            target = int(block_template["target"], 16)
            print(f"Mining target: {block_template['target']}")

            while True:  # Extra Nonce loop
                coinbase_tx = modify_coinbase_tx(block_template, extra_nonce)
                transactions = [{"data": coinbase_tx.hex()}] + block_template["transactions"]

                merkle_root = calculate_merkle_root(transactions)

                version = struct.pack("                prev_block_hash = bytes.fromhex(previous_block)[::-1]
                ntime = struct.pack("                nbits = bytes.fromhex(block_template["bits"])[::-1]
                nonce = 0

                while nonce < 2**32:  # Nonce range
                    header = (
                        version
                        + prev_block_hash
                        + merkle_root
                        + ntime
                        + nbits
                        + struct.pack("                    )
                    block_hash = calculate_block_hash(header)

                    if int(block_hash.hex(), 16) < target:
                        print(f"Mining successful! Block hash: {block_hash.hex()}")
                        print(f"Extra Nonce: {extra_nonce}, Nonce: {nonce}")

                        result = rpc_request("submitblock", [header.hex()])
                        if result is None:
                            print("Block successfully submitted!")
                        else:
                            print(f"Block submission failed: {result}")
                        return  # Exit mining loop

                    nonce += 1

                # Increase Extra Nonce when nonce is exhausted
                print(f"Nonce exhausted - Increasing Extra Nonce: {extra_nonce}")
                extra_nonce += 1

        except Exception as e:
            print(f"Error occurred: {e}")
            time.sleep(5)

if __name__ == "__main__":
    mine()
Jump to: