From 432604166336c4fe7970a898b001ca4c3b1134c7 Mon Sep 17 00:00:00 2001 From: miketout Date: Fri, 12 Oct 2018 21:09:45 -0700 Subject: [PATCH] Cheatcatcher tests to remove and change to max sequential POS --- src/cheatcatcher.cpp | 2 +- src/cheatcatcher.h | 2 +- src/pow.cpp | 10 +++++++++- src/rpc/misc.cpp | 2 +- src/wallet/wallet.cpp | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/cheatcatcher.cpp b/src/cheatcatcher.cpp index 65288147d..e896b2c1f 100644 --- a/src/cheatcatcher.cpp +++ b/src/cheatcatcher.cpp @@ -85,7 +85,7 @@ bool CCheatList::IsCheatInList(const CTransaction &tx, CTransaction *cheatTx) return false; } -bool CCheatList::Add(CTxHolder &txh) +bool CCheatList::Add(const CTxHolder &txh) { if (NetworkUpgradeActive(txh.height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { diff --git a/src/cheatcatcher.h b/src/cheatcatcher.h index 7f6e8cf17..8193c823a 100644 --- a/src/cheatcatcher.h +++ b/src/cheatcatcher.h @@ -70,7 +70,7 @@ class CCheatList } // add a potential cheat transaction to the list. we do this for all stake transactions from orphaned stakes - bool Add(CTxHolder &txh); + bool Add(const CTxHolder &txh); // remove a transaction from the the list void Remove(const CTxHolder &txh); diff --git a/src/pow.cpp b/src/pow.cpp index 450d9eb1e..6eef597d0 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -275,7 +275,15 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: if ((j - i) >= VERUS_CONSECUTIVE_POS_THRESHOLD) { // if this is real time, return zero - if (j == (N - 1)) + if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0 && + NetworkUpgradeActive(pindexLast->GetHeight(), params, Consensus::UPGRADE_SAPLING)) || + (strcmp(ASSETCHAINS_SYMBOL, "VERUSTEST") == 0 && pindexLast->GetHeight() > 600)) + { + // target of 0 (virtually impossible), if we hit max consecutive POS blocks + nextTarget.SetCompact(0); + return nextTarget.GetCompact(); + } + else if (j == (N - 1)) { // target of 0 (virtually impossible), if we hit max consecutive POS blocks nextTarget.SetCompact(0); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2a871460f..e914bb8ac 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -56,7 +56,7 @@ uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.2.1" -#define VERUS_VERSION "0.3.2" +#define VERUS_VERSION "0.4.0" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_MAGIC; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 119a23c83..20685a768 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1420,6 +1420,10 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe else return 0; + // TODO: REMOVE THIS: THIS MAKES A CHEAT TRANSACTION FOR EVERY STAKE FOR TESTING + CMutableTransaction cheat; + // UP TO HERE + // if we are staking with the extended format, add the opreturn data required // if (extendedStake) @@ -1436,10 +1440,31 @@ int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNe if ((pSrcIndex = mapBlockIndex[srcBlock]) == 0) return 0; + // TODO: REMOVE THIS: THIS MAKES A CHEAT TRANSACTION FOR EVERY STAKE FOR TESTING + cheat = CMutableTransaction(txNew); + cheat.vout[1].scriptPubKey << OP_RETURN + << CStakeParams(pSrcIndex->GetHeight(), tipindex->GetHeight() + 1, pSrcIndex->GetBlockHash(), pk).AsVector(); + // REMOVE UP TO HERE + txOut1.scriptPubKey << OP_RETURN << CStakeParams(pSrcIndex->GetHeight(), tipindex->GetHeight() + 1, tipindex->GetBlockHash(), pk).AsVector(); } + // TODO REMOVE THIS TOO + cheat.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee; + cheat.nLockTime = 0; + CTransaction cheatConst(cheat); + SignatureData cheatSig; + if (!ProduceSignature(TransactionSignatureCreator(&keystore, &cheatConst, 0, nValue, SIGHASH_ALL), stakeSource.vout[voutNum].scriptPubKey, cheatSig, consensusBranchId)) + fprintf(stderr,"failed to create cheat test signature\n"); + else + { + uint8_t *ptr; + UpdateTransaction(cheat,0,cheatSig); + cheatList.Add(CTxHolder(CTransaction(cheat), tipindex->GetHeight() + 1)); + } + // UP TO HERE + nValue = txNew.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee; txNew.nLockTime = 0; @@ -2767,6 +2792,8 @@ void CWallet::ReacceptWalletTransactions() } } + std::vector vwtxh; + // Try to add wallet transactions to memory pool BOOST_FOREACH(PAIRTYPE(const int64_t, CWalletTx*)& item, mapSorted) { @@ -2786,11 +2813,14 @@ void CWallet::ReacceptWalletTransactions() if (!wtx.IsCoinBase() && invalid && nDoS > 0) { LogPrintf("erasing transaction\n"); - //printf("erasing transaction\n"); - EraseFromWallets(wtx.GetHash()); + vwtxh.push_back(wtx.GetHash()); } } } + for (auto hash : vwtxh) + { + EraseFromWallet(hash); + } } bool CWalletTx::RelayWalletTransaction()