Coder Social home page Coder Social logo

Comments (15)

Sjenja87 avatar Sjenja87 commented on September 24, 2024

How did you connect to a stratum pool? Did you use a proxy ? and can you share your configs?

from open-source-fpga-bitcoin-miner.

FiveNina avatar FiveNina commented on September 24, 2024

from open-source-fpga-bitcoin-miner.

penguin359 avatar penguin359 commented on September 24, 2024

Likely, your hash rate is too slow to produce any shares in time. ASICs are too performant in this day and age for cheap, single FPGA to compete with them. When I ran this on my DE2 board a couple of years ago, I don't recall it producing any shares at the time.

from open-source-fpga-bitcoin-miner.

rockydemag avatar rockydemag commented on September 24, 2024

Hello penguin359,

Can you please guide me on how to get this project working on a different board.
I have a ZCU102 board and the projects in the projects folder are for older xilinx IDE. When I open the Kintex or K705, I cant see any block diagram.
What changes will be needed in order to get this to work on ZCu102 board that has ethernet, USB-JTAG and USB-Uart.

Can you steer me in the right direction if its not too much to ask?

Thanks,
Rocky

from open-source-fpga-bitcoin-miner.

penguin359 avatar penguin359 commented on September 24, 2024

What I would do is to first get a simpler Verilog project working on your board. First get a simple project working that will turn on an LED, then make it blink at a fixed rate. Try to make it blink at a rate of 1 Hz or 1 time per second. This will be important to make sure you have the correct clock rate and know how to divide it down appropriately. Once this is working, try writing a simple Verilog design that outputs the ASCII characters 'H' and 'i' followed by a short pause over a serial port or USB serial interface on your board, assuming you have one. Get this to work at some known baud rate and configuration like 9600 8N1 and make sure you can see the letters on a terminal emulator on your computer. Once you have this working, you should have most of the required basics needed to get this project going.

There should be plenty of guides online for how to write a UART or LED blinking in Verilog or VHDL online.

from open-source-fpga-bitcoin-miner.

kapoor7997 avatar kapoor7997 commented on September 24, 2024

Hi penguin359,

I followed your advice and ran the LED's and also got the serial working on the ZCU102 board.
I then also got the project VHDL_Xilinx_Port working on the (ZCu102) board and got the script to send and receive the data from the board.

At this point I am getting error in getwork with the given config file.
Attached is the miner.log.

In miner.log: two test cases
First data bunch is for BTCGuild
Second data bunch is for slushpool(account that I created on slushpool is used as username and password)

Contents of my config.py are
`fpgaport = "/dev/ttyUSB2"
pools = [
{
"name": "BTC Guild",
"servers": [
{"host": "btcguild.com", "port": 8332},
],
"username": "USERNAME",
"password": "PASSWORD",
},
]

OR

pools = [
{
"name": "Slushpool",
"servers": [
{"host": "ca.stratum.slushpool.com", "port": 3333},
],
"username": "kapoor7997.workerName",
"password": "maybe123",
},
]`

I am getting that the way to get work from the pool has changed.
Can you guide or direct me to any resource that guides me about what changes do I need in the miner.py to get this working.

Thanks,
[kapoor7997]
miner.log

from open-source-fpga-bitcoin-miner.

penguin359 avatar penguin359 commented on September 24, 2024

For Slush Pool, and most likely BTC Guild, they no longer support the older getwork protocol used by miner.py. They use a newer protocol called Stratum. You need to run a local proxy to convert between the two protocols. There's one here you can use:

https://github.com/slush0/stratum-mining-proxy

You will start that up first and configure it to connect to the correct upstream pool. Then configure miner.py to send it's getwork requests to localhost so it goes through the proxy instead. That will convert the request and send it to the pool upstream for results.

from open-source-fpga-bitcoin-miner.

kapoor7997 avatar kapoor7997 commented on September 24, 2024

Hi penguin359,

I really appreciate your reply.
Thank you for that.
I worked on the proxy and was able to install and get it to run on ubunut.
Console output of proxy running is this

