From f39cd2a4738da7423b31037686b817e5836198f6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 4 Nov 2019 08:17:27 -0500 Subject: [PATCH 1/6] Delete Verus junk, which breaks ARMv8/aarch64 builds --- DEVELOPING.md | 5 + src/Makefile.am | 43 +-- src/chain.h | 11 - src/hash.h | 91 +------ src/init.cpp | 19 -- src/komodo_bitcoind.h | 176 +------------ src/komodo_utils.h | 51 +--- src/main.cpp | 2 +- src/miner.cpp | 490 +---------------------------------- src/pow.cpp | 8 +- src/primitives/block.cpp | 84 ------ src/primitives/block.h | 48 +--- src/primitives/nonce.cpp | 63 ----- src/primitives/nonce.h | 52 +--- src/primitives/transaction.h | 36 --- src/rpc/blockchain.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 - src/wallet/wallet.cpp | 114 -------- src/wallet/wallet.h | 3 - 19 files changed, 43 insertions(+), 1261 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index a6b1d3a89..15942011d 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -29,6 +29,11 @@ When in doubt, if you run into a compile error, especially if it mentions `OCTET_STRING`, run `build.sh` again. Running `make clean` before switching branches can often prevent those problems. +``` +cryptoconditions/src/asn/SimpleSha256Condition.h:14:10: fatal error: OCTET_STRING.h: No such file or directory +``` + + ## Partial compiles At any point, you can modify hush source code and then use `make` or `build.sh` diff --git a/src/Makefile.am b/src/Makefile.am index a7dd21be8..30ecd9ff5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,8 +46,6 @@ LIBBITCOIN_COMMON=libbitcoin_common.a LIBBITCOIN_CLI=libbitcoin_cli.a LIBBITCOIN_UTIL=libbitcoin_util.a LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a -LIBVERUS_CRYPTO=crypto/libverus_crypto.a -LIBVERUS_PORTABLE_CRYPTO=crypto/libverus_portable_crypto.a LIBSECP256K1=secp256k1/libsecp256k1.la LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la LIBSNARK=snark/libsnark.a @@ -95,8 +93,6 @@ $(LIBCRYPTOCONDITIONS): $(wildcard cryptoconditions/src/*) $(wildcard cryptocond # But to build the less dependent modules first, we manually select their order here: EXTRA_LIBRARIES += \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_SERVER) \ @@ -183,9 +179,6 @@ BITCOIN_CORE_H = \ consensus/validation.h \ core_io.h \ core_memusage.h \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ deprecation.h \ hash.h \ httprpc.h \ @@ -316,8 +309,6 @@ libbitcoin_server_a_SOURCES = \ crosschain_authority.cpp \ crypto/haraka.h \ crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp \ deprecation.cpp \ httprpc.cpp \ httpserver.cpp \ @@ -420,11 +411,7 @@ crypto_libbitcoin_crypto_a_SOURCES = \ crypto/sha256.cpp \ crypto/sha256.h \ crypto/sha512.cpp \ - crypto/sha512.h \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp + crypto/sha512.h if ENABLE_MINING EQUIHASH_TROMP_SOURCES = \ @@ -438,20 +425,6 @@ crypto_libbitcoin_crypto_a_SOURCES += \ ${EQUIHASH_TROMP_SOURCES} endif -# Verus hash specific library - optimized -crypto_libverus_crypto_a_CPPFLAGS = -O3 -Wint-conversion -march=x86-64 -msse4 -msse4.1 -msse4.2 -mssse3 -mavx -maes -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CPPFLAGS) -crypto_libverus_crypto_a_CXXFLAGS = -O3 -Wint-conversion -march=x86-64 -msse4 -msse4.1 -msse4.2 -mssse3 -mavx -maes -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CXXFLAGS) -crypto_libverus_crypto_a_SOURCES = \ - crypto/haraka.h \ - crypto/haraka.c - -# Verus hash specific library - portable -crypto_libverus_portable_crypto_a_CPPFLAGS = -O3 -Wint-conversion -march=x86-64 -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CPPFLAGS) -crypto_libverus_portable_crypto_a_CXXFLAGS = -O3 -Wint-conversion -march=x86-64 -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CXXFLAGS) -crypto_libverus_portable_crypto_a_SOURCES = \ - crypto/haraka_portable.h \ - crypto/haraka_portable.c - # common: shared between zcashd and non-server tools libbitcoin_common_a_CPPFLAGS = -fPIC $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_common_a_CXXFLAGS = -fPIC $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -468,8 +441,6 @@ libbitcoin_common_a_SOURCES = \ core_write.cpp \ crypto/haraka.h \ crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp \ hash.cpp \ importcoin.cpp \ key.cpp \ @@ -558,8 +529,6 @@ komodod_LDADD = \ $(LIBBITCOIN_ZMQ) \ $(LIBBITCOIN_PROTON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBLEVELDB) \ @@ -581,8 +550,6 @@ komodod_LDADD += \ $(ZMQ_LIBS) \ $(PROTON_LIBS) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) if TARGET_DARWIN @@ -635,8 +602,6 @@ komodo_cli_LDADD = \ $(EVENT_LIBS) \ $(LIBZCASH) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) if ENABLE_WALLET @@ -644,8 +609,6 @@ wallet_utility_LDADD = \ libbitcoin_wallet.a \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBSECP256K1) \ $(LIBBITCOIN_UTIL) \ $(BOOST_LIBS) \ @@ -667,7 +630,7 @@ if TARGET_WINDOWS komodo_tx_SOURCES += bitcoin-tx-res.rc endif -# FIXME: Is libzcash needed for zcash_tx? +# FIXME: Is libzcash needed for hush-tx ? komodo_tx_LDADD = \ $(LIBUNIVALUE) \ $(LIBBITCOIN_COMMON) \ @@ -676,8 +639,6 @@ komodo_tx_LDADD = \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ $(LIBCRYPTOCONDITIONS) diff --git a/src/chain.h b/src/chain.h index 9a29026f4..c58127c42 100644 --- a/src/chain.h +++ b/src/chain.h @@ -470,17 +470,6 @@ public: CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; - int32_t GetVerusPOSTarget() const - { - return GetBlockHeader().GetVerusPOSTarget(); - } - - bool IsVerusPOSBlock() const - { - if ( ASSETCHAINS_LWMAPOS != 0 ) - return GetBlockHeader().IsVerusPOSBlock(); - else return(0); - } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/hash.h b/src/hash.h index 9a8edc72c..143516d89 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -221,78 +222,6 @@ public: } }; -/** A writer stream (for serialization) that computes a 256-bit Verus hash. */ -class CVerusHashWriter -{ -private: - CVerusHash state; - -public: - int nType; - int nVersion; - - CVerusHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn), state() { } - void Reset() { state.Reset(); } - - CVerusHashWriter& write(const char *pch, size_t size) { - state.Write((const unsigned char*)pch, size); - return (*this); - } - - // invalidates the object for further writing - uint256 GetHash() { - uint256 result; - state.Finalize((unsigned char*)&result); - return result; - } - - int64_t *xI64p() { return state.ExtraI64Ptr(); } - CVerusHash &GetState() { return state; } - - template - CVerusHashWriter& operator<<(const T& obj) { - // Serialize to this stream - ::Serialize(*this, obj); - return (*this); - } -}; - -/** A writer stream (for serialization) that computes a 256-bit Verus hash with key initialized to Haraka standard. */ -class CVerusHashV2Writer -{ -private: - CVerusHashV2 state; - -public: - int nType; - int nVersion; - - CVerusHashV2Writer(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn), state() {} - void Reset() { state.Reset(); } - - CVerusHashV2Writer& write(const char *pch, size_t size) { - state.Write((const unsigned char*)pch, size); - return (*this); - } - - // invalidates the object for further writing - uint256 GetHash() { - uint256 result; - state.Finalize((unsigned char*)&result); - return result; - } - - int64_t *xI64p() { return state.ExtraI64Ptr(); } - CVerusHashV2 &GetState() { return state; } - - template - CVerusHashV2Writer& operator<<(const T& obj) { - // Serialize to this stream - ::Serialize(*this, obj); - return (*this); - } -}; - /** Compute the 256-bit hash of an object's serialization. */ template uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION) @@ -302,24 +231,6 @@ uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL return ss.GetHash(); } -/** Compute the 256-bit Verus hash of an object's serialization. */ -template -uint256 SerializeVerusHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION) -{ - CVerusHashWriter ss(nType, nVersion); - ss << obj; - return ss.GetHash(); -} - -/** Compute the 256-bit Verus hash of an object's serialization. */ -template -uint256 SerializeVerusHashV2(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION) -{ - CVerusHashV2Writer ss(nType, nVersion); - ss << obj; - return ss.GetHash(); -} - unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector& vDataToHash); void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]); diff --git a/src/init.cpp b/src/init.cpp index e1cf892c6..3b6065e37 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -608,7 +608,6 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-ac_timelockgte", _("Timelocked coinbase minimum amount to be locked")); strUsage += HelpMessageOpt("-ac_timelockto", _("Timelocked coinbase stop height")); strUsage += HelpMessageOpt("-ac_txpow", _("Enforce transaction-rate limit, default 0")); - strUsage += HelpMessageOpt("-ac_veruspos", _("Use Verus Proof-Of-Stake (-ac_veruspos=50) default 0")); return strUsage; } @@ -1329,24 +1328,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) ECC_Start(); globalVerifyHandle.reset(new ECCVerifyHandle()); - /* - // set the hash algorithm to use for this chain - // Again likely better solution here, than using long IF ELSE. - extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1; - CVerusHash::init(); - CVerusHashV2::init(); - if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH) - { - // initialize VerusHash - CBlockHeader::SetVerusHash(); - } - else if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1) - { - // initialize VerusHashV2 - CBlockHeader::SetVerusHashV2(); - } - */ - //fprintf(stderr,"%s tik10\n", __FUNCTION__); // Sanity check if (!InitSanityCheck()) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c0850006b..924b44fae 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -17,8 +17,8 @@ #include #include -#include "primitives/nonce.h" #include "consensus/params.h" +#include "primitives/nonce.h" #include "komodo_defs.h" #include "script/standard.h" #include "cc/CCinclude.h" @@ -1755,177 +1755,7 @@ bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTr // for now, we will ignore slowFlag in the interest of keeping success/fail simpler for security purposes bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) { - CBlockIndex *pastBlockIndex; - uint256 txid, blkHash; - int32_t txn_count; - uint32_t voutNum; - CAmount value; - bool isPOS = false; - CTxDestination voutaddress, destaddress, cbaddress; - arith_uint256 target, hash; - CTransaction tx; - - if (!pblock->IsVerusPOSBlock()) - { - printf("%s, height %d not POS block\n", pblock->nNonce.GetHex().c_str(), height); - //pblock->nNonce.SetPOSTarget(pblock->nNonce.GetPOSTarget()); - //printf("%s after setting POS target\n", pblock->nNonce.GetHex().c_str()); - return false; - } - - char voutaddr[64], destaddr[64], cbaddr[64]; - - txn_count = pblock->vtx.size(); - - if ( txn_count > 1 ) - { - target.SetCompact(pblock->GetVerusPOSTarget()); - txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; - voutNum = pblock->vtx[txn_count-1].vin[0].prevout.n; - value = pblock->vtx[txn_count-1].vout[0].nValue; - - { - bool validHash = (value != 0); - bool enablePOSNonce = CPOSNonce::NewPOSActive(height); - uint256 rawHash; - arith_uint256 posHash; - - if (validHash && enablePOSNonce) - { - validHash = pblock->GetRawVerusPOSHash(rawHash, height); - posHash = UintToArith256(rawHash) / value; - if (!validHash || posHash > target) - { - validHash = false; - printf("ERROR: invalid nonce value for PoS block\nnNonce: %s\nrawHash: %s\nposHash: %s\nvalue: %lu\n", - pblock->nNonce.GetHex().c_str(), rawHash.GetHex().c_str(), posHash.GetHex().c_str(), value); - } - } - if (validHash) - { - if (slowflag == 0) - { - isPOS = true; - } - else if (!(pastBlockIndex = komodo_chainactive(height - 100))) - { - fprintf(stderr,"ERROR: chain not fully loaded or invalid PoS block %s - no past block found\n",blkHash.ToString().c_str()); - } - else -#ifndef KOMODO_ZCASH - if (!GetTransaction(txid, tx, Params().GetConsensus(), blkHash, true)) -#else - if (!GetTransaction(txid, tx, blkHash, true)) -#endif - { - fprintf(stderr,"ERROR: invalid PoS block %s - no source transaction\n",blkHash.ToString().c_str()); - } - else - { - CBlockHeader bh = pastBlockIndex->GetBlockHeader(); - uint256 pastHash = bh.GetVerusEntropyHash(height - 100); - - // if height is over when Nonce is required to be the new format, we check that the new format is correct - // if over when we have the new POS hash function, we validate that as well - // they are 100 blocks apart - CPOSNonce nonce = pblock->nNonce; - - //printf("before nNonce: %s, height: %d\n", pblock->nNonce.GetHex().c_str(), height); - //validHash = pblock->GetRawVerusPOSHash(rawHash, height); - //hash = UintToArith256(rawHash) / tx.vout[voutNum].nValue; - //printf("Raw POShash: %s\n", hash.GetHex().c_str()); - - hash = UintToArith256(tx.GetVerusPOSHash(&nonce, voutNum, height, pastHash)); - - //printf("after nNonce: %s, height: %d\n", nonce.GetHex().c_str(), height); - //printf("POShash: %s\n\n", hash.GetHex().c_str()); - - if (posHash == hash && hash <= target) - { - BlockMap::const_iterator it = mapBlockIndex.find(blkHash); - if ((it == mapBlockIndex.end()) || - !(pastBlockIndex = it->second) || - (height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE) - { - fprintf(stderr,"ERROR: invalid PoS block %s - stake source too new or not found\n",blkHash.ToString().c_str()); - } - else - { - // make sure we have the right target - CBlockIndex *previndex; - it = mapBlockIndex.find(pblock->hashPrevBlock); - if (it == mapBlockIndex.end() || !(previndex = it->second)) - { - fprintf(stderr,"ERROR: invalid PoS block %s - no prev block found\n",blkHash.ToString().c_str()); - } - else - { - arith_uint256 cTarget; - uint32_t nBits = lwmaGetNextPOSRequired(previndex, Params().GetConsensus()); - cTarget.SetCompact(nBits); - bool nonceOK = true; - - // check to see how many fail - //if (nonce != pblock->nNonce) - // printf("Mismatched nNonce: %s\nblkHash: %s, height: %d\n", nonce.GetHex().c_str(), pblock->GetHash().GetHex().c_str(), height); - - if (CPOSNonce::NewNonceActive(height) && !nonce.CheckPOSEntropy(pastHash, txid, voutNum)) - { - fprintf(stderr,"ERROR: invalid PoS block %s - nonce entropy corrupted or forged\n",blkHash.ToString().c_str()); - nonceOK = false; - } - else - { - if (cTarget != target) - { - fprintf(stderr,"ERROR: invalid PoS block %s - invalid diff target\n",blkHash.ToString().c_str()); - nonceOK = false; - } - } - if ( nonceOK && ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey, voutaddress) && - ExtractDestination(tx.vout[voutNum].scriptPubKey, destaddress) ) - { - strcpy(voutaddr, CBitcoinAddress(voutaddress).ToString().c_str()); - strcpy(destaddr, CBitcoinAddress(destaddress).ToString().c_str()); - if ( !strcmp(destaddr,voutaddr) ) - { - isPOS = true; - CTransaction &cbtx = pblock->vtx[0]; - for (int i = 0; i < cbtx.vout.size(); i++) - { - if (CScriptExt::ExtractVoutDestination(cbtx, i, cbaddress)) - { - strcpy(cbaddr, CBitcoinAddress(cbaddress).ToString().c_str()); - if (!strcmp(destaddr,cbaddr)) - continue; - } - else - { - if (cbtx.vout[i].scriptPubKey.IsOpReturn()) - continue; - isPOS = false; - break; - } - } - } - else - { - fprintf(stderr,"ERROR: invalid PoS block %s - invalid stake or coinbase destination\n",blkHash.ToString().c_str()); - } - } - } - } - } - else - { - printf("ERROR: malformed nonce value for PoS block\nnNonce: %s\nrawHash: %s\nposHash: %s\nvalue: %lu\n", - pblock->nNonce.GetHex().c_str(), rawHash.GetHex().c_str(), posHash.GetHex().c_str(), value); - } - } - } - } - } - return(isPOS); + return false; } uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) @@ -2290,11 +2120,13 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) // bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget ) { + /* // if proof of stake is active, check if this is a valid PoS block before we fail if (verusCheckPOSBlock(slowflag, pblock, height)) { return(0); } + */ } if ( (ASSETCHAINS_SYMBOL[0] != 0 || height > 792000) && bhash > bnTarget ) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 31e87d82b..01a046f62 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -30,8 +30,6 @@ #define portable_mutex_lock pthread_mutex_lock #define portable_mutex_unlock pthread_mutex_unlock -extern void verus_hash(void *result, const void *data, size_t len); - struct allocitem { uint32_t allocsize,type; }; struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; }; @@ -1026,45 +1024,24 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ // from all other blocks. the sequence is extremely likely, but not guaranteed to be unique for each block chain uint64_t komodo_block_prg(uint32_t nHeight) { - if (strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0 || nHeight >= 12800) + int i; + uint8_t hashSrc[8]; + uint64_t result=0, hashSrc64 = (uint64_t)ASSETCHAINS_MAGIC << 32 + nHeight; + bits256 hashResult; + + for ( i = 0; i < sizeof(hashSrc); i++ ) { - uint64_t i, result = 0, hashSrc64 = ((uint64_t)ASSETCHAINS_MAGIC << 32) | (uint64_t)nHeight; - uint8_t hashSrc[8]; - bits256 hashResult; - - for ( i = 0; i < sizeof(hashSrc); i++ ) - { - uint64_t x = hashSrc64 >> (i * 8); - hashSrc[i] = (uint8_t)(x & 0xff); - } - verus_hash(hashResult.bytes, hashSrc, sizeof(hashSrc)); - for ( i = 0; i < 8; i++ ) - { - result = (result << 8) | hashResult.bytes[i]; - } - return result; + hashSrc[i] = hashSrc64 & 0xff; + hashSrc64 >>= 8; + int8_t b = hashSrc[i]; } - else + + vcalc_sha256(0, hashResult.bytes, hashSrc, sizeof(hashSrc)); + for ( i = 0; i < 8; i++ ) { - int i; - uint8_t hashSrc[8]; - uint64_t result=0, hashSrc64 = (uint64_t)ASSETCHAINS_MAGIC << 32 + nHeight; - bits256 hashResult; - - for ( i = 0; i < sizeof(hashSrc); i++ ) - { - hashSrc[i] = hashSrc64 & 0xff; - hashSrc64 >>= 8; - int8_t b = hashSrc[i]; - } - - vcalc_sha256(0, hashResult.bytes, hashSrc, sizeof(hashSrc)); - for ( i = 0; i < 8; i++ ) - { - result = (result << 8) + hashResult.bytes[i]; - } - return result; + result = (result << 8) + hashResult.bytes[i]; } + return result; } // given a block height, this returns the unlock time for that block height, derived from diff --git a/src/main.cpp b/src/main.cpp index 264cb0643..63f062c65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5229,7 +5229,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C //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") + if (i == (block.vtx.size() - 1) && ASSETCHAINS_LWMAPOS && state.GetRejectReason() == "staking") { sTx = Tx; ptx = &sTx; diff --git a/src/miner.cpp b/src/miner.cpp index e3c88afb7..5f72ebfd2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -32,7 +33,6 @@ #include "consensus/validation.h" #ifdef ENABLE_MINING #include "crypto/equihash.h" -#include "crypto/verus_hash.h" #endif #include "hash.h" #include "key_io.h" @@ -149,7 +149,6 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ int64_t komodo_block_unlocktime(uint32_t nHeight); uint64_t komodo_commission(const CBlock *block,int32_t height); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); -int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t komodo_is_notarytx(const CTransaction& tx); @@ -588,15 +587,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if (ASSETCHAINS_LWMAPOS != 0) { - uint32_t nBitsPOS; - arith_uint256 posHash; - - siglen = verus_staked(pblock, txStaked, nBitsPOS, posHash, utxosig, pk); - blocktime = GetAdjustedTime(); - - // change the scriptPubKeyIn to the same output script exactly as the staking transaction - if (siglen > 0) - scriptPubKeyIn = CScript(txStaked.vout[0].scriptPubKey); } else { @@ -1135,477 +1125,8 @@ CBlockIndex *get_chainactive(int32_t height) return(0); } -/* - * A separate thread to stake, while the miner threads mine. - */ -void static VerusStaker(CWallet *pwallet) -{ - LogPrintf("Verus staker thread started\n"); - RenameThread("verus-staker"); - const CChainParams& chainparams = Params(); - auto consensusParams = chainparams.GetConsensus(); - - // Each thread has its own key - CReserveKey reservekey(pwallet); - - // Each thread has its own counter - unsigned int nExtraNonce = 0; - std::vector solnPlaceholder = std::vector(); - solnPlaceholder.resize(Eh200_9.SolutionWidth); - uint8_t *script; uint64_t total,checktoshis; int32_t i,j; - - while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->GetHeight() != 235300 && - { - sleep(1); - if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) - break; - } - - // try a nice clean peer connection to start - CBlockIndex *pindexPrev, *pindexCur; - do { - pindexPrev = chainActive.LastTip(); - MilliSleep(5000 + rand() % 5000); - waitForPeers(chainparams); - pindexCur = chainActive.LastTip(); - } while (pindexPrev != pindexCur); - - try { - while (true) - { - waitForPeers(chainparams); - CBlockIndex* pindexPrev = chainActive.LastTip(); - printf("Staking height %d for %s\n", pindexPrev->GetHeight() + 1, ASSETCHAINS_SYMBOL); - - // Create new block - unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - if ( Mining_height != pindexPrev->GetHeight()+1 ) - { - Mining_height = pindexPrev->GetHeight()+1; - Mining_start = (uint32_t)time(NULL); - } - - // Check for stop or if block needs to be rebuilt - boost::this_thread::interruption_point(); - - // try to stake a block - CBlockTemplate *ptr = NULL; - if (Mining_height > VERUS_MIN_STAKEAGE) - ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0, true); - - if ( ptr == 0 ) - { - // wait to try another staking block until after the tip moves again - while ( chainActive.LastTip() == pindexPrev ) - sleep(1); - continue; - } - - unique_ptr pblocktemplate(ptr); - if (!pblocktemplate.get()) - { - if (GetArg("-mineraddress", "").empty()) { - LogPrintf("Error in %s staker: Keypool ran out, please call keypoolrefill before restarting the mining thread\n", - ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - } else { - // Should never reach here, because -mineraddress validity is checked in init.cpp - LogPrintf("Error in %s staker: Invalid %s -mineraddress\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO], ASSETCHAINS_SYMBOL); - } - return; - } - - CBlock *pblock = &pblocktemplate->block; - LogPrintf("Staking with %u transactions in block (%u bytes)\n", pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); - // - // Search - // - int64_t nStart = GetTime(); - - // take up the necessary space for alignment - pblock->nSolution = solnPlaceholder; - - // we don't use this, but IncrementExtraNonce is the function that builds the merkle tree - unsigned int nExtraNonce = 0; - IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - - if (vNodes.empty() && chainparams.MiningRequiresPeers()) - { - if ( Mining_height > ASSETCHAINS_MINHEIGHT ) - { - fprintf(stderr,"no nodes, attempting reconnect\n"); - continue; - } - } - - if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60) - { - fprintf(stderr,"timeout, retrying\n"); - continue; - } - - if ( pindexPrev != chainActive.LastTip() ) - { - printf("Block %d added to chain\n", chainActive.LastTip()->GetHeight()); - MilliSleep(250); - continue; - } - - int32_t unlockTime = komodo_block_unlocktime(Mining_height); - int64_t subsidy = (int64_t)(pblock->vtx[0].vout[0].nValue); - - uint256 hashTarget = ArithToUint256(arith_uint256().SetCompact(pblock->nBits)); - - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); - - UpdateTime(pblock, consensusParams, pindexPrev); - - ProcessBlockFound(pblock, *pwallet, reservekey); - - LogPrintf("Using %s algorithm:\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - LogPrintf("Staked block found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); - printf("Found block %d \n", Mining_height ); - printf("staking reward %.8f %s!\n", (double)subsidy / (double)COIN, ASSETCHAINS_SYMBOL); - arith_uint256 post; - post.SetCompact(pblock->GetVerusPOSTarget()); - pindexPrev = get_chainactive(Mining_height - 100); - CTransaction &sTx = pblock->vtx[pblock->vtx.size()-1]; - printf("POS hash: %s \ntarget: %s\n", - CTransaction::_GetVerusPOSHash(&(pblock->nNonce), sTx.vin[0].prevout.hash, sTx.vin[0].prevout.n, Mining_height, pindexPrev->GetBlockHeader().GetVerusEntropyHash(Mining_height - 100), sTx.vout[0].nValue).GetHex().c_str(), ArithToUint256(post).GetHex().c_str()); - if (unlockTime > Mining_height && subsidy >= ASSETCHAINS_TIMELOCKGTE) - printf("- timelocked until block %i\n", unlockTime); - else - printf("\n"); - - // Check for stop or if block needs to be rebuilt - boost::this_thread::interruption_point(); - - sleep(3); - - // In regression test mode, stop mining after a block is found. - if (chainparams.MineBlocksOnDemand()) { - throw boost::thread_interrupted(); - } - } - } - catch (const boost::thread_interrupted&) - { - LogPrintf("VerusStaker terminated\n"); - throw; - } - catch (const std::runtime_error &e) - { - LogPrintf("VerusStaker runtime error: %s\n", e.what()); - return; - } -} - -void static BitcoinMiner_noeq(CWallet *pwallet) -#else -void static BitcoinMiner_noeq() #endif -{ - LogPrintf("%s miner started\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - RenameThread("verushash-miner"); - -#ifdef ENABLE_WALLET - // Each thread has its own key - CReserveKey reservekey(pwallet); -#endif - - const CChainParams& chainparams = Params(); - // Each thread has its own counter - unsigned int nExtraNonce = 0; - std::vector solnPlaceholder = std::vector(); - solnPlaceholder.resize(Eh200_9.SolutionWidth); - uint8_t *script; uint64_t total,checktoshis; int32_t i,j; - - while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->GetHeight() != 235300 && - { - sleep(1); - if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) - break; - } - - SetThreadPriority(THREAD_PRIORITY_LOWEST); - - // try a nice clean peer connection to start - CBlockIndex *pindexPrev, *pindexCur; - do { - pindexPrev = chainActive.LastTip(); - MilliSleep(5000 + rand() % 5000); - waitForPeers(chainparams); - pindexCur = chainActive.LastTip(); - } while (pindexPrev != pindexCur); - - // this will not stop printing more than once in all cases, but it will allow us to print in all cases - // and print duplicates rarely without having to synchronize - static CBlockIndex *lastChainTipPrinted; - - miningTimer.start(); - - try { - printf("Mining %s with %s\n", ASSETCHAINS_SYMBOL, ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - while (true) - { - miningTimer.stop(); - waitForPeers(chainparams); - - pindexPrev = chainActive.LastTip(); - sleep(1); - - // prevent forking on startup before the diff algorithm kicks in - if (pindexPrev->GetHeight() < 50 || pindexPrev != chainActive.LastTip()) - { - do { - pindexPrev = chainActive.LastTip(); - MilliSleep(5000 + rand() % 5000); - } while (pindexPrev != chainActive.LastTip()); - } - - // Create new block - unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - if ( Mining_height != pindexPrev->GetHeight()+1 ) - { - Mining_height = pindexPrev->GetHeight()+1; - Mining_start = (uint32_t)time(NULL); - } - - if (lastChainTipPrinted != pindexPrev) - { - printf("Mining height %d\n", Mining_height); - lastChainTipPrinted = pindexPrev; - } - - miningTimer.start(); - -#ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); -#else - CBlockTemplate *ptr = CreateNewBlockWithKey(); -#endif - if ( ptr == 0 ) - { - static uint32_t counter; - if ( ASSETCHAINS_STAKED == 0 && counter++ < 10 ) - fprintf(stderr,"created illegal block, retry\n"); - continue; - } - - unique_ptr pblocktemplate(ptr); - if (!pblocktemplate.get()) - { - if (GetArg("-mineraddress", "").empty()) { - LogPrintf("Error in %s miner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n", - ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - } else { - // Should never reach here, because -mineraddress validity is checked in init.cpp - LogPrintf("Error in %s miner: Invalid %s -mineraddress\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO], ASSETCHAINS_SYMBOL); - } - return; - } - CBlock *pblock = &pblocktemplate->block; - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - { - if ( ASSETCHAINS_REWARD[0] == 0 && !ASSETCHAINS_LASTERA ) - { - if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) - { - static uint32_t counter; - if ( counter++ < 10 ) - fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); - sleep(10); - continue; - } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); - } - } - IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - LogPrintf("Running %s miner with %u transactions in block (%u bytes)\n",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO], - pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); - // - // Search - // - uint32_t savebits; int64_t nStart = GetTime(); - - pblock->nSolution = solnPlaceholder; - savebits = pblock->nBits; - arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); - HASHTarget = arith_uint256().SetCompact(savebits); - arith_uint256 mask(ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO]); - - Mining_start = 0; - - if ( pindexPrev != chainActive.LastTip() ) - { - if (lastChainTipPrinted != chainActive.LastTip()) - { - lastChainTipPrinted = chainActive.LastTip(); - printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight()); - } - MilliSleep(250); - continue; - } - - if ( ASSETCHAINS_STAKED != 0 ) - { - int32_t percPoS,z; bool fNegative,fOverflow; - HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); - } - //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) - // HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); - - while (true) - { - arith_uint256 arNonce = UintToArith256(pblock->nNonce); - int64_t *extraPtr; - - // This seems to be a really bad way to do this, but its better than copy pasting the entire miner function at this stage. - CVerusHashWriter ss = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - ss << *((CBlockHeader *)pblock); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH ) - extraPtr = ss.xI64p(); - CVerusHash &vh = ss.GetState(); - uint256 hashResult = uint256(); - vh.ClearExtra(); - - CVerusHashV2Writer ss2 = CVerusHashV2Writer(SER_GETHASH, PROTOCOL_VERSION); - ss2 << *((CBlockHeader *)pblock); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) - extraPtr = ss2.xI64p(); - CVerusHashV2 &vh2 = ss2.GetState(); - vh2.ClearExtra(); - - int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; - int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; - if ( ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) - { - if ( KOMODO_MININGTHREADS > 0 ) - hashTarget = HASHTarget_POW; - else - hashTarget = HASHTarget; - } - else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 ) - hashTarget = HASHTarget; - //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) - // hashTarget = HASHTarget_POW; - - // for speed check NONCEMASK at a time - for (i = 0; i < count; i++) - { - *extraPtr = i; - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH ) - vh.ExtraHash((unsigned char *)&hashResult); - else if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) - vh2.ExtraHash((unsigned char *)&hashResult); - - if ( UintToArith256(hashResult) <= hashTarget ) - { - if (pblock->nSolution.size() != 1344) - { - LogPrintf("ERROR: Block solution is not 1344 bytes as it should be"); - sleep(5); - break; - } - - SetThreadPriority(THREAD_PRIORITY_NORMAL); - - *((int64_t *)&(pblock->nSolution.data()[pblock->nSolution.size() - 15])) = i; - - int32_t unlockTime = komodo_block_unlocktime(Mining_height); - int64_t subsidy = (int64_t)(pblock->vtx[0].vout[0].nValue); - - LogPrintf("Using %s algorithm:\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); - printf("Found block %d \n", Mining_height ); - printf("mining reward %.8f %s!\n", (double)subsidy / (double)COIN, ASSETCHAINS_SYMBOL); - printf(" hash: %s \ntarget: %s\n", pblock->GetHash().GetHex().c_str(), hashTarget.GetHex().c_str()); - if (unlockTime > Mining_height && subsidy >= ASSETCHAINS_TIMELOCKGTE) - printf("- timelocked until block %i\n", unlockTime); - else - printf("\n"); -#ifdef ENABLE_WALLET - ProcessBlockFound(pblock, *pwallet, reservekey); -#else - ProcessBlockFound(pblock)); -#endif - SetThreadPriority(THREAD_PRIORITY_LOWEST); - break; - } - // check periodically if we're stale - if (!--hashesToGo) - { - if ( pindexPrev != chainActive.LastTip() ) - { - if (lastChainTipPrinted != chainActive.LastTip()) - { - lastChainTipPrinted = chainActive.LastTip(); - printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight()); - } - break; - } - hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; - } - } - - { - LOCK(cs_metrics); - nHashCount += i; - } - - // Check for stop or if block needs to be rebuilt - boost::this_thread::interruption_point(); - - if (vNodes.empty() && chainparams.MiningRequiresPeers()) - { - if ( Mining_height > ASSETCHAINS_MINHEIGHT ) - { - fprintf(stderr,"no nodes, attempting reconnect\n"); - break; - } - } - - if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60) - { - fprintf(stderr,"timeout, retrying\n"); - break; - } - - if ( pindexPrev != chainActive.LastTip() ) - { - if (lastChainTipPrinted != chainActive.LastTip()) - { - lastChainTipPrinted = chainActive.LastTip(); - printf("Block %d added to chain\n", lastChainTipPrinted->GetHeight()); - } - break; - } - -#ifdef _WIN32 - printf("%llu mega hashes complete - working\n", (ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1) / 1048576); -#else - printf("%lu mega hashes complete - working\n", (ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1) / 1048576); -#endif - pblock->nBits = savebits; - break; - } - } - } - catch (const boost::thread_interrupted&) - { - miningTimer.stop(); - LogPrintf("%s miner terminated\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); - throw; - } - catch (const std::runtime_error &e) - { - miningTimer.stop(); - LogPrintf("%s miner runtime error: %s\n", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO], e.what()); - return; - } - miningTimer.stop(); -} int32_t gotinvalid; @@ -1617,7 +1138,7 @@ void static BitcoinMiner() { LogPrintf("HushMiner started\n"); SetThreadPriority(THREAD_PRIORITY_LOWEST); - RenameThread("komodo-miner"); + RenameThread("hush-miner"); const CChainParams& chainparams = Params(); #ifdef ENABLE_WALLET @@ -2119,9 +1640,8 @@ void static BitcoinMiner() minerThreads = new boost::thread_group(); #ifdef ENABLE_WALLET - if (ASSETCHAINS_LWMAPOS != 0 && VERUS_MINTBLOCKS) + if (ASSETCHAINS_LWMAPOS != 0) { - minerThreads->create_thread(boost::bind(&VerusStaker, pwallet)); } #endif @@ -2130,13 +1650,9 @@ void static BitcoinMiner() #ifdef ENABLE_WALLET if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); - else - minerThreads->create_thread(boost::bind(&BitcoinMiner_noeq, pwallet)); #else if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) minerThreads->create_thread(&BitcoinMiner); - else - minerThreads->create_thread(&BitcoinMiner_noeq); #endif } } diff --git a/src/pow.cpp b/src/pow.cpp index 95cda4443..b552df5db 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -650,11 +651,13 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: CBlockHeader hdr = pindexFirst->GetBlockHeader(); + /* if (hdr.IsVerusPOSBlock()) { nBits = hdr.GetVerusPOSTarget(); break; } + */ pindexFirst = pindexFirst->pprev; } @@ -675,11 +678,13 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: return nProofOfStakeLimit; CBlockHeader hdr = pindexFirst->GetBlockHeader(); + /* if (hdr.IsVerusPOSBlock()) { nBits = hdr.GetVerusPOSTarget(); break; } + */ } if (x) @@ -870,7 +875,8 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) // bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime); // Check proof of work matches claimed amount - if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) + //if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) + if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget ) { if ( KOMODO_LOADINGBLOCKS != 0 ) return true; diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index a7ec8d162..3243b4564 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -35,96 +35,12 @@ uint256 CBlockHeader::GetSHA256DHash() const return SerializeHash(*this); } -uint256 CBlockHeader::GetVerusHash() const -{ - if (hashPrevBlock.IsNull()) - // always use SHA256D for genesis block - return SerializeHash(*this); - else - return SerializeVerusHash(*this); -} - -uint256 CBlockHeader::GetVerusV2Hash() const -{ - if (hashPrevBlock.IsNull()) - // always use SHA256D for genesis block - return SerializeHash(*this); - else - return SerializeVerusHashV2(*this); -} void CBlockHeader::SetSHA256DHash() { CBlockHeader::hashFunction = &CBlockHeader::GetSHA256DHash; } -void CBlockHeader::SetVerusHash() -{ - CBlockHeader::hashFunction = &CBlockHeader::GetVerusHash; -} - -void CBlockHeader::SetVerusHashV2() -{ - CBlockHeader::hashFunction = &CBlockHeader::GetVerusV2Hash; -} - -// returns false if unable to fast calculate the VerusPOSHash from the header. -// if it returns false, value is set to 0, but it can still be calculated from the full block -// in that case. the only difference between this and the POS hash for the contest is that it is not divided by the value out -// this is used as a source of entropy -bool CBlockHeader::GetRawVerusPOSHash(uint256 &ret, int32_t nHeight) const -{ - // if below the required height or no storage space in the solution, we can't get - // a cached txid value to calculate the POSHash from the header - if (!(CPOSNonce::NewNonceActive(nHeight) && IsVerusPOSBlock())) - { - ret = uint256(); - return false; - } - - // if we can calculate, this assumes the protocol that the POSHash calculation is: - // hashWriter << ASSETCHAINS_MAGIC; - // hashWriter << nNonce; (nNonce is: - // (high 128 bits == low 128 bits of verus hash of low 128 bits of nonce) - // (low 32 bits == compact PoS difficult) - // (mid 96 bits == low 96 bits of HASH(pastHash, txid, voutnum) - // pastHash is hash of height - 100, either PoW hash of block or PoS hash, if new PoS - // ) - // hashWriter << height; - // return hashWriter.GetHash(); - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - hashWriter << ASSETCHAINS_MAGIC; - hashWriter << nNonce; - hashWriter << nHeight; - ret = hashWriter.GetHash(); - return true; -} - -bool CBlockHeader::GetVerusPOSHash(arith_uint256 &ret, int32_t nHeight, CAmount value) const -{ - uint256 raw; - if (GetRawVerusPOSHash(raw, nHeight)) - { - ret = UintToArith256(raw) / value; - return true; - } - return false; -} - -// depending on the height of the block and its type, this returns the POS hash or the POW hash -uint256 CBlockHeader::GetVerusEntropyHash(int32_t height) const -{ - uint256 retVal; - // if we qualify as PoW, use PoW hash, regardless of PoS state - if (GetRawVerusPOSHash(retVal, height)) - { - // POS hash - return retVal; - } - return GetHash(); -} - uint256 BuildMerkleTree(bool* fMutated, const std::vector leaves, std::vector &vMerkleTree) { diff --git a/src/primitives/block.h b/src/primitives/block.h index 6ef8e0633..41e7e3715 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -51,7 +52,9 @@ public: uint256 hashFinalSaplingRoot; uint32_t nTime; uint32_t nBits; - CPOSNonce nNonce; + //CPOSNonce nNonce; + uint256 nNonce; + std::vector nSolution; CBlockHeader() @@ -98,57 +101,14 @@ public: uint256 GetSHA256DHash() const; static void SetSHA256DHash(); - uint256 GetVerusHash() const; - static void SetVerusHash(); - bool GetRawVerusPOSHash(uint256 &ret, int32_t nHeight) const; - bool GetVerusPOSHash(arith_uint256 &ret, int32_t nHeight, CAmount value) const; // value is amount of stake tx - uint256 GetVerusEntropyHash(int32_t nHeight) const; - uint256 GetVerusV2Hash() const; - static void SetVerusHashV2(); int64_t GetBlockTime() const { return (int64_t)nTime; } - uint32_t GetVerusPOSTarget() const - { - uint32_t nBits = 0; - - for (const unsigned char *p = nNonce.begin() + 3; p >= nNonce.begin(); p--) - { - nBits <<= 8; - nBits += *p; - } - return nBits; - } - - bool IsVerusPOSBlock() const - { - if ( ASSETCHAINS_LWMAPOS != 0 ) - return nNonce.IsPOSNonce(); - else return(0); - } - - void SetVerusPOSTarget(uint32_t nBits) - { - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - arith_uint256 arNonce = UintToArith256(nNonce); - - // printf("before svpt: %s\n", ArithToUint256(arNonce).GetHex().c_str()); - - arNonce = (arNonce & CPOSNonce::entropyMask) | nBits; - - // printf("after clear: %s\n", ArithToUint256(arNonce).GetHex().c_str()); - - hashWriter << ArithToUint256(arNonce); - nNonce = CPOSNonce(ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce)); - - // printf(" after svpt: %s\n", nNonce.GetHex().c_str()); - } }; // this class is used to address the type mismatch that existed between nodes, where block headers diff --git a/src/primitives/nonce.cpp b/src/primitives/nonce.cpp index d90a4d78c..a512b757d 100644 --- a/src/primitives/nonce.cpp +++ b/src/primitives/nonce.cpp @@ -21,66 +21,3 @@ #include "nonce.h" #include -extern char ASSETCHAINS_SYMBOL[65]; - -arith_uint256 CPOSNonce::entropyMask = UintToArith256(uint256S("00000000000000000000000000000000ffffffffffffffffffffffff00000000")); -arith_uint256 CPOSNonce::posDiffMask = UintToArith256(uint256S("00000000000000000000000000000000000000000000000000000000ffffffff")); - -bool CPOSNonce::NewPOSActive(int32_t height) -{ - if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0) && (height < (96480 + 100))) - return false; - else - return true; -} - -bool CPOSNonce::NewNonceActive(int32_t height) -{ - if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0) && (height < 96480)) - return false; - else - return true; -} - -void CPOSNonce::SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum) -{ - // get low 96 bits of past hash and put it in top 96 bits of low 128 bits of nonce - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - // first hash the pastHash, txid, and voutNum, to create a combined 96 bits, which will be used in the nonce - hashWriter << pastHash; - hashWriter << txid; - hashWriter << voutNum; - - arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) | - (UintToArith256(hashWriter.GetHash()) & entropyMask); - - // printf("before %s\n", ArithToUint256(arNonce).GetHex().c_str()); - - hashWriter.Reset(); - hashWriter << ArithToUint256(arNonce); - - *this = CPOSNonce(ArithToUint256((UintToArith256(hashWriter.GetHash()) << 128) | arNonce)); - - // printf("after %s\n", this->GetHex().c_str()); -} - -bool CPOSNonce::CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum) -{ - // get low 96 bits of past hash and put it in top 96 bits of low 128 bits of nonce - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - // first hash the pastHash, txid, and voutNum, to create a combined 96 bits, which will be used in the nonce - hashWriter << pastHash; - hashWriter << txid; - hashWriter << voutNum; - - arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) | - (UintToArith256(hashWriter.GetHash()) & entropyMask); - - hashWriter.Reset(); - hashWriter << ArithToUint256(arNonce); - - return UintToArith256(*this) == (UintToArith256(hashWriter.GetHash()) << 128 | arNonce); -} - diff --git a/src/primitives/nonce.h b/src/primitives/nonce.h index 605564671..b17a9f01b 100644 --- a/src/primitives/nonce.h +++ b/src/primitives/nonce.h @@ -1,3 +1,4 @@ +// Copyright (c) 2019 Hush Developers // Copyright (c) 2018 Michael Toutonghi // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -25,55 +26,4 @@ #include "arith_uint256.h" -/** For POS blocks, the nNonce of a block header holds the entropy source for the POS contest - * in the latest VerusHash protocol - * */ -class CPOSNonce : public uint256 -{ -public: - static bool NewPOSActive(int32_t height); - static bool NewNonceActive(int32_t height); - - static arith_uint256 entropyMask; - static arith_uint256 posDiffMask; - - CPOSNonce() : uint256() { } - CPOSNonce(const base_blob<256> &b) : uint256(b) { } - CPOSNonce(const std::vector &vch) : uint256(vch) { } - - int32_t GetPOSTarget() const - { - uint32_t nBits = 0; - - for (const unsigned char *p = begin() + 3; p >= begin(); p--) - { - nBits <<= 8; - nBits += *p; - } - return nBits; - } - - bool IsPOSNonce() const - { - arith_uint256 arNonce = UintToArith256(*this); - arith_uint256 tmpNonce = ((arNonce << 128) >> 128); - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - hashWriter << ArithToUint256(tmpNonce); - return (*this == ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce)); - } - - void SetPOSTarget(uint32_t nBits) - { - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - arith_uint256 arNonce = (UintToArith256(*this) & entropyMask) | nBits; - hashWriter << ArithToUint256(arNonce); - - (uint256 &)(*this) = ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce); - } - - void SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum); - bool CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum); -}; - #endif // BITCOIN_PRIMITIVES_NONCE_H diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 0c20908b0..e83a519b1 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -30,7 +30,6 @@ #include "arith_uint256.h" #include "consensus/consensus.h" #include "hash.h" -#include "nonce.h" #ifndef __APPLE__ #include @@ -727,41 +726,6 @@ public: return a.hash != b.hash; } - // verus hash will be the same for a given txid, output number, block height, and blockhash of 100 blocks past - static uint256 _GetVerusPOSHash(CPOSNonce *pNonce, const uint256 &txid, int32_t voutNum, int32_t height, const uint256 &pastHash, int64_t value) - { - pNonce->SetPOSEntropy(pastHash, txid, voutNum); - CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - hashWriter << ASSETCHAINS_MAGIC; - - // we only use the new style of POS hash after changeover and 100 blocks of enforced proper nonce updating - if (CPOSNonce::NewPOSActive(height)) - { - hashWriter << *pNonce; - hashWriter << height; - return ArithToUint256(UintToArith256(hashWriter.GetHash()) / value); - } - else - { - hashWriter << pastHash; - hashWriter << height; - hashWriter << txid; - hashWriter << voutNum; - return ArithToUint256(UintToArith256(hashWriter.GetHash()) / value); - } - } - - // Nonce is modified to include the transaction information - uint256 GetVerusPOSHash(CPOSNonce *pNonce, int32_t voutNum, int32_t height, const uint256 &pastHash) const - { - uint256 txid = GetHash(); - - if (voutNum >= vout.size()) - return uint256S("ff0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - - return _GetVerusPOSHash(pNonce, txid, voutNum, height, pastHash, (uint64_t)vout[voutNum].nValue); - } std::string ToString() const; }; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 4f7374767..be87c16d9 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -326,7 +326,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("chainwork", blockindex->chainPower.chainWork.GetHex())); result.push_back(Pair("anchor", blockindex->hashFinalSproutRoot.GetHex())); - result.push_back(Pair("blocktype", block.IsVerusPOSBlock() ? "minted" : "mined")); + result.push_back(Pair("blocktype", "mined")); UniValue valuePools(UniValue::VARR); valuePools.push_back(ValuePoolDesc("sprout", blockindex->nChainSproutValue, blockindex->nSproutValue)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a93e6b4d8..c2935c0c0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5464,12 +5464,6 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) return(siglen); } -int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk) -{ - return pwalletMain->VerusStakeTransaction(pBlock, txNew, nBits, hashResult, utxosig, pk); -} - - #include "../cc/CCfaucet.h" #include "../cc/CCassets.h" #include "../cc/CCrewards.h" diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8f33f8d6d..1744ef0b6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1338,120 +1338,6 @@ CWallet::TxItems CWallet::OrderedTxItems(std::list& acentries, return txOrdered; } -// looks through all wallet UTXOs and checks to see if any qualify to stake the block at the current height. it always returns the qualified -// UTXO with the smallest coin age if there is more than one, as larger coin age will win more often and is worth saving -// each attempt consists of taking a VerusHash of the following values: -// ASSETCHAINS_MAGIC, nHeight, txid, voutNum -bool CWallet::VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult, CTransaction &stakeSource, int32_t &voutNum, int32_t nHeight, uint32_t &bnTarget) const -{ - arith_uint256 target; - arith_uint256 curHash; - vector vecOutputs; - COutput *pwinner = NULL; - CBlockIndex *pastBlockIndex; - txnouttype whichType; - std:vector> vSolutions; - - pBlock->nNonce.SetPOSTarget(bnTarget); - target.SetCompact(bnTarget); - - pwalletMain->AvailableCoins(vecOutputs, true, NULL, false, false); - - if (pastBlockIndex = komodo_chainactive(nHeight - 100)) - { - CBlockHeader bh = pastBlockIndex->GetBlockHeader(); - uint256 pastHash = bh.GetVerusEntropyHash(nHeight - 100); - CPOSNonce curNonce; - - BOOST_FOREACH(COutput &txout, vecOutputs) - { - if (txout.fSpendable && (UintToArith256(txout.tx->GetVerusPOSHash(&(pBlock->nNonce), txout.i, nHeight, pastHash)) <= target) && (txout.nDepth >= VERUS_MIN_STAKEAGE)) - { - if ((!pwinner || UintToArith256(curNonce) > UintToArith256(pBlock->nNonce)) && - (Solver(txout.tx->vout[txout.i].scriptPubKey, whichType, vSolutions) && (whichType == TX_PUBKEY || whichType == TX_PUBKEYHASH))) - { - //printf("Found PoS block\nnNonce: %s\n", pBlock->nNonce.GetHex().c_str()); - pwinner = &txout; - curNonce = pBlock->nNonce; - } - } - } - if (pwinner) - { - stakeSource = *(pwinner->tx); - voutNum = pwinner->i; - pBlock->nNonce = curNonce; - return true; - } - } - return false; -} - -int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &bnTarget, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey pk) const -{ - CTransaction stakeSource; - int32_t voutNum, siglen = 0; - int64_t nValue; - txnouttype whichType; - std::vector> vSolutions; - - CBlockIndex *tipindex = chainActive.LastTip(); - uint32_t stakeHeight = tipindex->GetHeight() + 1; - - pk = CPubKey(); - - bnTarget = lwmaGetNextPOSRequired(tipindex, Params().GetConsensus()); - - if (!VerusSelectStakeOutput(pBlock, hashResult, stakeSource, voutNum, tipindex->GetHeight() + 1, bnTarget) || - !Solver(stakeSource.vout[voutNum].scriptPubKey, whichType, vSolutions)) - { - LogPrintf("Searched for eligible staking transactions, no winners found\n"); - return 0; - } - - bool signSuccess; - SignatureData sigdata; - uint64_t txfee; - auto consensusBranchId = CurrentEpochBranchId(stakeHeight, Params().GetConsensus()); - - const CKeyStore& keystore = *pwalletMain; - txNew.vin.resize(1); - txNew.vout.resize(1); - txfee = 0; - txNew.vin[0].prevout.hash = stakeSource.GetHash(); - txNew.vin[0].prevout.n = voutNum; - - if (whichType == TX_PUBKEY) - { - txNew.vout[0].scriptPubKey << ToByteVector(vSolutions[0]) << OP_CHECKSIG; - if (!pk.IsValid()) - pk = CPubKey(vSolutions[0]); - } - else if (whichType == TX_PUBKEYHASH) - { - txNew.vout[0].scriptPubKey << OP_DUP << OP_HASH160 << ToByteVector(vSolutions[0]) << OP_EQUALVERIFY << OP_CHECKSIG; - } - else - return 0; - - nValue = txNew.vout[0].nValue = stakeSource.vout[voutNum].nValue - txfee; - - txNew.nLockTime = 0; - CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), stakeSource.vout[voutNum].scriptPubKey, sigdata, consensusBranchId); - if (!signSuccess) - fprintf(stderr,"failed to create signature\n"); - else - { - uint8_t *ptr; - UpdateTransaction(txNew,0,sigdata); - ptr = (uint8_t *)&sigdata.scriptSig[0]; - siglen = sigdata.scriptSig.size(); - for (int i=0; i Date: Mon, 4 Nov 2019 08:25:13 -0500 Subject: [PATCH 2/6] I think he does not like it, Mikey --- src/crypto/verus_hash.cpp | 180 -------------------------------------- src/crypto/verus_hash.h | 134 ---------------------------- 2 files changed, 314 deletions(-) delete mode 100644 src/crypto/verus_hash.cpp delete mode 100644 src/crypto/verus_hash.h diff --git a/src/crypto/verus_hash.cpp b/src/crypto/verus_hash.cpp deleted file mode 100644 index f5cb1c9f3..000000000 --- a/src/crypto/verus_hash.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// (C) 2018 The Verus Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -/* -This provides the PoW hash function for Verus, a CPU-optimized hash -function with a Haraka V2 core. Unlike Haraka, which is made for short -inputs only, Verus Hash takes any length of input and produces a 256 -bit output. -*/ -#include -#include "crypto/common.h" -#include "crypto/verus_hash.h" - -void (*CVerusHash::haraka512Function)(unsigned char *out, const unsigned char *in); - -void CVerusHash::Hash(void *result, const void *data, size_t _len) -{ - unsigned char buf[128]; - unsigned char *bufPtr = buf; - int nextOffset = 64; - uint32_t pos = 0, len = _len; - unsigned char *bufPtr2 = bufPtr + nextOffset; - unsigned char *ptr = (unsigned char *)data; - - // put our last result or zero at beginning of buffer each time - memset(bufPtr, 0, 32); - - // digest up to 32 bytes at a time - for ( ; pos < len; pos += 32) - { - if (len - pos >= 32) - { - memcpy(bufPtr + 32, ptr + pos, 32); - } - else - { - int i = (int)(len - pos); - memcpy(bufPtr + 32, ptr + pos, i); - memset(bufPtr + 32 + i, 0, 32 - i); - } - (*haraka512Function)(bufPtr2, bufPtr); - bufPtr2 = bufPtr; - bufPtr += nextOffset; - nextOffset *= -1; - } - memcpy(result, bufPtr, 32); -}; - -void CVerusHash::init() -{ - if (IsCPUVerusOptimized()) - { - haraka512Function = &haraka512_zero; - } - else - { - haraka512Function = &haraka512_port_zero; - } -} - -CVerusHash &CVerusHash::Write(const unsigned char *data, size_t _len) -{ - unsigned char *tmp; - uint32_t pos, len = _len; - - // digest up to 32 bytes at a time - for ( pos = 0; pos < len; ) - { - uint32_t room = 32 - curPos; - - if (len - pos >= room) - { - memcpy(curBuf + 32 + curPos, data + pos, room); - (*haraka512Function)(result, curBuf); - tmp = curBuf; - curBuf = result; - result = tmp; - pos += room; - curPos = 0; - } - else - { - memcpy(curBuf + 32 + curPos, data + pos, len - pos); - curPos += len - pos; - pos = len; - } - } - return *this; -} - -// to be declared and accessed from C -void verus_hash(void *result, const void *data, size_t len) -{ - return CVerusHash::Hash(result, data, len); -} - -void (*CVerusHashV2::haraka512Function)(unsigned char *out, const unsigned char *in); - -void CVerusHashV2::init() -{ - if (IsCPUVerusOptimized()) - { - load_constants(); - haraka512Function = &haraka512; - } - else - { - // load and tweak the haraka constants - load_constants_port(); - haraka512Function = &haraka512_port; - } -} - -void CVerusHashV2::Hash(void *result, const void *data, size_t len) -{ - unsigned char buf[128]; - unsigned char *bufPtr = buf; - int pos = 0, nextOffset = 64; - unsigned char *bufPtr2 = bufPtr + nextOffset; - unsigned char *ptr = (unsigned char *)data; - - // put our last result or zero at beginning of buffer each time - memset(bufPtr, 0, 32); - - // digest up to 32 bytes at a time - for ( ; pos < len; pos += 32) - { - if (len - pos >= 32) - { - memcpy(bufPtr + 32, ptr + pos, 32); - } - else - { - int i = (int)(len - pos); - memcpy(bufPtr + 32, ptr + pos, i); - memset(bufPtr + 32 + i, 0, 32 - i); - } - (*haraka512Function)(bufPtr2, bufPtr); - bufPtr2 = bufPtr; - bufPtr += nextOffset; - nextOffset *= -1; - } - memcpy(result, bufPtr, 32); -}; - -CVerusHashV2 &CVerusHashV2::Write(const unsigned char *data, size_t len) -{ - unsigned char *tmp; - - // digest up to 32 bytes at a time - for ( int pos = 0; pos < len; ) - { - int room = 32 - curPos; - - if (len - pos >= room) - { - memcpy(curBuf + 32 + curPos, data + pos, room); - (*haraka512Function)(result, curBuf); - tmp = curBuf; - curBuf = result; - result = tmp; - pos += room; - curPos = 0; - } - else - { - memcpy(curBuf + 32 + curPos, data + pos, len - pos); - curPos += len - pos; - pos = len; - } - } - return *this; -} - -// to be declared and accessed from C -void verus_hash_v2(void *result, const void *data, size_t len) -{ - return CVerusHashV2::Hash(result, data, len); -} diff --git a/src/crypto/verus_hash.h b/src/crypto/verus_hash.h deleted file mode 100644 index 63ff1aaaa..000000000 --- a/src/crypto/verus_hash.h +++ /dev/null @@ -1,134 +0,0 @@ -// (C) 2018 Michael Toutonghi -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -/* -This provides the PoW hash function for Verus, enabling CPU mining. -*/ -#ifndef VERUS_HASH_H_ -#define VERUS_HASH_H_ - -#include -#include - -#include - -extern "C" -{ -#include "crypto/haraka.h" -#include "crypto/haraka_portable.h" -} - -class CVerusHash -{ - public: - static void Hash(void *result, const void *data, size_t len); - static void (*haraka512Function)(unsigned char *out, const unsigned char *in); - - static void init(); - - CVerusHash() { } - - CVerusHash &Write(const unsigned char *data, size_t len); - - CVerusHash &Reset() - { - curBuf = buf1; - result = buf2; - curPos = 0; - std::fill(buf1, buf1 + sizeof(buf1), 0); - return *this; - } - - int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } - void ClearExtra() - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - } - } - void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } - - void Finalize(unsigned char hash[32]) - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - (*haraka512Function)(hash, curBuf); - } - else - std::memcpy(hash, curBuf, 32); - } - - private: - // only buf1, the first source, needs to be zero initialized - unsigned char buf1[64] = {0}, buf2[64]; - unsigned char *curBuf = buf1, *result = buf2; - size_t curPos = 0; -}; - -class CVerusHashV2 -{ - public: - static void Hash(void *result, const void *data, size_t len); - static void (*haraka512Function)(unsigned char *out, const unsigned char *in); - - static void init(); - - CVerusHashV2() {} - - CVerusHashV2 &Write(const unsigned char *data, size_t len); - - CVerusHashV2 &Reset() - { - curBuf = buf1; - result = buf2; - curPos = 0; - std::fill(buf1, buf1 + sizeof(buf1), 0); - return *this; - } - - int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } - void ClearExtra() - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - } - } - void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } - - void Finalize(unsigned char hash[32]) - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - (*haraka512Function)(hash, curBuf); - } - else - std::memcpy(hash, curBuf, 32); - } - - private: - // only buf1, the first source, needs to be zero initialized - unsigned char buf1[64] = {0}, buf2[64]; - unsigned char *curBuf = buf1, *result = buf2; - size_t curPos = 0; -}; - -extern void verus_hash(void *result, const void *data, size_t len); -extern void verus_hash_v2(void *result, const void *data, size_t len); - -inline bool IsCPUVerusOptimized() -{ - unsigned int eax,ebx,ecx,edx; - - if (!__get_cpuid(1,&eax,&ebx,&ecx,&edx)) - { - return false; - } - return ((ecx & (bit_AVX | bit_AES)) == (bit_AVX | bit_AES)); -}; - -#endif From 0eaee9dc8336f1d9f6ce7258b385e399b82030bb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 4 Nov 2019 10:53:36 -0500 Subject: [PATCH 3/6] Good riddance --- COPYING | 1 - README-mac.md | 55 --------------------------- qa/pull-tester/rpc-tests.sh | 3 +- qa/rpc-tests/ac_private.py | 3 +- src/Makefile.gtest.include | 2 +- src/Makefile.qt.include | 2 +- src/Makefile.qttest.include | 2 +- src/Makefile.test.include | 2 +- src/Makefile.zcash.include | 1 - src/assetchains.old | 4 -- src/cc/eval.h | 2 +- src/chainparams.cpp | 74 +++++++------------------------------ src/clientversion.h | 2 +- src/coins.h | 2 +- src/fiat/vrsc | 2 - src/hash.h | 1 - src/komodo_bitcoind.h | 49 ++---------------------- src/komodo_defs.h | 13 +++---- src/komodo_gateway.h | 2 +- src/komodo_globals.h | 27 ++++++-------- src/komodo_utils.h | 22 +++-------- src/main.cpp | 47 +---------------------- src/metrics.cpp | 7 +--- src/miner.cpp | 4 +- src/pow.cpp | 34 ++++------------- src/rpc/mining.cpp | 9 +---- src/rpc/misc.cpp | 2 +- src/util.cpp | 3 +- src/wallet-utility.cpp | 4 +- 29 files changed, 69 insertions(+), 312 deletions(-) delete mode 100644 README-mac.md delete mode 100755 src/fiat/vrsc diff --git a/COPYING b/COPYING index 7a9767ad0..4c4d2e838 100644 --- a/COPYING +++ b/COPYING @@ -3,7 +3,6 @@ Copyright (c) 2009-2018 Bitcoin Developers Copyright (c) 2016-2017 The Zcash developers Copyright (c) 2016-2019 The Komodo developers Copyright (c) 2018-2019 The Hush developers -Copyright (c) 2018 The VerusCoin developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README-mac.md b/README-mac.md deleted file mode 100644 index 1fbe7bf89..000000000 --- a/README-mac.md +++ /dev/null @@ -1,55 +0,0 @@ - -You will need Apple's Xcode (at least version 7, preferably 8.x) and the Xcode Command Line Tools: - -https://itunes.apple.com/us/app/xcode/id497799835?mt=12 - -And Homebrew: - -http://brew.sh/ - -Use the brewfile to install the necessary packages: - -```shell -brew bundle -``` - -or - -```shell -brew tap discoteq/discoteq; brew install flock autoconf autogen automake gcc@6 binutils protobuf coreutils wget -``` - -Get all that installed, then run: - -```shell -git clone https://github.com/MyHush/hush3 -cd hush3 -./zcutil/build-mac.sh -``` - -To build a distributable version of Hush then run the makeReleaseMac.sh script after building. This will fix the dependency references and move the komodod and komodo-cli binaries to the kmd/mac/verus-cli directory along with the 6 libraries required for it to work properly. - -When you are done building, you need to create `Komodo.conf` the Mac way. - -```shell -mkdir ~/Library/Application\ Support/Komodo -touch ~/Library/Application\ Support/Komodo/Komodo.conf -nano ~/Library/Application\ Support/Komodo/Komodo.conf -``` - -Add the following lines to the Komodo.conf file: - -```shell -rpcuser=dontuseweakusernameoryougetrobbed -rpcpassword=dontuseweakpasswordoryougetrobbed -txindex=1 -addnode=5.9.102.210 -addnode=78.47.196.146 -addnode=178.63.69.164 -addnode=88.198.65.74 -addnode=5.9.122.241 -addnode=144.76.94.38 -addnode=89.248.166.91 -``` - -Happy Building diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 24e8566d5..c525a5410 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Copyright 2019 The Hush developers + set -e -o pipefail CURDIR=$(cd $(dirname "$0"); pwd) @@ -14,7 +16,6 @@ testScripts=( 'dpow.py' 'dpowconfs.py' 'ac_private.py' - 'verushash.py' 'paymentdisclosure.py' 'prioritisetransaction.py' 'wallet_treestate.py' diff --git a/qa/rpc-tests/ac_private.py b/qa/rpc-tests/ac_private.py index fafc4b4cd..43febdeea 100755 --- a/qa/rpc-tests/ac_private.py +++ b/qa/rpc-tests/ac_private.py @@ -1,4 +1,5 @@ #!/usr/bin/env python2 +# Copyright (c) 2019 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -28,7 +29,7 @@ def generate_random_string(length): class AssetChainPrivateTest (BitcoinTestFramework): def setup_chain(self): - print("Initializing VerusHash test directory "+self.options.tmpdir) + print("Initializing ac_private test directory "+self.options.tmpdir) self.num_nodes = 1 initialize_chain_clean(self.options.tmpdir, self.num_nodes) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index ec3a4a12e..cb9aa844a 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -54,7 +54,7 @@ endif komodo_gtest_CPPFLAGS = $(AM_CPPFLAGS) -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC $(BITCOIN_INCLUDES) komodo_gtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -komodo_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +komodo_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) if ENABLE_ZMQ zcash_gtest_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 6afc3a707..c21016737 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -361,7 +361,7 @@ qt_komodo_qt_LDADD = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER) if ENABLE_WALLET qt_komodo_qt_LDADD += $(LIBBITCOIN_WALLET) endif -qt_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +qt_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) $(LIBZCASH_LIBS) qt_komodo_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_komodo_qt_LIBTOOLFLAGS = --tag CXX diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 2d56d07e3..3e57a8926 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -30,7 +30,7 @@ qt_test_test_komodo_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER) if ENABLE_WALLET qt_test_test_komodo_qt_LDADD += $(LIBBITCOIN_WALLET) endif -qt_test_test_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) \ +qt_test_test_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) \ $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) $(LIBZCASH_LIBS) qt_test_test_komodo_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 1f9f9ac1e..59c66ad43 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -113,7 +113,7 @@ endif test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) -fopenmp $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS) -test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) if ENABLE_WALLET diff --git a/src/Makefile.zcash.include b/src/Makefile.zcash.include index 4302b2e0d..da5b4344d 100644 --- a/src/Makefile.zcash.include +++ b/src/Makefile.zcash.include @@ -24,7 +24,6 @@ zcash_CreateJoinSplit_LDADD = \ $(LIBSNARK) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ $(BOOST_LIBS) \ $(LIBZCASH_LIBS) \ $(LIBCRYPTOCONDITIONS) \ diff --git a/src/assetchains.old b/src/assetchains.old index e0fe0eee9..0a2c4fb7b 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -35,7 +35,6 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -ac_ccactivate=205000 -addnode=46.101.124.153 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -ac_sapling=5000000 -addnode=51.68.215.104 & ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=95.213.238.98 & -~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & ./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=178.63.77.56 & @@ -48,10 +47,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=ILN -ac_supply=10000000000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=51.75.122.83 & ./komodod -pubkey=$pubkey -ac_name=RICK -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=95.217.44.58 -addnode=138.201.136.145 & ./komodod -pubkey=$pubkey -ac_name=MORTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=95.217.44.58 -addnode=138.201.136.145 & -<<<<<<< HEAD ./komodod -pubkey=$pubkey -ac_name=VOTE2019 -ac_supply=123651638 -ac_public=1 -addnode=95.213.238.98 & -======= ->>>>>>> beta ./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & ./komodod -pubkey=$pubkey -ac_name=ZEXO -ac_supply=100000000 -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_ccenable=236 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc -ac_public=1 -addnode=80.240.17.222 & ./komodod -pubkey=$pubkey -ac_name=K64 -ac_supply=64000777 -ac_reward=0 -ac_staked=10 -addnode=18.197.20.211 & diff --git a/src/cc/eval.h b/src/cc/eval.h index 1324d5e21..b2a99b6d4 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -1,3 +1,4 @@ +// Copyright 2019 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -36,7 +37,6 @@ * there should be a code identifying it. For example, * a possible code is EVAL_BITCOIN_SCRIPT, where the entire binary * after the code is interpreted as a bitcoin script. - * Verus EVAL_STAKEGUARD is 0x01 */ #define FOREACH_EVAL(EVAL) \ EVAL(EVAL_IMPORTPAYOUT, 0xe1) \ diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 07adada36..cfcf48313 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -581,22 +582,6 @@ void *chainparams_commandline() pCurrentParams->pchMessageStart[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; pCurrentParams->pchMessageStart[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; fprintf(stderr,">>>>>>>>>> %s: p2p.%u rpc.%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY); - if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH) - { - // this is only good for 60 second blocks with an averaging window of 45. for other parameters, use: - // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing - pCurrentParams->consensus.nLwmaAjustedWeight = 1350; - pCurrentParams->consensus.nPowAveragingWindow = 45; - pCurrentParams->consensus.powAlternate = uint256S("00000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - } - else if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1) - { - // this is only good for 60 second blocks with an averaging window of 45. for other parameters, use: - // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing - pCurrentParams->consensus.nLwmaAjustedWeight = 1350; - pCurrentParams->consensus.nPowAveragingWindow = 45; - pCurrentParams->consensus.powAlternate = uint256S("0000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - } if (ASSETCHAINS_LWMAPOS != 0) { @@ -604,54 +589,23 @@ void *chainparams_commandline() pCurrentParams->consensus.nPOSAveragingWindow = 45; // spacing is 1000 units per block to get better resolution, POS is 50% hard coded for now, we can vary it later // when we get reliable integer math on nLwmaPOSAjustedWeight - pCurrentParams->consensus.nPOSTargetSpacing = VERUS_BLOCK_POSUNITS * 2; + pCurrentParams->consensus.nPOSTargetSpacing = KOMODO_BLOCK_POSUNITS * 2; // nLwmaPOSAjustedWeight = (N+1)/2 * (0.9989^(500/nPOSAveragingWindow)) * nPOSTargetSpacing - // this needs to be recalculated if VERUS_BLOCK_POSUNITS is changed + // this needs to be recalculated if KOMODO_BLOCK_POSUNITS is changed pCurrentParams->consensus.nLwmaPOSAjustedWeight = 46531; } - // only require coinbase protection on Verus from the Komodo family of coins - if (strcmp(ASSETCHAINS_SYMBOL,"VRSC") == 0) - { - pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = 227520; - pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = 227520; - pCurrentParams->consensus.fCoinbaseMustBeProtected = true; - checkpointData = //(Checkpoints::CCheckpointData) - { - boost::assign::map_list_of - (0, pCurrentParams->consensus.hashGenesisBlock) - (10000, uint256S("0xac2cd7d37177140ea4991cf630c0b9c7f94d707b84fb0351bf3a44856d2ae5dc")) - (20000, uint256S("0xb0e8cb9f77aaa7ff5bd90d6c08d06f4c4bf03e00c2b8a35a042e760845590c8a")) - (30000, uint256S("0xf2112ca577338ad7104bf905fa6a63d36b17a86f914c97b73cd31d43fcd7557c")) - (40000, uint256S("0x00000000008f83378dab727864b763ce91a4ea5f75d55939c0c1390cfb8c38f1")) - (49170, uint256S("0x2add646c0089871ec2379f02f7cd60b3af6efd9c152a6f16fc10925458c270cc")), - (int64_t)1529910234, // * UNIX timestamp of last checkpoint block - (int64_t)63661, // * total number of transactions between genesis and last checkpoint - // (the tx=... number in the SetBestChain debug.log lines) - (double)2777 // * estimated number of transactions per day after checkpoint - // total number of tx / (checkpoint block height / (24 * 24)) - }; - - pCurrentParams->consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000001a8f4f23f8b2d1f7e"); - } - else - { - if (strcmp(ASSETCHAINS_SYMBOL,"VRSCTEST") == 0 || strcmp(ASSETCHAINS_SYMBOL,"VERUSTEST") == 0) - { - pCurrentParams->consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000000000001f7e"); - } - pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = ASSETCHAINS_SAPLING; - pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = ASSETCHAINS_OVERWINTER; - checkpointData = //(Checkpoints::CCheckpointData) - { - boost::assign::map_list_of - (0, pCurrentParams->consensus.hashGenesisBlock), - (int64_t)1231006505, - (int64_t)1, - (double)2777 // * estimated number of transactions per day after checkpoint - // total number of tx / (checkpoint block height / (24 * 24)) - }; - } + pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = ASSETCHAINS_SAPLING; + pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = ASSETCHAINS_OVERWINTER; + checkpointData = //(Checkpoints::CCheckpointData) + { + boost::assign::map_list_of + (0, pCurrentParams->consensus.hashGenesisBlock), + (int64_t)1231006505, + (int64_t)1, + (double)2777 // * estimated number of transactions per day after checkpoint + // total number of tx / (checkpoint block height / (24 * 24)) + }; } else { diff --git a/src/clientversion.h b/src/clientversion.h index 2cb13cb2e..d4868380a 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -56,7 +56,7 @@ #define DO_STRINGIZE(X) #X //! Copyright string used in Windows .rc files -#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core Developers, The Zcash developers, Komodo developers, Hush developers and Verus developers" +#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core Developers, The Zcash developers, Komodo developers, Hush developers" /** * bitcoind-res.rc includes this file, but it cannot cope with real c++ code. diff --git a/src/coins.h b/src/coins.h index d7e357e9e..9948a9e3c 100644 --- a/src/coins.h +++ b/src/coins.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -39,7 +40,6 @@ #include #include #include "zcash/IncrementalMerkleTree.hpp" -//#include "veruslaunch.h" /** * Pruned version of CTransaction: only retains metadata and unspent transaction outputs diff --git a/src/fiat/vrsc b/src/fiat/vrsc deleted file mode 100755 index 6cd4dd1fb..000000000 --- a/src/fiat/vrsc +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=VRSC $1 $2 $3 $4 $5 $6 diff --git a/src/hash.h b/src/hash.h index 143516d89..a062ea94c 100644 --- a/src/hash.h +++ b/src/hash.h @@ -24,7 +24,6 @@ #include "crypto/ripemd160.h" #include "crypto/sha256.h" -#include "crypto/verus_hash.h" #include "prevector.h" #include "serialize.h" #include "uint256.h" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 924b44fae..50832b190 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1,3 +1,5 @@ +// Copyright 2019 The Hush Developers + /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -1481,11 +1483,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } if ( m+n < 100 ) { - // We do actual PoS % at the start. Requires coin distribution in first 10 blocks! - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) - percPoS = (percPoS*100) / (m+n); - else - percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; + percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; } if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); @@ -1583,24 +1581,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; diff = (iter + blocktime - txtime - minage); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) - { - /*if ( PoSperc < ASSETCHAINS_STAKED ) - { - // Under PoS % target and we need to increase diff. - //fprintf(stderr, "PoS too low diff.%i changed to.",diff); - diff = diff * ( (ASSETCHAINS_STAKED - PoSperc + 1) * (ASSETCHAINS_STAKED - PoSperc + 1) * ( nHeight < 50 ? 1000 : 1)); - //fprintf(stderr, "%i \n",diff); - } - else */ - if ( PoSperc > ASSETCHAINS_STAKED ) - { - // Over PoS target need to lower diff. - //fprintf(stderr, "PoS too high diff.%i changed to.",diff); - diff = diff / ( (PoSperc - ASSETCHAINS_STAKED + 1) * (PoSperc - ASSETCHAINS_STAKED + 1) ); - //fprintf(stderr, "%i \n",diff); - } - } if ( diff < 0 ) diff = 60; else if ( diff > 3600*24*30 ) @@ -1611,17 +1591,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( iter > 0 ) diff += segid*2; coinage = (value * diff); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) - { - if ( PoSperc < ASSETCHAINS_STAKED ) - { - // Under PoS % target and we need to increase diff. - //fprintf(stderr, "PoS too low diff.%i changed to.",diff); - if ( blocktime+iter+segid*2 > prevtime+128 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+102)); - //fprintf(stderr, "%i \n",diff); - } - } if ( blocktime+iter+segid*2 > prevtime+480 ) coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); coinage256 = arith_uint256(coinage+1); @@ -1752,11 +1721,6 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ bool GetStakeParams(const CTransaction &stakeTx, CStakeParams &stakeParams); bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating); -// for now, we will ignore slowFlag in the interest of keeping success/fail simpler for security purposes -bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) -{ - return false; -} uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount) { @@ -2120,13 +2084,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) // bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime); if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget ) { - /* - // if proof of stake is active, check if this is a valid PoS block before we fail - if (verusCheckPOSBlock(slowflag, pblock, height)) - { - return(0); - } - */ } if ( (ASSETCHAINS_SYMBOL[0] != 0 || height > 792000) && bhash > bnTarget ) { diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 9bebea215..396a62764 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -1,3 +1,4 @@ +// Copyright © 2019 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -270,24 +271,23 @@ int32_t MAX_BLOCK_SIZE(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC; -extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER,ASSETCHAINS_BLOCKTIME; +extern int32_t ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER,ASSETCHAINS_BLOCKTIME; extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD; extern uint64_t ASSETCHAINS_TIMELOCKGTE; -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOMODO_INITDONE; +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH,KOMODO_INITDONE; extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED,KOMODO_NSPV; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; -extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; extern const char *ASSETCHAINS_ALGORITHMS[]; -extern int32_t VERUS_MIN_STAKEAGE; -extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; +extern uint32_t ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; extern std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; -extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; +extern int32_t KOMODO_BLOCK_POSUNITS, KOMODO_CONSECUTIVE_POS_THRESHOLD, KOMODO_NOPOS_THRESHHOLD; + extern uint256 KOMODO_EARLYTXID; extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; @@ -298,7 +298,6 @@ extern uint8_t ASSETCHAINS_CCDISABLES[256]; extern int32_t USE_EXTERNAL_PUBKEY; extern std::string NOTARY_PUBKEY; extern int32_t KOMODO_EXCHANGEWALLET; -extern int32_t VERUS_MIN_STAKEAGE; extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b2ffc26f0..036831af3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1,3 +1,4 @@ +// Copyright 2019 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -727,7 +728,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim return(-1); } } - // we don't want these checks in VRSC, leave it at the Sapling upgrade if ( ASSETCHAINS_SYMBOL[0] == 0 || ((ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD) && height > 1) || NetworkUpgradeActive(height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING) ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 817e51027..87cf95997 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -1,3 +1,5 @@ +// Copyright 2019 The Hush Developers + /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -46,13 +48,17 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; uint256 KOMODO_EARLYTXID; +int32_t KOMODO_BLOCK_POSUNITS = 1024; // one block is 1024 units +int32_t KOMODO_MIN_STAKEAGE = 150; // 1/2 this should also be a cap on the POS averaging window, or startup could be too easy +int32_t KOMODO_CONSECUTIVE_POS_THRESHOLD = 7; +int32_t KOMODO_NOPOS_THRESHHOLD = 150; // if we have no POS blocks in this many blocks, set to default difficulty + int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; int8_t ASSETCHAINS_ADAPTIVEPOW; -bool VERUS_MINTBLOCKS; std::vector Mineropret; std::vector vWhiteListAddress; char NOTARYADDRS[64][64]; @@ -83,23 +89,14 @@ std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 3; uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH; -uint32_t ASSETCHAINS_VERUSHASH = 1; -uint32_t ASSETCHAINS_VERUSHASHV1_1 = 2; -const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "verushash", "verushash11"}; -uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff,0xfffffff,0xfffffff}; -uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16,16}; -uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096,4096}; +const char *ASSETCHAINS_ALGORITHMS[] = {"equihash"}; +uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff}; +uint32_t ASSETCHAINS_NONCESHIFT[] = {32}; +uint32_t ASSETCHAINS_HASHESPERROUND[] = {1}; uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH; // min diff returned from GetNextWorkRequired needs to be added here for each algo, so they can work with ac_staked. -uint32_t ASSETCHAINS_MINDIFF[] = {537857807,504303375,487526159}; - // ^ wrong! -// Verus proof of stake controls +uint32_t ASSETCHAINS_MINDIFF[] = {537857807}; int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS -int32_t VERUS_BLOCK_POSUNITS = 1024; // one block is 1000 units -int32_t VERUS_MIN_STAKEAGE = 150; // 1/2 this should also be a cap on the POS averaging window, or startup could be too easy -int32_t VERUS_CONSECUTIVE_POS_THRESHOLD = 7; -int32_t VERUS_NOPOS_THRESHHOLD = 150; // if we have no POS blocks in this many blocks, set to default difficulty - int32_t ASSETCHAINS_SAPLING = -1; int32_t ASSETCHAINS_OVERWINTER = -1; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 01a046f62..20e294ce7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1055,19 +1055,11 @@ int64_t komodo_block_unlocktime(uint32_t nHeight) unlocktime = ASSETCHAINS_TIMEUNLOCKTO; else { - if (strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0 || nHeight >= 12800) - { - unlocktime = komodo_block_prg(nHeight) % (ASSETCHAINS_TIMEUNLOCKTO - ASSETCHAINS_TIMEUNLOCKFROM); - unlocktime += ASSETCHAINS_TIMEUNLOCKFROM; - } - else - { - unlocktime = komodo_block_prg(nHeight) / (0xffffffffffffffff / ((ASSETCHAINS_TIMEUNLOCKTO - ASSETCHAINS_TIMEUNLOCKFROM) + 1)); - // boundary and power of 2 can make it exceed to time by 1 - unlocktime = unlocktime + ASSETCHAINS_TIMEUNLOCKFROM; - if (unlocktime > ASSETCHAINS_TIMEUNLOCKTO) - unlocktime--; - } + unlocktime = komodo_block_prg(nHeight) / (0xffffffffffffffff / ((ASSETCHAINS_TIMEUNLOCKTO - ASSETCHAINS_TIMEUNLOCKFROM) + 1)); + // boundary and power of 2 can make it exceed to time by 1 + unlocktime = unlocktime + ASSETCHAINS_TIMEUNLOCKFROM; + if (unlocktime > ASSETCHAINS_TIMEUNLOCKTO) + unlocktime--; } return ((int64_t)unlocktime); } @@ -1977,7 +1969,7 @@ void komodo_args(char *argv0) // for now, we only support 50% PoS due to other parts of the algorithm needing adjustment for // other values - if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 ) + if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_lwmapos",0)) != 0 ) { ASSETCHAINS_LWMAPOS = 50; } @@ -2339,8 +2331,6 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); ASSETCHAINS_HALVING[0] *= 5; fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%llu\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,(long long)ASSETCHAINS_LASTERA); } - else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) - dpowconfs = 0; else if ( ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"-ac_private for a non-PIRATE chain is not supported. The only reason to have an -ac_private chain is for total privacy and that is best achieved with the largest anon set. PIRATE has that and it is recommended to just use PIRATE\n"); diff --git a/src/main.cpp b/src/main.cpp index 63f062c65..7636e1bdb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1110,42 +1110,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in */ bool ContextualCheckCoinbaseTransaction(int32_t slowflag,const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight,int32_t validateprices) { - // if time locks are on, ensure that this coin base is time locked exactly as it should be - if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) || - (((nHeight >= 31680) || strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0) && komodo_ac_block_subsidy(nHeight) >= ASSETCHAINS_TIMELOCKGTE)) - { - CScriptID scriptHash; - - // to be valid, it must be a P2SH transaction and have an op_return in vout[1] that - // holds the full output script, which may include multisig, etc., but starts with - // the time lock verify of the correct time lock for this block height - if (tx.vout.size() == 2 && - CScriptExt(tx.vout[0].scriptPubKey).IsPayToScriptHash(&scriptHash) && - tx.vout[1].scriptPubKey.size() >= 7 && // minimum for any possible future to prevent out of bounds - tx.vout[1].scriptPubKey[0] == OP_RETURN) - { - opcodetype op; - std::vector opretData = std::vector(); - CScript::const_iterator it = tx.vout[1].scriptPubKey.begin() + 1; - if (tx.vout[1].scriptPubKey.GetOp2(it, op, &opretData)) - { - if (opretData.size() > 0 && opretData.data()[0] == OPRETTYPE_TIMELOCK) - { - int64_t unlocktime; - CScriptExt opretScript = CScriptExt(&opretData[1], &opretData[opretData.size()]); - - if (CScriptID(opretScript) == scriptHash && - opretScript.IsCheckLockTimeVerify(&unlocktime) && - komodo_block_unlocktime(nHeight) == unlocktime) - { - return(true); - } - } - } - } - return(false); - } - else if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { } @@ -2837,16 +2802,6 @@ namespace Consensus { REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); } - // Ensure that coinbases cannot be spent to transparent outputs - // Disabled on regtest - if (fCoinbaseEnforcedProtectionEnabled && - consensusParams.fCoinbaseMustBeProtected && - !(tx.vout.size() == 0 || (tx.vout.size() == 1 && tx.vout[0].nValue == 0)) && - (strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0 || (nSpendHeight >= 12800 && coins->nHeight >= 12800))) { - return state.DoS(100, - error("CheckInputs(): tried to spend coinbase with transparent outputs"), - REJECT_INVALID, "bad-txns-coinbase-spend-has-transparent-outputs"); - } } // Check for negative or overflow input values diff --git a/src/metrics.cpp b/src/metrics.cpp index 7a46a6dfd..5102da584 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -137,12 +137,7 @@ int64_t GetUptime() double GetLocalSolPS() { - if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1) - { - return miningTimer.rate(nHashCount); - } - else - return miningTimer.rate(solutionTargetChecks); + return miningTimer.rate(solutionTargetChecks); } int EstimateNetHeightInner(int height, int64_t tipmediantime, diff --git a/src/miner.cpp b/src/miner.cpp index 5f72ebfd2..220984bab 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -593,7 +593,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 blocktime = GetAdjustedTime(); siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig); // if you skip this check it will create a block too far into the future and not pass ProcessBlock or AcceptBlock. - // This has been moved from the mining loop to save CPU, and to also make ac_staked work with the verus miner. + // This has been moved from the mining loop to save CPU, and to also make ac_staked work while ( blocktime-57 > GetAdjustedTime() ) { sleep(1); @@ -1634,7 +1634,7 @@ void static BitcoinMiner() return; } - if ((nThreads == 0 || !fGenerate) && (VERUS_MINTBLOCKS == 0 || pwallet == NULL)) + if ((nThreads == 0 || !fGenerate) && (pwallet == NULL)) return; minerThreads = new boost::thread_group(); diff --git a/src/pow.cpp b/src/pow.cpp index b552df5db..cabea5351 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -644,20 +644,13 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: // if we have had no POS block in the threshold number of blocks, we must return the default, otherwise, we'll now have // a starting point uint32_t nBits = nProofOfStakeLimit; - for (int64_t i = 0; i < VERUS_NOPOS_THRESHHOLD; i++) + for (int64_t i = 0; i < KOMODO_NOPOS_THRESHHOLD; i++) { if (!pindexFirst) return nProofOfStakeLimit; CBlockHeader hdr = pindexFirst->GetBlockHeader(); - /* - if (hdr.IsVerusPOSBlock()) - { - nBits = hdr.GetVerusPOSTarget(); - break; - } - */ pindexFirst = pindexFirst->pprev; } @@ -667,10 +660,10 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: for (int64_t i = N - 1; i >= 0; i--) { - // we measure our solve time in passing of blocks, where one bock == VERUS_BLOCK_POSUNITS units + // we measure our solve time in passing of blocks, where one bock == KOMODO_BLOCK_POSUNITS units // consecutive blocks in either direction have their solve times exponentially multiplied or divided by power of 2 int x; - for (x = 0; x < VERUS_CONSECUTIVE_POS_THRESHOLD; x++) + for (x = 0; x < KOMODO_CONSECUTIVE_POS_THRESHOLD; x++) { pindexFirst = pindexFirst->pprev; @@ -678,29 +671,17 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: return nProofOfStakeLimit; CBlockHeader hdr = pindexFirst->GetBlockHeader(); - /* - if (hdr.IsVerusPOSBlock()) - { - nBits = hdr.GetVerusPOSTarget(); - break; - } - */ } if (x) { idx[i].consecutive = false; - if (!memcmp(ASSETCHAINS_SYMBOL, "VRSC", 4) && pindexLast->GetHeight() < 67680) - { - idx[i].solveTime = VERUS_BLOCK_POSUNITS * (x + 1); - } - else { int64_t lastSolveTime = 0; - idx[i].solveTime = VERUS_BLOCK_POSUNITS; + idx[i].solveTime = KOMODO_BLOCK_POSUNITS; for (int64_t j = 0; j < x; j++) { - lastSolveTime = VERUS_BLOCK_POSUNITS + (lastSolveTime >> 1); + lastSolveTime = KOMODO_BLOCK_POSUNITS + (lastSolveTime >> 1); idx[i].solveTime += lastSolveTime; } } @@ -712,13 +693,13 @@ uint32_t lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus:: idx[i].nBits = nBits; // go forward and halve the minimum solve time for all consecutive blocks in this run, to get here, our last block is POS, // and if there is no POS block in front of it, it gets the normal solve time of one block - uint32_t st = VERUS_BLOCK_POSUNITS; + uint32_t st = KOMODO_BLOCK_POSUNITS; for (int64_t j = i; j < N; j++) { if (idx[j].consecutive == true) { idx[j].solveTime = st; - if ((j - i) >= VERUS_CONSECUTIVE_POS_THRESHOLD) + if ((j - i) >= KOMODO_CONSECUTIVE_POS_THRESHOLD) { // if this is real time, return zero if (j == (N - 1)) @@ -875,7 +856,6 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t //else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 ) // bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime); // Check proof of work matches claimed amount - //if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() ) if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget ) { if ( KOMODO_LOADINGBLOCKS != 0 ) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 6f5254cc3..db2fbb228 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -162,7 +162,6 @@ UniValue getnetworkhashps(const UniValue& params, bool fHelp) } #ifdef ENABLE_MINING -extern bool VERUS_MINTBLOCKS; UniValue getgenerate(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -184,7 +183,7 @@ UniValue getgenerate(const UniValue& params, bool fHelp) LOCK(cs_main); UniValue obj(UniValue::VOBJ); - bool staking = VERUS_MINTBLOCKS; + bool staking = false; if ( ASSETCHAINS_STAKED != 0 && GetBoolArg("-gen", false) && GetBoolArg("-genproclimit", -1) == 0 ) staking = true; obj.push_back(Pair("staking", staking)); @@ -374,13 +373,11 @@ UniValue setgenerate(const UniValue& params, bool fHelp) { if (fGenerate && !nGenProcLimit) { - VERUS_MINTBLOCKS = 1; fGenerate = GetBoolArg("-gen", false); KOMODO_MININGTHREADS = nGenProcLimit; } else if (!fGenerate) { - VERUS_MINTBLOCKS = 0; KOMODO_MININGTHREADS = 0; } else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; @@ -499,9 +496,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC())); obj.push_back(Pair("chain", Params().NetworkIDString())); #ifdef ENABLE_MINING - bool staking = VERUS_MINTBLOCKS; - if ( ASSETCHAINS_STAKED != 0 && GetBoolArg("-gen", false) && GetBoolArg("-genproclimit", -1) == 0 ) - staking = true; + bool staking = false; obj.push_back(Pair("staking", staking)); obj.push_back(Pair("generate", GetBoolArg("-gen", false) && GetBoolArg("-genproclimit", -1) != 0 )); obj.push_back(Pair("numthreads", (int64_t)KOMODO_MININGTHREADS)); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 86e6d44ea..624e7f006 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -353,7 +353,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) if ( ASSETCHAINS_STAKED != 0 ) obj.push_back(Pair("staked", ASSETCHAINS_STAKED)); if ( ASSETCHAINS_LWMAPOS != 0 ) - obj.push_back(Pair("veruspos", ASSETCHAINS_LWMAPOS)); + obj.push_back(Pair("lwmapos", ASSETCHAINS_LWMAPOS)); if ( ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH ) obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); } diff --git a/src/util.cpp b/src/util.cpp index cc66822ad..e75ed4ca8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1031,9 +1031,8 @@ std::string LicenseInfo() FormatParagraph(strprintf(_("Copyright (C) 2015-%i The Zcash Developers"), COPYRIGHT_YEAR)) + "\n" + FormatParagraph(strprintf(_("Copyright (C) 2015-%i jl777 and SuperNET developers"), COPYRIGHT_YEAR)) + "\n" + FormatParagraph(strprintf(_("Copyright (C) 2018-%i The Hush developers"), COPYRIGHT_YEAR)) + "\n" + - FormatParagraph(strprintf(_("Copyright (C) 2018-%i The Verus developers"), COPYRIGHT_YEAR)) + "\n" + "\n" + - FormatParagraph(_("This is experimental software.")) + "\n" + + FormatParagraph(_("This is experimental software!!!")) + "\n" + "\n" + FormatParagraph(_("Distributed under the MIT software license, see the accompanying file COPYING or .")) + "\n" + "\n" + diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index 06eee1f2a..6f7b195ac 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -17,14 +17,12 @@ uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint32_t ASSETCHAINS_EQUIHASH = 0; -uint32_t ASSETCHAINS_VERUSHASH = 1; -uint32_t ASSETCHAINS_VERUSHASHV1_1 = 2; uint32_t ASSETCHAINS_ALGO = 0; int32_t ASSETCHAINS_LWMAPOS = 0; -int32_t VERUS_BLOCK_POSUNITS = 1000; int32_t ASSETCHAINS_OVERWINTER = 227520; int32_t ASSETCHAINS_SAPLING = 227520; int32_t KOMODO_TESTNODE = 0; +int32_t KOMODO_BLOCK_POSUNITS = 1000; unsigned int MAX_BLOCK_SIGOPS = 20000; From f80fc3c0022681679af84b05689cbff0d76f306e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 4 Nov 2019 11:01:52 -0500 Subject: [PATCH 4/6] update manpages and other junk --- doc/man/komodo-cli.1 | 7 +++---- doc/man/komodo-tx.1 | 7 +++---- doc/man/komodod.1 | 11 +++-------- src/chainparams.cpp | 2 +- src/primitives/nonce.cpp | 1 + 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/doc/man/komodo-cli.1 b/doc/man/komodo-cli.1 index 8297286ed..1a6db770c 100644 --- a/doc/man/komodo-cli.1 +++ b/doc/man/komodo-cli.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.10. -.TH KOMODO-CLI "1" "October 2019" "komodo-cli v3.2.1" "User Commands" +.TH KOMODO-CLI "1" "November 2019" "komodo-cli v3.2.1" "User Commands" .SH NAME komodo-cli \- manual page for komodo-cli v3.2.1 .SH DESCRIPTION -Komodo RPC client version v3.2.1\-659ebb148 +Komodo RPC client version v3.2.1\-7965ffc29\-dirty .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . @@ -79,9 +79,8 @@ Copyright (C) 2009-2019 The Bitcoin Core Developers Copyright (C) 2015-2019 The Zcash Developers Copyright (C) 2015-2019 jl777 and SuperNET developers Copyright (C) 2018-2019 The Hush developers -Copyright (C) 2018-2019 The Verus developers -This is experimental software. +This is experimental software!!! Distributed under the MIT software license, see the accompanying file COPYING or . diff --git a/doc/man/komodo-tx.1 b/doc/man/komodo-tx.1 index df0808515..52073d0f3 100644 --- a/doc/man/komodo-tx.1 +++ b/doc/man/komodo-tx.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.10. -.TH KOMODO-TX "1" "October 2019" "komodo-tx v3.2.1" "User Commands" +.TH KOMODO-TX "1" "November 2019" "komodo-tx v3.2.1" "User Commands" .SH NAME komodo-tx \- manual page for komodo-tx v3.2.1 .SH DESCRIPTION -Hush komodo\-tx utility version v3.2.1\-659ebb148 +Hush komodo\-tx utility version v3.2.1\-7965ffc29\-dirty .SS "Usage:" .TP komodo\-tx [options] [commands] @@ -92,9 +92,8 @@ Copyright (C) 2009-2019 The Bitcoin Core Developers Copyright (C) 2015-2019 The Zcash Developers Copyright (C) 2015-2019 jl777 and SuperNET developers Copyright (C) 2018-2019 The Hush developers -Copyright (C) 2018-2019 The Verus developers -This is experimental software. +This is experimental software!!! Distributed under the MIT software license, see the accompanying file COPYING or . diff --git a/doc/man/komodod.1 b/doc/man/komodod.1 index 0caab5b23..dd7b5d854 100644 --- a/doc/man/komodod.1 +++ b/doc/man/komodod.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.10. -.TH KOMODOD "1" "October 2019" "komodod v3.2.1" "User Commands" +.TH KOMODOD "1" "November 2019" "komodod v3.2.1" "User Commands" .SH NAME komodod \- manual page for komodod v3.2.1 .SH DESCRIPTION -Hush Daemon version v3.2.1\-659ebb148 +Hush Daemon version v3.2.1\-7965ffc29\-dirty .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . @@ -617,10 +617,6 @@ Timelocked coinbase stop height \fB\-ac_txpow\fR .IP Enforce transaction\-rate limit, default 0 -.HP -\fB\-ac_veruspos\fR -.IP -Use Verus Proof\-Of\-Stake (\fB\-ac_veruspos\fR=\fI\,50\/\fR) default 0 .SH COPYRIGHT In order to ensure you are adequately protecting your privacy when using Hush, @@ -630,9 +626,8 @@ Copyright (C) 2009-2019 The Bitcoin Core Developers Copyright (C) 2015-2019 The Zcash Developers Copyright (C) 2015-2019 jl777 and SuperNET developers Copyright (C) 2018-2019 The Hush developers -Copyright (C) 2018-2019 The Verus developers -This is experimental software. +This is experimental software!!! Distributed under the MIT software license, see the accompanying file COPYING or . diff --git a/src/chainparams.cpp b/src/chainparams.cpp index cfcf48313..28c738891 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -105,7 +105,7 @@ public: strNetworkID = "main"; strCurrencyUnits = "KMD"; bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md - consensus.fCoinbaseMustBeProtected = false; // true this is only true wuth Verus and enforced after block 12800 + consensus.fCoinbaseMustBeProtected = false; consensus.nSubsidySlowStartInterval = 20000; consensus.nSubsidyHalvingInterval = 840000; consensus.nMajorityEnforceBlockUpgrade = 750; diff --git a/src/primitives/nonce.cpp b/src/primitives/nonce.cpp index a512b757d..a1fbd667d 100644 --- a/src/primitives/nonce.cpp +++ b/src/primitives/nonce.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2019 The Hush Developers // Copyright (c) 2018 Michael Toutonghi // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. From e87d02996854b4f8eabc95c0f4c009fe1df0640e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 5 Nov 2019 09:39:11 -0500 Subject: [PATCH 5/6] Mostly-working Hush full node sans Verus!!! Every line of Verus-specific code has been removed from the codebase. This code compiles on Linux and can do a partial sync. A full sync and other extensive tests need to be done before it's merged into the duke branch. BUGS: One known bug is that the node starts to CPU mine by default, lol. --- src/Makefile.am | 1 - src/cc/CCinclude.h | 11 --- src/cc/COptCCParams.cpp | 116 -------------------------------- src/keystore.h | 1 - src/main.cpp | 1 - src/main.h | 1 - src/miner.cpp | 33 ++------- src/script/script_ext.cpp | 137 -------------------------------------- src/script/script_ext.h | 65 ------------------ src/wallet/rpcwallet.cpp | 7 +- src/wallet/wallet.cpp | 8 ++- 11 files changed, 13 insertions(+), 368 deletions(-) delete mode 100644 src/cc/COptCCParams.cpp delete mode 100644 src/script/script_ext.cpp delete mode 100644 src/script/script_ext.h diff --git a/src/Makefile.am b/src/Makefile.am index 30ecd9ff5..99ef1a36a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -457,7 +457,6 @@ libbitcoin_common_a_SOURCES = \ script/cc.cpp \ script/interpreter.cpp \ script/script.cpp \ - script/script_ext.cpp \ script/script_error.cpp \ script/sign.cpp \ script/standard.cpp \ diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2ee42f0fa..0e9f7bad2 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -103,17 +103,6 @@ struct CC_utxo int32_t vout; }; -// these are the parameters stored after Verus crypto-condition vouts. new versions may change -// the format -struct CC_meta -{ - std::vector version; - uint8_t evalCode; - bool is1of2; - uint8_t numDestinations; - // followed by address destinations -}; - struct CCcontract_info { // this is for spending from 'unspendable' CC address diff --git a/src/cc/COptCCParams.cpp b/src/cc/COptCCParams.cpp deleted file mode 100644 index 41c9ba874..000000000 --- a/src/cc/COptCCParams.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*Descriptson and examples of COptCCParams class found in: - script/standard.h/cpp - class COptCCParams - -structure of data in vData payload attached to end of CCvout: - param - OP_1 - param - OP_2 ... etc until OP_16 - OP_PUSHDATA4 is the last OP code to tell things its at the end. - - taken from standard.cpp line 22: COptCCParams::COptCCParams(std::vector &vch) - -EXAMPLE taken from Verus how to create scriptPubKey from COptCCParams class: -EXAMPLE taken from Verus how to decode scriptPubKey from COptCCParams class: -*/ - -bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxOut &vout) -{ - CCcontract_info *cp, C; - cp = CCinit(&C,EVAL_STAKEGUARD); - - CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr)); - - // return an output that is bound to the stake transaction and can be spent by presenting either a signed condition by the original - // destination address or a properly signed stake transaction of the same utxo on a fork - vout = MakeCC1of2vout(EVAL_STAKEGUARD, value, dest, ccAddress); - - std::vector vPubKeys = std::vector(); - vPubKeys.push_back(dest); - vPubKeys.push_back(ccAddress); - - std::vector> vData = std::vector>(); - - CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - hw << stakeTx.vin[0].prevout.hash; - hw << stakeTx.vin[0].prevout.n; - - uint256 utxo = hw.GetHash(); - vData.push_back(std::vector(utxo.begin(), utxo.end())); // Can we use any data here to construct vector? - - CStakeParams p; - if (GetStakeParams(stakeTx, p)) - { - // prev block hash and height is here to make validation easy - vData.push_back(std::vector(p.prevHash.begin(), p.prevHash.end())); - std::vector height = std::vector(4); - for (int i = 0; i < 4; i++) - { - height[i] = (p.blkHeight >> (8 * i)) & 0xff; - } - vData.push_back(height); - - COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_STAKEGUARD, 1, 2, vPubKeys, vData); - - vout.scriptPubKey << ccp.AsVector() << OP_DROP; - return true; - } - return false; -} - -bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating) -{ - // an invalid or non-matching stake transaction cannot cheat - cheating = false; - - //printf("ValidateMatchingStake: ccTx.vin[0].prevout.hash: %s, ccTx.vin[0].prevout.n: %d\n", ccTx.vin[0].prevout.hash.GetHex().c_str(), ccTx.vin[0].prevout.n); - - if (ccTx.IsCoinBase()) - { - CStakeParams p; - if (ValidateStakeTransaction(stakeTx, p)) - { - std::vector> vParams = std::vector>(); - CScript dummy; - - if (ccTx.vout[voutNum].scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() > 0) - { - COptCCParams ccp = COptCCParams(vParams[0]); - if (ccp.IsValid() & ccp.vData.size() >= 3 && ccp.vData[2].size() <= 4) - { - CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); - - hw << stakeTx.vin[0].prevout.hash; - hw << stakeTx.vin[0].prevout.n; - uint256 utxo = hw.GetHash(); - - uint32_t height = 0; - int i, dataLen = ccp.vData[2].size(); - for (i = dataLen - 1; i >= 0; i--) - { - height = (height << 8) + ccp.vData[2][i]; - } - // for debugging strange issue - // printf("iterator: %d, height: %d, datalen: %d\n", i, height, dataLen); - - if (utxo == uint256(ccp.vData[0])) - { - if (p.prevHash != uint256(ccp.vData[1]) && p.blkHeight >= height) - { - cheating = true; - return true; - } - // if block height is equal and we are at the else, prevHash must have been equal - else if (p.blkHeight == height) - { - return true; - } - } - } - } - } - } - return false; -} diff --git a/src/keystore.h b/src/keystore.h index bab236e24..c2e1f25d9 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -25,7 +25,6 @@ #include "pubkey.h" #include "script/script.h" #include "script/standard.h" -#include "script/script_ext.h" #include "sync.h" #include "zcash/Address.hpp" #include "zcash/NoteEncryption.hpp" diff --git a/src/main.cpp b/src/main.cpp index 7636e1bdb..f1beaa2c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4122,7 +4122,6 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - //if ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))) if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0))) { #ifdef ENABLE_WALLET diff --git a/src/main.h b/src/main.h index 800f05745..f49c30518 100644 --- a/src/main.h +++ b/src/main.h @@ -37,7 +37,6 @@ #include "script/script.h" #include "script/serverchecker.h" #include "script/standard.h" -#include "script/script_ext.h" #include "spentindex.h" #include "sync.h" #include "tinyformat.h" diff --git a/src/miner.cpp b/src/miner.cpp index 220984bab..090cf83cf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -691,31 +691,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { - int32_t opretlen, p2shlen, scriptlen; - CScriptExt opretScript = CScriptExt(); - - txNew.vout.resize(2); - - // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins - // protected only by the time lock rather than 100% inaccessible - opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); - if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) - { - fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); - if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) - { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); - } - return 0; - } - - opretScript += scriptPubKeyIn; - - txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); - txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); - txNew.vout[1].nValue = 0; - // timelocks and commissions are currently incompatible due to validation complexity of the combination + fprintf(stderr,"timelocked chains not supported in this code!\n"); + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + return(0); } else if ( fNotarisationBlock && ASSETCHAINS_NOTARY_PAY[0] != 0 && pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) { @@ -749,7 +728,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; - // if not Verus stake, setup nonce, otherwise, leave it alone + // if not staking, setup nonce, otherwise, leave it alone if (!isStake || ASSETCHAINS_LWMAPOS == 0) { // Randomise nonce @@ -765,7 +744,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashFinalSaplingRoot = sapling_tree.root(); - // all Verus PoS chains need this data in the block at all times + // all PoS chains need this data in the block at all times if ( ASSETCHAINS_LWMAPOS || ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || KOMODO_MININGTHREADS > 0 ) { UpdateTime(pblock, Params().GetConsensus(), pindexPrev); diff --git a/src/script/script_ext.cpp b/src/script/script_ext.cpp deleted file mode 100644 index f1d903946..000000000 --- a/src/script/script_ext.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2018 The Verus developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -/****************************************************************************** - * Copyright © 2014-2019 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#include "script_ext.h" - -using namespace std; - -bool CScriptExt::IsPayToScriptHash(CScriptID *scriptID) const -{ - if (((CScript *)this)->IsPayToScriptHash()) - { - *scriptID = CScriptID(uint160(std::vector(this->begin() + 2, this->end() - 1))); - return true; - } - return false; -} - -// P2PKH script, adds to whatever is already in the script (for example CLTV) -const CScriptExt &CScriptExt::AddPayToPubKeyHash(const CKeyID &key) const -{ - *((CScript *)this) << OP_DUP; - *((CScript *)this) << OP_HASH160; - *((CScript *)this) << ToByteVector(key); - *((CScript *)this) << OP_EQUALVERIFY; - *((CScript *)this) << OP_CHECKSIG; - return *this; -} - -// push data into an op_return script with an opret type indicator, fails if the op_return is too large -const CScriptExt &CScriptExt::OpReturnScript(const vector &data, unsigned char opretType) const -{ - ((CScript *)this)->clear(); - if (data.size() < MAX_SCRIPT_ELEMENT_SIZE) - { - vector scratch = vector(data); - scratch.insert(scratch.begin(), opretType); - *((CScript *)this) << OP_RETURN; - *((CScript *)this) << scratch; - } - return *this; -} - -// push data into an op_return script with an opret type indicator, fails if the op_return is too large -const CScriptExt &CScriptExt::OpReturnScript(const CScript &src, unsigned char opretType) const -{ - vector vch = vector(src.begin(), src.end()); - return OpReturnScript(vch, opretType); -} - -// P2SH script, adds to whatever is already in the script (for example CLTV) -const CScriptExt &CScriptExt::PayToScriptHash(const CScriptID &scriptID) const -{ - ((CScript *)this)->clear(); - *((CScript *)this) << OP_HASH160; - *((CScript *)this) << ToByteVector(scriptID); - *((CScript *)this) << OP_EQUAL; - return *this; -} - -// P2SH script, adds to whatever is already in the script (for example CLTV) -const CScriptExt &CScriptExt::AddCheckLockTimeVerify(int64_t unlocktime) const -{ - if (unlocktime > 0) - { - *((CScript *)this) << CScriptNum::serialize(unlocktime); - *((CScript *)this) << OP_CHECKLOCKTIMEVERIFY; - *((CScript *)this) << OP_DROP; - return *this; - } - return *this; -} - -// combined CLTV script and P2PKH -const CScriptExt &CScriptExt::TimeLockSpend(const CKeyID &key, int64_t unlocktime) const -{ - ((CScript *)this)->clear(); - this->AddCheckLockTimeVerify(unlocktime); - this->AddPayToPubKeyHash(key); - return *this; -} - -/** - * provide destination extraction for non-standard, timelocked coinbase transactions - * as well as other transactions - */ -bool CScriptExt::ExtractVoutDestination(const CTransaction& tx, int32_t voutNum, CTxDestination& addressRet) -{ - if (tx.vout.size() <= voutNum) - return false; - - CScriptID scriptHash; - CScriptExt spk = tx.vout[voutNum].scriptPubKey; - - // if this is a timelocked transaction, get the destination behind the time lock - if (tx.IsCoinBase() && tx.vout.size() == 2 && voutNum == 0 && - spk.IsPayToScriptHash(&scriptHash) && - tx.vout[1].scriptPubKey.IsOpReturn()) - { - opcodetype op; - std::vector opretData = std::vector(); - CScript::const_iterator it = tx.vout[1].scriptPubKey.begin() + 1; - if (tx.vout[1].scriptPubKey.GetOp2(it, op, &opretData)) - { - if (opretData.size() > 0 && opretData[0] == OPRETTYPE_TIMELOCK) - { - int64_t unlocktime; - CScriptExt se = CScriptExt(&opretData[1], &opretData[opretData.size()]); - - if (CScriptID(se) == scriptHash && - se.IsCheckLockTimeVerify(&unlocktime)) - { - spk = se; - } - } - } - } - return ExtractDestination(spk, addressRet); -} - diff --git a/src/script/script_ext.h b/src/script/script_ext.h deleted file mode 100644 index e14cbd1f7..000000000 --- a/src/script/script_ext.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2018 The Verus developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -/****************************************************************************** - * Copyright © 2014-2019 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#ifndef BITCOIN_SCRIPT_SCRIPT_EXT_H -#define BITCOIN_SCRIPT_SCRIPT_EXT_H - -#include "script.h" -#include "standard.h" -#include "pubkey.h" - -#include - -class CScriptExt : public CScript -{ - public: - CScriptExt() { } - CScriptExt(const CScript& b) : CScript(b) { } - CScriptExt(const_iterator pbegin, const_iterator pend) : CScript(pbegin, pend) { } - CScriptExt(const unsigned char* pbegin, const unsigned char* pend) : CScript(pbegin, pend) { } - - // overload to return the hash of the referenced script - bool IsPayToScriptHash(CScriptID *scriptID) const; - - // P2PKH script, adds to whatever is already in the script (for example CLTV) - const CScriptExt &AddPayToPubKeyHash(const CKeyID &key) const; - - // push data into an op_return script with an opret type indicator, fails if the op_return is too large - const CScriptExt &OpReturnScript(const std::vector &data, unsigned char opretType) const; - - // push data into an op_return script with an opret type indicator, fails if the op_return is too large - const CScriptExt &OpReturnScript(const CScript &src, unsigned char opretType) const; - - // P2SH script - const CScriptExt &PayToScriptHash(const CScriptID &scriptID) const; - - // P2SH script, adds to whatever is already in the script (for example CLTV) - const CScriptExt &AddCheckLockTimeVerify(int64_t unlocktime) const; - - // combined CLTV script and P2PKH - const CScriptExt &TimeLockSpend(const CKeyID &key, int64_t unlocktime) const; - - // lookup for destinations that includes non-standard destinations for time locked coinbases - static bool ExtractVoutDestination(const CTransaction& tx, int32_t voutNum, CTxDestination& addressRet); -}; - -#endif - diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c2935c0c0..b233ad3bd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -1858,11 +1859,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe entry.push_back(Pair("involvesWatchonly", true)); entry.push_back(Pair("account", account)); - CTxDestination dest; - if (CScriptExt::ExtractVoutDestination(wtx, r.vout, dest)) - MaybePushAddress(entry, dest); - else - MaybePushAddress(entry, r.destination); + MaybePushAddress(entry, r.destination); if (bIsCoinbase) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1744ef0b6..41aa9eabe 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -2084,13 +2085,13 @@ bool CWallet::IsMine(const CTransaction& tx) return false; } -// special case handling for non-standard/Verus OP_RETURN script outputs, which need the transaction +// special case handling for non-standard OP_RETURN script outputs, which need the transaction // to determine ownership isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) { vector vSolutions; txnouttype whichType; - const CScriptExt scriptPubKey = CScriptExt(tx.vout[voutNum].scriptPubKey); + const CScript scriptPubKey = CScript(tx.vout[voutNum].scriptPubKey); if (!Solver(scriptPubKey, whichType, vSolutions)) { if (this->HaveWatchOnly(scriptPubKey)) @@ -2100,7 +2101,7 @@ isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) CKeyID keyID; CScriptID scriptID; - CScriptExt subscript; + CScript subscript; int voutNext = voutNum + 1; switch (whichType) @@ -2134,6 +2135,7 @@ isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum) case TX_SCRIPTHASH: scriptID = CScriptID(uint160(vSolutions[0])); + //TODO: remove CLTV stuff not relevant to Hush if (this->GetCScript(scriptID, subscript)) { // if this is a CLTV, handle it differently From 9bfd9fce6a8f65c205a64cf100702d575b796280 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 14 Nov 2019 22:46:31 -0500 Subject: [PATCH 6/6] Fix logic bug that started mining by default and clean up lots of stuff --- src/miner.cpp | 22 ++++++---------------- src/rpc/mining.cpp | 23 +++++------------------ 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 090cf83cf..b04ff285d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1604,28 +1604,18 @@ void static BitcoinMiner() minerThreads = NULL; } - //fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate); - if ( ASSETCHAINS_STAKED > 0 && nThreads == 0 && fGenerate ) - { - if ( pwallet != NULL ) - nThreads = 1; - else - return; - } + fprintf(stderr,"%s: nThreads.%d fGenerate.%d\n",__FUNCTION__, (int32_t)nThreads,fGenerate); - if ((nThreads == 0 || !fGenerate) && (pwallet == NULL)) + if (nThreads == 0) + return; + if (!fGenerate) + return; + if (pwallet == NULL) return; minerThreads = new boost::thread_group(); -#ifdef ENABLE_WALLET - if (ASSETCHAINS_LWMAPOS != 0) - { - } -#endif - for (int i = 0; i < nThreads; i++) { - #ifdef ENABLE_WALLET if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index db2fbb228..5354b7d07 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -369,25 +370,11 @@ UniValue setgenerate(const UniValue& params, bool fHelp) //if (nGenProcLimit == 0) // fGenerate = false; } - if ( ASSETCHAINS_LWMAPOS != 0 ) - { - if (fGenerate && !nGenProcLimit) - { - fGenerate = GetBoolArg("-gen", false); - KOMODO_MININGTHREADS = nGenProcLimit; - } - else if (!fGenerate) - { - KOMODO_MININGTHREADS = 0; - } - else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; - } - else - { - KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; - } - mapArgs["-gen"] = (fGenerate ? "1" : "0"); + KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; + fprintf(stderr,"%s:KOMODO_MININGTHREADS=%d\n", __FUNCTION__, KOMODO_MININGTHREADS); + + mapArgs["-gen"] = (fGenerate ? "1" : "0"); mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); #ifdef ENABLE_WALLET