Code Monkey home page Code Monkey logo

ntgbtminer's Introduction

ntgbtminer

ntgbtminer is a no thrills getblocktemplate Bitcoin miner. It is not performant, but demonstrates basic use of the getblocktemplate protocol for a standalone Bitcoin miner. It has no dependencies outside of standard Python libraries and a JSON-HTTP connection to your local Bitcoin daemon.

Donations are welcome at 15PKyTs3jJ3Nyf3i6R7D9tfGCY1ZbtqWdv :)

Usage

  • Configure rpcuser and rpcpass in ~/.bitcoin/bitcoin.conf

  • Start bitcoind

$ bitcoind -testnet -daemon
  • Run ntgbtminer
$ RPC_USER=bitcoinrpc RPC_PASS=foobar RPC_URL="http://127.0.0.1:18332" \
    python3 ntgbtminer.py "Hello from vsergeev!" "mr9zpiUkvGukpg1uZ99NdAxwJmuSYYmNA3"

License

ntgbtminer is MIT licensed. See the provided LICENSE file.

ntgbtminer's People

Contributors

fraccaman avatar justintarthur avatar vsergeev avatar zeeshanyousaf094 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ntgbtminer's Issues

How could we use Bech32 addresses?

Hi @vsergeev,

First of all I'd like to thank you for this awesome code. I'm playing a lot with it :)

I'm writing you to ask a question. In this part of the code here I've seen that ntgbtminer is using a type 1 bitcoin adress.

I'd like to adapt the code in order to use a Bech32 address type.

It looks like we are transforming the address in this part. Do you know what we would need to change in order to use addresses like this one bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?

Thanks in advance ;)

Merkle Root and Address

Hello,

First of all, thank you for sharing your nice work with us.
I am pretty much new to bitcoin mining and I have two questions regarding your code.
My first question is about the Merkle root. I see that my generated Merkle root is different from the one which has been mined through the successful miner of that block.
Does every miner have its own Merkle root and is it ok to have a different Merkle root from the successfully mined block? if yes, the nonce will be also different for each miner?
My second question is about the address used as the second parameter for the ntgbtminer.py. Shall we use the public key for this purpose?
I know that my questions might be very much general and low-level but your answer would save a lot of time for me.
Thank you in advance for your response.

Submission Error: bad-txnmrklroot while submitting results

Hi,

Running some nodes in testreg mode, ntgbtminer works flawless, if the only transactions pending are coinbase generation.

So for example, if i run some:

$ node1 generatetoaddress 1 $(node2 getnewaddress)

And after that I try to run ntgbtminer, it runs flawless.

However as soon as i send a transaction like:

node2 sendtoaddress $(node1 getnewaddress) 0.1

I start to get errors like:

Solved a block! Block hash: $HASH
Submitting: 
$RESULTS

Submission Error: bad-txnmrklroot

On my server side i get the following error:

node1_1   | 2021-04-06T11:05:37Z ERROR: ProcessNewBlock: AcceptBlock FAILED (bad-txnmrklroot, hashMerkleRoot mismatch (code 16))

As soon as i generate a new bitcoin again, the ntgbtminer starts to work again.

is that an expected behavior?

Unit test script fails with runtime error 'TypeError: 'NoneType' object is not subscriptable'

Firstly thank you for writing this program, I was amazed that it connected and ran the very first time I started it, as that rarely happens with this type of software so I want to compliment you before dumping this error on you lol :)

I encountered an error while running the "test_ntgbtminer.py" script on two seperate computers, and have copied the error message below:

:~/ntgbtminer$ python3 test_ntgbtminer.py 
..E.......
======================================================================
ERROR: test_block_mine (__main__.TestBlock)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_ntgbtminer.py", line 262, in test_block_mine
    self.assertEqual(mined_block['hash'], "000000000000000a369033d52a4aa264844b50857f0c6104c555d53938e9c8d7")
TypeError: 'NoneType' object is not subscriptable

----------------------------------------------------------------------
Ran 10 tests in 61.002s

FAILED (errors=1)

coinbase transaction integration in block mine method seems incorrect

I had been experimenting on some miner codes.
While going through the ntgbtminer source code at line 398 to ...
I found that the coinbase_tx calculated isnt used any where and also the coinbase tx added to the block is empty.

Is it supposed to be empty or the coinbase_tx should be updated there ?

Also as per this book online https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch08.html

The generation transaction implementation should have our mining reward transaction there.

Thanks for the rpc implementation and looking forward for future collaboration.

Error on block submission

I am trying to mining on private peercoin forked network. When the block is found, an error occurred during submission of block.

Solved a block! Block hash: 0000000d5ab62bdb1eab6e896445cf1aef78fe826770738b7258fd67fc4ea212
Submitting: 0300000094c7f068b4fe7ffd581c1b75e5ee20eca72780e309bf6de73a49395f0300000053a1ec385c7b91514c73386cbf7253bc4765a9cda352cf04c73575735219ee2341ed265effff0f1d100eac2e0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff18010148656c6c6f2066726f6d205370696465722100000000ffffffff0100078142170000001976a914a9c679338365a9006088646cb630b7cfd535e22288ac00000000 

Inside rpc
Preparing Request
Traceback (most recent call last):
  File "ntgbtminer.py", line 435, in <module>
    standalone_miner(bin2hex("Hello from Spider!"), "PQ4s7ZxMAGt197eL9ths3Jensn7vSqbJ6r")
  File "ntgbtminer.py", line 432, in standalone_miner
    rpc_submitblock(submission)
  File "ntgbtminer.py", line 63, in rpc_submitblock
    try: return rpc("submitblock", [block_submission])
  File "ntgbtminer.py", line 42, in rpc
    f = urllib2.urlopen(request)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 435, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error

bad-txnmrklroot

This only worked when the pending transcation list was empty (block_template['transactions'] = []). Otherwise it gives this error: "Submission Error: bad-txnmrklroot"

It also gives an "Submission Error: bad-cb-height" error at very low heights.

test_ntgbtminer.py failing

Trying to understand the bitcoin mining algorithm, ran into this issue:

bob@orangepi2:~/ntgbtminer$ python2.7 test_ntgbtminer.py
..E.....E.
======================================================================
ERROR: test_block_mine (__main__.TestBlock)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_ntgbtminer.py", line 148, in test_block_mine
    self.assertEqual(mined_block['hash'], test_vector)
TypeError: 'NoneType' object has no attribute '__getitem__'

======================================================================
ERROR: test_make_coinbase (__main__.TestTransaction)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_ntgbtminer.py", line 58, in test_make_coinbase
    self.assertEqual(tx_make_coinbase(coinbase_script, address, value), test_vector)
TypeError: tx_make_coinbase() takes exactly 4 arguments (3 given)

----------------------------------------------------------------------
Ran 10 tests in 70.814s

FAILED (errors=2)

Running this on an armv7l processor

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.