dev@dev-MS-7B98:~/Downloads/bitCoinMiningFPGA/slushpoolProxy/slush0-stratum-mining-proxy-bc562bb$ python mining_proxy.py -o us-east.stratum.slushpool.com -sh 0.0.0.0 -sp 3333
2022-04-23 12:43:32,694 INFO proxy jobs.<module> # C extension for midstate not available. Using default implementation instead.
2022-04-23 12:43:32,694 WARNING proxy mining_proxy.main # Stratum proxy version: 1.5.7
2022-04-23 12:43:32,695 WARNING proxy mining_proxy.test_update # Checking for updates...
2022-04-23 12:43:33,403 WARNING proxy mining_proxy.main # Trying to connect to Stratum pool at us-east.stratum.slushpool.com:3333
2022-04-23 12:43:33,515 INFO stats stats.print_stats # 1 peers connected, state changed 1 times
2022-04-23 12:43:33,515 INFO proxy mining_proxy.on_connect # Connected to Stratum pool at us-east.stratum.slushpool.com:3333
2022-04-23 12:43:33,515 INFO proxy mining_proxy.on_connect # Subscribing for mining jobs
2022-04-23 12:43:33,621 WARNING proxy mining_proxy.main # -----------------------------------------------------------------------
2022-04-23 12:43:33,621 WARNING proxy mining_proxy.main # PROXY IS LISTENING ON ALL IPs ON PORT 3333 (stratum) AND 8332 (getwork)
2022-04-23 12:43:33,621 WARNING proxy mining_proxy.main # -----------------------------------------------------------------------
2022-04-23 12:43:33,621 INFO proxy client_service.handle_event # Setting new difficulty: 8192
2022-04-23 12:43:33,622 INFO proxy client_service.handle_event # New job 1980f83320 for prevhash 94466a0d, clean_jobs=True
2022-04-23 12:43:35,623 INFO proxy client_service.handle_event # New job 1980fb8153 for prevhash 94466a0d, clean_jobs=False

The error I get when running miner.py is attached.
miner_py_Error
What changes will it require to get the proxy running.

