Clean up stake rebroadcasting and mempool checking

This commit is contained in:
miketout
2018-10-11 19:52:32 -07:00
parent ae773246f8
commit 271326fafd
5 changed files with 39 additions and 42 deletions

View File

@@ -1509,7 +1509,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
} }
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee) bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, int dosLevel)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
if (pfMissingInputs) if (pfMissingInputs)
@@ -1551,7 +1551,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
} }
// DoS level set to 10 to be more forgiving. // DoS level set to 10 to be more forgiving.
// Check transaction contextually against the set of consensus rules which apply in the next block to be mined. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined.
if (!ContextualCheckTransaction(tx, state, nextBlockHeight, 10)) if (!ContextualCheckTransaction(tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel))
{ {
return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); return error("AcceptToMemoryPool: ContextualCheckTransaction failed");
} }
@@ -3708,14 +3708,16 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
list<CTransaction> removed; list<CTransaction> removed;
CValidationState stateDummy; CValidationState stateDummy;
// don't keep staking or invalid transactions // don't keep staking or invalid transactions
if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (block.IsVerusPOSBlock() || (komodo_isPoS((CBlock *)&block) != 0))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL))
{ {
mempool.remove(tx, removed, true); mempool.remove(tx, removed, true);
} }
// if this is a staking tx, and we are on Verus Sapling with nothing at stake solution, // if this is a staking tx, and we are on Verus Sapling with nothing at stake solution,
// save staking tx as a possible cheat // save staking tx as a possible cheat
if ((i == (block.vtx.size() - 1)) && (block.IsVerusPOSBlock())) if (NetworkUpgradeActive(pindexDelete->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING) &&
ASSETCHAINS_LWMAPOS && (i == (block.vtx.size() - 1)) &&
(block.IsVerusPOSBlock()))
{ {
CTxHolder txh(block.vtx[i], pindexDelete->GetHeight()); CTxHolder txh(block.vtx[i], pindexDelete->GetHeight());
cheatList.Add(txh); cheatList.Add(txh);
@@ -3746,7 +3748,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
for (int i = 0; i < block.vtx.size(); i++) for (int i = 0; i < block.vtx.size(); i++)
{ {
CTransaction &tx = block.vtx[i]; CTransaction &tx = block.vtx[i];
if ((i == (block.vtx.size() - 1)) && (block.IsVerusPOSBlock() || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))) if ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0))))
{ {
EraseFromWallets(tx.GetHash()); EraseFromWallets(tx.GetHash());
} }
@@ -4521,9 +4523,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
for (i=0; i<block.vtx.size(); i++) for (i=0; i<block.vtx.size(); i++)
{ {
CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i]; CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i];
if ( tx.IsCoinBase() != 0 ) if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))))
continue;
else if ( ASSETCHAINS_STAKED != 0 && (i == (block.vtx.size() - 1)) && (block.IsVerusPOSBlock() || komodo_isPoS((CBlock *)&block) != 0) )
continue; continue;
Tx = tx; Tx = tx;
if ( myAddtomempool(Tx) == false ) // happens with out of order tx in block on resync if ( myAddtomempool(Tx) == false ) // happens with out of order tx in block on resync

View File

@@ -273,7 +273,7 @@ void PruneAndFlush();
/** (try to) add transaction to memory pool **/ /** (try to) add transaction to memory pool **/
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
bool* pfMissingInputs, bool fRejectAbsurdFee=false); bool* pfMissingInputs, bool fRejectAbsurdFee=false, int dosLevel=-1);
struct CNodeStateStats { struct CNodeStateStats {

View File

@@ -306,7 +306,15 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
} }
} }
// now add transations from the mem pool if (cheatSpend)
{
std::list<CTransaction> removed;
mempool.removeConflicts(cheatSpend.value(), removed);
printf("CAUGHT STAKE CHEATER! Adding cheat spend for %.8f at block #%d, coinbase tx\n%s\n",
(double)cheatSpend.value().vout[0].nValue / (double)COIN, nHeight, cheatSpend.value().vin[0].prevout.hash.GetHex().c_str());
}
// now add transactions from the mem pool
for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
mi != mempool.mapTx.end(); ++mi) mi != mempool.mapTx.end(); ++mi)
{ {
@@ -326,20 +334,6 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
//fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime);
continue; continue;
} }
if (cheatSpend)
{
bool skip = false;
for (const CTxIn &txin : tx.vin)
{
if (txin.prevout.hash == cbHash)
{
skip = true;
break;
}
}
if (skip)
continue;
}
COrphan* porphan = NULL; COrphan* porphan = NULL;
double dPriority = 0; double dPriority = 0;

