Skip to content

Commit

Permalink
Merge pull request #57 from zcoinofficial/Lyra2Z
Browse files Browse the repository at this point in the history
Final Lyra2Z
  • Loading branch information
aizensou authored Feb 7, 2017
2 parents 85e0d66 + b0f1f60 commit 0d0da58
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Lyra2Z/Lyra2Z.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void lyra2z_hash(const char* input, char* output)
sph_blake256 (&ctx_blake, input, 80);
sph_blake256_close (&ctx_blake, hashA);

LYRA2(hashB, 32, hashA, 32, hashA, 32, 2, 16, 16);
LYRA2(hashB, 32, hashA, 32, hashA, 32, 8, 8, 8);

memcpy(output, hashB, 32);
}
Expand Down
8 changes: 4 additions & 4 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ namespace Checkpoints

static MapCheckpoints mapCheckpointsTestnet =
boost::assign::map_list_of
( 0, uint256("0xe900c15110857ca650625825761b00381699ef41451915468b1488644295671a"))
( 0, uint256("0x"))
;
static const CCheckpointData dataTestnet = {
&mapCheckpointsTestnet,
1398863062,
1,
960.0
1414776313,
0,
100.0
};

const CCheckpointData &Checkpoints() {
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 8
#define CLIENT_VERSION_REVISION 7
#define CLIENT_VERSION_BUILD 3
#define CLIENT_VERSION_BUILD 4

// Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
7 changes: 4 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// RECURSIVE, SET NEW ID
BOOST_FOREACH(const CZerocoinEntry& pubCoinItem, listPubCoin) {

if(pubCoinItem.nHeight < lastCalculatedZCBlock){
if(!fReindex && pubCoinItem.nHeight < lastCalculatedZCBlock){
continue;
}else{
CZerocoinEntry pubCoinTx;
Expand All @@ -1065,11 +1065,12 @@ bool AppInit2(boost::thread_group& threadGroup)
{
while (pindexRecur)
{
//printf("PROCESS BLOCK = %d\n", pindexRecur->nHeight);
if(pindexRecur->nHeight < lastCalculatedZCBlock){

if(!fReindex && (pindexRecur->nHeight < lastCalculatedZCBlock)){
pindexRecur = pindexRecur->pnext;
continue;
}else{
printf("PROCESS BLOCK = %d\n", pindexRecur->nHeight);
CBlock blockRecur;
blockRecur.ReadFromDisk(pindexRecur);

Expand Down
42 changes: 23 additions & 19 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ bool CTransaction::CheckTransaction(CValidationState &state, uint256 hashTx, boo

// CHECKING PROCESS
BOOST_FOREACH(const CZerocoinEntry& pubCoinItem, listPubCoin) {
if (pubCoinItem.value == pubCoin)
if (pubCoinItem.value == pubCoin && pubCoinItem.denomination == denomination)
{
isAlreadyStored = true;
}
Expand Down Expand Up @@ -831,6 +831,7 @@ bool CTransaction::CheckTransaction(CValidationState &state, uint256 hashTx, boo

// CHECK PUBCOIN ID
int pubcoinId = txin.nSequence;
//printf("====================== pubcoinId = %d\n", pubcoinId);
if (pubcoinId < 1 && pubcoinId == INT_MAX) { // IT BEGINS WITH 1
return state.DoS(100, error("CTransaction::CheckTransaction() : Error: nSequence is not correct format"));
}
Expand Down Expand Up @@ -2240,8 +2241,8 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
{
// Testnet has min-difficulty blocks
// after nTargetSpacing*16 time between blocks:
//if (fTestNet && nTime > nTargetSpacing*16)
// return bnProofOfWorkLimit.GetCompact();
if (fTestNet && nTime > nTargetSpacing*3)
return bnProofOfWorkLimit.GetCompact();

CBigNum bnResult;
bnResult.SetCompact(nBase);
Expand Down Expand Up @@ -2361,14 +2362,13 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl
uint32_t PastBlocksMin = PastSecondsMin / BlocksTargetSpacing; // 36 blocks
uint32_t PastBlocksMax = PastSecondsMax / BlocksTargetSpacing; // 1008 blocks

/* if (fTestNet) {
// If the new block's timestamp is more than nTargetSpacing*16
// then allow mining of a min-difficulty block.
if (pblock->nTime > pindexLast->nTime + nTargetSpacing*16)
{
if (fTestNet) {
// If the new block's timestamp is more than nTargetSpacing*6
// then allow mining of a min-difficulty block
if (pblock->nTime > pindexLast->nTime + nTargetSpacing*6) {
return bnProofOfWorkLimit.GetCompact();
}
}*/
}

// 9/29/2016 - Reset to Lyra2(2,block_height,256) due to ASIC KnC Miner Scrypt
// 36 block look back, reset to mininmun diff
Expand All @@ -2378,11 +2378,12 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl

}

/*
if(fTestNet && pindexLast->nHeight + 1 >= 138 && pindexLast->nHeight + 1 <= 173){
return bnProofOfWorkLimit.GetCompact();
}
}*/


if ((pindexLast->nHeight+1) % nInterval != 0) // Retarget every nInterval blocks
Expand Down Expand Up @@ -3189,7 +3190,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
pubCoinTx.value = pubCoinItem.value;
pubCoinTx.nHeight = -1;
walletdb.WriteZerocoinEntry(pubCoinTx);
printf("- Connect Reset Pubcoin Id: %d Height: %d\n", pubCoinTx.id, pindex->nHeight);
printf("- Connect Reset Pubcoin Denomination: %d Pubcoin Id: %d Height: %d\n", pubCoinTx.denomination, pubCoinTx.id, pindex->nHeight);
zercoinMintHeight = pindex->nHeight;
}
}
Expand All @@ -3205,7 +3206,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
pubCoinTx.serialNumber = pubCoinItem.serialNumber;
pubCoinTx.value = pubCoin;
pubCoinTx.nHeight = -1;
printf("- Connect Reset Pubcoin Id: %d Height: %d\n", pubCoinTx.id, pubCoinItem.nHeight);
printf("- Connect Reset Pubcoin Denomination: %d Pubcoin Id: %d Height: %d\n", pubCoinTx.denomination, pubCoinTx.id, pindex->nHeight);
walletdb.WriteZerocoinEntry(pubCoinTx);
}

Expand Down Expand Up @@ -3272,7 +3273,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
if (currentId == countItemPubcoin.id && countItemPubcoin.denomination == pubCoinItem.denomination) {
countExistingItems++;
}
//printf("pubCoinItem.id = %d\n", countItemPubcoin.id);
printf("pubCoinItem.id = %d\n", countItemPubcoin.id);
}

// IF IT IS NOT 10 -> ADD MORE
Expand All @@ -3290,7 +3291,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
pubCoinTx.serialNumber = pubCoinItem.serialNumber;
pubCoinTx.value = pubCoinItem.value;
pubCoinTx.nHeight = pindex->nHeight;
printf("REORG PUBCOIN ID: %d HEIGHT: %d\n", pubCoinTx.id, pubCoinTx.nHeight);
printf("REORG PUBCOIN DENOMINATION: %d PUBCOIN ID: %d HEIGHT: %d\n", pubCoinTx.denomination, pubCoinTx.id, pubCoinTx.nHeight);
walletdb.WriteZerocoinEntry(pubCoinTx);
}
}
Expand Down Expand Up @@ -6360,6 +6361,7 @@ void static ZcoinMiner(CWallet *pwallet)
unsigned int nExtraNonce = 0;

try { loop {

while (vNodes.empty())
MilliSleep(1000);

Expand Down Expand Up @@ -6406,21 +6408,23 @@ void static ZcoinMiner(CWallet *pwallet)
{
if ( (!fTestNet && pindexPrev->nHeight + 1 >= 20500) ) {
lyra2z_hash(BEGIN(pblock->nVersion), BEGIN(thash));
} else if (fTestNet && pindexPrev->nHeight + 1 >= 3) { // for testnet
} else if (fTestNet && pindexPrev->nHeight + 1 >= 500) { // for testnet
lyra2z_hash(BEGIN(pblock->nVersion), BEGIN(thash));
printf("thash: %s\n", thash.ToString().c_str());
printf("hashTarget: %s\n", hashTarget.ToString().c_str());
//printf("lyra2z thash: %s\n", thash.ToString().c_str());
} else if( !fTestNet && pindexPrev->nHeight + 1 >= 8192){
LYRA2(BEGIN(thash), 32, BEGIN(pblock->nVersion), 80, BEGIN(pblock->nVersion), 80, 2, 8192, 256);
} else if( !fTestNet && pindexPrev->nHeight + 1 >= 500){
LYRA2(BEGIN(thash), 32, BEGIN(pblock->nVersion), 80, BEGIN(pblock->nVersion), 80, 2, pindexPrev->nHeight + 1, 256);
// }else if(fTestNet && pindexPrev->nHeight + 1 >= 138){
// LYRA2(BEGIN(thash), 32, BEGIN(pblock->nVersion), 80, BEGIN(pblock->nVersion), 80, 2, pindexPrev->nHeight + 1, 256);
}else if(fTestNet && pindexPrev->nHeight + 1 >= 138){
LYRA2(BEGIN(thash), 32, BEGIN(pblock->nVersion), 80, BEGIN(pblock->nVersion), 80, 2, pindexPrev->nHeight + 1, 256);
printf("LYRA2 thash: %s\n", thash.ToString().c_str());
} else{
unsigned long int scrypt_scratpad_size_current_block = ((1 << (GetNfactor(pblock->nTime) + 1)) * 128 ) + 63;
char scratchpad[scrypt_scratpad_size_current_block];
scrypt_N_1_1_256_sp_generic(BEGIN(pblock->nVersion), BEGIN(thash), scratchpad, GetNfactor(pblock->nTime));
printf("scrypt thash: %s\n", thash.ToString().c_str());
}
//printf("hashTarget: %s\n", hashTarget.ToString().c_str());

if (thash <= hashTarget)
{
Expand Down
6 changes: 3 additions & 3 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -1360,14 +1360,14 @@ class CBlockHeader

if (!fTestNet && height >= 20500) {
lyra2z_hash(BEGIN(nVersion), BEGIN(thash));
} else if (fTestNet && height >= 3) { // for testnet
} else if (fTestNet && height >= 500) { // for testnet
lyra2z_hash(BEGIN(nVersion), BEGIN(thash));
} else if( !fTestNet && height >= 8192){
LYRA2(BEGIN(thash), 32, BEGIN(nVersion), 80, BEGIN(nVersion), 80, 2, 8192, 256);
}else if( !fTestNet && height >= 500){
LYRA2(BEGIN(thash), 32, BEGIN(nVersion), 80, BEGIN(nVersion), 80, 2, height, 256);
//}else if(fTestNet && height >= 138){
// LYRA2(BEGIN(thash), 32, BEGIN(nVersion), 80, BEGIN(nVersion), 80, 2, height, 256);
}else if(fTestNet && height >= 138){
LYRA2(BEGIN(thash), 32, BEGIN(nVersion), 80, BEGIN(nVersion), 80, 2, height, 256);
}else{
scrypt_N_1_1_256(BEGIN(nVersion), BEGIN(thash), GetNfactor(nTime));
}
Expand Down
8 changes: 6 additions & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,14 @@ Value getwork(const Array& params, bool fHelp)
{
// Parse parameters
vector<unsigned char> vchData = ParseHex(params[0].get_str());
if (vchData.size() != 128)
for(int i = 0; i < 4; i++)
{
vchData.insert(vchData.begin(), 0);
}

if (vchData.size() != 132)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
CBlock* pdata = (CBlock*)&vchData[0];

// Byte reverse
for (int i = 0; i < 128/4; i++)
((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern const std::string CLIENT_DATE;
// network protocol versioning
//

static const int PROTOCOL_VERSION = 90019;
static const int PROTOCOL_VERSION = 90020;

// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 90013;
Expand Down

0 comments on commit 0d0da58

Please sign in to comment.