diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1bf909cf6..91ffc9043 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1805,6 +1805,7 @@ uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) //fprintf(stderr, "notarizedht.%d prevnotarizedht.%d pprevnotarizedht.%d \n",notarizedht,prevnotarizedht,pprevnotarizedht); // We cannot pay out if 3 notarisation's have not yet happened! + // redundant now... should never happen. if ( pprevnotarizedht == 0 ) { fprintf(stderr, "need 3 notarizations to happen before notaries can be paid.\n"); diff --git a/src/miner.cpp b/src/miner.cpp index 00270dcd8..60c4086dd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -396,52 +396,58 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { // Can't make payment until 3 notarizations have happened. if ( !check_pprevnotarizedht() ) - fNotarisation = false; - // check if the notarization found is actually valid. - if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { - // Get the OP_RETURN for the notarisation - uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; - int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size(); - if ( script[0] == OP_RETURN ) + fNotarisation = false; + fNotarisationBlock = false; + } + else + { + // check if the notarization found is actually valid. + if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { - int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); - if ( notarizedheight != 0 ) + // Get the OP_RETURN for the notarisation + uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; + int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size(); + if ( script[0] == OP_RETURN ) { - if ( last_notarizedheight == 0 ) + int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); + if ( notarizedheight != 0 ) { - // this is the first one we see, add it to the block as TX1 - NotarisationNotaries = TMP_NotarisationNotaries; - dPriority = 1e16; - fNotarisationBlock = true; - last_notarizedheight = notarizedheight; - fprintf(stderr, "Notarisation %s set to maximum priority\n",hash.ToString().c_str()); + if ( last_notarizedheight == 0 ) + { + // this is the first one we see, add it to the block as TX1 + NotarisationNotaries = TMP_NotarisationNotaries; + dPriority = 1e16; + fNotarisationBlock = true; + last_notarizedheight = notarizedheight; + fprintf(stderr, "Notarisation %s set to maximum priority\n",hash.ToString().c_str()); + } + else if ( notarizedheight > last_notarizedheight ) + continue; // leave this notarisation for the next block, it will be valid! + else if ( notarizedheight == last_notarizedheight ) + continue; // this shouldnt happen, it would mean there are 2 notarisations for the same block! + else + { + // we need to remove the last seen notarzation from block + const CTransaction& Tx = *(vecPriority.front().get<2>()); + TxPriorityCompare comparer(0); + std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + vecPriority.pop_back(); + // add this one as its valid before the other one. + NotarisationNotaries = TMP_NotarisationNotaries; + dPriority = 1e16; + fNotarisationBlock = true; + fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); + } } - else if ( notarizedheight > last_notarizedheight ) - continue; // leave this notarisation for the next block, it will be valid! - else if ( notarizedheight == last_notarizedheight ) - continue; // this shouldnt happen, it would mean there are 2 notarisations for the same block! - else + else if ( fNotarisationBlock == true ) { - // we need to remove the last seen notarzation from block - const CTransaction& Tx = *(vecPriority.front().get<2>()); - TxPriorityCompare comparer(0); - std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); - vecPriority.pop_back(); - // add this one as its valid before the other one. - NotarisationNotaries = TMP_NotarisationNotaries; - dPriority = 1e16; - fNotarisationBlock = true; - fprintf(stderr, "Notarisation %s set to maximum priority replacing notarization %s\n",hash.ToString().c_str(), Tx.GetHash().ToString().c_str()); + // Any attempted notarization needs to be in its own block! + // If we find a valid one and place it in position 1, an invalid one must wait until the next block to be mined. + continue; } } - else if ( fNotarisationBlock == true ) - { - // Any attempted notarization needs to be in its own block! - // If we find a valid one and place it in position 1, an invalid one must wait until the next block to be mined. - continue; - } } } }