View File

@@ -361,19 +361,20 @@ static const CRPCCommand vRPCCommands[] =
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, false }, { "rawtransactions", "fundrawtransaction", &fundrawtransaction, false },
#endif #endif
/* auction */ /*
// auction
{ "auction", "auctionaddress", &auctionaddress, true }, { "auction", "auctionaddress", &auctionaddress, true },
/* lotto */ // lotto
{ "lotto", "lottoaddress", &lottoaddress, true }, { "lotto", "lottoaddress", &lottoaddress, true },
/* fsm */ // fsm
{ "FSM", "FSMaddress", &FSMaddress, true }, { "FSM", "FSMaddress", &FSMaddress, true },
{ "FSM", "FSMcreate", &FSMcreate, true }, { "FSM", "FSMcreate", &FSMcreate, true },
{ "FSM", "FSMlist", &FSMlist, true }, { "FSM", "FSMlist", &FSMlist, true },
{ "FSM", "FSMinfo", &FSMinfo, true }, { "FSM", "FSMinfo", &FSMinfo, true },
/* rewards */ // rewards
{ "rewards", "rewardslist", &rewardslist, true }, { "rewards", "rewardslist", &rewardslist, true },
{ "rewards", "rewardsinfo", &rewardsinfo, true }, { "rewards", "rewardsinfo", &rewardsinfo, true },
{ "rewards", "rewardscreatefunding", &rewardscreatefunding, true }, { "rewards", "rewardscreatefunding", &rewardscreatefunding, true },
@@ -382,16 +383,16 @@ static const CRPCCommand vRPCCommands[] =
{ "rewards", "rewardsunlock", &rewardsunlock, true }, { "rewards", "rewardsunlock", &rewardsunlock, true },
{ "rewards", "rewardsaddress", &rewardsaddress, true }, { "rewards", "rewardsaddress", &rewardsaddress, true },
/* faucet */ // faucet
{ "faucet", "faucetinfo", &faucetinfo, true }, { "faucet", "faucetinfo", &faucetinfo, true },
{ "faucet", "faucetfund", &faucetfund, true }, { "faucet", "faucetfund", &faucetfund, true },
{ "faucet", "faucetget", &faucetget, true }, { "faucet", "faucetget", &faucetget, true },
{ "faucet", "faucetaddress", &faucetaddress, true }, { "faucet", "faucetaddress", &faucetaddress, true },
/* MofN */ // MofN
{ "MofN", "mofnaddress", &mofnaddress, true }, { "MofN", "mofnaddress", &mofnaddress, true },
/* Channels */ // Channels
{ "channels", "channelsaddress", &channelsaddress, true }, { "channels", "channelsaddress", &channelsaddress, true },
{ "channels", "channelsinfo", &channelsinfo, true }, { "channels", "channelsinfo", &channelsinfo, true },
{ "channels", "channelsopen", &channelsopen, true }, { "channels", "channelsopen", &channelsopen, true },
@@ -400,7 +401,7 @@ static const CRPCCommand vRPCCommands[] =
{ "channels", "channelsstop", &channelsstop, true }, { "channels", "channelsstop", &channelsstop, true },
{ "channels", "channelsrefund", &channelsrefund, true }, { "channels", "channelsrefund", &channelsrefund, true },
/* Oracles */ // Oracles
{ "oracles", "oraclesaddress", &oraclesaddress, true }, { "oracles", "oraclesaddress", &oraclesaddress, true },
{ "oracles", "oracleslist", &oracleslist, true }, { "oracles", "oracleslist", &oracleslist, true },
{ "oracles", "oraclesinfo", &oraclesinfo, true }, { "oracles", "oraclesinfo", &oraclesinfo, true },
@@ -410,19 +411,19 @@ static const CRPCCommand vRPCCommands[] =
{ "oracles", "oraclesdata", &oraclesdata, true }, { "oracles", "oraclesdata", &oraclesdata, true },
{ "oracles", "oraclessamples", &oraclessamples, true }, { "oracles", "oraclessamples", &oraclessamples, true },
/* Prices */ // Prices
{ "prices", "pricesaddress", &pricesaddress, true }, { "prices", "pricesaddress", &pricesaddress, true },
/* Pegs */ // Pegs
{ "pegs", "pegsaddress", &pegsaddress, true }, { "pegs", "pegsaddress", &pegsaddress, true },
/* Triggers */ // Triggers
{ "triggers", "triggersaddress", &triggersaddress, true }, { "triggers", "triggersaddress", &triggersaddress, true },
/* Payments */ // Payments
{ "payments", "paymentsaddress", &paymentsaddress, true }, { "payments", "paymentsaddress", &paymentsaddress, true },
/* Gateways */ // Gateways
{ "gateways", "gatewaysaddress", &gatewaysaddress, true }, { "gateways", "gatewaysaddress", &gatewaysaddress, true },
{ "gateways", "gatewayslist", &gatewayslist, true }, { "gateways", "gatewayslist", &gatewayslist, true },
{ "gateways", "gatewaysinfo", &gatewaysinfo, true }, { "gateways", "gatewaysinfo", &gatewaysinfo, true },
@@ -433,7 +434,7 @@ static const CRPCCommand vRPCCommands[] =
{ "gateways", "gatewayspending", &gatewayspending, true }, { "gateways", "gatewayspending", &gatewayspending, true },
{ "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true }, { "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true },
/* dice */ // dice
{ "dice", "dicelist", &dicelist, true }, { "dice", "dicelist", &dicelist, true },
{ "dice", "diceinfo", &diceinfo, true }, { "dice", "diceinfo", &diceinfo, true },
{ "dice", "dicefund", &dicefund, true }, { "dice", "dicefund", &dicefund, true },
@@ -443,7 +444,7 @@ static const CRPCCommand vRPCCommands[] =
{ "dice", "dicestatus", &dicestatus, true }, { "dice", "dicestatus", &dicestatus, true },
{ "dice", "diceaddress", &diceaddress, true }, { "dice", "diceaddress", &diceaddress, true },
/* tokens */ // tokens
{ "tokens", "tokeninfo", &tokeninfo, true }, { "tokens", "tokeninfo", &tokeninfo, true },
{ "tokens", "tokenlist", &tokenlist, true }, { "tokens", "tokenlist", &tokenlist, true },
{ "tokens", "tokenorders", &tokenorders, true }, { "tokens", "tokenorders", &tokenorders, true },
@@ -459,8 +460,8 @@ static const CRPCCommand vRPCCommands[] =
{ "tokens", "tokencancelask", &tokencancelask, true }, { "tokens", "tokencancelask", &tokencancelask, true },
{ "tokens", "tokenfillask", &tokenfillask, true }, { "tokens", "tokenfillask", &tokenfillask, true },
//{ "tokens", "tokenfillswap", &tokenfillswap, true }, //{ "tokens", "tokenfillswap", &tokenfillswap, true },
*/
/* Address index */ /* Address index */
{ "addressindex", "getaddressmempool", &getaddressmempool, true }, { "addressindex", "getaddressmempool", &getaddressmempool, true },
{ "addressindex", "getaddressutxos", &getaddressutxos, false }, { "addressindex", "getaddressutxos", &getaddressutxos, false },
{ "addressindex", "getaddressdeltas", &getaddressdeltas, false }, { "addressindex", "getaddressdeltas", &getaddressdeltas, false },

View File

@@ -2755,7 +2755,9 @@ void CWallet::ReacceptWalletTransactions()
CWalletTx& wtx = *(item.second); CWalletTx& wtx = *(item.second);
LOCK(mempool.cs); LOCK(mempool.cs);
wtx.AcceptToMemoryPool(false); CValidationState state;
// attempt to add them, but don't set any DOS level
::AcceptToMemoryPool(mempool, state, wtx, false, NULL, true, 0);
} }
} }