From 45bb468139a16f14e99b7877b0494c44964c6323 Mon Sep 17 00:00:00 2001 From: miketout Date: Sat, 27 Oct 2018 14:53:18 -0700 Subject: [PATCH] Better cheat catcher --- src/main.cpp | 5 +++-- src/miner.cpp | 16 +++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 11ed27928..a4e6aa202 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1898,7 +1898,7 @@ bool myAddtomempool(CTransaction &tx, CValidationState *pstate) pstate = &state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); + return(AcceptToMemoryPool(mempool, *pstate, tx, false, &fMissingInputs, !fOverrideFees)); else return(true); } @@ -3721,7 +3721,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CValidationState stateDummy; // don't keep staking or invalid transactions - 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)) + if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) { mempool.remove(tx, removed, true); } @@ -4558,6 +4558,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C Tx = tx; if ( myAddtomempool(Tx, &state) == false ) // happens with out of order tx in block on resync { + //LogPrintf("Rejected by mempool, reason: .%s.\n", state.GetRejectReason().c_str()); // take advantage of other checks, but if we were only rejected because it is a valid staking // transaction, sync with wallets and don't mark as a reject if (i == (block.vtx.size() - 1) && ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock() && state.GetRejectReason() == "staking") diff --git a/src/miner.cpp b/src/miner.cpp index 51ca2e85b..46d669563 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -303,14 +303,6 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, tb.AddOpRet(mtx.vout[mtx.vout.size() - 1].scriptPubKey); cheatSpend = tb.Build(); - if (cheatSpend) - { - cheatTx = boost::get(cheatSpend); - unsigned int nTxSize = ::GetSerializeSize(cheatTx, SER_NETWORK, PROTOCOL_VERSION); - double dPriority = cheatTx.ComputePriority(dPriority, nTxSize); - CFeeRate feeRate(DEFAULT_TRANSACTION_MAXFEE, nTxSize); - vecPriority.push_back(TxPriority(dPriority, feeRate, &cheatTx)); - } } } } @@ -321,9 +313,15 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, if (cheatSpend) { std::list removed; - mempool.removeConflicts(cheatSpend.value(), removed); + mempool.removeConflicts(cheatTx, removed); printf("Found cheating stake! Adding cheat spend for %.8f at block #%d, coinbase tx\n%s\n", (double)cb.GetValueOut() / (double)COIN, nHeight, cheatSpend.value().vin[0].prevout.hash.GetHex().c_str()); + + // add to mem pool and relay + if (myAddtomempool(cheatTx)) + { + RelayTransaction(cheatTx); + } } // now add transactions from the mem pool