From de646890858f06a30fe72ed2ec97e53c5e27e590 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 28 Mar 2019 14:45:34 +0800 Subject: [PATCH 001/122] fix rewards minrelease validation --- src/cc/rewards.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 73f723453..129cbc47f 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -258,11 +258,11 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) return eval->Invalid("txfee is too high"); reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); + if ( reward == 0 ) + return eval->Invalid("no elegible rewards"); if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( reward == 0 ) - return eval->Invalid("unlock recover no rewards"); - else if ( tx.vout[1].nValue != 10000 ) + if ( tx.vout[1].nValue != 10000 ) return eval->Invalid("wrong marker vour value"); else if ( tx.vout[1].scriptPubKey != tx.vout[0].scriptPubKey ) return eval->Invalid("unlock recover tx vout.1 mismatched scriptPubKey"); From 87b039a2673ad0f0758c5f9c18a23da5084be8b1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 28 Mar 2019 14:56:51 +0800 Subject: [PATCH 002/122] fix --- src/cc/rewards.cpp | 3 +-- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 129cbc47f..152842bbd 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -263,7 +263,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( tx.vout[1].nValue != 10000 ) - return eval->Invalid("wrong marker vour value"); + return eval->Invalid("wrong marker vout value"); else if ( tx.vout[1].scriptPubKey != tx.vout[0].scriptPubKey ) return eval->Invalid("unlock recover tx vout.1 mismatched scriptPubKey"); else if ( tx.vout[0].scriptPubKey != vinTx.vout[1].scriptPubKey ) @@ -285,7 +285,6 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else if ( tx.vout[1].scriptPubKey != vinTx.vout[1].scriptPubKey ) return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); amount = vinTx.vout[0].nValue; - reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) diff --git a/src/main.cpp b/src/main.cpp index e520ad83f..019507c55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1383,7 +1383,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio } } if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) - return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-vout-negative"); + return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-opret-too-big"); nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) return state.DoS(100, error("CheckTransaction(): txout total out of range"), From 394b00366e05193a4e98cc0d1c8f79acfa091f5a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 28 Mar 2019 20:34:55 +0800 Subject: [PATCH 003/122] fixed! --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 152842bbd..bc9464fb8 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -257,9 +257,10 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) return eval->Invalid("txfee is too high"); + amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); if ( reward == 0 ) - return eval->Invalid("no elegible rewards"); + return eval->Invalid("no eligible rewards"); if ( numvins == 1 && tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( tx.vout[1].nValue != 10000 ) @@ -284,7 +285,6 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.1 is CC output"); else if ( tx.vout[1].scriptPubKey != vinTx.vout[1].scriptPubKey ) return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); - amount = vinTx.vout[0].nValue; if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) From ddc0fb6de14f2f866c26175ba56ed650f42dc4f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 20:09:38 -1100 Subject: [PATCH 004/122] Check for lag2 --- src/komodo_gateway.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 932efd051..10c8718d9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1712,7 +1712,12 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) lag2 = (int32_t)(komodo_heightstamp(nHeight-1) - pricebits[0]); if ( lag < -60 ) // avoid data from future { - fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); + fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag); + return(-1); + } + if ( lag2 < 0 ) + { + fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag2.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); return(-1); } // else need to check against current blocktime to prevent pricebits[0] games From 5150bed539d194da8212b8e863b669341e6b03fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 20:16:42 -1100 Subject: [PATCH 005/122] Skip block 1 --- src/komodo_gateway.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 10c8718d9..b8a62792a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1706,7 +1706,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) n = (int32_t)(vopret.size() / sizeof(uint32_t)); memcpy(pricebits,vopret.data(),Mineropret.size()); memset(maxflags,0,sizeof(maxflags)); - if ( nHeight > 1 ) + if ( nHeight > 2 ) { lag = (int32_t)(now - pricebits[0]); lag2 = (int32_t)(komodo_heightstamp(nHeight-1) - pricebits[0]); @@ -1720,7 +1720,6 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag2.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); return(-1); } - // else need to check against current blocktime to prevent pricebits[0] games btcusd = (double)pricebits[1]/10000; btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; From 5d1010c35ada8b091291814bc6a77fb974fdab78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 20:28:33 -1100 Subject: [PATCH 006/122] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b8a62792a..e8b33c073 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1712,12 +1712,12 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) lag2 = (int32_t)(komodo_heightstamp(nHeight-1) - pricebits[0]); if ( lag < -60 ) // avoid data from future { - fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag); + fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",nHeight,now,komodo_heightstamp(nHeight-1),pricebits[0],lag); return(-1); } if ( lag2 < 0 ) { - fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag2.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); + fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lag2.%d\n",nHeight,now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); return(-1); } btcusd = (double)pricebits[1]/10000; From 8a9eaea869704f6407855833989bf420e83254ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 20:40:26 -1100 Subject: [PATCH 007/122] Pass through block and previndex --- src/komodo_gateway.h | 19 +++++++++++++------ src/main.cpp | 12 ++++++------ src/main.h | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e8b33c073..724525795 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1695,9 +1695,9 @@ CScript komodo_mineropret(int32_t nHeight) // pass in blockhash and nTime, latch if it is rejected due to local price, then if localprice changes in a way that would validate then issue reconsiderblock // add rpc call for extracting rawprices -int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) +int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { - std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,maxflag,lag,lag2,n; uint32_t now = (uint32_t)time(NULL); + std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,prevtime,maxflag,lag,lag2,lag3,n; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { GetOpReturnData(scriptPubKey,vopret); @@ -1708,16 +1708,23 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) memset(maxflags,0,sizeof(maxflags)); if ( nHeight > 2 ) { + prevtime = previndex->nTime; lag = (int32_t)(now - pricebits[0]); - lag2 = (int32_t)(komodo_heightstamp(nHeight-1) - pricebits[0]); + lag2 = (int32_t)(pricebits[0] - prevtime); + lag3 = (int32_t)(block->nTime - pricebits[0]); if ( lag < -60 ) // avoid data from future { - fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",nHeight,now,komodo_heightstamp(nHeight-1),pricebits[0],lag); + fprintf(stderr,"ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < 0 ) + if ( lag2 < 0 ) // must be after last block timestamp { - fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lag2.%d\n",nHeight,now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); + fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); + return(-1); + } + if ( lag3 < -60 || lag > ASSETCHAINS_BLOCKTIME ) + { + fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } btcusd = (double)pricebits[1]/10000; diff --git a/src/main.cpp b/src/main.cpp index 1036670d6..a037bd828 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -977,7 +977,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in * Ensure that a coinbase transaction is structured according to the consensus rules of the * chain */ -bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeight) +bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight) { // if time locks are on, ensure that this coin base is time locked exactly as it should be if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) || @@ -1020,7 +1020,7 @@ bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeigh } else if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 && tx.vout.size() > 0 ) { - if ( komodo_opretvalidate(nHeight,tx.vout[tx.vout.size()-1].scriptPubKey) < 0 ) + if ( komodo_opretvalidate(block,previndex,nHeight,tx.vout[tx.vout.size()-1].scriptPubKey) < 0 ) return(false); } return(true); @@ -1035,7 +1035,7 @@ bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeigh * and ContextualCheckBlock (which calls this function). * 3. The isInitBlockDownload argument is only to assist with testing. */ -bool ContextualCheckTransaction( +bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const previndex, const CTransaction& tx, CValidationState &state, const int nHeight, @@ -1171,7 +1171,7 @@ bool ContextualCheckTransaction( if (tx.IsCoinBase()) { - if (!ContextualCheckCoinbaseTransaction(tx, nHeight)) + if (!ContextualCheckCoinbaseTransaction(block,previndex,tx, nHeight)) return state.DoS(100, error("CheckTransaction(): invalid script data for coinbase time lock"), REJECT_INVALID, "bad-txns-invalid-script-data-for-coinbase-time-lock"); } @@ -1679,7 +1679,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } // DoS level set to 10 to be more forgiving. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. - if (!fSkipExpiry && !ContextualCheckTransaction(tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel)) + if (!fSkipExpiry && !ContextualCheckTransaction(0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel)) { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } @@ -5173,7 +5173,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn const CTransaction& tx = block.vtx[i]; // Check transaction contextually against consensus rules at block height - if (!ContextualCheckTransaction(tx, state, nHeight, 100)) { + if (!ContextualCheckTransaction(&block,pindexPrev,tx, state, nHeight, 100)) { return false; // Failure reason has been set in validation state object } diff --git a/src/main.h b/src/main.h index f12bcb8cd..0cdb0b7a8 100644 --- a/src/main.h +++ b/src/main.h @@ -706,7 +706,7 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons std::vector *pvChecks = NULL); /** Check a transaction contextually against a set of consensus rules */ -bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, +bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, bool (*isInitBlockDownload)() = IsInitialBlockDownload); /** Apply the effects of this transaction on the UTXO set represented by view */ From c8d70aa804dbaf58dee13fd01f5bc7fdd586c1ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 20:49:11 -1100 Subject: [PATCH 008/122] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 724525795..1661e3225 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1714,17 +1714,17 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i lag3 = (int32_t)(block->nTime - pricebits[0]); if ( lag < -60 ) // avoid data from future { - fprintf(stderr,"ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); + fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } if ( lag2 < 0 ) // must be after last block timestamp { - fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); + fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } if ( lag3 < -60 || lag > ASSETCHAINS_BLOCKTIME ) { - fprintf(stderr,"ht.%d now.%u htstamp.%u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); + fprintf(stderr,"C ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } btcusd = (double)pricebits[1]/10000; From b1e8644e050a35b3f1a0a4ab703d0d28b520cdee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 21:30:32 -1100 Subject: [PATCH 009/122] testchain_exemption = 500 --- src/komodo_gateway.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1661e3225..847c50248 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1697,6 +1697,7 @@ CScript komodo_mineropret(int32_t nHeight) int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { + int32_t testchain_exemption = 500; std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,prevtime,maxflag,lag,lag2,lag3,n; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { @@ -1720,9 +1721,10 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i if ( lag2 < 0 ) // must be after last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); - return(-1); + if ( nHeight > testchain_exemption ) + return(-1); } - if ( lag3 < -60 || lag > ASSETCHAINS_BLOCKTIME ) + if ( lag3 < -60 || lag3 > ASSETCHAINS_BLOCKTIME ) { fprintf(stderr,"C ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); @@ -1733,7 +1735,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcusd/btceur,btcgbp/btceur,lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - if ( nHeight < 500 ) + if ( nHeight < testchain_exemption ) { for (i=0; i= PRICES_SIZEBIT0 ) { memcpy(localbits,Mineropret.data(),Mineropret.size()); - if ( nHeight < 500 ) + if ( nHeight < testchain_exemption ) { for (i=0; i Date: Mon, 1 Apr 2019 21:33:39 -1100 Subject: [PATCH 010/122] if ( nHeight > testchain_exemption ) --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 847c50248..100dd2a57 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1727,7 +1727,8 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i if ( lag3 < -60 || lag3 > ASSETCHAINS_BLOCKTIME ) { fprintf(stderr,"C ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); - return(-1); + if ( nHeight > testchain_exemption ) + return(-1); } btcusd = (double)pricebits[1]/10000; btcgbp = (double)pricebits[2]/10000; From 034479cf780eedac9f53774dffdd2832d0482592 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 21:37:18 -1100 Subject: [PATCH 011/122] 506 --- 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 100dd2a57..3f90b4b60 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1697,7 +1697,7 @@ CScript komodo_mineropret(int32_t nHeight) int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { - int32_t testchain_exemption = 500; + int32_t testchain_exemption = 506; std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,prevtime,maxflag,lag,lag2,lag3,n; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { From 244c924fe1343dcba2cf26e565a146e86db7db60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 21:49:56 -1100 Subject: [PATCH 012/122] Allow more variance from prev timestamp --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3f90b4b60..9452b62ed 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1697,7 +1697,7 @@ CScript komodo_mineropret(int32_t nHeight) int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { - int32_t testchain_exemption = 506; + int32_t testchain_exemption = 350; std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,prevtime,maxflag,lag,lag2,lag3,n; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { @@ -1718,7 +1718,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < 0 ) // must be after last block timestamp + if ( lag2 < -ASSETCHAINS_BLOCKTIME ) // must be close to last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); if ( nHeight > testchain_exemption ) From 698ea547d0351caa20f63ac5a8c712cd3bbf92bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 21:53:49 -1100 Subject: [PATCH 013/122] +print --- 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 9452b62ed..3ed1cab49 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1720,7 +1720,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i } if ( lag2 < -ASSETCHAINS_BLOCKTIME ) // must be close to last block timestamp { - fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); + fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME); if ( nHeight > testchain_exemption ) return(-1); } From 3a9b1492000f316135b6f46fd508e85b967c7f89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 21:57:23 -1100 Subject: [PATCH 014/122] int32_t --- src/bitcoind.cpp | 2 +- src/chainparams.cpp | 2 +- src/komodo_defs.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 0afb47894..b65fcf1a9 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -59,7 +59,7 @@ static bool fDaemon; #include "komodo_defs.h" #define KOMODO_ASSETCHAIN_MAXLEN 65 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern uint32_t ASSETCHAINS_BLOCKTIME; +extern int32_t ASSETCHAINS_BLOCKTIME; extern uint64_t ASSETCHAINS_CBOPRET; void komodo_passport_iteration(); uint64_t komodo_interestsum(); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6bfcc0e5c..26e29d9de 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -91,7 +91,7 @@ static CBlock CreateGenesisBlock(uint32_t nTime, const uint256& nNonce, const st */ void *chainparams_commandline(void *ptr); #include "komodo_defs.h" -uint32_t ASSETCHAINS_BLOCKTIME = 60; +int32_t ASSETCHAINS_BLOCKTIME = 60; const arith_uint256 maxUint = UintToArith256(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 0f053f6ca..b0f618e93 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -42,8 +42,8 @@ extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC,ASSETCHAINS_BLOCKTIME; -extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER; +extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC; +extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER,ASSETCHAINS_BLOCKTIME; extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD; extern uint64_t ASSETCHAINS_TIMELOCKGTE; From d464a48a0d6aba57bcaf880ff28391f09fc07146 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 22:11:26 -1100 Subject: [PATCH 015/122] 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 3ed1cab49..52d9f0776 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1718,7 +1718,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < -ASSETCHAINS_BLOCKTIME ) // must be close to last block timestamp + if ( lag2 < -60 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME); if ( nHeight > testchain_exemption ) From 79dab848b4b73a652e7a81aa9b36047a6b096872 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 22:16:21 -1100 Subject: [PATCH 016/122] 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 52d9f0776..7624a57d5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1718,7 +1718,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < -60 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp + if ( lag2 < -63 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME); if ( nHeight > testchain_exemption ) From cbd4c636d4ea16550b2bcbef5d79d5848803368d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 22:17:59 -1100 Subject: [PATCH 017/122] -120 --- 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 7624a57d5..7e1ede5d5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1718,7 +1718,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < -63 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp + if ( lag2 < -120 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME); if ( nHeight > testchain_exemption ) From 175d0fa4a6f78d75d3d493f0b596fb9fb59c0811 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 22:19:33 -1100 Subject: [PATCH 018/122] 500 --- 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 7e1ede5d5..401199837 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1697,7 +1697,7 @@ CScript komodo_mineropret(int32_t nHeight) int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { - int32_t testchain_exemption = 350; + int32_t testchain_exemption = 500; std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,prevtime,maxflag,lag,lag2,lag3,n; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { From c90448edbae897f41dca1225d240656ecfec5135 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Apr 2019 23:09:51 -1100 Subject: [PATCH 019/122] prices rpc call stub --- src/komodo_gateway.h | 26 ++++++++++---- src/rpc/blockchain.cpp | 80 ++++++++++++++++++++++++++++++++---------- src/rpc/server.cpp | 1 + src/rpc/server.h | 2 ++ 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 401199837..a59e47a04 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1553,7 +1553,7 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define PRICES_SIZEBIT0 (sizeof(uint32_t) * 4) // 4 uint32_t unixtimestamp, BTCUSD, BTCGBP and BTCEUR // komodo_heightpricebits() extracts the price data in the coinbase for nHeight -int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight) +int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) { CBlockIndex *pindex; CBlock block; CTransaction tx; int32_t numvouts; std::vector vopret; if ( (pindex= komodo_chainactive(nHeight)) != 0 ) @@ -1565,8 +1565,8 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight) GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); if ( vopret.size() >= PRICES_SIZEBIT0 ) { - memcpy(prevbits,vopret.data(),vopret.size()); - return(0); + memcpy(heightbits,vopret.data(),vopret.size()); + return((int32_t)(vopret.size()/sizeof(uint32_t))); } } } @@ -1574,6 +1574,20 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight) return(-1); } +int32_t komodo_prices(uint32_t *prices,uint32_t *correlated,uint32_t *smoothed,int32_t height) +{ + int32_t i,n; + n = komodo_heightpricebits(prices,height); + for (i=0; i 0 ) { memcpy(pricebits,Mineropret.data(),Mineropret.size()); memset(maxflags,0,sizeof(maxflags)); @@ -1718,7 +1732,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < -120 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp + if ( lag2 < -testchain_exemption ) // must be close to last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME); if ( nHeight > testchain_exemption ) @@ -1734,7 +1748,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcusd/btceur,btcgbp/btceur,lag2); - if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) + if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 ) { if ( nHeight < testchain_exemption ) { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6dac120e4..fc9ec5f7a 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1174,38 +1174,80 @@ UniValue paxprice(const UniValue& params, bool fHelp) return ret; } -UniValue paxprices(const UniValue& params, bool fHelp) +int32_t komodo_prices(uint32_t *prices,uint32_t *correlated,uint32_t *smoothed,int32_t height); + +UniValue prices(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() != 3 ) - throw runtime_error("paxprices \"base\" \"rel\" maxsamples\n"); + if ( fHelp || params.size() != 1 ) + throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); uint64_t relvolume,prices[4096]; uint32_t i,n; int32_t heights[sizeof(prices)/sizeof(*prices)]; - std::string base = params[0].get_str(); - std::string rel = params[1].get_str(); - int32_t maxsamples = atoi(params[2].get_str().c_str()); + UniValue ret(UniValue::VOBJ); uint32_t *prices,*correlated,*smoothed; uint32_t i,firstn=-1,n,nextheight,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + int32_t maxsamples = atoi(params[0].get_str().c_str()); if ( maxsamples < 1 ) maxsamples = 1; else if ( maxsamples > sizeof(heights)/sizeof(*heights) ) maxsamples = sizeof(heights)/sizeof(*heights); - ret.push_back(Pair("base", base)); - ret.push_back(Pair("rel", rel)); - n = komodo_paxprices(heights,prices,maxsamples,(char *)base.c_str(),(char *)rel.c_str()); + nextheight = komodo_nextheight(); UniValue a(UniValue::VARR); - for (i=0; idaywindow+2; i++,ht--) { - UniValue item(UniValue::VOBJ); - if ( heights[i] < 0 || heights[i] > chainActive.Height() ) + if ( ht < 0 || ht > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { - CBlockIndex *pblockindex = chainActive[heights[i]]; - - item.push_back(Pair("t", (int64_t)pblockindex->nTime)); - item.push_back(Pair("p", (double)prices[i] / COIN)); - a.push_back(item); + if ( (n= komodo_prices(rawprices,ht)) > 0 ) + { + if ( firstn == -1 ) + firstn = n; + else if ( n != firstn ) + throw JSONRPCError(RPC_INVALID_PARAMETER, "numprices != first numprices"); + else + { + for (j=0; j Date: Tue, 2 Apr 2019 00:08:01 -1100 Subject: [PATCH 020/122] KOMODO_LOCALPRICE_CACHESIZE --- src/bitcoind.cpp | 4 +- src/komodo_gateway.h | 176 ++++++++++++++++++++++++++++++++--------- src/komodo_utils.h | 4 +- src/rpc/blockchain.cpp | 82 ++++++++++--------- 4 files changed, 187 insertions(+), 79 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index b65fcf1a9..4e010d28e 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -64,7 +64,7 @@ extern uint64_t ASSETCHAINS_CBOPRET; void komodo_passport_iteration(); uint64_t komodo_interestsum(); int32_t komodo_longestchain(); -void komodo_cbopretupdate(); +void komodo_cbopretupdate(int32_t forceflag); void WaitForShutdown(boost::thread_group* threadGroup) { @@ -89,7 +89,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) //komodo_interestsum(); //komodo_longestchain(); if ( ASSETCHAINS_CBOPRET != 0 ) - komodo_cbopretupdate(); + komodo_cbopretupdate(0); for (i=0; i<=ASSETCHAINS_BLOCKTIME/5; i++) { fShutdown = ShutdownRequested(); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a59e47a04..6035cf82f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1551,6 +1551,15 @@ void komodo_passport_iteration() extern std::vector Mineropret; // opreturn data set by the data gathering code #define PRICES_MAXCHANGE (COIN / 100) // maximum acceptable change, set at 1% #define PRICES_SIZEBIT0 (sizeof(uint32_t) * 4) // 4 uint32_t unixtimestamp, BTCUSD, BTCGBP and BTCEUR +#define KOMODO_LOCALPRICE_CACHESIZE 7 +uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)]; + +void komodo_PriceCache_shift() +{ + int32_t i; + for (i=KOMODO_LOCALPRICE_CACHESIZE-1; i>=0; i--) + memcpy(PriceCache[i],PriceCache[i-1],sizeof(PriceCache[i])); +} // komodo_heightpricebits() extracts the price data in the coinbase for nHeight int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) @@ -1574,20 +1583,6 @@ int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) return(-1); } -int32_t komodo_prices(uint32_t *prices,uint32_t *correlated,uint32_t *smoothed,int32_t height) -{ - int32_t i,n; - n = komodo_heightpricebits(prices,height); - for (i=0; i vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,prevtime,maxflag,lag,lag2,lag3,n; uint32_t now = (uint32_t)time(NULL); + std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { GetOpReturnData(scriptPubKey,vopret); @@ -1778,16 +1773,48 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i if ( localbits[i] == 0 ) localbits[i] = prevbits[i]; } - for (i=1; i 0 && localbits[i] < prevbits[i] ) - return(-1); - else if ( maxflag < 0 && localbits[i] > prevbits[i] ) - return(-1); + if ( (maxflag= maxflags[i]) != 0 ) + { + // make sure local price is moving in right direction + fprintf(stderr,"maxflag.%d i.%d localbits.%u vs pricebits.%u prevbits.%u\n",maxflag,i,localbits[i],pricebits[i],prevbits[i]); + if ( maxflag > 0 && localbits[i] < prevbits[i] ) + { + if ( iter == 0 ) + break; + // second iteration checks recent prices to see if within local volatility + for (j=0; j= prevbits[i] ) + { + fprintf(stderr,"within recent localprices[%d] %u >= %u\n",j,PriceCache[j][i],prevbits[i]); + continue; + } + break; + } + else if ( maxflag < 0 && localbits[i] > prevbits[i] ) + { + if ( iter == 0 ) + break; + for (j=0; j 333 ) - ASSETCHAINS_CBOPRET = 7; +if ( komodo_nextheight() > 333 ) // for debug only! + ASSETCHAINS_CBOPRET = 7; size = PRICES_SIZEBIT0; if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) size += sizeof(forexprices); @@ -2076,31 +2104,48 @@ void komodo_cbopretupdate() if ( Mineropret.size() < size ) Mineropret.resize(size); size = PRICES_SIZEBIT0; - if ( now > lastbtc+120 && get_btcusd(pricebits) == 0 ) + if ( (forceflag != 0 || now > lastbtc+120) && get_btcusd(pricebits) == 0 ) { - memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); - lastbtc = (uint32_t)time(NULL); + if ( flags == 0 ) + komodo_PriceCache_shift(); + memcpy(PriceCache[0],pricebits,PRICES_SIZEBIT0); + flags |= 1; } if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { - if ( now > lasttime+3600*5 || forexprices[0] == 0 ) + if ( now > lasttime+3600*5 || forexprices[0] == 0 ) // cant assume timestamp is valid for forex price as it is a daily weekday changing thing anyway. { get_dailyfx(forexprices); - memcpy(&Mineropret.data()[size],forexprices,sizeof(forexprices)); - lasttime = (uint32_t)time(NULL); + if ( flags == 0 ) + komodo_PriceCache_shift(); + flags |= 2; + memcpy(&PriceCache[0][size],forexprices,sizeof(forexprices)); } size += sizeof(forexprices); } if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) { - if ( now > lastcrypto+100 ) + if ( forceflag != 0 || flags != 0 ) { get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); - memcpy(&Mineropret.data()[size],cryptoprices,sizeof(cryptoprices)); - lastcrypto = (uint32_t)time(NULL); + if ( flags == 0 ) + komodo_PriceCache_shift(); + memcpy(&PriceCache[0][size],cryptoprices,sizeof(cryptoprices)); + flags |= 4; // very rarely we can see flags == 6 case } size += sizeof(cryptoprices); } + if ( flags != 0 ) + { + now = (uint32_t)time(NULL); + if ( (flags & 1) != 0 ) + lastbtc = now; + if ( (flags & 2) != 0 ) + lasttime = now; + if ( (flags & 4) != 0 ) + lastcrypto = now; + memcpy(Mineropret.data(),PriceCache[0],size); + } //int32_t i; for (i=0; i sizeof(heights)/sizeof(*heights) ) - maxsamples = sizeof(heights)/sizeof(*heights); nextheight = komodo_nextheight(); UniValue a(UniValue::VARR); + if ( daywindow < 7 ) + daywindow = 7; prices = (uint32_t *)calloc(sizeof(*prices),maxsamples+daywindow); correlated = (uint32_t *)calloc(sizeof(*correlated),maxsamples+daywindow); smoothed = (uint32_t *)calloc(sizeof(*smoothed),maxsamples+daywindow); @@ -1198,7 +1201,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { - if ( (n= komodo_prices(rawprices,ht)) > 0 ) + if ( (n= komodo_heightpricebits(rawprices,ht)) > 0 ) { if ( firstn == -1 ) firstn = n; @@ -1212,42 +1215,45 @@ UniValue prices(const UniValue& params, bool fHelp) } else throw JSONRPCError(RPC_INVALID_PARAMETER, "no komodo_rawprices found"); } } + for (i=0; i Date: Tue, 2 Apr 2019 00:10:28 -1100 Subject: [PATCH 021/122] Rearrange --- src/komodo_gateway.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6035cf82f..ccc1e05ce 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1552,6 +1552,16 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define PRICES_MAXCHANGE (COIN / 100) // maximum acceptable change, set at 1% #define PRICES_SIZEBIT0 (sizeof(uint32_t) * 4) // 4 uint32_t unixtimestamp, BTCUSD, BTCGBP and BTCEUR #define KOMODO_LOCALPRICE_CACHESIZE 7 + + +#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) + +const char *Cryptos[] = { "KMD", "ETH", "LTC", "BCHABC", "XMR", "IOTA", "DASH", "XEM", "ZEC", "WAVES", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" }; // must be on binance (for now) + +const char *Forex[] = +{ "BGN","NZD","ILS","RUB","CAD","PHP","CHF","AUD","JPY","TRY","HKD","MYR","HRK","CZK","IDR","DKK","NOK","HUF","GBP","MXN","THB","ISK","ZAR","BRL","SGD","PLN","INR","KRW","RON","CNY","SEK","EUR" +}; // must be in ECB list + uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)]; void komodo_PriceCache_shift() @@ -1923,13 +1933,6 @@ cJSON *send_curl(char *url,char *fname) // get_urljson just returns the JSON returned by the URL using issue_curl -#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) - -const char *Cryptos[] = { "KMD", "ETH", "LTC", "BCHABC", "XMR", "IOTA", "DASH", "XEM", "ZEC", "WAVES", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" }; - -const char *Forex[] = -{ "BGN","NZD","ILS","RUB","CAD","PHP","CHF","AUD","JPY","TRY","HKD","MYR","HRK","CZK","IDR","DKK","NOK","HUF","GBP","MXN","THB","ISK","ZAR","BRL","SGD","PLN","INR","KRW","RON","CNY","SEK","EUR" -}; /* const char *Techstocks[] = From aa2f4d910926f9d6f71fce28f306ad55131802e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 00:14:47 -1100 Subject: [PATCH 022/122] Arr --- src/rpc/blockchain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 20a2a8ac2..29979a489 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1178,6 +1178,8 @@ int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); uint32_t komodo_pricesmoothed(uint32_t *correlatedp,uint32_t *rawprices,int32_t numprices); uint32_t komodo_timestampset(uint32_t *correlatedp,uint32_t *rawprices,int32_t numprices); +int32_t komodo_nextheight(); +uint32_t komodo_heightstamp(int32_t height); UniValue prices(const UniValue& params, bool fHelp) { @@ -1237,9 +1239,9 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*(maxsamples+daywindow) + i; smoothed[offset] = komodo_pricesmoothed(&correlated[offset],&rawprices[offset],daywindow); UniValue parr(UniValue::VARR); - parr.push_back((double)prices[offset]/10000.); - parr.push_back((double)correlated[offset]/10000.); - parr.push_back((double)smoothed[offset]/10000.); + parr.push_back((uint64_t)prices[offset]); + parr.push_back((uint64_t)correlated[offset]); + parr.push_back((uint64_t)smoothed[offset]); prices.push_back(parr); } item.push_back(Pair("prices",prices)); From fa309e5b0e84c9287556234784d3abce1198c713 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 2 Apr 2019 19:14:51 +0800 Subject: [PATCH 023/122] Add context flag to stop checking twice --- src/chain.h | 5 ++++- src/main.cpp | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/chain.h b/src/chain.h index ee56c7662..d810ed4cb 100644 --- a/src/chain.h +++ b/src/chain.h @@ -102,6 +102,9 @@ enum BlockStatus: uint32_t { //! Scripts & signatures ok. Implies all parents are also at least SCRIPTS. BLOCK_VALID_SCRIPTS = 5, + // flag to check if contextual check block has passed in Accept block, if it has not check at connect block. + BLOCK_VALID_CONTEXT = 6, + //! All validity bits. BLOCK_VALID_MASK = BLOCK_VALID_HEADER | BLOCK_VALID_TREE | BLOCK_VALID_TRANSACTIONS | BLOCK_VALID_CHAIN | BLOCK_VALID_SCRIPTS, @@ -115,7 +118,7 @@ enum BlockStatus: uint32_t { BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, BLOCK_ACTIVATES_UPGRADE = 128, //! block activates a network upgrade - BLOCK_IN_TMPFILE = 256 + BLOCK_IN_TMPFILE = 256 }; //! Short-hand for the highest consensus validity we implement. diff --git a/src/main.cpp b/src/main.cpp index 20a963287..e8fe3810c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3274,14 +3274,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - // check pindex->CONTEXT_VALIDATED flag - if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 + if ( fCheckPOW != 0 && (pindex->nStatus & BLOCK_VALID_CONTEXT) != BLOCK_VALID_CONTEXT ) // Activate Jan 15th, 2019 { - fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); - if ( pindex->nTime > 1547510400 ) - return false; - fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); + if ( !ContextualCheckBlock(block, state, pindex->pprev) ) + { + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); + if ( pindex->nTime > 1547510400 ) + return false; + fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); + } else pindex->nStatus |= BLOCK_VALID_CONTEXT; } + // Do this here before the block is moved to the main block files. if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 ) { @@ -5340,7 +5343,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // See method docstring for why this is always disabled auto verifier = libzcash::ProofVerifier::Disabled(); - if ((!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) + bool fContextualCheckBlock = ContextualCheckBlock(block, state, pindex->pprev); + if ( (!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !fContextualCheckBlock ) { static int32_t saplinght = -1; CBlockIndex *tmpptr; @@ -5365,6 +5369,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C return false; } } + if ( fContextualCheckBlock ) + pindex->nStatus |= BLOCK_VALID_CONTEXT; int nHeight = pindex->GetHeight(); // Temp File fix. LABS has been using this for ages with no bad effects. From a29c2f179ea0545ce05b583cc7a925ab7681a6df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 00:29:03 -1100 Subject: [PATCH 024/122] Test --- src/komodo_gateway.h | 12 +++++++---- src/rpc/blockchain.cpp | 46 +++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ccc1e05ce..021abbd60 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2213,14 +2213,18 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } -uint32_t komodo_timestampset(uint32_t *correlatedp,uint32_t *rawtimestamps,int32_t numtimestamps) +int64_t komodo_timestampset(int64_t *correlatedp,uint32_t *rawtimestamps,int32_t numtimestamps) { *correlatedp = rawtimestamps[0]; - return(rawtimestamps[0]); // really to do this would need to do it on a per pricefeed and which prices were used in the correlation, but that is a lot of extra work for a field which is not critical + return(*correlatedp); // really to do this would need to do it on a per pricefeed and which prices were used in the correlation, but that is a lot of extra work for a field which is not critical } -uint32_t komodo_pricesmoothed(uint32_t *correlatedp,uint32_t *rawprices,int32_t numprices) +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) { - + return(0); } +int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) +{ + return(0); +} diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 29979a489..01939bb7d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1176,8 +1176,9 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -uint32_t komodo_pricesmoothed(uint32_t *correlatedp,uint32_t *rawprices,int32_t numprices); -uint32_t komodo_timestampset(uint32_t *correlatedp,uint32_t *rawprices,int32_t numprices); +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices); +int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices); +int64_t komodo_timestampset(int64_t *correlatedp,uint32_t *rawprices,int32_t numprices); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1186,7 +1187,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); char name[64],*str; uint32_t rawprices[2048],*prices,*correlated,*smoothed; uint32_t i,j,firstn=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,firstn=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; int32_t maxsamples = atoi(params[0].get_str().c_str()); if ( maxsamples < 1 ) maxsamples = 1; @@ -1194,10 +1195,11 @@ UniValue prices(const UniValue& params, bool fHelp) UniValue a(UniValue::VARR); if ( daywindow < 7 ) daywindow = 7; - prices = (uint32_t *)calloc(sizeof(*prices),maxsamples+daywindow); - correlated = (uint32_t *)calloc(sizeof(*correlated),maxsamples+daywindow); - smoothed = (uint32_t *)calloc(sizeof(*smoothed),maxsamples+daywindow); - for (ht=nextheight-1,i=0; idaywindow+2; i++,ht--) + width = maxsamples+2*daywindow; + prices = (uint32_t *)calloc(sizeof(*prices),width); + correlated = (int64_t *)calloc(sizeof(*correlated),width); + //smoothed = (uint32_t *)calloc(sizeof(*smoothed),width); + for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); @@ -1212,7 +1214,7 @@ UniValue prices(const UniValue& params, bool fHelp) else { for (j=0; j Date: Tue, 2 Apr 2019 00:55:09 -1100 Subject: [PATCH 025/122] Fix --- src/komodo_gateway.h | 21 +++++++++++++-------- src/rpc/blockchain.cpp | 36 ++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 021abbd60..450f42aeb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2213,18 +2213,23 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } -int64_t komodo_timestampset(int64_t *correlatedp,uint32_t *rawtimestamps,int32_t numtimestamps) -{ - *correlatedp = rawtimestamps[0]; - return(*correlatedp); // really to do this would need to do it on a per pricefeed and which prices were used in the correlation, but that is a lot of extra work for a field which is not critical -} - int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) { - return(0); + int32_t i; + for (i=0; i2*daywindow+2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) @@ -1207,9 +1208,7 @@ UniValue prices(const UniValue& params, bool fHelp) { if ( (n= komodo_heightpricebits(rawprices,ht)) > 0 ) { - if ( firstn == -1 ) - firstn = n; - else if ( n != firstn ) + if ( n != numpricefeeds ) throw JSONRPCError(RPC_INVALID_PARAMETER, "numprices != first numprices"); else { @@ -1222,15 +1221,12 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 00:56:12 -1100 Subject: [PATCH 026/122] uint32_t price; --- 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 450f42aeb..578b36cd6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2224,7 +2224,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) { - int64_t sum = 0; uint32_t price; + int32_t i; uint32_t price; int64_t sum = 0; for (i=0; i Date: Tue, 2 Apr 2019 00:58:55 -1100 Subject: [PATCH 027/122] daywindow --- src/rpc/blockchain.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 09c297ab9..bc8df8132 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1187,6 +1187,9 @@ UniValue prices(const UniValue& params, bool fHelp) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); UniValue ret(UniValue::VOBJ); int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + if ( ASSETCHAINS_CBOPRET == 0 ) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + int32_t maxsamples = atoi(params[0].get_str().c_str()); if ( maxsamples < 1 ) maxsamples = 1; @@ -1256,7 +1259,7 @@ UniValue prices(const UniValue& params, bool fHelp) ret.push_back(Pair("height",(int64_t)nextheight-1)); ret.push_back(Pair("maxsamples",(int64_t)maxsamples)); ret.push_back(Pair("width",(int64_t)width)); - ret.push_back(Pair("daywidth",(int64_t)daywidth)); + ret.push_back(Pair("daywindow",(int64_t)daywindow)); ret.push_back(Pair("numpricefeeds",(int64_t)numpricefeeds)); free(prices); free(correlated); From ef41124c631d401166bbbd1899e5d01b0650ec98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 01:06:00 -1100 Subject: [PATCH 028/122] +print --- src/rpc/blockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bc8df8132..6485bc2cc 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1235,6 +1235,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( (str= komodo_pricename(name,j)) != 0 ) { item.push_back(Pair("name",str)); + fprintf(stderr,"%s from %d to %d width.%d\n",name,j*width,j*width+maxsamples+daywindow,width); for (i=0; i Date: Tue, 2 Apr 2019 01:11:41 -1100 Subject: [PATCH 029/122] Fix off by one in PriceCache copy --- src/komodo_gateway.h | 8 ++++++-- src/rpc/blockchain.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 578b36cd6..c780306d0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1567,8 +1567,12 @@ uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][4+sizeof(Cryptos)/sizeof(*Crypt void komodo_PriceCache_shift() { int32_t i; - for (i=KOMODO_LOCALPRICE_CACHESIZE-1; i>=0; i--) + for (i=KOMODO_LOCALPRICE_CACHESIZE-1; i>0; i--) + { memcpy(PriceCache[i],PriceCache[i-1],sizeof(PriceCache[i])); + //for (j=0; j<4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex); j++) + // PriceCache[i][j] = PriceCache[i-1][j]; + } } // komodo_heightpricebits() extracts the price data in the coinbase for nHeight @@ -1787,7 +1791,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i { for (i=1; i Date: Tue, 2 Apr 2019 01:16:42 -1100 Subject: [PATCH 030/122] NOT raw prices, that is just single blocks data --- src/komodo_gateway.h | 2 ++ src/rpc/blockchain.cpp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c780306d0..a78927c05 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2199,6 +2199,7 @@ char *komodo_pricename(char *name,int32_t ind) if ( ind < sizeof(Forex)/sizeof(*Forex) ) { strcpy(name,Forex[ind]); + strcat(name,"USD"); return(name); } else ind -= sizeof(Forex)/sizeof(*Forex); } @@ -2209,6 +2210,7 @@ char *komodo_pricename(char *name,int32_t ind) if ( ind < sizeof(Cryptos)/sizeof(*Cryptos) ) { strcpy(name,Cryptos[ind]); + strcat(name,"BTC"); return(name); } else ind -= sizeof(Cryptos)/sizeof(*Cryptos); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 52a56f1ac..2ee802fb3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1224,7 +1224,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 01:19:26 -1100 Subject: [PATCH 031/122] Test --- src/rpc/blockchain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 2ee802fb3..a1beefefd 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1231,7 +1231,7 @@ UniValue prices(const UniValue& params, bool fHelp) } for (j=1; j Date: Tue, 2 Apr 2019 01:20:34 -1100 Subject: [PATCH 032/122] Double --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a1beefefd..ac1690634 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1246,7 +1246,7 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back((double)prices[offset]/10000); + parr.push_back((double)(prices[offset]/10000)); parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); From f6232685cd04397b681e97e9a4a4e804a0dd78eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 01:21:19 -1100 Subject: [PATCH 033/122] Cons --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ac1690634..550217e2d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1246,7 +1246,7 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back((double)(prices[offset]/10000)); + parr.push_back(ValueFromAmount(prices[offset]*10000)); parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); From d93b34b04a92360a531bc941a6bbea9b90232c96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 01:25:45 -1100 Subject: [PATCH 034/122] Test --- src/komodo_gateway.h | 2 ++ src/rpc/blockchain.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a78927c05..6b8df1834 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2235,7 +2235,9 @@ int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) { if ( (price= rawprices[i]) == 0 ) return(0); + fprintf(stderr,"%.4f ",(double)price/10000); sum += price * 10000; } + fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); return(sum / numprices); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 550217e2d..8a2752088 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1229,13 +1229,12 @@ UniValue prices(const UniValue& params, bool fHelp) ret.push_back(Pair("timestamps",timestamps)); ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); } - for (j=1; j Date: Tue, 2 Apr 2019 01:29:54 -1100 Subject: [PATCH 035/122] Limit copy range --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8a2752088..a748e63c4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1203,7 +1203,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds); correlated = (int64_t *)calloc(sizeof(*correlated),width); - for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) + for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); From 61e193953fa380ccb41fb22c786d80972e987a8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 01:33:28 -1100 Subject: [PATCH 036/122] Cross copy --- src/rpc/blockchain.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a748e63c4..c1eb1bac6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1203,7 +1203,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds); correlated = (int64_t *)calloc(sizeof(*correlated),width); - for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) + for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); @@ -1215,8 +1215,12 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "numprices != first numprices"); else { - for (j=0; j Date: Tue, 2 Apr 2019 01:34:31 -1100 Subject: [PATCH 037/122] ; --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index c1eb1bac6..d5c78e68a 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1219,7 +1219,7 @@ UniValue prices(const UniValue& params, bool fHelp) { prices[j*width + i] = rawprices[j]; if ( j == 1 ) - fprintf(stderr,"[%d] <- %.1f ",j*width+i,(double)rawprices[j]/10000) + fprintf(stderr,"[%d] <- %.1f ",j*width+i,(double)rawprices[j]/10000); } } } else throw JSONRPCError(RPC_INVALID_PARAMETER, "no komodo_rawprices found"); From 7b0d2efa74c8a3939ad5670180408ab2d0c212e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 01:37:16 -1100 Subject: [PATCH 038/122] cast --- src/komodo_gateway.h | 4 ++-- src/rpc/blockchain.cpp | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6b8df1834..6ecfd170c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2235,8 +2235,8 @@ int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) { if ( (price= rawprices[i]) == 0 ) return(0); - fprintf(stderr,"%.4f ",(double)price/10000); - sum += price * 10000; + fprintf(stderr,"%.0f ",(double)price/10000); + sum += (int64_t)price * 10000; } fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); return(sum / numprices); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index d5c78e68a..32b1c9cb7 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1216,11 +1216,7 @@ UniValue prices(const UniValue& params, bool fHelp) else { for (j=0; j Date: Tue, 2 Apr 2019 01:45:33 -1100 Subject: [PATCH 039/122] Fix --- src/komodo_gateway.h | 4 ++-- src/rpc/blockchain.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6ecfd170c..a87a04e57 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2235,9 +2235,9 @@ int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) { if ( (price= rawprices[i]) == 0 ) return(0); - fprintf(stderr,"%.0f ",(double)price/10000); + //fprintf(stderr,"%.0f ",(double)price/10000); sum += (int64_t)price * 10000; } - fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); + //fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); return(sum / numprices); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 32b1c9cb7..f927cf050 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1229,7 +1229,7 @@ UniValue prices(const UniValue& params, bool fHelp) ret.push_back(Pair("timestamps",timestamps)); ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); } - for (j=1; j<2; j++) + for (j=1; j Date: Tue, 2 Apr 2019 01:54:47 -1100 Subject: [PATCH 040/122] -print --- src/komodo_gateway.h | 4 ++-- src/rpc/blockchain.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a87a04e57..bb67d1e8d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2230,13 +2230,13 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) { - int32_t i; uint32_t price; int64_t sum = 0; + int32_t i; int64_t price,sum = 0; for (i=0; i Date: Tue, 2 Apr 2019 01:58:18 -1100 Subject: [PATCH 041/122] Rescale --- src/rpc/blockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1288c02ea..2b0186f22 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1245,9 +1245,9 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back(((int64_t)prices[offset]*10000)); - parr.push_back((correlated[i])); - parr.push_back((smoothed)); + parr.push_back(ValueFromAmount((int64_t)prices[offset])); + parr.push_back(ValueFromAmount(correlated[i]/10000)); + parr.push_back(ValueFromAmount(smoothed/10000)); p.push_back(parr); } item.push_back(Pair("prices",p)); From b5af10d99f56f11d17bb22dcef8ebab7e6502a8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:05:27 -1100 Subject: [PATCH 042/122] Normalize all prices --- src/komodo_gateway.h | 7 ++++--- src/rpc/blockchain.cpp | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bb67d1e8d..bbad94c51 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2228,15 +2228,16 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) return(correlated[0]); } -int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices) +int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices) { int32_t i; int64_t price,sum = 0; for (i=0; i= 36 ) + price *= 10000; + sum += price; } //fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); return(sum / numprices); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 2b0186f22..c628ab074 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1246,8 +1246,8 @@ UniValue prices(const UniValue& params, bool fHelp) smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); parr.push_back(ValueFromAmount((int64_t)prices[offset])); - parr.push_back(ValueFromAmount(correlated[i]/10000)); - parr.push_back(ValueFromAmount(smoothed/10000)); + parr.push_back(ValueFromAmount(correlated[i])); + parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); } item.push_back(Pair("prices",p)); From cf281b048edc19fdbdeb1fbb567f8964d1bcaa48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:07:32 -1100 Subject: [PATCH 043/122] int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices) --- src/rpc/blockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index c628ab074..eab787f17 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1177,7 +1177,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices); -int64_t komodo_pricecorrelated(uint32_t *rawprices,int32_t numprices); +int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1238,7 +1238,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 02:13:20 -1100 Subject: [PATCH 044/122] Reverse --- src/komodo_gateway.h | 14 +++++++++----- src/rpc/blockchain.cpp | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bbad94c51..293b57367 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1576,9 +1576,11 @@ void komodo_PriceCache_shift() } // komodo_heightpricebits() extracts the price data in the coinbase for nHeight -int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) +int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight) { CBlockIndex *pindex; CBlock block; CTransaction tx; int32_t numvouts; std::vector vopret; + if ( seedp != 0 ) + *seedp = 0; if ( (pindex= komodo_chainactive(nHeight)) != 0 ) { if ( komodo_blockload(block,pindex) == 0 ) @@ -1588,6 +1590,8 @@ int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); if ( vopret.size() >= PRICES_SIZEBIT0 ) { + if ( seedp != 0 ) + memcpy(seedp,&pindex->hashMerkleRoot,sizeof(*seedp)); memcpy(heightbits,vopret.data(),vopret.size()); return((int32_t)(vopret.size()/sizeof(uint32_t))); } @@ -1682,7 +1686,7 @@ CScript komodo_mineropret(int32_t nHeight) if ( numzero != 0 ) fprintf(stderr,"numzero.%d\n",numzero); } - if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 ) + if ( komodo_heightpricebits(0,prevbits,nHeight-1) > 0 ) { memcpy(pricebits,Mineropret.data(),Mineropret.size()); memset(maxflags,0,sizeof(maxflags)); @@ -1757,7 +1761,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcusd/btceur,btcgbp/btceur,lag2); - if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 ) + if ( komodo_heightpricebits(0,prevbits,nHeight-1) > 0 ) { if ( nHeight < testchain_exemption ) { @@ -2228,14 +2232,14 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) return(correlated[0]); } -int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices) { int32_t i; int64_t price,sum = 0; for (i=0; i= 36 ) + if ( ind < 36 ) price *= 10000; sum += price; } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index eab787f17..1cfcf4eb7 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1174,10 +1174,10 @@ UniValue paxprice(const UniValue& params, bool fHelp) return ret; } -int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight); +int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices); -int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1186,7 +1186,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); uint64_t seed; int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1198,7 +1198,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( daywindow < 7 ) daywindow = 7; width = maxsamples+2*daywindow; - numpricefeeds = komodo_heightpricebits(rawprices,nextheight-1); + numpricefeeds = komodo_heightpricebits(&seed,rawprices,nextheight-1); if ( numpricefeeds <= 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds); @@ -1209,7 +1209,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { - if ( (n= komodo_heightpricebits(rawprices,ht)) > 0 ) + if ( (n= komodo_heightpricebits(0,rawprices,ht)) > 0 ) { if ( n != numpricefeeds ) throw JSONRPCError(RPC_INVALID_PARAMETER, "numprices != first numprices"); @@ -1238,7 +1238,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 02:17:35 -1100 Subject: [PATCH 045/122] Again --- src/rpc/blockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1cfcf4eb7..5bbf1ef1f 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1245,8 +1245,8 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back(ValueFromAmount((int64_t)prices[offset])); - parr.push_back(ValueFromAmount(correlated[i])); + parr.push_back(ValueFromAmount((int64_t)prices[offset]*10000)); + parr.push_back(ValueFromAmount(correlated[i]*ind<36?10000:1)); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); } From 57b769c44d11e62a0af9dd73eb22991fc238efcd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:19:32 -1100 Subject: [PATCH 046/122] J --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5bbf1ef1f..772c590b6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1246,7 +1246,7 @@ UniValue prices(const UniValue& params, bool fHelp) smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); parr.push_back(ValueFromAmount((int64_t)prices[offset]*10000)); - parr.push_back(ValueFromAmount(correlated[i]*ind<36?10000:1)); + parr.push_back(ValueFromAmount(correlated[i]*j<36?10000:1)); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); } From 8e84d8e0ea186f1645b8d83e660d30fb71ecc172 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:24:31 -1100 Subject: [PATCH 047/122] ugh --- src/komodo_gateway.h | 4 ++-- src/rpc/blockchain.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 293b57367..1f1ce8dc6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2202,8 +2202,8 @@ char *komodo_pricename(char *name,int32_t ind) return(0); if ( ind < sizeof(Forex)/sizeof(*Forex) ) { - strcpy(name,Forex[ind]); - strcat(name,"USD"); + name[0] = 'U', name[1] = 'S', name[2] = 'D'; + strcpy(name+3,Forex[ind]); return(name); } else ind -= sizeof(Forex)/sizeof(*Forex); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 772c590b6..5ba28438b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1245,8 +1245,8 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back(ValueFromAmount((int64_t)prices[offset]*10000)); - parr.push_back(ValueFromAmount(correlated[i]*j<36?10000:1)); + parr.push_back(ValueFromAmount((int64_t)prices[offset]*j<36?10000:1)); + parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); } From d701423bfbc274a0ab520f4c8ff52a17ac9d4db0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:27:08 -1100 Subject: [PATCH 048/122] Fiddle --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5ba28438b..9f4b24235 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1245,7 +1245,7 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back(ValueFromAmount((int64_t)prices[offset]*j<36?10000:1)); + parr.push_back(ValueFromAmount((int64_t)prices[offset]*10000)); parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); From 2df1a61d73ed3dc27c7ae91353313dda6127cde5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:28:59 -1100 Subject: [PATCH 049/122] Finally --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 9f4b24235..bbf90f163 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1245,7 +1245,7 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back(ValueFromAmount((int64_t)prices[offset]*10000)); + parr.push_back(ValueFromAmount((int64_t)prices[offset]* j<36?10000:1)); parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); From b952e57e95448b2b85b0f2c492eca4941e708e06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:34:32 -1100 Subject: [PATCH 050/122] ?: precedence --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bbf90f163..668081934 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1245,7 +1245,7 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow); UniValue parr(UniValue::VARR); - parr.push_back(ValueFromAmount((int64_t)prices[offset]* j<36?10000:1)); + parr.push_back(ValueFromAmount((int64_t)prices[offset] * (j<36?10000:1))); parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); From d725af022effeb935cefc2f05d8efe19cc7ef00a Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 2 Apr 2019 06:44:09 -0700 Subject: [PATCH 051/122] Client name is not a consensus-related option, it can be configured by any node --- src/clientversion.cpp | 2 +- src/init.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 663e2e937..084bbd5ce 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -35,7 +35,7 @@ * for both bitcoind and bitcoin-core, to make it harder for attackers to * target servers or GUI users specifically. */ -const std::string CLIENT_NAME = GetArg("-ac_clientname", "MagicBean"); +const std::string CLIENT_NAME = GetArg("-clientname", "MagicBean"); /** * Client version number diff --git a/src/init.cpp b/src/init.cpp index d2546347d..24b32a720 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -367,6 +367,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-blocknotify=", _("Execute command when the best block changes (%s in cmd is replaced by block hash)")); strUsage += HelpMessageOpt("-checkblocks=", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 288)); strUsage += HelpMessageOpt("-checklevel=", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), 3)); + strUsage += HelpMessageOpt("-clientname=", _("Full node client name, default 'MagicBean'")); strUsage += HelpMessageOpt("-conf=", strprintf(_("Specify configuration file (default: %s)"), "komodo.conf")); if (mode == HMM_BITCOIND) { @@ -571,7 +572,6 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-ac_cclib", _("Cryptoconditions dynamicly loadable library")); strUsage += HelpMessageOpt("-ac_ccenable", _("Cryptoconditions to enable")); strUsage += HelpMessageOpt("-ac_ccactivate", _("Block height to enable Cryptoconditions")); - strUsage += HelpMessageOpt("-ac_clientname", _("Full node client name, default 'MagicBean'")); strUsage += HelpMessageOpt("-ac_decay", _("Percentage of block reward decrease at each halving")); strUsage += HelpMessageOpt("-ac_end", _("Block height at which block rewards will end")); strUsage += HelpMessageOpt("-ac_eras", _("Block reward eras")); From 4b7a2ca365e9d37fd21584c927ea19a643ecbbe2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:16:20 -1100 Subject: [PATCH 052/122] First version correlator --- src/komodo_gateway.h | 42 ++++++++++++++++++++++++++++++++---------- src/rpc/blockchain.cpp | 4 +++- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1f1ce8dc6..b59a6fbf1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2232,17 +2232,39 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) return(correlated[0]); } -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) { - int32_t i; int64_t price,sum = 0; - for (i=0; i= daywindow ) + i = 0; + if ( (price= rawprices[i]) == 0 ) + return(-1); + if ( price >= lowprice && price <= highprice ) + { + sum += price; + correlation++; + if ( correlation > (daywindow>>1) ) + { + fprintf(stderr,"iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + return(sum / correlation) + } + } + } } - //fprintf(stderr," ave %.8f [%d]\n",((double)sum/numprices)/COIN,numprices); - return(sum / numprices); + return(0); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 668081934..c68d4b14b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1238,7 +1238,8 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 03:17:38 -1100 Subject: [PATCH 053/122] 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 b59a6fbf1..9bfc76835 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2261,7 +2261,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( correlation > (daywindow>>1) ) { fprintf(stderr,"iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); - return(sum / correlation) + return(sum / correlation); } } } From e3a910b8cbf3c181cc37e15f0a65f7df03511a17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:30:46 -1100 Subject: [PATCH 054/122] +print --- src/komodo_gateway.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9bfc76835..d19325778 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1807,7 +1807,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i for (j=0; j= prevbits[i] ) { - fprintf(stderr,"within recent localprices[%d] %u >= %u\n",j,PriceCache[j][i],prevbits[i]); + fprintf(stderr,"i.%d within recent localprices[%d] %u >= %u\n",i,j,PriceCache[j][i],prevbits[i]); continue; } break; @@ -1819,7 +1819,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i for (j=0; j 333 ) // for debug only! get_stocks(Techstocks,(int32_t)(sizeof(Techstocks)/sizeof(*Techstocks))); }*/ } + pending = 0; } char *komodo_pricename(char *name,int32_t ind) @@ -2242,8 +2250,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int sum = correlation = 0; i = (j + seed) % daywindow; refprice = rawprices[i] * (ind < 36 ? 10000 : 1); - highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE/2)) / COIN; - lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE/2)) / COIN; + highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE/10)) / COIN; + lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE/10)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) @@ -2260,7 +2268,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation++; if ( correlation > (daywindow>>1) ) { - fprintf(stderr,"iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); return(sum / correlation); } } From 790873660f8d93046bf70a4b42d4bb17f295c870 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:33:11 -1100 Subject: [PATCH 055/122] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d19325778..bda57fab4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2250,8 +2250,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int sum = correlation = 0; i = (j + seed) % daywindow; refprice = rawprices[i] * (ind < 36 ? 10000 : 1); - highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE/10)) / COIN; - lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE/10)) / COIN; + highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE)) / COIN; + lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) From 8209b487d8eb9d7ae94d4964ef708ed224acca46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:36:05 -1100 Subject: [PATCH 056/122] Test --- src/komodo_gateway.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bda57fab4..2e7a3f5ea 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2242,7 +2242,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) { - int32_t i,j,iter,correlation; int64_t price,sum; uint32_t refprice,lowprice,highprice; + int32_t i,j,iter,correlation,maxcorrelation=0; int64_t price,sum; uint32_t refprice,lowprice,highprice; if ( daywindow < 2 ) return(-1); for (iter=0; iter maxcorrelation ) + maxcorrelation = correlation; } + fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d\n",ind,itermaxcorrelation); return(0); } From c808e4c196cd08a1d25c2c96d86f538a53d0721a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:45:08 -1100 Subject: [PATCH 057/122] Weighted correlation --- src/komodo_gateway.h | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2e7a3f5ea..3dc5b1bd8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2242,12 +2242,12 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) { - int32_t i,j,iter,correlation,maxcorrelation=0; int64_t price,sum; uint32_t refprice,lowprice,highprice; + int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den; uint32_t refprice,lowprice,highprice; if ( daywindow < 2 ) return(-1); for (iter=0; iter= lowprice && price <= highprice ) { - sum += price; correlation++; if ( correlation > (daywindow>>1) ) { - fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); - return(sum / correlation); + n = 0; + i = (j + seed) % daywindow; + for (j=0; j= daywindow ) + i = 0; + if ( n >= (daywindow>>1) ) + rawprices[i] = 0; + else + { + price = rawprices[i]; + if ( price < lowprice || price > highprice ) + rawprices[i] = 0; + else n++; + } + } + fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); + if ( n != correlation ) + return(-1); + sum = den = n = 0; + for (i=0; i %.8f\n",((double)sum / den) / COIN); + return(sum / den); } } } From 24ff9d6e54b281a2ce558f51ad7f3bc4218f16ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:46:40 -1100 Subject: [PATCH 058/122] if ( n != correlation ) return(-1); --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3dc5b1bd8..9254980b2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2250,8 +2250,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation = 0; i = (j + seed) % daywindow; refprice = rawprices[i] * (ind < 36 ? 10000 : 1); - highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE)) / COIN; - lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE)) / COIN; + highprice = ((int64_t)refprice * (COIN + 10*PRICES_MAXCHANGE)) / COIN; + lowprice = ((int64_t)refprice * (COIN - 10*PRICES_MAXCHANGE)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) @@ -2306,6 +2306,6 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( correlation > maxcorrelation ) maxcorrelation = correlation; } - fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d\n",ind,itermaxcorrelation); + fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d\n",ind,iter,maxcorrelation); return(0); } From db8fff57ab9a8ad1b8e3c989ccac3eadf545b686 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:55:45 -1100 Subject: [PATCH 059/122] Scale prices --- src/komodo_gateway.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9254980b2..06e263616 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2250,8 +2250,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation = 0; i = (j + seed) % daywindow; refprice = rawprices[i] * (ind < 36 ? 10000 : 1); - highprice = ((int64_t)refprice * (COIN + 10*PRICES_MAXCHANGE)) / COIN; - lowprice = ((int64_t)refprice * (COIN - 10*PRICES_MAXCHANGE)) / COIN; + highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE)) / COIN; + lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) @@ -2262,6 +2262,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int i = 0; if ( (price= rawprices[i]) == 0 ) return(-1); + if ( ind < 36 ) + price *= 10000; if ( price >= lowprice && price <= highprice ) { correlation++; @@ -2306,6 +2308,6 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( correlation > maxcorrelation ) maxcorrelation = correlation; } - fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d\n",ind,iter,maxcorrelation); + fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d ref.%u high.%u low.%u\n",ind,iter,maxcorrelation,refprice,highprice,lowprice); return(0); } From a4788f61e7550553a2ba86e6314267771f65819d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 03:56:29 -1100 Subject: [PATCH 060/122] Test --- src/komodo_gateway.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 06e263616..5c578fc5e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2242,14 +2242,17 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) { - int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den; uint32_t refprice,lowprice,highprice; + int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den; uint32_t mult,refprice,lowprice,highprice; if ( daywindow < 2 ) return(-1); + if ( ind < 36 ) + mult = 10000; + else mult = 1; for (iter=0; iter= lowprice && price <= highprice ) { correlation++; From f99fa65eda198c2e976c5f0c45c33f8d623643b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:01:54 -1100 Subject: [PATCH 061/122] Test --- src/komodo_gateway.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5c578fc5e..b5e000eb9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2242,7 +2242,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) { - int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den; uint32_t mult,refprice,lowprice,highprice; + int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den,mult,refprice,lowprice,highprice; if ( daywindow < 2 ) return(-1); if ( ind < 36 ) @@ -2253,8 +2253,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation = 0; i = (j + seed) % daywindow; refprice = rawprices[i] * mult; - highprice = ((int64_t)refprice * (COIN + PRICES_MAXCHANGE)) / COIN; - lowprice = ((int64_t)refprice * (COIN - PRICES_MAXCHANGE)) / COIN; + highprice = (refprice * (COIN + PRICES_MAXCHANGE)) / COIN; + lowprice = (refprice * (COIN - PRICES_MAXCHANGE)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) @@ -2268,10 +2268,11 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int price *= mult; if ( price >= lowprice && price <= highprice ) { + sum += price; correlation++; if ( correlation > (daywindow>>1) ) { - n = 0; + /*n = 0; i = (j + seed) % daywindow; for (j=0; j %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); - if ( n != correlation ) + }*/ + fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + /*if ( n != correlation ) return(-1); sum = den = n = 0; for (i=0; i %.8f\n",((double)sum / den) / COIN); - return(sum / den); + return(sum / den);*/ + return(sum / correlation); } } } From c159b78f6f0bb33c89c86dac13ab2dba7640130b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:08:11 -1100 Subject: [PATCH 062/122] Test --- src/komodo_gateway.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b5e000eb9..09559d960 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2231,15 +2231,6 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } -int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) -{ - int32_t i; - for (i=0; i %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + //fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); /*if ( n != correlation ) return(-1); sum = den = n = 0; @@ -2312,6 +2303,17 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( correlation > maxcorrelation ) maxcorrelation = correlation; } - fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d ref.%u high.%u low.%u\n",ind,iter,maxcorrelation,refprice,highprice,lowprice); + fprintf(stderr,"ind.%d iter.%d maxcorrelation.%d ref.%llu high.%llu low.%llu\n",ind,iter,maxcorrelation,(long long)refprice,(long long)highprice,(long long)lowprice); return(0); } + + +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) +{ + int32_t i; + for (i=0; i Date: Tue, 2 Apr 2019 04:18:44 -1100 Subject: [PATCH 063/122] Init sum --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 09559d960..b0b21b49f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2243,23 +2243,23 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int { correlation = 0; i = (j + seed) % daywindow; - refprice = rawprices[i] * mult; + refprice = rawprices[i]; highprice = (refprice * (COIN + PRICES_MAXCHANGE)) / COIN; lowprice = (refprice * (COIN - PRICES_MAXCHANGE)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) lowprice--; + sum = 0; for (j=0; j= daywindow ) i = 0; if ( (price= rawprices[i]) == 0 ) return(-1); - price *= mult; if ( price >= lowprice && price <= highprice ) { - sum += price; + sum += price * mult; correlation++; if ( correlation > (daywindow>>1) ) { From 2b1dff7b0c5c6d9325de82bf4fd6395a7f7a1781 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:19:05 -1100 Subject: [PATCH 064/122] Allow more variance --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b0b21b49f..7df402d69 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2244,8 +2244,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation = 0; i = (j + seed) % daywindow; refprice = rawprices[i]; - highprice = (refprice * (COIN + PRICES_MAXCHANGE)) / COIN; - lowprice = (refprice * (COIN - PRICES_MAXCHANGE)) / COIN; + highprice = (refprice * (COIN + PRICES_MAXCHANGE*2)) / COIN; + lowprice = (refprice * (COIN - PRICES_MAXCHANGE*2)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) From 47f2069490780624642adf8d4350da9033b1cfbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:29:54 -1100 Subject: [PATCH 065/122] Weight correlated price --- src/komodo_gateway.h | 33 +++++++++++++++++++-------------- src/rpc/blockchain.cpp | 9 ++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7df402d69..66e9fae78 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2231,7 +2231,7 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *rawprices2) { int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den,mult,refprice,lowprice,highprice; if ( daywindow < 2 ) @@ -2239,13 +2239,15 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( ind < 36 ) mult = 10000; else mult = 1; + if ( memcmp(rawprices,rawprices2,daywindow*sizeof(*rawprices)) != 0 ) + fprintf(stderr,"ind.%d rawprices2 != rawprices\n",ind); for (iter=0; iter (daywindow>>1) ) { - /*n = 0; + n = 0; i = (j + seed) % daywindow; for (j=0; j= daywindow ) i = 0; if ( n >= (daywindow>>1) ) - rawprices[i] = 0; + rawprices2[i] = 0; else { price = rawprices[i]; if ( price < lowprice || price > highprice ) - rawprices[i] = 0; - else n++; + rawprices2[i] = 0; + else + { + rawprices2[i] = price; + n++; + } } - }*/ - //fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); - /*if ( n != correlation ) + } + fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + if ( n != correlation ) return(-1); sum = den = n = 0; for (i=0; i %.8f\n",((double)sum / den) / COIN); - return(sum / den);*/ - return(sum / correlation); + fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); + return((sum * mult) / den); } } } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index c68d4b14b..c41803908 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1177,7 +1177,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices); -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1186,7 +1186,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); uint64_t seed; int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); uint64_t seed; int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1203,6 +1203,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds); correlated = (int64_t *)calloc(sizeof(*correlated),width); + prices2 = (int64_t *)calloc(sizeof(*prices2),width); for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) @@ -1238,7 +1239,8 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 04:31:40 -1100 Subject: [PATCH 066/122] Test --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index c41803908..9b0f5ec0a 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1203,7 +1203,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds); correlated = (int64_t *)calloc(sizeof(*correlated),width); - prices2 = (int64_t *)calloc(sizeof(*prices2),width); + prices2 = (uint32_t *)calloc(sizeof(*prices2),width); for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) From a589a789f1eeee708896253bc50d125e7e1f7bb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:35:59 -1100 Subject: [PATCH 067/122] +print --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 66e9fae78..85c24c475 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2299,7 +2299,10 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int } } if ( n != correlation || sum == 0 || den == 0 ) + { + fprintf(stderr,"n.%d vs correlation.%d sum %llu, den %llu\n",n,correlation,(long long)sum,(long long)den); return(-1); + } fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } From 41748a83fc55884bbd78e101245f59e8a1562153 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:39:01 -1100 Subject: [PATCH 068/122] Test --- src/komodo_gateway.h | 10 +++++----- src/rpc/blockchain.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 85c24c475..a3a6445f6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2233,14 +2233,14 @@ char *komodo_pricename(char *name,int32_t ind) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *rawprices2) { - int32_t i,j,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den,mult,refprice,lowprice,highprice; + int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den,mult,refprice,lowprice,highprice; if ( daywindow < 2 ) return(-1); if ( ind < 36 ) mult = 10000; else mult = 1; - if ( memcmp(rawprices,rawprices2,daywindow*sizeof(*rawprices)) != 0 ) - fprintf(stderr,"ind.%d rawprices2 != rawprices\n",ind); + //if ( memcmp(rawprices,rawprices2,daywindow*sizeof(*rawprices)) != 0 ) + // fprintf(stderr,"ind.%d rawprices2 != rawprices\n",ind); for (iter=0; iter= daywindow ) i = 0; @@ -2300,7 +2300,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int } if ( n != correlation || sum == 0 || den == 0 ) { - fprintf(stderr,"n.%d vs correlation.%d sum %llu, den %llu\n",n,correlation,(long long)sum,(long long)den); + fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 9b0f5ec0a..bc2e50fe4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1239,7 +1239,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 04:42:42 -1100 Subject: [PATCH 069/122] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a3a6445f6..5fabf72b2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2271,7 +2271,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int { if ( i >= daywindow ) i = 0; - if ( n >= (daywindow>>1) ) + if ( n > (daywindow>>1) ) rawprices2[i] = 0; else { @@ -2285,7 +2285,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int } } } - fprintf(stderr,"ind.%d iter.%d j.%d i.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,correlation,(long long)refprice,(long long)sum/correlation); + fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); if ( n != correlation ) return(-1); sum = den = n = 0; From 306314dceef91dc37ad0de86bf2ddf707c15e36b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 04:54:34 -1100 Subject: [PATCH 070/122] Smoother --- src/komodo_gateway.h | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5fabf72b2..d4b629f0d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2239,8 +2239,6 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( ind < 36 ) mult = 10000; else mult = 1; - //if ( memcmp(rawprices,rawprices2,daywindow*sizeof(*rawprices)) != 0 ) - // fprintf(stderr,"ind.%d rawprices2 != rawprices\n",ind); for (iter=0; iter %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); + //fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); if ( n != correlation ) return(-1); sum = den = n = 0; @@ -2303,7 +2301,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } - fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); + //fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } @@ -2318,10 +2316,32 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) { - int32_t i; - for (i=0; i Date: Tue, 2 Apr 2019 05:00:31 -1100 Subject: [PATCH 071/122] Anchor to latest --- src/komodo_gateway.h | 7 ++++--- src/rpc/blockchain.cpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d4b629f0d..e7186ccc3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2233,7 +2233,7 @@ char *komodo_pricename(char *name,int32_t ind) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *rawprices2) { - int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t price,sum,den,mult,refprice,lowprice,highprice; + int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice; if ( daywindow < 2 ) return(-1); if ( ind < 36 ) @@ -2287,12 +2287,13 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( n != correlation ) return(-1); sum = den = n = 0; + firstprice = rawprices2[0]; for (i=0; i> 1); n++; } } @@ -2337,7 +2338,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) sum = den = 0; for (i=0; i> 1); den += (numprices - i); } smoothed = (sum / den); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bc2e50fe4..2ff865f88 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1256,6 +1256,7 @@ UniValue prices(const UniValue& params, bool fHelp) item.push_back(Pair("prices",p)); } else item.push_back(Pair("name","error")); a.push_back(item); +break; } ret.push_back(Pair("pricefeeds",a)); ret.push_back(Pair("result","success")); From fd3996cb88064c718cede483310d0d62b4d4b8bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:04:22 -1100 Subject: [PATCH 072/122] 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 e7186ccc3..9f0f1e7fe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2302,7 +2302,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } - //fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); + fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } From 88eee07c7ffca378f30f8b07d6c9ad845438f30f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:08:03 -1100 Subject: [PATCH 073/122] tst --- src/komodo_gateway.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9f0f1e7fe..57835ab7a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1617,7 +1617,7 @@ uint32_t komodo_pricenew(char *maxflagp,uint32_t price,uint32_t refprice,int64_t lowprice--; if ( price >= highprice ) { - fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + //fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); if ( price > highprice ) // return non-zero only if we violate the tolerance { *maxflagp = 2; @@ -2287,7 +2287,10 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( n != correlation ) return(-1); sum = den = n = 0; - firstprice = rawprices2[0]; + for (i=0; i> 1); n++; - } + } else return(-1); } if ( n != correlation || sum == 0 || den == 0 ) { fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } - fprintf(stderr,"weighted -> %.8f\n",((double)(sum*mult) / den) / COIN); + //fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } From fcea5524d7df451cb9ce0dafaf82e1c94d0f842a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:10:45 -1100 Subject: [PATCH 074/122] Skip --- 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 57835ab7a..e0efd5734 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2298,7 +2298,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int den += (daywindow - i); sum += (daywindow - i) * ((price + firstprice) >> 1); n++; - } else return(-1); + } } if ( n != correlation || sum == 0 || den == 0 ) { From 4c0eaa7a1f5411f3eddf2faa3d5e8ede5b7e7ffd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:15:02 -1100 Subject: [PATCH 075/122] 2/3 --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e0efd5734..3e6d8061a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2296,7 +2296,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= rawprices2[i]) != 0 ) { den += (daywindow - i); - sum += (daywindow - i) * ((price + firstprice) >> 1); + sum += (daywindow - i) * ((price + firstprice*2) / 3); n++; } } @@ -2305,7 +2305,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } - //fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); + fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } @@ -2341,7 +2341,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) sum = den = 0; for (i=0; i> 1); + sum += (numprices - i) * ((correlated[i] + firstprice*2) / 3); den += (numprices - i); } smoothed = (sum / den); From fe9eb8df39f1ca763cfdddb22c0435f1942de5f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:19:01 -1100 Subject: [PATCH 076/122] nonzprices --- src/komodo_gateway.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3e6d8061a..57b537606 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2231,7 +2231,7 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *rawprices2) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *nonzprices) { int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice; if ( daywindow < 2 ) @@ -2270,15 +2270,16 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( i >= daywindow ) i = 0; if ( n > (daywindow>>1) ) - rawprices2[i] = 0; + nonzprices[i] = 0; else { price = rawprices[i]; if ( price < lowprice || price > highprice ) - rawprices2[i] = 0; + nonzprices[i] = 0; else { - rawprices2[i] = price; + nonzprices[i] = price; + fprintf(stderr,"(%d %u) ",i,rawprices[i]); n++; } } @@ -2288,12 +2289,13 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int return(-1); sum = den = n = 0; for (i=0; i Date: Tue, 2 Apr 2019 05:23:32 -1100 Subject: [PATCH 077/122] Test --- src/rpc/blockchain.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 2ff865f88..bc8302589 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1186,7 +1186,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); uint64_t seed; int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1230,8 +1230,10 @@ UniValue prices(const UniValue& params, bool fHelp) ret.push_back(Pair("timestamps",timestamps)); ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); } + rngval = seed; for (j=1; j Date: Tue, 2 Apr 2019 05:28:11 -1100 Subject: [PATCH 078/122] Iter + seed --- src/komodo_gateway.h | 4 ++-- src/rpc/blockchain.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 57b537606..eff32b495 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2242,7 +2242,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int for (iter=0; iter (daywindow>>1) ) { n = 0; - i = (j + seed) % daywindow; + i = (iter + seed) % daywindow; for (k=0; k= daywindow ) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bc8302589..7055e65c3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1241,7 +1241,6 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 05:31:47 -1100 Subject: [PATCH 079/122] Rngval inside inner loop --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 7055e65c3..fc476657d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1233,7 +1233,6 @@ UniValue prices(const UniValue& params, bool fHelp) rngval = seed; for (j=1; j Date: Tue, 2 Apr 2019 05:38:06 -1100 Subject: [PATCH 080/122] Test --- src/rpc/blockchain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index fc476657d..eaeae8f60 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1231,6 +1231,9 @@ UniValue prices(const UniValue& params, bool fHelp) ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); } rngval = seed; + for (i=0; i Date: Tue, 2 Apr 2019 05:42:40 -1100 Subject: [PATCH 081/122] tst --- src/rpc/blockchain.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index eaeae8f60..a72f0c341 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1222,16 +1222,13 @@ UniValue prices(const UniValue& params, bool fHelp) } else throw JSONRPCError(RPC_INVALID_PARAMETER, "no komodo_rawprices found"); } } + ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); + UniValue timestamps(UniValue::VARR); for (i=0; i Date: Tue, 2 Apr 2019 05:47:10 -1100 Subject: [PATCH 082/122] Test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index eff32b495..2ea4c2753 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2263,6 +2263,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation++; if ( correlation > (daywindow>>1) ) { + return(sum*mult/correlation); n = 0; i = (iter + seed) % daywindow; for (k=0; k Date: Tue, 2 Apr 2019 05:50:12 -1100 Subject: [PATCH 083/122] Test --- src/komodo_gateway.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2ea4c2753..e6bdd9a8f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2251,6 +2251,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( lowprice == refprice ) lowprice--; sum = 0; + fprintf(stderr,"firsti.%d: ",firsti); for (j=0; j= daywindow ) @@ -2259,10 +2260,12 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int return(-1); if ( price >= lowprice && price <= highprice ) { - sum += price * mult; + fprintf(stderr,"%.1f ",(double)price/10000); + sum += price; correlation++; if ( correlation > (daywindow>>1) ) { + fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); return(sum*mult/correlation); n = 0; i = (iter + seed) % daywindow; From 9b75e70178dddf5064f0eae97861e1f3dcdc4de2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:51:17 -1100 Subject: [PATCH 084/122] I --- 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 e6bdd9a8f..446619eb7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2251,7 +2251,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( lowprice == refprice ) lowprice--; sum = 0; - fprintf(stderr,"firsti.%d: ",firsti); + fprintf(stderr,"firsti.%d: ",i); for (j=0; j= daywindow ) From 355ce81643952bfb6e5beddb40665b2cc68781fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:54:30 -1100 Subject: [PATCH 085/122] -print --- src/komodo_gateway.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 446619eb7..36de71951 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2251,7 +2251,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( lowprice == refprice ) lowprice--; sum = 0; - fprintf(stderr,"firsti.%d: ",i); + //fprintf(stderr,"firsti.%d: ",i); for (j=0; j= daywindow ) @@ -2260,13 +2260,13 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int return(-1); if ( price >= lowprice && price <= highprice ) { - fprintf(stderr,"%.1f ",(double)price/10000); + //fprintf(stderr,"%.1f ",(double)price/10000); sum += price; correlation++; if ( correlation > (daywindow>>1) ) { - fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); - return(sum*mult/correlation); + //fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); + //return(sum*mult/correlation); n = 0; i = (iter + seed) % daywindow; for (k=0; k %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); + //fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } From fae4422d85b83a007d4c7e52441e6feeab8a94fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 05:55:26 -1100 Subject: [PATCH 086/122] Rc --- src/rpc/blockchain.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a72f0c341..5e426b88e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1228,9 +1228,9 @@ UniValue prices(const UniValue& params, bool fHelp) timestamps.push_back((int64_t)prices[i]); ret.push_back(Pair("timestamps",timestamps)); rngval = seed; - for (i=0; i Date: Tue, 2 Apr 2019 06:03:24 -1100 Subject: [PATCH 087/122] Test --- src/komodo_gateway.h | 18 ++++++++++-------- src/rpc/blockchain.cpp | 8 +++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 36de71951..2d708f036 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2239,6 +2239,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( ind < 36 ) mult = 10000; else mult = 1; + memset(nonzprices,0,sizeof(*nonzprices)*daywindow); for (iter=0; iter2*daywindow+2; i++,ht--) { @@ -1247,7 +1248,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Tue, 2 Apr 2019 06:31:42 -1100 Subject: [PATCH 088/122] Update --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2d708f036..65f534778 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1832,6 +1832,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i { fprintf(stderr,"force update prices\n"); komodo_cbopretupdate(1); + memcpy(localbits,Mineropret.data(),Mineropret.size()); } else return(-1); } } From 503eadb7d989ff3db774ef8cfe7acdded257686f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 06:48:55 -1100 Subject: [PATCH 089/122] komodo_cbopretupdate if zero price --- src/komodo_gateway.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 65f534778..7b6227b92 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1684,7 +1684,10 @@ CScript komodo_mineropret(int32_t nHeight) if ( pricebits[i] == 0 ) numzero++; if ( numzero != 0 ) - fprintf(stderr,"numzero.%d\n",numzero); + { + fprintf(stderr,"komodo_mineropret numzero.%d vs n.%d\n",numzero,n); + komodo_cbopretupdate(1); + } } if ( komodo_heightpricebits(0,prevbits,nHeight-1) > 0 ) { From 8be53197b396c244eab12b09d8e27e26aaa7223d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 06:52:50 -1100 Subject: [PATCH 090/122] +prnt --- src/komodo_gateway.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7b6227b92..c04bfb381 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1682,11 +1682,15 @@ CScript komodo_mineropret(int32_t nHeight) memcpy(pricebits,Mineropret.data(),Mineropret.size()); for (i=numzero=0; i 0 ) @@ -2167,10 +2171,10 @@ if ( komodo_nextheight() > 333 ) // for debug only! if ( (flags & 4) != 0 ) lastcrypto = now; memcpy(Mineropret.data(),PriceCache[0],size); + int32_t i; for (i=0; i Date: Tue, 2 Apr 2019 06:58:35 -1100 Subject: [PATCH 091/122] Fix init conditions --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c04bfb381..99462fdd3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1573,6 +1573,7 @@ void komodo_PriceCache_shift() //for (j=0; j<4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex); j++) // PriceCache[i][j] = PriceCache[i-1][j]; } + memcpy(PriceCache[0],Mineropret.data(),Mineropret.size()); } // komodo_heightpricebits() extracts the price data in the coinbase for nHeight @@ -2173,7 +2174,7 @@ if ( komodo_nextheight() > 333 ) // for debug only! memcpy(Mineropret.data(),PriceCache[0],size); int32_t i; for (i=0; i Date: Tue, 2 Apr 2019 07:02:57 -1100 Subject: [PATCH 092/122] /sizeof(uint32_t) --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 99462fdd3..f13dbdd47 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1691,7 +1691,7 @@ CScript komodo_mineropret(int32_t nHeight) { fprintf(stderr," komodo_mineropret numzero.%d vs n.%d\n",numzero,n); komodo_cbopretupdate(1); - sleep(5); + sleep(61); } } if ( komodo_heightpricebits(0,prevbits,nHeight-1) > 0 ) @@ -1702,7 +1702,7 @@ CScript komodo_mineropret(int32_t nHeight) { // if the new prices are outside tolerance, update Mineropret with clamped prices komodo_priceclamp(n,pricebits,prevbits,PRICES_MAXCHANGE); - fprintf(stderr,"update Mineropret to clamped prices\n"); + //fprintf(stderr,"update Mineropret to clamped prices\n"); memcpy(Mineropret.data(),pricebits,Mineropret.size()); } } @@ -2146,7 +2146,7 @@ if ( komodo_nextheight() > 333 ) // for debug only! if ( flags == 0 ) komodo_PriceCache_shift(); flags |= 2; - memcpy(&PriceCache[0][size],forexprices,sizeof(forexprices)); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],forexprices,sizeof(forexprices)); } size += sizeof(forexprices); } @@ -2157,7 +2157,7 @@ if ( komodo_nextheight() > 333 ) // for debug only! get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); if ( flags == 0 ) komodo_PriceCache_shift(); - memcpy(&PriceCache[0][size],cryptoprices,sizeof(cryptoprices)); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],cryptoprices,sizeof(cryptoprices)); flags |= 4; // very rarely we can see flags == 6 case } size += sizeof(cryptoprices); From 62a9756bc0de1d2b130b3ad34330e7b14ce813ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 07:07:09 -1100 Subject: [PATCH 093/122] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f13dbdd47..6d2fef363 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2172,9 +2172,9 @@ if ( komodo_nextheight() > 333 ) // for debug only! if ( (flags & 4) != 0 ) lastcrypto = now; memcpy(Mineropret.data(),PriceCache[0],size); - int32_t i; for (i=0; i Date: Tue, 2 Apr 2019 08:13:43 -1100 Subject: [PATCH 094/122] Test --- src/komodo_gateway.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6d2fef363..dbc879806 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2345,7 +2345,10 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz if ( correlated[i] == 0 ) correlated[i] = correlated[i-1]; if ( firstprice == 0 && correlated[i] != 0 ) + { firstprice = correlated[i]; + break; + } } if ( firstprice != 0 ) { @@ -2358,7 +2361,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 08:34:57 -1100 Subject: [PATCH 095/122] Pre-smoother --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dbc879806..276bb8667 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2312,7 +2312,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= nonzprices[i]) != 0 ) { den += (daywindow - i); - sum += (daywindow - i) * price;//((price + firstprice*2) / 3); + sum += (daywindow - i) * ((price + firstprice) / 2); n++; } } @@ -2361,7 +2361,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 08:38:18 -1100 Subject: [PATCH 096/122] 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 276bb8667..d5f9c98f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2361,7 +2361,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 09:35:01 -1100 Subject: [PATCH 097/122] 2/3 --- 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 d5f9c98f9..a926e3de0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2361,7 +2361,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 09:38:09 -1100 Subject: [PATCH 098/122] 1:1 --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a926e3de0..9c9b3959e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2312,7 +2312,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= nonzprices[i]) != 0 ) { den += (daywindow - i); - sum += (daywindow - i) * ((price + firstprice) / 2); + sum += (daywindow - i) * price; n++; } } @@ -2361,7 +2361,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 09:43:58 -1100 Subject: [PATCH 099/122] 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 9c9b3959e..120267dad 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2364,7 +2364,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum += (daywindow - i) * correlated[i]; den += (daywindow - i); } - smoothed = (sum / den); + smoothed = ((sum / den) + firstprice) >> 1; } return(smoothed); } From 480349a221c09c65957e9becc61a75df6a4067e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 09:49:48 -1100 Subject: [PATCH 100/122] 0.9 decay --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 120267dad..78d320c91 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2312,7 +2312,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= nonzprices[i]) != 0 ) { den += (daywindow - i); - sum += (daywindow - i) * price; + sum += ((daywindow - i) * (price + firstprice*9)) / 10; n++; } } @@ -2361,10 +2361,10 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i> 1; + smoothed = (sum / den); } return(smoothed); } From 05bd8d8af63d51ea3ba11f4c7816f48b97f7bd7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:16:03 -1100 Subject: [PATCH 101/122] Smooth coifs --- src/komodo_gateway.h | 36 +++++++++++++++++++++++++++--------- src/rpc/blockchain.cpp | 11 ++++++----- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 78d320c91..afa3b40c1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2312,7 +2312,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= nonzprices[i]) != 0 ) { den += (daywindow - i); - sum += ((daywindow - i) * (price + firstprice*9)) / 10; + sum += ((daywindow - i) * (price + firstprice*2)) / 3; n++; } } @@ -2334,11 +2334,17 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int } -int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices) +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices,int32_t smoothwidth) { - int32_t i; int64_t sum,den,smoothed=0,firstprice = correlated[0]; + const int64_t coeffs[7] = { 7, 13, 5, 4, 6, 7, 3 }; + int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); + if ( sizeof(smoothed)/sizeof(*smoothed) ) + { + fprintf(stderr,"smoothwidth %d != %d\n",smoothwidth,(int32_t)(sizeof(smoothed)/sizeof(*smoothed))); + return(0); + } memset(nonzprices,0,sizeof(*nonzprices)*daywindow); for (i=1; i %.4f\n",(double)(smoothedsum/smoothedden)/10000); + return(smoothedsum/smoothedden); } - return(smoothed); + return(0); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0080c9b2c..520307c4b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1183,6 +1183,7 @@ uint32_t komodo_heightstamp(int32_t height); UniValue prices(const UniValue& params, bool fHelp) { + int32_t smoothwidth = 7; if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); @@ -1197,7 +1198,7 @@ UniValue prices(const UniValue& params, bool fHelp) UniValue a(UniValue::VARR); if ( daywindow < 7 ) daywindow = 7; - width = maxsamples+2*daywindow; + width = maxsamples+2*daywindow+smoothwidth; numpricefeeds = komodo_heightpricebits(&seed,rawprices,nextheight-1); if ( numpricefeeds <= 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); @@ -1205,7 +1206,7 @@ UniValue prices(const UniValue& params, bool fHelp) correlated = (int64_t *)calloc(sizeof(*correlated),width); correlated2 = (int64_t *)calloc(sizeof(*correlated2),width); prices2 = (uint32_t *)calloc(sizeof(*prices2),width); - for (ht=nextheight-1,i=0; i2*daywindow+2; i++,ht--) + for (ht=nextheight-1,i=0; i2*daywindow+2+smoothwidth; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); @@ -1238,17 +1239,17 @@ UniValue prices(const UniValue& params, bool fHelp) if ( (str= komodo_pricename(name,j)) != 0 ) { item.push_back(Pair("name",str)); - for (i=0; i Date: Tue, 2 Apr 2019 10:17:38 -1100 Subject: [PATCH 102/122] Smooth width --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 520307c4b..e31f5d8a4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1176,7 +1176,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices,int64_t *correlated2); +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices,int64_t *correlated2,int32_t smoothwidth); int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); From 778b70285efca1d9aab687f007644c638ae9be4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:19:24 -1100 Subject: [PATCH 103/122] Add condition --- 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 afa3b40c1..d0539426e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2340,7 +2340,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); - if ( sizeof(smoothed)/sizeof(*smoothed) ) + if ( smoothwidth != sizeof(smoothed)/sizeof(*smoothed) ) { fprintf(stderr,"smoothwidth %d != %d\n",smoothwidth,(int32_t)(sizeof(smoothed)/sizeof(*smoothed))); return(0); From 903455b07b0332e031c561e186615fae64d1ad7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:24:52 -1100 Subject: [PATCH 104/122] Gilt --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d0539426e..9543cc1b9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2336,7 +2336,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices,int32_t smoothwidth) { - const int64_t coeffs[7] = { 7, 13, 5, 4, 6, 7, 3 }; + const int64_t coeffs[7] = { 7, 7, 7, 7, 7, 7, 7 }; int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); @@ -2378,8 +2378,8 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz for (i=0; i<7; i++) { fprintf(stderr,"%.4f ",(double)smoothed[i]/10000); - smoothedsum += coeffs[i] * smoothed[i]; - smoothedden += coeffs[i]; + smoothedsum += (7-i) * smoothed[i]; + smoothedden += (7-i); } fprintf(stderr,"-> %.4f\n",(double)(smoothedsum/smoothedden)/10000); return(smoothedsum/smoothedden); From a5957af75a3170c0816866658656787bc5e56109 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:25:59 -1100 Subject: [PATCH 105/122] 1:1 --- 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 9543cc1b9..8da2a94bf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2369,7 +2369,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 10:32:08 -1100 Subject: [PATCH 106/122] Test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8da2a94bf..63e6898eb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2254,8 +2254,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int correlation = 0; i = (iter + seed) % daywindow; refprice = rawprices[i]; - highprice = (refprice * (COIN + PRICES_MAXCHANGE*3)) / COIN; - lowprice = (refprice * (COIN - PRICES_MAXCHANGE*3)) / COIN; + highprice = (refprice * (COIN + PRICES_MAXCHANGE*4)) / COIN; + lowprice = (refprice * (COIN - PRICES_MAXCHANGE*4)) / COIN; if ( highprice == refprice ) highprice++; if ( lowprice == refprice ) @@ -2312,7 +2312,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= nonzprices[i]) != 0 ) { den += (daywindow - i); - sum += ((daywindow - i) * (price + firstprice*2)) / 3; + sum += ((daywindow - i) * (price + firstprice*9)) / 10; n++; } } @@ -2369,7 +2369,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 10:34:58 -1100 Subject: [PATCH 107/122] Arg --- src/komodo_gateway.h | 7 +++++-- src/rpc/blockchain.cpp | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 63e6898eb..0d4274ae5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2240,7 +2240,7 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *nonzprices) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t daywindow,uint32_t *nonzprices,int32_t smoothwidth) { int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice; if ( daywindow < 2 ) @@ -2249,7 +2249,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int mult = 10000; else mult = 1; memset(nonzprices,0,sizeof(*nonzprices)*daywindow); - for (iter=0; iter= daywindow ) i = 0; if ( (price= rawprices[i]) == 0 ) + { + fprintf(stderr,"null rawprice.[%d]\n",i); return(-1); + } if ( price >= lowprice && price <= highprice ) { //fprintf(stderr,"%.1f ",(double)price/10000); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e31f5d8a4..6e6746a30 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1177,7 +1177,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices,int64_t *correlated2,int32_t smoothwidth); -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1243,7 +1243,7 @@ UniValue prices(const UniValue& params, bool fHelp) { offset = j*width + i; rngval = (rngval*11109 + 13849); - if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow+smoothwidth,prices2)) < 0 ) + if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow+smoothwidth,prices2,smoothwidth)) < 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price"); } for (i=0; i Date: Tue, 2 Apr 2019 10:38:42 -1100 Subject: [PATCH 108/122] -smoothwidth --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6e6746a30..e471492ce 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1243,7 +1243,7 @@ UniValue prices(const UniValue& params, bool fHelp) { offset = j*width + i; rngval = (rngval*11109 + 13849); - if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow+smoothwidth,prices2,smoothwidth)) < 0 ) + if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow,prices2,smoothwidth)) < 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price"); } for (i=0; i Date: Tue, 2 Apr 2019 10:42:03 -1100 Subject: [PATCH 109/122] .9 --- 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 0d4274ae5..28913c08e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2372,7 +2372,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 10:47:41 -1100 Subject: [PATCH 110/122] 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 28913c08e..6d6f8f155 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2372,7 +2372,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz sum = den = 0; for (i=0; i Date: Tue, 2 Apr 2019 10:53:33 -1100 Subject: [PATCH 111/122] Test --- src/komodo_gateway.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6d6f8f155..64fcbb957 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2339,7 +2339,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices,int32_t smoothwidth) { - const int64_t coeffs[7] = { 7, 7, 7, 7, 7, 7, 7 }; + const int64_t coeffs[7] = { -1, 9, -45, 0, 45, -9, 1 }; // / 60 int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); @@ -2377,12 +2377,13 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz } smoothed[iter] = (sum / den); } - smoothedsum = smoothedden = 0; + smoothedsum = 0; + smoothedden = 60; for (i=0; i<7; i++) { fprintf(stderr,"%.4f ",(double)smoothed[i]/10000); - smoothedsum += (7-i) * smoothed[i]; - smoothedden += (7-i); + smoothedsum += coeffs[i] * smoothed[i]; + //smoothedden += (7-i); } fprintf(stderr,"-> %.4f\n",(double)(smoothedsum/smoothedden)/10000); return(smoothedsum/smoothedden); From 966fafb2700a4c5543e5381f9191cadf7e1e84f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:54:20 -1100 Subject: [PATCH 112/122] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 64fcbb957..6f72f855b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2339,7 +2339,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices,int32_t smoothwidth) { - const int64_t coeffs[7] = { -1, 9, -45, 0, 45, -9, 1 }; // / 60 + const int64_t coeffs[7] = { -1, 9, -45, 1, 45, -9, 1 }; // / 60 int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); @@ -2378,7 +2378,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz smoothed[iter] = (sum / den); } smoothedsum = 0; - smoothedden = 60; + smoothedden = 1; for (i=0; i<7; i++) { fprintf(stderr,"%.4f ",(double)smoothed[i]/10000); From 79120f3cac81e208c97156640c05c9f0b73b7f6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 10:58:48 -1100 Subject: [PATCH 113/122] Test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6f72f855b..7507122f3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2339,7 +2339,8 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonzprices,int32_t smoothwidth) { - const int64_t coeffs[7] = { -1, 9, -45, 1, 45, -9, 1 }; // / 60 + //const int64_t coeffs[7] = { -1, 9, -45, 1, 45, -9, 1 }; // / 60 + const int64_t coeffs[7] = { -2, 0, 18, 32, 18, 0, -2 }; int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); @@ -2378,7 +2379,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz smoothed[iter] = (sum / den); } smoothedsum = 0; - smoothedden = 1; + smoothedden = 64; for (i=0; i<7; i++) { fprintf(stderr,"%.4f ",(double)smoothed[i]/10000); From 8adcc5022c167ac1aed17181a1eabe2b7caa1bd8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 11:04:32 -1100 Subject: [PATCH 114/122] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7507122f3..778f5b318 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2315,7 +2315,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( (price= nonzprices[i]) != 0 ) { den += (daywindow - i); - sum += ((daywindow - i) * (price + firstprice*9)) / 10; + sum += ((daywindow - i) * (price + firstprice*4)) / 5; n++; } } @@ -2382,11 +2382,11 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz smoothedden = 64; for (i=0; i<7; i++) { - fprintf(stderr,"%.4f ",(double)smoothed[i]/10000); + //fprintf(stderr,"%.4f ",(double)smoothed[i]/10000); smoothedsum += coeffs[i] * smoothed[i]; //smoothedden += (7-i); } - fprintf(stderr,"-> %.4f\n",(double)(smoothedsum/smoothedden)/10000); + //fprintf(stderr,"-> %.4f\n",(double)(smoothedsum/smoothedden)/10000); return(smoothedsum/smoothedden); } return(0); From 6cf121c5d5d1f9c82d399b2358ac2db6934933ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 11:18:19 -1100 Subject: [PATCH 115/122] Smooth64 --- src/komodo_gateway.h | 76 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 778f5b318..6659dcced 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2336,12 +2336,82 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int return(0); } +int64_t _pairave64(int64_t valA,int64_t valB) +{ + if ( valA != 0 && valB != 0 ) + return((valA + valB) / 2); + else if ( valA != 0 ) return(valA); + else return(valB); +} + +int64_t _pairdiff64(register int64_t valA,register int64_t valB) +{ + if ( valA != 0 && valB != 0 ) + return(valA - valB); + else return(0); +} + +int64_t balanced_ave64(int64_t buf[],int32_t i,int32_t width) +{ + register int32_t nonz,j; register int64_t sum,price; + nonz = 0; + sum = 0; + for (j=-width; j<=width; j++) + { + price = buf[i + j]; + if ( price != 0 ) + { + sum += price; + nonz++; + } + } + if ( nonz != 0 ) + sum /= nonz; + return(sum); +} + +void buf_trioave64(int64_t dest[],int64_t src[],int32_t n) +{ + register int32_t i,j,width = 3; + for (i=0; i<128; i++) + src[i] = 0; + //for (i=n-width-1; i>width; i--) + // dest[i] = balanced_ave(src,i,width); + //for (i=width; i>0; i--) + // dest[i] = balanced_ave(src,i,i); + for (i=1; i Date: Tue, 2 Apr 2019 11:19:38 -1100 Subject: [PATCH 116/122] smoothwidth --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6659dcced..25b87d6e3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2400,8 +2400,8 @@ void smooth64(int64_t dest[],int64_t src[],int32_t width,int32_t smoothiters) buf_trioave64(smoothbufA,src,width); for (i=0; i Date: Tue, 2 Apr 2019 11:20:39 -1100 Subject: [PATCH 117/122] Trioave64 --- 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 25b87d6e3..b1dbfbfe7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2403,7 +2403,7 @@ void smooth64(int64_t dest[],int64_t src[],int32_t width,int32_t smoothiters) buf_trioave64(smoothbufB,smoothbufA,width); buf_trioave64(smoothbufA,smoothbufB,width); } - buf_trioave(dest,smoothbufA,width); + buf_trioave64(dest,smoothbufA,width); } else memcpy(dest,src,width*sizeof(*dest)); } From 9b72450a1f2064c080ad86a6083b361be0e71afb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 11:24:20 -1100 Subject: [PATCH 118/122] Revert --- src/komodo_gateway.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b1dbfbfe7..d16fa4bc5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2411,7 +2411,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz { //const int64_t coeffs[7] = { -1, 9, -45, 1, 45, -9, 1 }; // / 60 const int64_t coeffs[7] = { -2, 0, 18, 32, 18, 0, -2 }; - int32_t i,iter; int64_t dest[1440*3],orig[1440*3],smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; + int32_t i,iter; int64_t smoothedden,smoothedsum,sum,den,smoothed[7],firstprice = correlated[0]; if ( daywindow < 2 ) return(0); if ( smoothwidth != sizeof(smoothed)/sizeof(*smoothed) ) @@ -2438,19 +2438,19 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t daywindow,int64_t *nonz correlated[i] = firstprice; else break; } - memcpy(orig,correlated,(daywindow+smoothwidth)*sizeof(*correlated)); + //memcpy(orig,correlated,(daywindow+smoothwidth)*sizeof(*correlated)); for (iter=0; iter Date: Tue, 2 Apr 2019 21:12:33 -1100 Subject: [PATCH 119/122] Fix localcache scan control flow --- src/komodo_gateway.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d16fa4bc5..16a96b526 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1816,9 +1816,10 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i if ( PriceCache[j][i] >= prevbits[i] ) { fprintf(stderr,"i.%d within recent localprices[%d] %u >= %u\n",i,j,PriceCache[j][i],prevbits[i]); - continue; + break; } - break; + if ( j == KOMODO_LOCALPRICE_CACHESIZE ) + break; } else if ( maxflag < 0 && localbits[i] > prevbits[i] ) { @@ -1828,9 +1829,10 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i if ( PriceCache[j][i] <= prevbits[i] ) { fprintf(stderr,"i.%d within recent localprices[%d] %u <= prev %u\n",i,j,PriceCache[j][i],prevbits[i]); - continue; + break; } - break; + if ( j == KOMODO_LOCALPRICE_CACHESIZE ) + break; } } } From 4a704517b9d3cbafe5e841a61ef72cd12a310c42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 21:17:05 -1100 Subject: [PATCH 120/122] +print --- src/cc/gamescc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index b804216d7..2a8be815e 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -110,6 +110,7 @@ if ( cp->evalcode == EVAL_GAMES ) \ return(games_settle(txfee,cp,params)); \ else \ { \ +fprintf(stderr,"invalid method (%s)\n",method); \ result.push_back(Pair("result","error")); \ result.push_back(Pair("error","invalid gamescc method")); \ return(result); \ From 1b6bb2d0a18aa58b22164345013e9dd7477da1bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 21:18:45 -1100 Subject: [PATCH 121/122] +print --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 00a7c6fe0..370b1b8e3 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -195,7 +195,7 @@ cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) { UniValue result(UniValue::VOBJ); uint64_t txfee = 10000; int32_t m; cJSON *params = cclib_reparse(&m,jsonstr); - //fprintf(stderr,"method.(%s) -> (%s)\n",jsonstr!=0?jsonstr:"",params!=0?jprint(params,0):""); + fprintf(stderr,"method.(%s) -> (%s)\n",jsonstr!=0?jsonstr:"",params!=0?jprint(params,0):""); #ifdef BUILD_ROGUE if ( cp->evalcode == EVAL_ROGUE ) { From 679d310c5edbd762cd59443f7ae3645afeed1d60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 21:20:45 -1100 Subject: [PATCH 122/122] Fix crash on missing method --- src/cc/cclib.cpp | 4 ++-- src/cc/gamescc.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 370b1b8e3..8552cfa1b 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -351,7 +351,7 @@ UniValue CClib_info(struct CCcontract_info *cp) UniValue CClib(struct CCcontract_info *cp,char *method,char *jsonstr) { UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; cJSON *params; - //printf("CClib params.(%s)\n",jsonstr!=0?jsonstr:""); +//printf("CClib params.(%s)\n",jsonstr!=0?jsonstr:""); for (i=0; ievalcode == CClib_methods[i].evalcode && strcmp(method,CClib_methods[i].method) == 0 ) @@ -369,7 +369,7 @@ UniValue CClib(struct CCcontract_info *cp,char *method,char *jsonstr) } } result.push_back(Pair("result","error")); - result.push_back(Pair("method",CClib_methods[i].method)); + result.push_back(Pair("method",method)); result.push_back(Pair("error","method not found")); return(result); } diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 2a8be815e..b804216d7 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -110,7 +110,6 @@ if ( cp->evalcode == EVAL_GAMES ) \ return(games_settle(txfee,cp,params)); \ else \ { \ -fprintf(stderr,"invalid method (%s)\n",method); \ result.push_back(Pair("result","error")); \ result.push_back(Pair("error","invalid gamescc method")); \ return(result); \