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_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..cf4fa0138 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,7 +2587,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, { txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now } - + interest = 0; { LOCK2(cs_main, cs_wallet); { @@ -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) {