From 9152feb5df097b71944cf1e0594b9fbf21ce8c07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Feb 2017 04:04:53 +0200 Subject: [PATCH 1/6] lastmined --- src/komodo.h | 5 +++++ src/komodo_globals.h | 1 + src/miner.cpp | 7 ++++--- src/rpcmisc.cpp | 3 +++ src/wallet/wallet.cpp | 34 ++++++++++++++++++++++++++-------- 5 files changed, 39 insertions(+), 11 deletions(-) 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) { From bd041a518215da017a4fa86b1667237afabb4e72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Feb 2017 04:15:04 +0200 Subject: [PATCH 2/6] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2417f077e..2b10cb192 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 ) From 182dcdecac19f0aacda0578bf691c7fd43241fd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Feb 2017 04:31:22 +0200 Subject: [PATCH 3/6] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2b10cb192..4a17c29c8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -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' ) From bc4c5ceb1534e89e4860b4e7ab32f10626116202 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Feb 2017 04:33:54 +0200 Subject: [PATCH 4/6] test --- 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 cf4fa0138..0be71e34a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2587,13 +2587,13 @@ 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); { nFeeRet = 0; while (true) { + interest = 0; txNew.vin.clear(); txNew.vout.clear(); wtxNew.fFromMe = true; From 608252ed2fe0a28c4d159ed54af3601618ec87fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Feb 2017 04:59:49 +0200 Subject: [PATCH 5/6] test --- src/wallet/wallet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0be71e34a..9eea082cd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2662,7 +2662,9 @@ 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; @@ -2673,8 +2675,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; From 85cb030e3e232d1ae9075a9b685eb94ecf42f9a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Feb 2017 05:46:24 +0200 Subject: [PATCH 6/6] test --- src/wallet/wallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9eea082cd..909750010 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2665,6 +2665,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, { 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;