From 07b041fd943a20a57a6620787e639b4c4fcd7cc0 Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 15 Feb 2024 10:40:22 -0500 Subject: [PATCH 1/2] Do not apply overwinter/sapling consensus rules to block 0 --- src/hush-tx.cpp | 6 ++++-- src/main.cpp | 14 +++++++------- src/miner.cpp | 4 ++-- src/rpc/rawtransaction.cpp | 2 +- src/validationinterface.cpp | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- src/wallet/wallet.cpp | 16 ++++++++++------ 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/hush-tx.cpp b/src/hush-tx.cpp index 431821f15..6d5793bb1 100644 --- a/src/hush-tx.cpp +++ b/src/hush-tx.cpp @@ -195,12 +195,14 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para { CMutableTransaction mtx; - bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); + const bool isOverwintered = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); + const bool isSapling = nHeight>=1 ? true : false; if (isOverwintered) { mtx.fOverwintered = true; mtx.nExpiryHeight = nHeight + 60; - if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { + //if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { + if(isSapling) { mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; } else { diff --git a/src/main.cpp b/src/main.cpp index 4236e3571..f5e684996 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -931,8 +931,8 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRE bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) { - const bool overwinterActive = true; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); - const bool saplingActive = true; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING); + const bool overwinterActive = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); + const bool saplingActive = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING); if (saplingActive) { // Sapling standard rules apply @@ -3073,7 +3073,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // However, this is only reliable if the last block was on or after // the Sapling activation height. Otherwise, the last anchor was the // empty root. - const bool sapling = true; // NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING); + const bool sapling = pindex->pprev->GetHeight() >= 1 ? true : false; // NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING); if (sapling) { view.PopAnchor(pindex->pprev->hashFinalSaplingRoot, SAPLING); } else { @@ -3492,7 +3492,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // If Sapling is active, block.hashFinalSaplingRoot must be the // same as the root of the Sapling tree - const bool sapling = true; //NetworkUpgradeActive(pindex->GetHeight(), chainparams.GetConsensus(), Consensus::UPGRADE_SAPLING); + const bool sapling = pindex->GetHeight()>=1 ? true : false; //NetworkUpgradeActive(pindex->GetHeight(), chainparams.GetConsensus(), Consensus::UPGRADE_SAPLING); if (sapling) { if (block.hashFinalSaplingRoot != sapling_tree.root()) { return state.DoS(100, @@ -5219,7 +5219,7 @@ bool ContextualCheckBlock(int32_t slowflag,const CBlock& block, CValidationState { const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->GetHeight() + 1; const Consensus::Params& consensusParams = Params().GetConsensus(); - bool sapling = true; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); + // bool sapling = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); // Check that all transactions are finalized for (uint32_t i = 0; i < block.vtx.size(); i++) { @@ -8214,12 +8214,12 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; } else { - bool isOverwintered = true; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); + const bool isOverwintered = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); if (isOverwintered) { mtx.fOverwintered = true; mtx.nExpiryHeight = nHeight + expiryDelta; - const bool sapling = true; + const bool sapling = nHeight>=1 ? true : false; if (sapling) // NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; diff --git a/src/miner.cpp b/src/miner.cpp index ed0b05c5c..fccd6e073 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -233,8 +233,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 const int nHeight = pindexPrev->GetHeight() + 1; const Consensus::Params &consensusParams = chainparams.GetConsensus(); uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, consensusParams); - // Sapling NU is always active - const bool sapling = true; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); + // Sapling NU is always active for height>=1 + const bool sapling = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); uint32_t proposedTime = GetTime(); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index b09f60c12..5b0201e73 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -690,7 +690,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp, const CPubKey& } if (params.size() > 3 && !params[3].isNull()) { - const bool overwinter = true; + const bool overwinter = nextBlockHeight>=1 ? true : false; if (overwinter) { // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { int64_t nExpiryHeight = params[3].get_int64(); if (nExpiryHeight < 0 || nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD) { diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 5294f851b..ff90db3fa 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -149,7 +149,7 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip) // the Sapling activation height. Otherwise, the last anchor was the // empty root. SaplingMerkleTree oldSaplingTree; - const bool sapling = true; + const bool sapling = pindex->pprev->GetHeight() >= 1 ? true : false; if (sapling) { // NetworkUpgradeActive(pindex->pprev->GetHeight(),Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { assert(pcoinsTip->GetSaplingAnchorAt(pindex->pprev->hashFinalSaplingRoot, oldSaplingTree)); } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 78dbb1908..c5ac5f8dc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5467,7 +5467,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& myp } int nextBlockHeight = chainActive.Height() + 1; - bool overwinterActive = true; // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); + bool overwinterActive = nextBlockHeight>=1 ? true : false; // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); unsigned int max_tx_size = MAX_TX_SIZE_AFTER_SAPLING; // Prepare to get coinbase utxos @@ -5714,7 +5714,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& myp } const int nextBlockHeight = chainActive.Height() + 1; - const bool overwinterActive = true; // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); + const bool overwinterActive = nextBlockHeight >=1 ? true : false; // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); // Validate the destination address auto destaddress = params[1].get_str(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4954ac505..d217c41ec 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -511,6 +511,9 @@ void CWallet::RunSaplingSweep(int blockHeight) { // if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { // return; // } + if (blockHeight == 0) + return; + AssertLockHeld(cs_wallet); if (!fSweepEnabled) { return; @@ -3688,7 +3691,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt txNew.nLockTime = (uint32_t)chainActive.Tip()->GetMedianTimePast(); // Activates after Overwinter network upgrade - const bool overwinter = true; + const bool overwinter = nextBlockHeight >=1 ? true : false; if (overwinter) { // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { if (txNew.nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD){ strFailReason = _("nExpiryHeight must be less than TX_EXPIRY_HEIGHT_THRESHOLD."); @@ -3697,7 +3700,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt } unsigned int max_tx_size = MAX_TX_SIZE_AFTER_SAPLING; - /* Sapling is always active + /* Sapling is always active since height=1 if (!NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { max_tx_size = MAX_TX_SIZE_BEFORE_SAPLING; } @@ -3898,13 +3901,13 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt // All Hush Arrakis Chains always have overwinter NU and so this option was never used // Check mempooltxinputlimit to avoid creating a transaction which the local mempool rejects // const size_t limit = 0; // (size_t)GetArg("-mempooltxinputlimit", 0); - { - LOCK(cs_main); - const bool overwinter = true; + //{ + // LOCK(cs_main); + //const bool overwinter = true; //if (NetworkUpgradeActive(chainActive.Height() + 1, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { // limit = 0; //} - } + //} /* if (limit > 0) { size_t n = txNew.vin.size(); @@ -5044,6 +5047,7 @@ SpendingKeyAddResult AddSpendingKeyToWallet::operator()(const libzcash::SaplingE if (params.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight == Consensus::NetworkUpgrade::ALWAYS_ACTIVE) { m_wallet->mapSaplingZKeyMetadata[ivk].nCreateTime = nTime; } else { + // TODO: set a better time for HUSH+DRAGONX // 154051200 seconds from epoch is Friday, 26 October 2018 00:00:00 GMT - definitely before Sapling activates m_wallet->mapSaplingZKeyMetadata[ivk].nCreateTime = std::max((int64_t) 154051200, nTime); } From a581f8fc8e108589a251c45175216788b9e74b81 Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 15 Feb 2024 11:03:05 -0500 Subject: [PATCH 2/2] Fix compile error and remove some cryptocondition dingleberries --- qa/rpc-tests/README.md | 2 -- src/cc/Makefile_custom | 7 +++---- src/cc/README.md | 8 -------- src/init.cpp | 4 ---- src/main.cpp | 33 +-------------------------------- 5 files changed, 4 insertions(+), 50 deletions(-) delete mode 100644 src/cc/README.md diff --git a/qa/rpc-tests/README.md b/qa/rpc-tests/README.md index ac61e327e..4f7d116d1 100644 --- a/qa/rpc-tests/README.md +++ b/qa/rpc-tests/README.md @@ -14,8 +14,6 @@ You can run a single test by calling `qa/pull-tester/rpc-tests.sh `. Run all possible tests with `qa/pull-tester/rpc-tests.sh -extended`. -Also it's possible to run CryptoConditions tests only by `qa/pull-tester/cc-tests.sh --noshutdown --tracerpc` - Possible options: ``` diff --git a/src/cc/Makefile_custom b/src/cc/Makefile_custom index 5cedceec0..3c71a60c0 100644 --- a/src/cc/Makefile_custom +++ b/src/cc/Makefile_custom @@ -3,9 +3,9 @@ CC = gcc CC_DARWIN = g++-8 CC_WIN = x86_64-w64-mingw32-gcc-posix CC_AARCH64 = aarch64-linux-gnu-g++ -CFLAGS_DARWIN = -DBUILD_CUSTOMCC -std=c++11 -arch x86_64 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I../leveldb/include -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib -CFLAGS = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I../leveldb/include -I.. -I. -fPIC -shared -CFLAGS_WIN = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/x86_64-w64-mingw32/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I../leveldb/include -I.. -I. -fPIC -shared +CFLAGS_DARWIN = -DBUILD_CUSTOMCC -std=c++11 -arch x86_64 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../leveldb/include -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib +CFLAGS = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../leveldb/include -I.. -I. -fPIC -shared +CFLAGS_WIN = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/x86_64-w64-mingw32/include -I../univalue/include -I../leveldb/include -I.. -I. -fPIC -shared DEBUGFLAGS = -O0 -D _DEBUG RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program $(info $(OS)) @@ -15,7 +15,6 @@ TARGET = customcc.so TARGET_DARWIN = customcc.dylib TARGET_WIN = customcc.dll SOURCES = cclib.cpp -#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ all: $(TARGET) diff --git a/src/cc/README.md b/src/cc/README.md deleted file mode 100644 index bb358aca4..000000000 --- a/src/cc/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## CCLIB - -Please follow the below instructions to build the cryptoconditions library - -``` -make clean -make -``` diff --git a/src/init.cpp b/src/init.cpp index f793bef28..977dc7323 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -601,12 +601,8 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageGroup(_("Hush Arrakis Chain options:")); strUsage += HelpMessageOpt("-ac_algo", _("Choose PoW mining algorithm, either 'equihash' or 'randomx'. default is Equihash (200,9)")); strUsage += HelpMessageOpt("-ac_blocktime", _("Block time in seconds, default is 60")); - strUsage += HelpMessageOpt("-ac_cc", _("Cryptoconditions, default 0")); strUsage += HelpMessageOpt("-ac_beam", _("BEAM integration")); strUsage += HelpMessageOpt("-ac_coda", _("CODA integration")); - strUsage += HelpMessageOpt("-ac_cclib", _("Cryptoconditions dynamicly loadable library")); - strUsage += HelpMessageOpt("-ac_ccenable", _("Cryptoconditions to enable")); - strUsage += HelpMessageOpt("-ac_ccactivate", _("Block height to enable Cryptoconditions")); strUsage += HelpMessageOpt("-ac_decay", _("Percentage of block reward decrease at each halving")); strUsage += HelpMessageOpt("-ac_end", _("Block height at which block rewards will end")); strUsage += HelpMessageOpt("-ac_eras", _("Block reward eras")); diff --git a/src/main.cpp b/src/main.cpp index f44e9bf6c..ef82853a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1224,6 +1224,7 @@ bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockInde const bool saplingActive = nHeight >=1 ? true : false; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING); const bool isSprout = false; //!overwinterActive; + /* // If Sprout rules apply, reject transactions which are intended for Overwinter and beyond if (isSprout && tx.fOverwintered) { int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight; @@ -3074,13 +3075,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // However, this is only reliable if the last block was on or after // the Sapling activation height. Otherwise, the last anchor was the // empty root. -<<<<<<< HEAD const bool sapling = pindex->pprev->GetHeight() >= 1 ? true : false; // NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING); -||||||| merged common ancestors - const bool sapling = true; // NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING); -======= - const bool sapling = pindex->GetHeight() >= 2 ? true : false; // NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING); ->>>>>>> duke if (sapling) { view.PopAnchor(pindex->pprev->hashFinalSaplingRoot, SAPLING); } else { @@ -3493,13 +3488,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // If Sapling is active, block.hashFinalSaplingRoot must be the // same as the root of the Sapling tree -<<<<<<< HEAD const bool sapling = pindex->GetHeight()>=1 ? true : false; //NetworkUpgradeActive(pindex->GetHeight(), chainparams.GetConsensus(), Consensus::UPGRADE_SAPLING); -||||||| merged common ancestors - const bool sapling = true; //NetworkUpgradeActive(pindex->GetHeight(), chainparams.GetConsensus(), Consensus::UPGRADE_SAPLING); -======= - const bool sapling = pindex->GetHeight() >= 1 ? true : false; //NetworkUpgradeActive(pindex->GetHeight(), chainparams.GetConsensus(), Consensus::UPGRADE_SAPLING); ->>>>>>> duke if (sapling) { if (block.hashFinalSaplingRoot != sapling_tree.root()) { return state.DoS(100, @@ -5225,16 +5214,8 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta bool ContextualCheckBlock(int32_t slowflag,const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev) { const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->GetHeight() + 1; -<<<<<<< HEAD - const Consensus::Params& consensusParams = Params().GetConsensus(); - // bool sapling = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); -||||||| merged common ancestors - const Consensus::Params& consensusParams = Params().GetConsensus(); - bool sapling = true; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); -======= //const Consensus::Params& consensusParams = Params().GetConsensus(); //bool sapling = true; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING); ->>>>>>> duke // Check that all transactions are finalized for (uint32_t i = 0; i < block.vtx.size(); i++) { @@ -8229,24 +8210,12 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; } else { -<<<<<<< HEAD const bool isOverwintered = nHeight>=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); -||||||| merged common ancestors - bool isOverwintered = true; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); -======= - const bool isOverwintered = nHeight >=1 ? true : false; //NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); ->>>>>>> duke if (isOverwintered) { mtx.fOverwintered = true; mtx.nExpiryHeight = nHeight + expiryDelta; -<<<<<<< HEAD - const bool sapling = nHeight>=1 ? true : false; -||||||| merged common ancestors - const bool sapling = true; -======= const bool sapling = nHeight >=1 ? true : false; ->>>>>>> duke if (sapling) // NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID;