From d8edaa38ecf3b9aa3be5470c89d1ec508bcc3380 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 01:36:30 +0800 Subject: [PATCH 01/14] make wallet filter work for testnet notary --- src/wallet/wallet.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1208a77f2..003404c97 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1772,7 +1772,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl 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 ( 0 && !tx.IsCoinBase() && !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) + if ( !tx.IsCoinBase() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) { int numvinIsOurs = 0, numvoutIsOurs = 0, numvinIsWhiteList = 0; int64_t totalvoutvalue = 0; for (size_t i = 0; i < tx.vin.size(); i++) @@ -1782,7 +1782,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl { if (ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address)) { - if ( CBitcoinAddress(address).ToString() == NOTARY_ADDRESS ) + if ( CBitcoinAddress(address).ToString() == "RXhapCShoqNeWytLXeWR2wX7m5xfNYfxNx" ) numvinIsOurs++; if ( !WHITELIST_ADDRESS.empty() ) { @@ -1803,6 +1803,11 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl // Count vouts, check if OUR notary address is the receiver. if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 ) { + // 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; @@ -1815,11 +1820,6 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl } } } - // if MIN_RECV_SATS is 0, we are on full lock down mode, accept NO transactions. - if ( MIN_RECV_SATS == 0 ) { - fprintf(stderr, "This node is on full lock down all txs are ignored! \n"); - return false; - } // 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"); From 7e74cb117ca964bf7a415656b2e622edc95d3599 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 01:39:38 +0800 Subject: [PATCH 02/14] fix --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 003404c97..592a22c34 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1804,7 +1804,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl if ( numvinIsOurs == 0 && numvinIsWhiteList == 0 ) { // if MIN_RECV_SATS is 0, we are on full lock down mode, accept NO transactions. - if ( 1 ) //MIN_RECV_SATS == 0 ) { + if ( 1 ) { //MIN_RECV_SATS == 0 ) { fprintf(stderr, "This node is on full lock down all txs are ignored! \n"); return false; } From faea9232848f80892130f6f3d76cc0372560ed98 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 05:10:52 +0800 Subject: [PATCH 03/14] set notary address from -pubkey filter still default to on. --- src/wallet/wallet.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 592a22c34..c16720e60 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1751,6 +1751,8 @@ 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; +bool WALLET_FILTER = true; +#include "cc/CCinclude.h" bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) { @@ -1769,41 +1771,41 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl return false; } } + static std::string NotaryAddress; static bool didinit; + if ( !didinit && NotaryAddress.empty() && NOTARY_PUBKEY33[0] != 0 ) + { + didinit = true; + char Raddress[64]; + pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); + NotaryAddress.assign(Raddress); + } 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() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) + if ( !tx.IsCoinBase() && WALLET_FILTER && !NotaryAddress.empty() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) { - int numvinIsOurs = 0, numvoutIsOurs = 0, numvinIsWhiteList = 0; int64_t totalvoutvalue = 0; + int numvinIsOurs = 0, numvinIsWhiteList = 0; // numvoutIsOurs = 0, int64_t totalvoutvalue = 0; for (size_t i = 0; i < tx.vin.size(); i++) { uint256 hash; CTransaction txin; CTxDestination address; - if (GetTransaction(tx.vin[i].prevout.hash,txin,hash,false)) + if ( GetTransaction(tx.vin[i].prevout.hash,txin,hash,false) && ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address) ) { - if (ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address)) - { - if ( CBitcoinAddress(address).ToString() == "RXhapCShoqNeWytLXeWR2wX7m5xfNYfxNx" ) - numvinIsOurs++; - if ( !WHITELIST_ADDRESS.empty() ) - { - //fprintf(stderr, "white list address: %s recv address: %s\n", WHITELIST_ADDRESS.c_str(),CBitcoinAddress(address).ToString().c_str()); - if ( CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) { - //fprintf(stderr, "whitlisted is set to true here.\n"); - numvinIsWhiteList++; - } - } - } + if ( CBitcoinAddress(address).ToString() == NotaryAddress ) + numvinIsOurs++; + if ( !WHITELIST_ADDRESS.empty() && 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",NOTARY_ADDRESS.c_str(),numvinIsOurs); + 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 ) { - // if MIN_RECV_SATS is 0, we are on full lock down mode, accept NO transactions. + 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; @@ -1832,7 +1834,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl // 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; - } + } */ } } From a30fb4ae364d3040e352dc154d197c3a6ba33c8f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 05:38:10 +0800 Subject: [PATCH 04/14] test --- src/wallet/wallet.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c16720e60..ac6b7d6c0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1778,6 +1778,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl char Raddress[64]; pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); NotaryAddress.assign(Raddress); + fprintf(stderr, "1 notary address.%s\n", NotaryAddress.c_str()); } if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0) { @@ -1790,12 +1791,14 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl uint256 hash; CTransaction txin; CTxDestination address; if ( GetTransaction(tx.vin[i].prevout.hash,txin,hash,false) && ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address) ) { + fprintf(stderr, "2 notary address.%s address.%s\n", NotaryAddress.c_str(), address.c_str()); if ( CBitcoinAddress(address).ToString() == NotaryAddress ) numvinIsOurs++; if ( !WHITELIST_ADDRESS.empty() && CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) numvinIsWhiteList++; } } + fprintf(stderr, "3 notary address.%s\n", NotaryAddress.c_str()); // 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); From 0d587ccc31697e1a758d27e9bd4da10aa3093a60 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 05:39:34 +0800 Subject: [PATCH 05/14] fix --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ac6b7d6c0..279b149e8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1791,7 +1791,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl uint256 hash; CTransaction txin; CTxDestination address; if ( GetTransaction(tx.vin[i].prevout.hash,txin,hash,false) && ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address) ) { - fprintf(stderr, "2 notary address.%s address.%s\n", NotaryAddress.c_str(), address.c_str()); + fprintf(stderr, "2 notary address.%s address.%s\n", NotaryAddress.c_str(), CBitcoinAddress(address).ToString().c_str()); if ( CBitcoinAddress(address).ToString() == NotaryAddress ) numvinIsOurs++; if ( !WHITELIST_ADDRESS.empty() && CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) From 6f5e339884dcee6c825c59de2aa339e2db2be1cb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 05:50:06 +0800 Subject: [PATCH 06/14] fix --- src/wallet/wallet.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 279b149e8..f4a52cf24 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1778,7 +1778,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl char Raddress[64]; pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); NotaryAddress.assign(Raddress); - fprintf(stderr, "1 notary address.%s\n", NotaryAddress.c_str()); + fprintf(stderr, "notary address set to %s\n", NotaryAddress.c_str()); } if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0) { @@ -1791,14 +1791,12 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl uint256 hash; CTransaction txin; CTxDestination address; if ( GetTransaction(tx.vin[i].prevout.hash,txin,hash,false) && ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address) ) { - fprintf(stderr, "2 notary address.%s address.%s\n", NotaryAddress.c_str(), CBitcoinAddress(address).ToString().c_str()); if ( CBitcoinAddress(address).ToString() == NotaryAddress ) numvinIsOurs++; if ( !WHITELIST_ADDRESS.empty() && CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) numvinIsWhiteList++; } } - fprintf(stderr, "3 notary address.%s\n", NotaryAddress.c_str()); // 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); From e101aa3f9bf3e5e831237dd5519d06a93c0a040b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 06:10:02 +0800 Subject: [PATCH 07/14] make -whitelistaddress= activate wallet filter --- src/wallet/wallet.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index f4a52cf24..35edc24c6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1751,7 +1751,6 @@ 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; -bool WALLET_FILTER = true; #include "cc/CCinclude.h" bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) @@ -1783,7 +1782,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl 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() && WALLET_FILTER && !NotaryAddress.empty() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) + if ( !tx.IsCoinBase() && !WHITELIST_ADDRESS.empty() && !NotaryAddress.empty() ) //&& !NOTARY_ADDRESS.empty() && IS_STAKED_NOTARY > -1 ) { int numvinIsOurs = 0, numvinIsWhiteList = 0; // numvoutIsOurs = 0, int64_t totalvoutvalue = 0; for (size_t i = 0; i < tx.vin.size(); i++) @@ -1793,7 +1792,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl { if ( CBitcoinAddress(address).ToString() == NotaryAddress ) numvinIsOurs++; - if ( !WHITELIST_ADDRESS.empty() && CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) + if ( CBitcoinAddress(address).ToString() == WHITELIST_ADDRESS ) numvinIsWhiteList++; } } From 237f11559425593a0a65554fc01d093f596b88dd Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 9 Apr 2019 18:53:32 +0800 Subject: [PATCH 08/14] Clean up some LABS related code, remove un-used/needed stuff. Adds actual working and feild tested wallet filter. Can set any amount of whitelist address's, in conf file or commandline args. fix daemon deadlock, when doing z_mergetoaddress and mining at same time (needs more testing on staking chains) Set z_mergtoaddress to use a 0 expiry height when not doing z-tx's. They were failing and peers were getting banned trying to broadcast them. --- src/komodo.h | 10 ------ src/komodo_defs.h | 4 +-- src/komodo_globals.h | 10 +++--- src/komodo_utils.h | 2 -- src/main.cpp | 3 -- src/miner.cpp | 35 +++++---------------- src/notaries_staked.cpp | 16 ++-------- src/notaries_staked.h | 1 - src/wallet/rpcwallet.cpp | 4 ++- src/wallet/wallet.cpp | 67 ++++++++++++---------------------------- 10 files changed, 40 insertions(+), 112 deletions(-) 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); From bce0b87e6f2735dff3c1137780cb6418da3798b8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 10 Apr 2019 02:11:40 +0800 Subject: [PATCH 09/14] . --- src/komodo_bitcoind.h | 32 ++++++++++++---------- src/rpc/client.cpp | 1 + src/rpc/crosschain.cpp | 60 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e537df018..aa21896aa 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1917,33 +1917,37 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &Notar return(total); } -uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height) +bool GetNotarisationNotaries(uint8_t notarypubkeys[64][33], int8_t &numNN, const std::vector &vin, std::vector &NotarisationNotaries) { - std::vector NotarisationNotaries; - uint32_t timestamp = pblock->nTime; - int8_t numSN = 0; uint8_t notarypubkeys[64][33] = {0}; - numSN = komodo_notaries(notarypubkeys, height, timestamp); - - // No point going further, no notaries can be paid. - if ( notarypubkeys[0][0] == 0 ) - return(0); - uint8_t *script; int32_t scriptlen; - // Loop over the notarisation and extract the position of the participating notaries in the array of pukeys for this era. - BOOST_FOREACH(const CTxIn& txin, pblock->vtx[1].vin) + if ( notarypubkeys[0][0] == 0 ) + return false; + BOOST_FOREACH(const CTxIn& txin, vin) { uint256 hash; CTransaction tx1; if ( GetTransaction(txin.prevout.hash,tx1,hash,false) ) { - for (int8_t i = 0; i < numSN; i++) + for (int8_t i = 0; i < numNN; i++) { script = (uint8_t *)&tx1.vout[txin.prevout.n].scriptPubKey[0]; scriptlen = (int32_t)tx1.vout[txin.prevout.n].scriptPubKey.size(); if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[i],33) == 0 ) NotarisationNotaries.push_back(i); } - } + } else return false; } + return true; +} + +uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height) +{ + std::vector NotarisationNotaries; uint8_t *script; int32_t scriptlen; + uint64_t timestamp = pblock->nTime; + int8_t numSN = 0; uint8_t notarypubkeys[64][33] = {0}; + numSN = komodo_notaries(notarypubkeys, height, timestamp); + if ( !GetNotarisationNotaries(notarypubkeys, numSN, pblock->vtx[1].vin, NotarisationNotaries) ) + return(0); + // check a notary didnt sign twice (this would be an invalid notarisation later on and cause problems) std::set checkdupes( NotarisationNotaries.begin(), NotarisationNotaries.end() ); if ( checkdupes.size() != NotarisationNotaries.size() ) { diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 19910b25c..cab89092c 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -171,6 +171,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "assetchainproof", 1}, { "crosschainproof", 1}, { "getproofroot", 2}, + { "getNotarisationsForBlock", 0}, { "height_MoM", 1}, { "calc_MoM", 2}, }; diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 710f99f09..72c24086f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -33,6 +33,7 @@ #include "script/script_error.h" #include "script/sign.h" #include "script/standard.h" +#include "notaries_staked.h" #include "key_io.h" @@ -49,6 +50,7 @@ int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height); struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); extern std::string ASSETCHAINS_SELFIMPORT; uint256 Parseuint256(char *hexstr); @@ -406,7 +408,63 @@ UniValue selfimport(const UniValue& params, bool fHelp) return result; } +bool GetNotarisationNotaries(uint8_t notarypubkeys[64][33], int8_t &numNN, const std::vector &vin, std::vector &NotarisationNotaries); + UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) +{ + // TODO take timestamp as param, and loop blockindex to get starting/finish height. + if (fHelp || params.size() != 1) + throw runtime_error("getNotarisationsForBlock height\n\n" + "Takes a block height and returns notarisation information " + "within the block"); + + LOCK(cs_main); + int32_t height = params[0].get_int(); + if ( height < 0 || height > chainActive.Height() ) + throw runtime_error("height out of range.\n"); + + uint256 blockHash = chainActive[height]->GetBlockHash(); + + NotarisationsInBlock nibs; + GetBlockNotarisations(blockHash, nibs); + UniValue out(UniValue::VOBJ); + //out.push_back(make_pair("blocktime",(int))); + UniValue labs(UniValue::VARR); + UniValue kmd(UniValue::VARR); + // Gets KMD notaries on KMD... but LABS notaries on labs chains needs to be fixed so LABS are identified on KMD. + int8_t numNN = 0; uint8_t notarypubkeys[64][33] = {0}; + numNN = komodo_notaries(notarypubkeys, height, chainActive[height]->nTime); + + BOOST_FOREACH(const Notarisation& n, nibs) + { + UniValue item(UniValue::VOBJ); UniValue notaryarr(UniValue::VARR); std::vector NotarisationNotaries; + if ( is_STAKED(n.second.symbol) != 0 ) + continue; // for now just skip this... need to fetch diff pubkeys for these chains. labs.push_back(item); + uint256 hash; CTransaction tx; + if ( GetTransaction(n.first,tx,hash,false) ) + { + if ( !GetNotarisationNotaries(notarypubkeys, numNN, tx.vin, NotarisationNotaries) ) + continue; + if ( NotarisationNotaries.size() < numNN/5 ) + continue; + } + item.push_back(make_pair("txid", n.first.GetHex())); + item.push_back(make_pair("chain", n.second.symbol)); + item.push_back(make_pair("height", (int)n.second.height)); + item.push_back(make_pair("blockhash", n.second.blockHash.GetHex())); + item.push_back(make_pair("KMD_height", height)); // for when timstamp input is used. + + for ( auto notary : NotarisationNotaries ) + notaryarr.push_back(notary); + item.push_back(make_pair("notaries",notaryarr)); + kmd.push_back(item); + } + out.push_back(make_pair("KMD", kmd)); + //out.push_back(make_pair("LABS", labs)); + return out; +} + +/*UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error("getNotarisationsForBlock blockHash\n\n" @@ -426,7 +484,7 @@ UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) out.push_back(item); } return out; -} +}*/ UniValue scanNotarisationsDB(const UniValue& params, bool fHelp) From df79068ab65e64eb8d91cdfafcc5528560f40a12 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 10 Apr 2019 02:12:52 +0800 Subject: [PATCH 10/14] y --- src/notarystats.py | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/notarystats.py diff --git a/src/notarystats.py b/src/notarystats.py new file mode 100644 index 000000000..cc67ad10e --- /dev/null +++ b/src/notarystats.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +""" +build komodod from here: https://github.com/blackjok3rtt/komodo/tree/nota_stats +sudo apt-get install python3-dev +sudo apt-get install python3 libgnutls28-dev libssl-dev +sudo apt-get install python3-pip +pip3 install setuptools +pip3 install wheel +pip3 install base58 slick-bitcoinrpc +./notarystats.py +------------------------------------------------ +""" +import platform +import os +import re +import sys +import time +import pprint +from slickrpc import Proxy + +# fucntion to define rpc_connection +def def_credentials(chain): + rpcport = ''; + operating_system = platform.system() + if operating_system == 'Darwin': + ac_dir = os.environ['HOME'] + '/Library/Application Support/Komodo' + elif operating_system == 'Linux': + ac_dir = os.environ['HOME'] + '/.komodo' + elif operating_system == 'Windows': + ac_dir = '%s/komodo/' % os.environ['APPDATA'] + if chain == 'KMD': + coin_config_file = str(ac_dir + '/komodo.conf') + else: + coin_config_file = str(ac_dir + '/' + chain + '/' + chain + '.conf') + with open(coin_config_file, 'r') as f: + for line in f: + l = line.rstrip() + if re.search('rpcuser', l): + rpcuser = l.replace('rpcuser=', '') + elif re.search('rpcpassword', l): + rpcpassword = l.replace('rpcpassword=', '') + elif re.search('rpcport', l): + rpcport = l.replace('rpcport=', '') + if len(rpcport) == 0: + if chain == 'KMD': + rpcport = 7771 + else: + print("rpcport not in conf file, exiting") + print("check " + coin_config_file) + exit(1) + return (Proxy("http://%s:%s@127.0.0.1:%d" % (rpcuser, rpcpassword, int(rpcport)))) + + +rpc = def_credentials('KMD') +pp = pprint.PrettyPrinter(indent=2) + +#Second time filter for assetchains (block 821657) +notarynames = [ "0dev1_jl777", "0dev2_kolo", "0dev3_kolo", "0dev4_decker", "a-team_SH", "artik_AR", "artik_EU", "artik_NA", "artik_SH", "badass_EU", "badass_NA", "batman_AR", "batman_SH", "ca333_EU", "chainmakers_EU", "chainmakers_NA", "chainstrike_SH", "cipi_AR", "cipi_NA", "crackers_EU", "crackers_NA", "dwy_EU", "emmanux_SH", "etszombi_EU", "fullmoon_AR", "fullmoon_NA", "fullmoon_SH", "goldenman_EU", "indenodes_AR", "indenodes_EU", "indenodes_NA", "indenodes_SH", "jackson_AR", "jeezy_EU", "karasugoi_NA", "komodoninja_EU", "komodoninja_SH", "komodopioneers_SH", "libscott_SH", "lukechilds_AR", "madmax_AR", "meshbits_AR", "meshbits_SH", "metaphilibert_AR", "metaphilibert_SH", "patchkez_SH", "pbca26_NA", "peer2cloud_AR", "peer2cloud_SH", "polycryptoblog_NA", "hyper_AR", "hyper_EU", "hyper_SH", "hyper_NA", "popcornbag_AR", "popcornbag_NA", "alien_AR", "alien_EU", "thegaltmines_NA", "titomane_AR", "titomane_EU", "titomane_SH", "webworker01_NA", "xrobesx_NA" ] +notaries = 64 * [0] + +startheight = 821657 +stopheight = 1300000 +for i in range(startheight,stopheight): + ret = rpc.getNotarisationsForBlock(i) + KMD = ret['KMD'] + if len(KMD) > 0: + for obj in KMD: + # sanity check, KMD nota dont appear in DB anyway! + if obj['chain'] == 'KMD': + continue; + for notary in obj['notaries']: + notaries[notary] = notaries[notary] + 1 + +i = 0 +SH = [] +AR = [] +EU = [] +NA = [] +for notary in notaries: + tmpnotary = {} + tmpnotary['node'] = notarynames[i] + tmpnotary['ac_count'] = notary + if notarynames[i].endswith('SH'): + SH.append(tmpnotary) + elif notarynames[i].endswith('AR'): + AR.append(tmpnotary) + elif notarynames[i].endswith('EU'): + EU.append(tmpnotary) + elif notarynames[i].endswith('NA'): + NA.append(tmpnotary) + i = i + 1 + +regions = {} +regions['SH'] = sorted(SH, key=lambda k: k['ac_count'], reverse=True) +regions['AR'] = sorted(AR, key=lambda k: k['ac_count'], reverse=True) +regions['EU'] = sorted(EU, key=lambda k: k['ac_count'], reverse=True) +regions["NA"] = sorted(NA, key=lambda k: k['ac_count'], reverse=True) + +pp.pprint(regions) From e688959c6e3343f1c93c24b4642310ba4e93a062 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 10 Apr 2019 11:41:29 +0800 Subject: [PATCH 11/14] ... --- src/notarystats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/notarystats.py diff --git a/src/notarystats.py b/src/notarystats.py old mode 100644 new mode 100755 index cc67ad10e..c8b3ab1f1 --- a/src/notarystats.py +++ b/src/notarystats.py @@ -58,14 +58,14 @@ pp = pprint.PrettyPrinter(indent=2) notarynames = [ "0dev1_jl777", "0dev2_kolo", "0dev3_kolo", "0dev4_decker", "a-team_SH", "artik_AR", "artik_EU", "artik_NA", "artik_SH", "badass_EU", "badass_NA", "batman_AR", "batman_SH", "ca333_EU", "chainmakers_EU", "chainmakers_NA", "chainstrike_SH", "cipi_AR", "cipi_NA", "crackers_EU", "crackers_NA", "dwy_EU", "emmanux_SH", "etszombi_EU", "fullmoon_AR", "fullmoon_NA", "fullmoon_SH", "goldenman_EU", "indenodes_AR", "indenodes_EU", "indenodes_NA", "indenodes_SH", "jackson_AR", "jeezy_EU", "karasugoi_NA", "komodoninja_EU", "komodoninja_SH", "komodopioneers_SH", "libscott_SH", "lukechilds_AR", "madmax_AR", "meshbits_AR", "meshbits_SH", "metaphilibert_AR", "metaphilibert_SH", "patchkez_SH", "pbca26_NA", "peer2cloud_AR", "peer2cloud_SH", "polycryptoblog_NA", "hyper_AR", "hyper_EU", "hyper_SH", "hyper_NA", "popcornbag_AR", "popcornbag_NA", "alien_AR", "alien_EU", "thegaltmines_NA", "titomane_AR", "titomane_EU", "titomane_SH", "webworker01_NA", "xrobesx_NA" ] notaries = 64 * [0] -startheight = 821657 -stopheight = 1300000 +startheight = 1300000 #821657 +stopheight = 99999999 for i in range(startheight,stopheight): ret = rpc.getNotarisationsForBlock(i) KMD = ret['KMD'] if len(KMD) > 0: for obj in KMD: - # sanity check, KMD nota dont appear in DB anyway! + #for now skip KMD for this. As official stats are from BTC chain? if obj['chain'] == 'KMD': continue; for notary in obj['notaries']: From 3d83dda142d7fceafd951255d8738e90bc0521cb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 10 Apr 2019 12:07:31 +0800 Subject: [PATCH 12/14] fix script --- src/notarystats.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/notarystats.py b/src/notarystats.py index c8b3ab1f1..b606db1a6 100755 --- a/src/notarystats.py +++ b/src/notarystats.py @@ -54,18 +54,18 @@ def def_credentials(chain): rpc = def_credentials('KMD') pp = pprint.PrettyPrinter(indent=2) -#Second time filter for assetchains (block 821657) notarynames = [ "0dev1_jl777", "0dev2_kolo", "0dev3_kolo", "0dev4_decker", "a-team_SH", "artik_AR", "artik_EU", "artik_NA", "artik_SH", "badass_EU", "badass_NA", "batman_AR", "batman_SH", "ca333_EU", "chainmakers_EU", "chainmakers_NA", "chainstrike_SH", "cipi_AR", "cipi_NA", "crackers_EU", "crackers_NA", "dwy_EU", "emmanux_SH", "etszombi_EU", "fullmoon_AR", "fullmoon_NA", "fullmoon_SH", "goldenman_EU", "indenodes_AR", "indenodes_EU", "indenodes_NA", "indenodes_SH", "jackson_AR", "jeezy_EU", "karasugoi_NA", "komodoninja_EU", "komodoninja_SH", "komodopioneers_SH", "libscott_SH", "lukechilds_AR", "madmax_AR", "meshbits_AR", "meshbits_SH", "metaphilibert_AR", "metaphilibert_SH", "patchkez_SH", "pbca26_NA", "peer2cloud_AR", "peer2cloud_SH", "polycryptoblog_NA", "hyper_AR", "hyper_EU", "hyper_SH", "hyper_NA", "popcornbag_AR", "popcornbag_NA", "alien_AR", "alien_EU", "thegaltmines_NA", "titomane_AR", "titomane_EU", "titomane_SH", "webworker01_NA", "xrobesx_NA" ] notaries = 64 * [0] -startheight = 1300000 #821657 -stopheight = 99999999 +startheight = 821657 #Second time filter for assetchains (block 821657) for KMD its 814000 +stopheight = rpc.getblockcount() # @kolo what height does season end?! for i in range(startheight,stopheight): ret = rpc.getNotarisationsForBlock(i) KMD = ret['KMD'] if len(KMD) > 0: for obj in KMD: - #for now skip KMD for this. As official stats are from BTC chain? + #for now skip KMD for this. As official stats are from BTC chain + # this can be reversed to !== to count KMD numbers :) if obj['chain'] == 'KMD': continue; for notary in obj['notaries']: From 2fbb858beff294255787898d38963c1222ba2346 Mon Sep 17 00:00:00 2001 From: blackjok3rtt <30971146+blackjok3rtt@users.noreply.github.com> Date: Wed, 10 Apr 2019 12:27:53 +0800 Subject: [PATCH 13/14] remove git link --- src/notarystats.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/notarystats.py b/src/notarystats.py index b606db1a6..0e7673833 100755 --- a/src/notarystats.py +++ b/src/notarystats.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """ -build komodod from here: https://github.com/blackjok3rtt/komodo/tree/nota_stats sudo apt-get install python3-dev sudo apt-get install python3 libgnutls28-dev libssl-dev sudo apt-get install python3-pip From 2e2bb2b51883c2e2479df531e1cff33a624e3046 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 10 Apr 2019 16:53:08 +0800 Subject: [PATCH 14/14] fix getsnapshot2 thanks to dimxy's advice. --- src/txdb.cpp | 28 +++++++++++++--------------- src/txdb.h | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 93000d9fb..4c9ea31ca 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -458,7 +458,7 @@ uint32_t komodo_segid32(char *coinaddr); {"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY", 1} \ }; -int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top, bool fRPC ,std::vector > &vaddr, UniValue &ret) +int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top ,std::vector > &vaddr, UniValue *ret) { int64_t total = 0; int64_t totalAddresses = 0; std::string address; int64_t utxos = 0; int64_t ignoredAddresses = 0, cryptoConditionsUTXOs = 0, cryptoConditionsTotals = 0; @@ -542,30 +542,28 @@ int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top, bool fRPC ,s if ( top == topN ) break; } - // this is for the snapshot RPC, you can skip this by passing false to the 3rd arugment. - // Still needs UniValue defined to use SnapShot2 though, can this be changed to just pass 0? - // I tried to make it a pointer, and check if the pointer was 0, but UniValue class didnt like that. - if ( fRPC ) + // this is for the snapshot RPC, you can skip this by passing a 0 as the last argument. + if (ret) { // Total amount in this snapshot, which is less than circulating supply if top parameter is used // Use the address_total for a total of all address included when using top parameter. - ret.push_back(make_pair("total", (double) (total+cryptoConditionsTotals)/ COIN )); + ret->push_back(make_pair("total", (double) (total+cryptoConditionsTotals)/ COIN )); // Average amount in each address of this snapshot - ret.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + ret->push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); // Total number of utxos processed in this snaphot - ret.push_back(make_pair("utxos", utxos)); + ret->push_back(make_pair("utxos", utxos)); // Total number of addresses in this snaphot - ret.push_back(make_pair("total_addresses", top ? top : totalAddresses )); + ret->push_back(make_pair("total_addresses", top ? top : totalAddresses )); // Total number of ignored addresses in this snaphot - ret.push_back(make_pair("ignored_addresses", ignoredAddresses)); + ret->push_back(make_pair("ignored_addresses", ignoredAddresses)); // Total number of crypto condition utxos we skipped - ret.push_back(make_pair("skipped_cc_utxos", cryptoConditionsUTXOs)); + ret->push_back(make_pair("skipped_cc_utxos", cryptoConditionsUTXOs)); // Total value of skipped crypto condition utxos - ret.push_back(make_pair("cc_utxo_value", (double) cryptoConditionsTotals / COIN)); + ret->push_back(make_pair("cc_utxo_value", (double) cryptoConditionsTotals / COIN)); // total of all the address's, does not count coins in CC vouts. - ret.push_back(make_pair("address_total", (double) total/ COIN )); + ret->push_back(make_pair("address_total", (double) total/ COIN )); // The snapshot finished at this block height - ret.push_back(make_pair("ending_height", chainActive.Height())); + ret->push_back(make_pair("ending_height", chainActive.Height())); } return(topN); } @@ -577,7 +575,7 @@ UniValue CBlockTreeDB::Snapshot(int top) UniValue result(UniValue::VOBJ); UniValue addressesSorted(UniValue::VARR); result.push_back(Pair("start_time", (int) time(NULL))); - if ( Snapshot2(0,top,true,vaddr,result) != 0 ) + if ( Snapshot2(0,top,vaddr,&result) != 0 ) { for (std::vector>::iterator it = vaddr.begin(); it!=vaddr.end(); ++it) { diff --git a/src/txdb.h b/src/txdb.h index 8b98994a2..b4c4cd6bd 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -116,7 +116,7 @@ public: bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); UniValue Snapshot(int top); - int32_t Snapshot2(int64_t dustthreshold, int32_t top, bool fRPC ,std::vector > &vaddr, UniValue &ret); + int32_t Snapshot2(int64_t dustthreshold, int32_t top,std::vector > &vaddr, UniValue *ret); }; #endif // BITCOIN_TXDB_H