fix miner better

This commit is contained in:
blackjok3r
2019-02-14 21:59:05 +08:00
parent 695eb871bb
commit 52450bf202
2 changed files with 42 additions and 47 deletions

View File

@@ -709,6 +709,10 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
{ {
if ( fJustCheck ) if ( fJustCheck )
return(-2); return(-2);
// On the first notarization initilise previous previous to 0.
if ( sp->NUM_NPOINTS == 1 )
sp->PPNOTARIZED_HEIGHT = 0;
sp->PPNOTARIZED_HEIGHT = sp->PNOTARIZED_HEIGHT; sp->PPNOTARIZED_HEIGHT = sp->PNOTARIZED_HEIGHT;
sp->PNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT; sp->PNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT;
sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HEIGHT = *notarizedheightp;

View File

@@ -392,62 +392,53 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
if (fNotarisation) if ( fNotarisation && check_pprevnotarizedht() )
{ {
// Can't make payment until 3 notarizations have happened. // check if the notarization found is actually valid.
if ( !check_pprevnotarizedht() ) if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 )
{ {
fNotarisation = false; // Get the OP_RETURN for the notarisation
fNotarisationBlock = false; uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0];
} int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size();
else if ( script[0] == OP_RETURN )
{
// 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 int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen);
uint8_t *script = (uint8_t *)&tx.vout[1].scriptPubKey[0]; if ( notarizedheight != 0 )
int32_t scriptlen = (int32_t)tx.vout[1].scriptPubKey.size();
if ( script[0] == OP_RETURN )
{ {
int32_t notarizedheight = komodo_getnotarizedheight(pblock->nTime, nHeight, script, scriptlen); if ( last_notarizedheight == 0 )
if ( notarizedheight != 0 )
{ {
if ( last_notarizedheight == 0 ) // this is the first one we see, add it to the block as TX1
{ NotarisationNotaries = TMP_NotarisationNotaries;
// this is the first one we see, add it to the block as TX1 dPriority = 1e16;
NotarisationNotaries = TMP_NotarisationNotaries; fNotarisationBlock = true;
dPriority = 1e16; last_notarizedheight = notarizedheight;
fNotarisationBlock = true; fprintf(stderr, "Notarisation %s set to maximum priority\n",hash.ToString().c_str());
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 ( fNotarisationBlock == true ) 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
{ {
// Any attempted notarization needs to be in its own block! // we need to remove the last seen notarzation from 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. const CTransaction& Tx = *(vecPriority.front().get<2>());
continue; 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 ( 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;
}
} }
} }
} }