diff --git a/src/komodo.h b/src/komodo.h index 791adba33..3ceb29cc3 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -836,16 +836,6 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) int8_t numSN = numStakedNotaries(tmp_pubkeys,staked_era); UpdateNotaryAddrs(tmp_pubkeys,numSN); STAKED_ERA = staked_era; - if ( NOTARYADDRS[0][0] != 0 && NOTARY_PUBKEY33[0] != 0 ) - { - if ( (IS_STAKED_NOTARY= updateStakedNotary()) > -1 ) - { - IS_KOMODO_NOTARY = 0; - if ( MIN_RECV_SATS == -1 ) - MIN_RECV_SATS = 100000000; - fprintf(stderr, "Staked Notary Protection Active! NotaryID.%d RADD.%s ERA.%d MIN_TX_VALUE.%lu \n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),staked_era,MIN_RECV_SATS); - } - } lastStakedEra = staked_era; } } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 49aa67081..9377ea276 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -80,9 +80,9 @@ extern int32_t VERUS_MIN_STAKEAGE; extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; +extern char NOTARYADDRS[64][64]; int tx_height( const uint256 &hash ); -extern char NOTARYADDRS[64][36]; -extern uint8_t NUM_NOTARIES; +extern std::vector vWhiteListAddress; void komodo_netevent(std::vector payload); int32_t komodo_priceind(char *symbol); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 1c47e72e6..eccbb34f1 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -47,12 +47,14 @@ unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; 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; 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,WHITELIST_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,NUM_NOTARIES,ASSETCHAINS_MARMARA; +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; bool VERUS_MINTBLOCKS; std::vector Mineropret; +std::vector vWhiteListAddress; +char NOTARYADDRS[64][64]; -char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096],NOTARYADDRS[64][36]; +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_BEAMPORT,ASSETCHAINS_CODAPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1,STAKING_MIN_DIFF; uint32_t ASSETCHAINS_MAGIC = 2387029918; @@ -99,7 +101,7 @@ int32_t ASSETCHAINS_OVERWINTER = -1; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; int32_t ASSETCHAINS_STAKED; -uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10,MIN_RECV_SATS,ASSETCHAINS_FOUNDERS_REWARD; +uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10,ASSETCHAINS_FOUNDERS_REWARD; uint32_t KOMODO_INITDONE; char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2d0fe4f4e..043d7282e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1677,8 +1677,6 @@ void komodo_args(char *argv0) fprintf(stderr, "Cannot be STAKED and KMD notary at the same time!\n"); exit(0); } - MIN_RECV_SATS = GetArg("-mintxvalue",-1); - WHITELIST_ADDRESS = GetArg("-whitelistaddress",""); memset(ccenables,0,sizeof(ccenables)); memset(disablebits,0,sizeof(disablebits)); if ( GetBoolArg("-gen", false) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 8fbc0f1dd..faa9e6a9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1270,9 +1270,6 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState } } -extern char NOTARYADDRS[64][36]; -extern uint8_t NUM_NOTARIES; - int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only { static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; diff --git a/src/miner.cpp b/src/miner.cpp index f131bc90e..54b18195a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -224,8 +224,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 CBlockIndex* pindexPrev = 0; { - ENTER_CRITICAL_SECTION(cs_main); - ENTER_CRITICAL_SECTION(mempool.cs); + LOCK2(cs_main,mempool.cs); pindexPrev = chainActive.LastTip(); const int nHeight = pindexPrev->GetHeight() + 1; const Consensus::Params &consensusParams = chainparams.GetConsensus(); @@ -564,11 +563,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x stake.%i\n", nBlockSize,blocktime,pblock->nBits,isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight); - + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); if (ASSETCHAINS_LWMAPOS != 0) { uint32_t nBitsPOS; @@ -593,7 +591,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { sleep(1); if ( (rand() % 100) < 1 ) - fprintf(stderr, "%u seconds until elegible, waiting.\n", blocktime-((uint32_t)GetAdjustedTime()+57)); + fprintf(stderr, "%u seconds until elegible, waiting...\n", blocktime-((uint32_t)GetAdjustedTime()+57)); if ( chainActive.LastTip()->GetHeight() >= stakeHeight ) { fprintf(stderr, "Block Arrived, reset staking loop.\n"); @@ -603,7 +601,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 return(0); } } - + ENTER_CRITICAL_SECTION(cs_main); + ENTER_CRITICAL_SECTION(mempool.cs); if ( siglen > 0 ) { CAmount txfees; @@ -616,7 +615,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nFees += txfees; pblock->nTime = blocktime; //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); - } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); + } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } // Create coinbase tx @@ -688,11 +687,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 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; } @@ -714,11 +708,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( totalsats == 0 ) { fprintf(stderr, "Could not create notary payment, trying again.\n"); - if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) - { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); - } return(0); } fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats); @@ -789,11 +778,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 else { fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n"); - if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) - { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); - } return(0); } } @@ -808,11 +792,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"valid\n"); } } - if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) - { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); - } //fprintf(stderr,"done new block\n"); return pblocktemplate.release(); } diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index a3278ac12..0b7c97ceb 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -4,11 +4,11 @@ #include "cc/CCinclude.h" #include -extern char NOTARYADDRS[64][36]; +extern char NOTARYADDRS[64][64]; extern std::string NOTARY_ADDRESS,NOTARY_PUBKEY; extern int32_t STAKED_ERA,IS_STAKED_NOTARY,IS_KOMODO_NOTARY; extern pthread_mutex_t staked_mutex; -extern uint8_t NOTARY_PUBKEY33[33],NUM_NOTARIES; +extern uint8_t NOTARY_PUBKEY33[33]; int8_t is_STAKED(const char *chain_name) { @@ -46,16 +46,6 @@ int32_t STAKED_era(int timestamp) return(0); }; -int8_t updateStakedNotary() { - std::string notaryname; - char Raddress[18]; uint8_t pubkey33[33]; - decode_hex(pubkey33,33,(char *)NOTARY_PUBKEY.c_str()); - pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); - NOTARY_ADDRESS.clear(); - NOTARY_ADDRESS.assign(Raddress); - return(StakedNotaryID(notaryname,Raddress)); -} - int8_t StakedNotaryID(std::string ¬aryname, char *Raddress) { if ( STAKED_ERA != 0 ) { @@ -116,7 +106,6 @@ void UpdateNotaryAddrs(uint8_t pubkeys[64][33],int8_t numNotaries) { // null pubkeys, era 0. pthread_mutex_lock(&staked_mutex); memset(NOTARYADDRS,0,sizeof(NOTARYADDRS)); - NUM_NOTARIES = 0; pthread_mutex_unlock(&staked_mutex); } else @@ -125,7 +114,6 @@ void UpdateNotaryAddrs(uint8_t pubkeys[64][33],int8_t numNotaries) { pthread_mutex_lock(&staked_mutex); for (int i = 0; i builder; if (isToSaplingZaddr || saplingNoteInputs.size() > 0) { builder = TransactionBuilder(Params().GetConsensus(), nextBlockHeight, pwalletMain); - } + } else + contextualTx.nExpiryHeight = 0; // set non z-tx to have no expiry height. + // Create operation and add to global queue std::shared_ptr q = getAsyncRPCQueue(); std::shared_ptr operation( diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 35edc24c6..9b2975db1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -38,6 +38,7 @@ #include "crypter.h" #include "coins.h" #include "zcash/zip32.h" +#include "cc/CCinclude.h" #include @@ -1747,11 +1748,6 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx) * pblock is optional, but should be provided if the transaction is known to be in a block. * If fUpdate is true, existing transactions will be updated. */ -extern uint8_t NOTARY_PUBKEY33[33]; -extern std::string NOTARY_ADDRESS,WHITELIST_ADDRESS; -extern int32_t IS_STAKED_NOTARY; -extern uint64_t MIN_RECV_SATS; -#include "cc/CCinclude.h" bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) { @@ -1777,14 +1773,20 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl char Raddress[64]; pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); NotaryAddress.assign(Raddress); - fprintf(stderr, "notary address set to %s\n", NotaryAddress.c_str()); + vWhiteListAddress = mapMultiArgs["-whitelistaddress"]; + if ( !vWhiteListAddress.empty() ) + { + fprintf(stderr, "Activated Wallet Filter \n Notary Address: %s \n Adding whitelist address's:\n", NotaryAddress.c_str()); + for ( auto wladdr : vWhiteListAddress ) + fprintf(stderr, " %s\n", wladdr.c_str()); + } } if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0) { - // wallet filter for notary nodes. Disabled! Can be reenabled or customised for any specific use, pools could also use this to prevent wallet dwy attack. - if ( !tx.IsCoinBase() && !WHITELIST_ADDRESS.empty() && !NotaryAddress.empty() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) + // wallet filter for notary nodes. Enables by setting -whitelistaddress= as startup param or in conf file (works same as -addnode byut with R-address's) + if ( !tx.IsCoinBase() && !vWhiteListAddress.empty() && !NotaryAddress.empty() ) { - int numvinIsOurs = 0, numvinIsWhiteList = 0; // numvoutIsOurs = 0, int64_t totalvoutvalue = 0; + int numvinIsOurs = 0, numvinIsWhiteList = 0; for (size_t i = 0; i < tx.vin.size(); i++) { uint256 hash; CTransaction txin; CTxDestination address; @@ -1792,50 +1794,21 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl { if ( CBitcoinAddress(address).ToString() == NotaryAddress ) numvinIsOurs++; - if ( CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) - numvinIsWhiteList++; - } - } - // Now we know if it was a tx sent to us, that wasnt from ourself or the whitelist address if set.. - if ( numvinIsOurs != 0 ) - fprintf(stderr, "We sent from address: %s vins: %d\n",NotaryAddress.c_str(),numvinIsOurs); - if ( numvinIsWhiteList != 0 ) - fprintf(stderr, "We received from whitelisted address: %s\n",WHITELIST_ADDRESS.c_str()); - // Count vouts, check if OUR notary address is the receiver. - if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 ) - { - return false; - /*/ if MIN_RECV_SATS is 0, we are on full lock down mode, accept NO transactions. - if ( 1 ) { //MIN_RECV_SATS == 0 ) { - fprintf(stderr, "This node is on full lock down all txs are ignored! \n"); - return false; - } - for (size_t i = 0; i < tx.vout.size() ; i++) - { - CTxDestination address2; - if ( ExtractDestination(tx.vout[i].scriptPubKey, address2)) + for ( auto wladdr : vWhiteListAddress ) { - if ( CBitcoinAddress(address2).ToString() == NOTARY_ADDRESS ) + if ( CBitcoinAddress(address).ToString() == wladdr ) { - numvoutIsOurs++; - totalvoutvalue += tx.vout[i].nValue; + //fprintf(stderr, "We received from whitelisted address.%s\n", wladdr.c_str()); + numvinIsWhiteList++; } } } - // If no vouts are to the notary address we will ignore them. - if ( numvoutIsOurs == 0 ) { - fprintf(stderr, "Received transaction to address other than notary address, ignored! \n"); - return false; - } - fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,(int32_t)numvoutIsOurs); - // here we add calculation for number if vouts received, average size and determine if we accept them to wallet or not. - int64_t avgVoutSize = totalvoutvalue / numvoutIsOurs; - if ( avgVoutSize < MIN_RECV_SATS ) { - // average vout size is less than set minimum, default is 1 coin, we will ignore it - fprintf(stderr, "ignored: %d vouts average size of %ld sats.\n",numvoutIsOurs, (long)avgVoutSize); - return false; - } */ } + // Now we know if it was a tx sent to us, by either a whitelisted address, or ourself. + if ( numvinIsOurs != 0 ) + fprintf(stderr, "We sent from address: %s vins: %d\n",NotaryAddress.c_str(),numvinIsOurs); + if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 ) + return false; } CWalletTx wtx(this,tx);