On the other note, I would like to get the stratum working on this.
I see that the two parameters sent (for hashing) to the board via serial are state and data.
I am assuming we will be sending the same parameters to the FPGA via serial when using STRATUM.
OR has that changed when stratum is used(asking cause bitcoin fundamentally hasn't changed)?

Do you know or have the code for stratum for the miner.py? Or can you guide me to any resource that clears that up for me?

Thanks,
Kapoor7997

from open-source-fpga-bitcoin-miner.

penguin359 avatar penguin359 commented on September 24, 2024

Do you have miner.py connecting to localhost at the getwork port listed in the output of the stratum proxy (8332)? Did the script act like it was able to connect to the proxy.

The fundamental difference between getwork and stratum is that getwork just gives you the block header fully constructed by itself for you to hash and stratum gives you all of the inputs that go into building the block header. With stratum, you can see all of the transactions that are being included with this block and what part of the chain this block is building on. With getwork, you just have the block header and you won't be able to determine where in the chain this block fits or what transactions will be included in it. All of the work of making the block header is done by the pool owner instead. That makes getwork much simpler to implement as you will have to do all the work of building the Merkle tree and generating the block header when implementing the stratum protocol.

The reason for choosing stratum is because you can verify that the pool owner is giving you legitimate work and you are building on the tip of the current block chain whereas with getwork, a malicious pool owner could give you a task to build on a fork of the current block chain and you won't be able to tell.

If you really want to include support for stratum in miner.py, that getwork -> stratum proxy I linked to above is written in Python and fully open source. Spend some time researching both protocols so you understand them and then try merging in the code that the proxy uses to convert between the two. If you can get it working, then you can submit a pull request with it as both projects are GPLv3. I probably won't have much time to help, but all the code is there and there is documentation on both protocols if you Google them.

https://braiins.com/stratum-v1
https://en.bitcoin.it/wiki/Getwork

Otherwise, the proxy itself should be fine.

from open-source-fpga-bitcoin-miner.

kapoor7997 avatar kapoor7997 commented on September 24, 2024

Hi penguin359,

I will work on getting the stratum to work but first I would like to see it work with proxy so I am sure spending time in understanding the code in proxy is worth it.

With proxy running, I tried using the localhost but I get an exception in the following line of code in the miner.py in the getwork method.
conn.request("POST", s.path, req, headers)

My entry in the config.py is this
pools = [
{
"name": "localhost",
"servers": [
{"host": "http://localhost", "port": 8332},
],
# "username": "kapoor7997.workerName",
# "password": "anything123",
},
]

seems like my url in the config.py is not right.
what should my entry in the config.py look like???

my proxy seems to connect to the servers but the miner.py is not connecting to the localhost.
proxyCodeError

I changed the port that i used when I ran the proxy.
I changed the command from this
python mining_proxy.py -o ca.stratum.slushpool.com -sh 0.0.0.0 -sp 3333
to this
python mining_proxy.py -o ca.stratum.slushpool.com -sh 0.0.0.0 -sp 8332

There is an error in the proxy code
exceptions.AttributeError: 'int' object has no attribute 'splitlines'

which wasnt there when I didnt change the port from 3333 to 8332.

Again can you guide me to
what should my entry in the config.py look like???

Thanks,
Kapoor7997

proxyCodeErrorFull.txt

from open-source-fpga-bitcoin-miner.

penguin359 avatar penguin359 commented on September 24, 2024

You have the Python backtrace and the code that produced it. I would recommend you try to look at the code calling splitlines() and try to debug it yourself. This should be a good learning exercise. Make judicious use of print() and see what values are going in and try to debug it. Figuring this out should be easier than the work required to merge stratum into miner.py so I would start with this project. You probably also want to look in the getwork_listener.py from the backtrace above that calls into the twisted HTTP framework.

from open-source-fpga-bitcoin-miner.

kapoor7997 avatar kapoor7997 commented on September 24, 2024

Hi penguin359,

Looks Like "I AM MINING"

I used the following command to run the proxy
sudo python mining_proxy.py -o ca.stratum.slushpool.com -sh 0.0.0.0 -sp 3333 -cu kapoor7997.workerName -cp
and
It seems to be mining now.
The console output of the miner.py is this
Screenshot from 2022-04-26 12-07-37

And

The console output of the proxy is thiis
Screenshot from 2022-04-26 11-54-33

I am receiving jobs and submitting job solutions

But I am not getting why the calculation of the mining speed done in the function "run" of miner.py
is done based on a constant
self.mhps = 45.335163 / delta

Do you know where this constant 45.335163 comes from?
Based on this calculation my hashrate is showing to be around 128MH/s.
Is that something too show it as a worker on my workers on my slushpool account(Pic is attached)
My worker is not showing on my slushpool account

Screenshot from 2022-04-26 11-59-46

Thanks,
kapoor7997

from open-source-fpga-bitcoin-miner.

penguin359 avatar penguin359 commented on September 24, 2024

As I mentioned earlier in this thread, this is good for a learning exercise, but don't expect to make any kind of profit from this mining. As I recall, a hash rate of 128 MH/s sounds about right for a single FPGA and matches what I see here:

https://www.nandland.com/articles/using-your-fpga-to-mine-for-bitcoins.html

However, that is probably too low to be recognized as generating any work for Slushpool (or any other pool these days) and you can find others with a similar issue here:

https://www.reddit.com/r/BitcoinMining/comments/kx110v/minimum_mining_hash_rate_required/

He has a hash rate of 333 MH/s from an old ASIC miner and is complaining that Slushpool is not recognizing him as producing any work. The general consensus seem to be that you need a hash rate of 1 GH/s minimum to get any work accredited. There is just so much mining power currently on Bitcoin that the block difficulty has shot to the moon and requires more serious investment to contribute. However, if you just want to learn about how mining works or FPGAs, this is a nice introduction project.

from open-source-fpga-bitcoin-miner.

fpgaminer avatar fpgaminer commented on September 24, 2024

Do you know where this constant 45.335163 comes from?

I didn't write that Python code, but based on context I can give you my best guess.

self.mine(Job(None, binascii.unhexlify("1625cbf1a5bc6ba648d1218441389e00a9dc79768a2fc6f2b79c70cf576febd0"), "\0" * 64 + binascii.unhexlify("4c0afa494de837d81a269421"), binascii.unhexlify("7bc2b302")))
endtime = datetime.datetime.utcnow()
delta = (endtime - starttime).total_seconds() - 0.0145
self.mhps = 45.335163 / delta

That code is doing an initial benchmark of the FPGA by submitting a known job with a known solution and timing how long the FPGA takes to return with a solution. The code likely assumes the FPGA is doing a linear sweep of nonces. For example the solution might be a nonce of 0x10000000. If the FPGA takes 1 second to return 0x10000000, we know the FPGA just spent 1 second running 268,435,456 hashes. We can then calculate hash rate like so:

hashrate = 0x10000000 / time

Which would be 268MH/s in this example.

Back to the actual code, we can infer that the correct solution nonce must then be 45,335,163, hence the constant of 45.335163. I don't know for sure if that's accurate; you could verify by debugging the Python code to see what solution the FPGA is returning for the benchmark job.

from open-source-fpga-bitcoin-miner.

kapoor7997 avatar kapoor7997 commented on September 24, 2024

Hello penguin359, fpgaminer,

penguin359, I really really appreciate your help and guidence. Thank you for clearning that out for me. I knew I couldnt make any profit but was just not sure why slushpool wasnt showing anything on the workers. I do understand that the hashrate is too slow. But I was expecting a worker registered with a hashrate of 0 or Nill.

fpgaminer.
Thank you for providing direction. I will check my outputs from the script.

To both of you angels,
If possible, can you please direct me to any resource that explains the details of how stratum works i.e. what kind of inputs/data does the stratum receive and how it builds the merkel tree and block header with it. I want to understand the steps and the maths involved.

Thanks,
Rahul Kapoor

from open-source-fpga-bitcoin-miner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.