I got Bitcoin Core set up on my laptop, synced everything, and it’s running fine. I even wrote a Python script to do some solo mining by connecting to Bitcoin Core using RPC.
In my script, I've added an algorithm that creates different nonce values for the mining process. I know the chances of actually mining a block are super slim, but I want to double-check if my solo mining Python script is technically sound and if it runs without any glitches on the Bitcoin network.
I'd really appreciate it if you could take a look at my program and let me know if you spot any mistakes or if there are improvements I could make. Thanks a ton for your help with this.
Here’s the code:
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:
Yes, to not use python.
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.
It can even be used with a CPU.
Using cpuminer-opt: https://github.com/JayDDee/cpuminer-opt.
USER and PASS are credentials of CKpool. CPU miner connects to pool via stratum and receives block templates.
You REALLY should ref https://bitcointalk.org/index.php?topic=2415854.0 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.
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 ?
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...
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:
To get the probability of finding a block at once (one hash), divide it by 2^256.
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:
To calculate this with high precision, you need to make use of special libraries:
Results:
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.
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?
It says it does for Intel Rocket Lake: https://bitcointalk.org/index.php?topic=5226770.msg53865575#msg53865575.
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.
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.
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!.
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
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.
FWIW, you could use also hashcat built-in benchmark.
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.
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).
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
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.