Rough instructions for merge-mining with Namecoin Core

Post Reply
domob
Posts: 1124
Joined: Mon Jun 24, 2013 11:27 am
Contact:

Rough instructions for merge-mining with Namecoin Core

Post by domob » Thu May 28, 2015 1:47 pm

Some time ago, I've written rough instructions about merge-mining Namecoin (based on Namecoin Core, not sure how much one would have to change for the old client). This was in response to a support request by email, so it is not polished as a tutorial or so. Nevertheless, I think it makes sense to share it here. Feel free to use it for a wiki page or something. But note that I've never personally set up a production mining system - all "experience" I have is from implementing auxpow in the client and the regtesting scripts. Here we go:

Code: Select all

First of all, you need (of course) to run a Namecoin client.  I suggest
you to try Namecoin Core [1] instead of the legacy client [2].  While it
is definitely still "experimental" software, it is based on Bitcoin 0.10
instead of ancient code and it has been in production use by a major
pool since December without any problems.

  [1] https://github.com/namecoin/namecore/
  [2] https://github.com/namecoin/namecoin/

With the client running, the merge-mining procedure looks (on a high
level) like this:

1) You call "namecoind getauxblock" via the RPC interface.  This returns
an object like this:

{
    "hash" : HASH,
    "chainid" : 1,
    ...
    "bits" : "184927b0",
    "_target" :
"000000000000000000000000000000000000000000b027490000000000000000"
}

The important information is the block hash, the chain id (always 1 for
Namecoin) and the difficulty bits / target.  (Note that _target has
reversed byte order due to legacy usage.)

2) You mine on your Bitcoin block as usual, but the coinbase input
includes a special data string.  Every now and then (especially if a new
Namecoin block arrives!) you have to repeat step 1 in order to update
the Namecoin block you mine for.  This implies updating the Bitcoin
block's coinbase input as well.

3) When you find a Bitcoin block header that matches Namecoin's
difficulty as returned by "getauxblock" (even if the block doesn't match
Bitcoin's difficulty), you've found an auxpow.

4) You call "namecoind getauxblock HASH AUXPOW" to submit the block to
the Namecoin network.  HASH is the HASH returned by "getauxblock" in
step 1 and AUXPOW is a hex string that encodes the auxpow (see below).

Now, two important steps remain open:

A) How the Bitcoin coinbase should look like.

B) How the auxpow hex string is constructed.

Piece A is easy if you do not intend to merge-mine any other coins (it
is also not too hard if you do, but for a beginning you can try
without).  For instance, Namecoin block
2a130cf885ee077f329434c1206a0307ced1a926f7311146c47036d63feede75 was
merge-mined with Bitcoin's
00000000000000000cfe6c72e9ee1f8bfff1dcd80ce788d59ff9834a3cbb17db.

If you look in the Bitcoin block's coinbase input, it is (with added
line breaks):

0372530504001a900849124d696e656420627920425443204775696c642c
fabe6d6d2a130cf885ee077f329434c1206a0307ced1a926f7311146c47036d63feede75
01000000000000000800207fbbf6ce0000

The second line contains the so-called "merge-mining header" fabe6d6d
followed by the Namecoin block hash.  The next eight bytes are also
required (in particular the 4-byte integer 1 is important, I think the
following 4-byte integer 0 could be anything in this case).

If you want to take a look at the code that checks this, look at
auxpow.cpp in the Namecoin Core code (linked above).

Finally, regarding the auxpow hex string construction:  Look at auxpow.h
to see, roughly, how a CAuxPow object is serialised.  You need to
construct such a serialisation in hex.  If you follow the advice above
(not merge-mining other coins for now), your "chain Merkle branch" will
always be empty, and your "chain index" will always be 0.  The parent
block is the 80-byte block header of your mined Bitcoin block.  The
initial part of the auxpow is a serialisation of the Bitcoin coinbase tx
including its Merkle branch.

You can also take a look at src/tests/auxpow_tests.cpp and
qa/rpc-tests/auxpow.py.  There is code in there that constructs and
mines (with regtest difficulty) an auxpow.
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

biolizard89
Posts: 1987
Joined: Tue Jun 05, 2012 6:25 am
os: linux

Re: Rough instructions for merge-mining with Namecoin Core

Post by biolizard89 » Fri May 29, 2015 6:28 am

Thanks Daniel. Would be good to get this onto the Jekyll based website somewhere (when that site is ready).
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5

phelix
Posts: 1631
Joined: Thu Aug 18, 2011 6:59 am

Re: Rough instructions for merge-mining with Namecoin Core

Post by phelix » Tue Aug 11, 2015 11:48 am

Maybe we should update the mining proxy: https://github.com/namecoin/namecoin/bl ... mine-proxy
nx.bit - some namecoin stats
nf.bit - shortcut to this forum

biolizard89
Posts: 1987
Joined: Tue Jun 05, 2012 6:25 am
os: linux

Re: Rough instructions for merge-mining with Namecoin Core

Post by biolizard89 » Wed Aug 12, 2015 5:26 am

phelix wrote:Maybe we should update the mining proxy: https://github.com/namecoin/namecoin/bl ... mine-proxy
To my knowledge most miners are not using that proxy. Or at least, that's what Luke-Jr said, if I recall correctly.
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5

phelix
Posts: 1631
Joined: Thu Aug 18, 2011 6:59 am

Re: Rough instructions for merge-mining with Namecoin Core

Post by phelix » Thu Aug 13, 2015 9:29 pm

biolizard89 wrote:
phelix wrote:Maybe we should update the mining proxy: https://github.com/namecoin/namecoin/bl ... mine-proxy
To my knowledge most miners are not using that proxy. Or at least, that's what Luke-Jr said, if I recall correctly.
Well, there should be something usable available. With instructions.
nx.bit - some namecoin stats
nf.bit - shortcut to this forum

biolizard89
Posts: 1987
Joined: Tue Jun 05, 2012 6:25 am
os: linux

Re: Rough instructions for merge-mining with Namecoin Core

Post by biolizard89 » Fri Aug 14, 2015 3:14 am

phelix wrote:
biolizard89 wrote:
phelix wrote:Maybe we should update the mining proxy: https://github.com/namecoin/namecoin/bl ... mine-proxy
To my knowledge most miners are not using that proxy. Or at least, that's what Luke-Jr said, if I recall correctly.
Well, there should be something usable available. With instructions.
I think most miners (including Eligius) are using Eloipool. Eligius told me that their proxy worked fine with Namecoin Core except that they had to rename "target" to "_target".
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5

Post Reply