Bitcoin Core and Solo Mining Script

19 replies 166 views
Posts: 1 · Reputation: 84
#1Jan 18, 2017, 10:52 AM
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:
4 Reply Quote Share
alt21Senior Member
Posts: 398 · Reputation: 1732
#2Jan 19, 2017, 10:36 AM
Please, use code brackets like this: I will review the code later today, but again, please learn and use proper bbcode tags.
0 Reply Quote Share
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#3Jan 19, 2017, 12:12 PM
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.
4 Reply Quote Share
alt21Senior Member
Posts: 398 · Reputation: 1732
#4Jan 19, 2017, 03:36 PM
Doesn't this require an ASIC to work? Can it be used with small solo mining devices like Mars Lander or Gekkoscience R909?
4 Reply Quote Share
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#5Jan 19, 2017, 05:20 PM
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.
2 Reply Quote Share
alt21Senior Member
Posts: 398 · Reputation: 1732
#6Jan 19, 2017, 09:52 PM
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.
1 Reply Quote Share
darkguruHero Member
Posts: 849 · Reputation: 4147
#7Jan 19, 2017, 10:35 PM
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.
2 Reply Quote Share
WildWolfMember
Posts: 36 · Reputation: 205
#8Jan 19, 2017, 10:50 PM
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 ?
2 Reply Quote Share
alt21Senior Member
Posts: 398 · Reputation: 1732
#9Jan 20, 2017, 03:27 AM
Hello. What is your equipment, if I may ask?
4 Reply Quote Share
darkguruHero Member
Posts: 849 · Reputation: 4147
#10Jan 20, 2017, 06:57 AM
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...
6 Reply Quote Share
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#11Jan 20, 2017, 10:10 AM
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.
5 Reply Quote Share
ColdMatrixFull Member
Posts: 32 · Reputation: 329
#12Jan 20, 2017, 01:43 PM
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?
2 Reply Quote Share
paul.stakeHero Member
Posts: 651 · Reputation: 3798
#13Jan 20, 2017, 06:46 PM
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.
2 Reply Quote Share
WildGuruFull Member
Posts: 77 · Reputation: 559
#14Jan 20, 2017, 11:23 PM
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!.
3 Reply Quote Share
hash_bossLegendary
Posts: 1166 · Reputation: 5261
#15Jan 21, 2017, 03:38 AM
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
1 Reply Quote Share
ColdMatrixFull Member
Posts: 32 · Reputation: 329
#16Jan 21, 2017, 08:41 AM
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.
1 Reply Quote Share
hash_bossLegendary
Posts: 1166 · Reputation: 5261
#17Jan 21, 2017, 05:29 PM
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.
2 Reply Quote Share
ColdMatrixFull Member
Posts: 32 · Reputation: 329
#18Jan 21, 2017, 10:59 PM
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).
4 Reply Quote Share
ColdMatrixFull Member
Posts: 32 · Reputation: 329
#19Jan 22, 2017, 01:42 AM
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
2 Reply Quote Share
WildWolfMember
Posts: 36 · Reputation: 205
#20Jan 22, 2017, 03:14 AM
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.
6 Reply Quote Share

Related topics