fix mempool fix. Stops lockups and slow sync of blocks.

This commit is contained in:
blackjok3r
2018-12-15 01:01:49 +08:00
parent e2bec5a99b
commit cf9cf67f1a

View File

@@ -4680,7 +4680,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
int32_t i,j,rejects=0,lastrejects=0; int32_t i,j,rejects=0,lastrejects=0;
//fprintf(stderr,"put block's tx into mempool\n"); //fprintf(stderr,"put block's tx into mempool\n");
// Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid. // Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid.
LOCK(mempool.cs); LOCK2(cs_main,mempool.cs);
//fprintf(stderr, "starting... mempoolsize.%ld\n",mempool.size());
list<CTransaction> transactionsToRemove; list<CTransaction> transactionsToRemove;
BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) {
const CTransaction &tx = e.GetTx(); const CTransaction &tx = e.GetTx();
@@ -4698,6 +4699,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
// CC validation shouldnt (cant) depend on the state of mempool! // CC validation shouldnt (cant) depend on the state of mempool!
while ( 1 ) while ( 1 )
{ {
list<CTransaction> removed;
for (i=0; i<block.vtx.size(); i++) for (i=0; i<block.vtx.size(); i++)
{ {
CValidationState state; CValidationState state;
@@ -4717,7 +4719,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
ptx = &sTx; ptx = &sTx;
} else rejects++; } else rejects++;
} }
// here we remove any txs in the temp mempool that were included in the block.
tmpmempool.remove(tx, removed, false);
} }
//fprintf(stderr, "removed.%ld\n",removed.size());
if ( rejects == 0 || rejects == lastrejects ) if ( rejects == 0 || rejects == lastrejects )
{ {
if ( 0 && lastrejects != 0 ) if ( 0 && lastrejects != 0 )
@@ -4764,35 +4769,15 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
if ( ASSETCHAINS_CC != 0 ) if ( ASSETCHAINS_CC != 0 )
{ {
// here we add back all txs from the temp mempool to the main mempool. // here we add back all txs from the temp mempool to the main mempool.
// which removes any tx locally that were invalid after the block arrives. BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx)
int numadded,numiters = 0;
CValidationState state; bool fMissingInputs,fOverrideFees = false;
list<CTransaction> removed;
LOCK(mempool.cs);
while ( 1 )
{ {
numiters++; const CTransaction &tx = e.GetTx();
numadded = 0; const uint256 &hash = tx.GetHash();
list<CTransaction> ToRemove; if ( tx.vjoinsplit.size() == 0 ) {
BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) mempool.addUnchecked(hash,e,true);
{
CTransaction tx = e.GetTx();
if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees) == true )
{
numadded++;
ToRemove.push_back(tx);
}
} }
BOOST_FOREACH(const CTransaction& tx, ToRemove)
{
tmpmempool.remove(tx, removed, false);
}
ToRemove.clear();
if ( numadded == 0 )
break;
} }
//if ( 0 && numadded > 0 ) //fprintf(stderr, "finished adding back. mempoolsize.%ld\n",mempool.size());
fprintf(stderr, "CC mempool add: numiters.%d remains.%d\n",numiters,(int32_t)tmpmempool.size());
// empty the temp mempool for next time. // empty the temp mempool for next time.
tmpmempool.clear(); tmpmempool.clear();
} }