Primecoin- deciphering the block to get the origin

I am new to primecoins (and more generally crypto currencies) and have a few questions:

A) I am trying to understand how to get the block header hash from a given primecoin block.

For example, using primecoind, I can get block info:

./primecoind getblock b56ce048d64313380d2a947cbb99bda97825646d89c6fd4222d154fc7f145bdd
{
“hash” : “b56ce048d64313380d2a947cbb99bda97825646d89c6fd4222d154fc7f145bdd”,
“confirmations” : 347122,
“size” : 198,
“height” : 10000,
“version” : 2,
“merkleroot” : “478aa31ca6011384884c60a5a3c864475640dfa546be26631f1cc58366b3d2ad”,
“tx” : [
“478aa31ca6011384884c60a5a3c864475640dfa546be26631f1cc58366b3d2ad”
],
“time” : 1373505507,
“nonce” : 627,
“bits” : “07a62bc2”,
“difficulty” : 7.64910519,
“transition” : 7.97894430,
“primechain” : “TWN07.ecf7e1”,
“primeorigin” : “3137429839290119515389894171750697301735643977360059424820833454775626872284966 6432245972690”,
“previousblockhash” : “835228e99c1617650f8d72a3167fc92a8a3cf4bebcf60860a645d5b5309f8f87”,
“nextblockhash” : “54d6ec1f98ba10f897f7d8ea0991a042438f38b066702fc53fa05b52f93c3525”
}

My understanding (?) is that the primeorigin should be divisible by the `block header hash’ of the previous block.
But how do I determine the block header hash? I don’t think it is the " “previousblockhash” which, in this example, is “835228e99c1617650f8d72a3167fc92a8a3cf4bebcf60860a645d5b5309f8f87” because when I convert this hex string to decimal I don’t get a number that divides the given primeorigin.

B) I am also after a more detailed description of the primecoin specs. Sunny King’s paper is very broad and not at the level that describes the particulars of implementation. For example, for the Cunningham prime chains, would the primecoin network accept any prime chains where the origin is any multiple of the block header hash (so long as the other requirements such as difficulty, size of primes etc are satisfied)? I noticed that primorials are built into the multiple in primecoind’s search for prime chains, but I am guessing that it is not an actual requirement.

C) Also, I am trying to reverse engineer how primecoind searches for Cunningham chains. Can anyone point me to documentation or a description of the actual implementation.

D) Finally, what precisely do primespersec and chainsperday refer to here:
./primecoind getmininginfo
{
“blocks” : 357131,
“chainspermin” : 5,
“chainsperday” : 0.02283714,
“currentblocksize” : 4614,
“currentblocktx” : 5,
“difficulty” : 10.38302714,
“errors” : “”,
“generate” : true,
“genproclimit” : -1,
“primespersec” : 854,
“pooledtx” : 5,
“sieveextensions” : 9,
“sievepercentage” : 10,
“sievesize” : 1000000,
“testnet” : false
}

Thanks in advance for your help.

I’ve been trying to figure this out myself. There really isn’t anywhere I have seen that gives any description (low or high level) of the algorithm used to find the chains. I tried looking at the code, but it wasn’t very clear to me either.

any chance of putting bounties on this to get someone interested in answering this…

I posted the same question on bitcointalk and got some info:
https://bitcointalk.org/index.php?topic=413204.0

Well, to answer your questions briefly:

A) The block header hash is different from the block hash. The block header hash is used during mining but normally you don’t see it anywhere. What you see in the output of ‘getblock’ is the block hash. Technically you can calculate the header hash from the output, and I see someone on Bitcointalk has already shown that.

The two hashes are defined as follows in the code:
blockHeaderHash = HASH(nVersion, hashPrevBlock, hashMerkleRoot, nTime, nBits, nNonce)
blockHash = HASH(nVersion, hashPrevBlock, hashMerkleRoot, nTime, nBits, nNonce, bnPrimeChainMultiplier)

B) I think the source code is the best source of information with regards to how Primecoin works. There are some restrictions (mainly some size limits) on which prime chains are accepted by the network. The origin doesn’t need to include a primorial but in practice the primorial gives a big mining performance boost.

C) “May the source be with you.”

D) Primespersec is an arbitrary counter that tries to count how many chains started with at least one prime. It’s not accurate in the reference miner because some chains are skipped because of optimizations. Also, it’s completely broken in many forks of jhPrimeminer. They are actually counting the total number of chains tested (which is equivalent to tests/h in reference miner).

Chainsperday tries to estimate the expected number of chains meeting the minimum length required by the network that you are going to find in one day. Since difficulty is about 10.4 now, it’s calculating how many chains would have 10 primes or more.

The basic idea is to first calculate an estimate for Pr(sieved number is prime). We know that the probability of numbers around X being prime is about 1 / ln(X) according to the Prime Number Theorem. So we first estimate how big X is and then our basic prime probability will be 1 / ln(X). We also know that sieving increases this probability roughly 20.1 times (using the default settings in Primecoin HP). The final result will be that Pr(sieved number is prime) is somewhere between 0.085 and 0.090. This mainly depends on which primorial is used.

Once we know what Pr(sieved number is prime) roughly is, we can calculate chains/day as follows:
chains/day = tests/day * Pr(sieved number is prime)^k

Assuming that k is the required minimum length of the chain (which is 10 right now).

I hope this helps.