diff --git a/README.md b/README.md index 28160dd6e..ff9545fe9 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Dependencies ``` #The following packages are needed: -sudo apt-get install build-essential pkg-config libcurl-gnutls libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libdb++-dev ntp ntpdate +sudo apt-get install build-essential pkg-config libcurl-gnutls-dev libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libdb++-dev ntp ntpdate ``` Komodo diff --git a/src/komodo.h b/src/komodo.h index 0e8f8891c..5a379eb92 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -335,6 +335,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { + if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 ) + { + printf("KOMODO_LASTMINED.%d -> %d\n",KOMODO_LASTMINED,height); + KOMODO_LASTMINED = height; + } decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); /*for (k=0; k<33; k++) printf("%02x",crypto777[k]); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2417f077e..4a17c29c8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -704,7 +704,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); typestr = "deposit"; - if ( kmdheight <= height ) + if ( kmdheight > 195000 || kmdheight <= height ) { didstats = 0; if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) @@ -769,7 +769,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( seed != 0 && kmdheight > 182000 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD check %.8f seed.%llu\n",base,dstr(fiatoshis),kmdheight,dstr(value),dstr(checktoshis),(long long)seed); - } else printf("paxdeposit height.%d vs kmdheight.%d\n",height,kmdheight); + } //else printf("paxdeposit height.%d vs kmdheight.%d\n",height,kmdheight); } } else if ( opretbuf[0] == 'I' ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 833169626..1faf91a26 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -40,6 +40,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET; +int32_t KOMODO_LASTMINED; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; diff --git a/src/miner.cpp b/src/miner.cpp index 486251435..26166a416 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -522,6 +522,7 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese int32_t komodo_baseid(char *origbase); int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height); int32_t FOUND_BLOCK; +extern int32_t KOMODO_LASTMINED; void static BitcoinMiner(CWallet *pwallet) { @@ -641,7 +642,7 @@ void static BitcoinMiner(CWallet *pwallet) if ( externalflag == 0 && i != 66 ) printf("VIOLATION at %d\n",i); for (i=0; i<66; i++) - { + {break; for (j=0; j<33; j++) printf("%02x",pubkeys[i][j]); printf(" p%d -> %d\n",i,komodo_minerid(pindexPrev->nHeight-i,pubkeys[i])); @@ -658,7 +659,7 @@ void static BitcoinMiner(CWallet *pwallet) if ( mids[j] == notaryid ) break; } else fprintf(stderr,"no nonz pubkeys\n"); - if ( j == 65 ) + if ( j == 65 && Mining_height > KOMODO_LASTMINED+64 ) { hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1); @@ -799,7 +800,7 @@ void static BitcoinMiner(CWallet *pwallet) { FOUND_BLOCK = 0; fprintf(stderr,"FOUND_BLOCK!\n"); - sleep(2000); + //sleep(2000); } if (vNodes.empty() && chainparams.MiningRequiresPeers()) { diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index f0ca17041..0681265af 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -45,6 +45,7 @@ uint64_t komodo_interestsum(); int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); int32_t komodo_whoami(char *pubkeystr,int32_t height); +extern int32_t KOMODO_LASTMINED; Value getinfo(const Array& params, bool fHelp) { @@ -128,6 +129,8 @@ Value getinfo(const Array& params, bool fHelp) notaryid = komodo_whoami(pubkeystr,longestchain); obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("pubkey", pubkeystr)); + if ( KOMODO_LASTMINED != 0 ) + obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); } return obj; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 419f9dec3..0671c6ae6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2342,7 +2342,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int setCoinsRet.clear(); memset(interests,0,sizeof(interests)); nValueRet = 0; - *interestp = 0; + //*interestp = 0; // List of values less than target pair > coinLowestLarger; coinLowestLarger.first = std::numeric_limits::max(); @@ -2458,10 +2458,12 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. - uint64_t tmp; + uint64_t tmp,interest = 0; if ( interestp == 0 ) + { interestp = &tmp; - *interestp = 0; + *interestp = 0; + } vector vCoinsNoCoinbase, vCoinsWithCoinbase; AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false); AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true); @@ -2510,9 +2512,25 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set= nTargetValue); } //fprintf(stderr,"nValueRet %8f vs target %.8f\n",(double)nValueRet/COIN,(double)nTargetValue/COIN); - return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) || - SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) || - (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp))); + if ( SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,&interest) != 0 ) + { + *interestp += interest; + return(true); + } + else if ( SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,&interest) != 0 ) + { + *interestp += interest; + return(true); + } + else if ( bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,&interest) != 0 ) + { + *interestp += interest; + return(true); + } + return(false); + //return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) || + // SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) || + // (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp))); } bool CWallet::CreateTransaction(const vector& vecSend, @@ -2569,13 +2587,13 @@ bool CWallet::CreateTransaction(const vector& vecSend, { txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now } - { LOCK2(cs_main, cs_wallet); { nFeeRet = 0; while (true) { + interest = 0; txNew.vin.clear(); txNew.vout.clear(); wtxNew.fFromMe = true; @@ -2623,7 +2641,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CAmount nValueIn = 0; bool fOnlyCoinbaseCoins = false; bool fNeedCoinbaseCoins = false; - interest = interest2 = 0; + interest2 = 0; if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest)) { if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) { @@ -2644,7 +2662,10 @@ bool CWallet::CreateTransaction(const vector& vecSend, //But mempool inputs might still be in the mempool, so their age stays 0 //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); if ( KOMODO_EXCHANGEWALLET == 0 ) + { interest2 += pcoin.first->vout[pcoin.second].interest; + fprintf(stderr,"%.8f ",(double)pcoin.first->vout[pcoin.second].interest/COIN); + } int age = pcoin.first->GetDepthInMainChain(); if (age != 0) age += 1; @@ -2655,8 +2676,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, //fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); interest = 0; } - CAmount nChange = (nValueIn - nValue + interest); -fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); + CAmount nChange = (nValueIn - nValue + interest2); +fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)interest/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; @@ -2782,6 +2803,8 @@ fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(do } CAmount nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool); + if ( nFeeNeeded < 5000 ) + nFeeNeeded = 5000; // If we made it here and we aren't even able to meet the relay fee on the next pass, give up // because we must be at the maximum allowed fee.