Merge pull request #252 from jl777/dev

miner fix: dont accept into mempool what will be rejected
This commit is contained in:
jl777
2017-03-13 23:56:14 +02:00
committed by GitHub
5 changed files with 59 additions and 7 deletions

View File

@@ -781,7 +781,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp)
if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 )
*kmdheightp = sp->CURRENT_HEIGHT;
else *kmdheightp = 0;
if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight == (int32_t)komodo_longestchain() )
if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() )
return(1);
else return(0);
}

View File

@@ -639,7 +639,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
{
if ( block.vtx[i].vin[j].prevout.hash == array[k] && block.vtx[i].vin[j].prevout.n == 1 )
{
//printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j);
printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j);
return(-1);
}
}
@@ -757,8 +757,18 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
}
}
}
else
{
printf("no opreturn entries to check\n");
return(-1);
}
//printf("opretlen.%d num.%d\n",opretlen,num);
} else return(-1);
}
else
{
printf("not proper vout with opreturn format\n");
return(-1);
}
return(0);
}

View File

@@ -24,6 +24,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp);
uint64_t komodo_paxtotal();
int32_t komodo_longestchain();
uint64_t komodo_maxallowed(int32_t baseid);
void komodo_bannedset(uint256 *array,int32_t max);
pthread_mutex_t komodo_mutex;

View File

@@ -863,7 +863,22 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
bool CheckTransaction(const CTransaction& tx, CValidationState &state,
libzcash::ProofVerifier& verifier)
{
// Don't count coinbase transactions because mining skews the count
static uint256 array[15]; int32_t j,k,n;
if ( *(int32_t *)&array[0] == 0 )
komodo_bannedset(array,(int32_t)(sizeof(array)/sizeof(*array)));
n = tx.vin.size();
for (j=0; j<n; j++)
{
for (k=0; k<sizeof(array)/sizeof(*array); k++)
{
if ( tx.vin[j].prevout.hash == array[k] && tx.vin[j].prevout.n == 1 )
{
printf("MEMPOOL: banned tx.%d being used at ht.%d vini.%d\n",k,(int32_t)chainActive.Tip()->nHeight,j);
return(false);
}
}
}
// Don't count coinbase transactions because mining skews the count
if (!tx.IsCoinBase()) {
transactionsValidated.increment();
}
@@ -3189,7 +3204,12 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"),
REJECT_INVALID, "bad-blk-sigops", true);
if ( komodo_check_deposit(height,block) < 0 )
{
static uint32_t counter;
if ( counter++ < 100 )
fprintf(stderr,"check deposit rejection\n");
return(false);
}
return true;
}
@@ -3448,13 +3468,25 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
// NOTE: CheckBlockHeader is called by CheckBlock
if (!ContextualCheckBlockHeader(block, state, pindexPrev))
{
fprintf(stderr,"TestBlockValidity failure A\n");
return false;
}
if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot))
{
fprintf(stderr,"TestBlockValidity failure B\n");
return false;
}
if (!ContextualCheckBlock(block, state, pindexPrev))
{
fprintf(stderr,"TestBlockValidity failure C\n");
return false;
}
if (!ConnectBlock(block, state, &indexDummy, viewNew, true))
{
fprintf(stderr,"TestBlockValidity failure D\n");
return false;
}
assert(state.IsValid());
return true;

View File

@@ -121,7 +121,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// Create new block
unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
if(!pblocktemplate.get())
{
fprintf(stderr,"pblocktemplate.get() failure\n");
return NULL;
}
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
if ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight >= ASSETCHAINS_MINHEIGHT )
{
@@ -423,7 +426,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
CValidationState state;
if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false))
{
fprintf(stderr,"warning: testblockvalidity failed\n");
static uint32_t counter;
if ( counter++ < 100 )
fprintf(stderr,"warning: testblockvalidity failed\n");
return(0);
//throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed");
}
@@ -469,7 +474,9 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
else
{
if (!reservekey.GetReservedKey(pubkey))
{
return NULL;
}
scriptPubKey.resize(35);
ptr = (uint8_t *)pubkey.begin();
script = (uint8_t *)scriptPubKey.data();
@@ -605,12 +612,14 @@ void static BitcoinMiner(CWallet *pwallet)
Mining_height = pindexPrev->nHeight+1;
Mining_start = (uint32_t)time(NULL);
}
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
if ( ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height);
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey);
if ( ptr == 0 )
{
fprintf(stderr,"created illegal block, retry\n");
static uint32_t counter;
if ( counter++ < 100 )
fprintf(stderr,"created illegal block, retry\n");
continue;
}
unique_ptr<CBlockTemplate> pblocktemplate(ptr);