| 17 | |
| 18 | |
| 19 | uint256 CBlockHeader::GetHash(int nHeight,int Mining) const |
| 20 | { |
| 21 | //printf("%s height = %d (00) Mining ? %d\n",__func__,nHeight,Mining); |
| 22 | if (nHeight==0) |
| 23 | return Phi1612(BEGIN(nVersion), END(nNonce)); |
| 24 | |
| 25 | //printf("%s height = %d (01)\n",__func__,nHeight); |
| 26 | |
| 27 | bool randomxblock = (nHeight>=Params().SwitchRX2Block())? true:false; |
| 28 | bool phi2block = (nHeight>=Params().SwitchPhi2Block() && randomxblock!=true)? true:false; |
| 29 | |
| 30 | // printf("height = %d randomxblock %d phi2block %d switchrandomxblock %d switchphi2block %d \n",nHeight,randomxblock,phi2block,Params().SwitchRX2Block(),Params().SwitchPhi2Block()); |
| 31 | |
| 32 | // phi2 algo |
| 33 | if (phi2block && (nVersion & (1 << 30))) |
| 34 | return phi2_hash(BEGIN(nVersion), END(hashUTXORoot)); |
| 35 | |
| 36 | if (phi2block && (nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION)) |
| 37 | return phi2_hash(BEGIN(nVersion), END(nNonce)); |
| 38 | |
| 39 | // randomX algo |
| 40 | if (randomxblock) { |
| 41 | uint256 thisSeed; |
| 42 | if (Mining == 1 || Mining == 2) |
| 43 | thisSeed = GetRandomXSeed(nHeight); |
| 44 | // barrysPreposterouslyNamedSeedHashFunction(nHeight, thisSeed); |
| 45 | uint256 thash; |
| 46 | if (Mining == 1) { |
| 47 | // std::cout << " 1 height " << nHeight << " seed " << thisSeed.GetHex().c_str() << "size of the seed " << strlen(thisSeed.GetHex().c_str()) << std::endl; |
| 48 | |
| 49 | rx_slow_hash((char*)this,(char*)&thash,144,thisSeed); |
| 50 | return thash; |
| 51 | } else if (Mining == 2) { |
| 52 | // std::cout << "2 height " << nHeight << " seed " << thisSeed.GetHex().c_str() << "size of the seed " << strlen(thisSeed.GetHex().c_str()) << std::endl; |
| 53 | rx_slow_hash2((char*)this,(char*)&thash,144,thisSeed); |
| 54 | return thash; |
| 55 | } else { |
| 56 | if ((nVersion & (1 << 30))) |
| 57 | return phi2_hash(BEGIN(nVersion), END(hashUTXORoot)); |
| 58 | |
| 59 | if ((nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION)) |
| 60 | return phi2_hash(BEGIN(nVersion), END(nNonce)); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | // for genesis hash and case the function is called without argument (nHeight==0) |
| 66 | return Phi1612(BEGIN(nVersion), END(nNonce)); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | uint256 CBlock::BuildMerkleTree(bool* fMutated) const |