From 6d134de514f1075d350266315922195813faa83e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:20:08 -1100 Subject: [PATCH 01/59] +print --- src/komodo_gateway.h | 7 ++++--- src/scheduler.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d74947d2d..5d5f74155 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2628,7 +2628,7 @@ void komodo_pricesinit() void komodo_pricesupdate(int32_t height,CBlock *pblock) { static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf; - int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[4]; + int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[PRICES_MAXDATAPOINTS*2]; width = PRICES_DAYWINDOW;//(2*PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH); if ( numprices == 0 ) { @@ -2662,6 +2662,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) if ( (correlated= komodo_pricecorrelated(rngval,ind,&ptr32[offset],-numprices,0,PRICES_SMOOTHWIDTH)) > 0 ) { fseek(PRICES[ind].fp,height * sizeof(int64_t) * PRICES_MAXDATAPOINTS,SEEK_SET); + memset(buf,0,sizeof(buf)); buf[0] = rawprices[ind]; buf[1] = rawprices[0]; // timestamp memcpy(&buf[2],&correlated,sizeof(correlated)); @@ -2670,7 +2671,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) else if ( height > PRICES_DAYWINDOW*2 ) { fseek(PRICES[ind].fp,(height-PRICES_DAYWINDOW+1) * PRICES_MAXDATAPOINTS * sizeof(int64_t),SEEK_SET); - if ( fread(ptr64,sizeof(int64_t),(PRICES_DAYWINDOW-1)*PRICES_MAXDATAPOINTS+2,PRICES[ind].fp) == (PRICES_DAYWINDOW-1)*PRICES_MAXDATAPOINTS+2 ) + if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*PRICES_MAXDATAPOINTS,PRICES[ind].fp) == PRICES_DAYWINDOW*PRICES_MAXDATAPOINTS ) { if ( (smoothed= komodo_priceave(tmpbuf,&ptr64[(PRICES_DAYWINDOW-1)*PRICES_MAXDATAPOINTS+1],-PRICES_MAXDATAPOINTS)) > 0 ) { @@ -2687,7 +2688,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) } else fprintf(stderr,"error reading rawprices for ht.%d\n",height); } else fprintf(stderr,"height.%d <= width.%d\n",height,width); } else fprintf(stderr,"null PRICES[0].fp\n"); - } else fprintf(stderr,"numprices mismatch\n"); + } else fprintf(stderr,"numprices mismatch, height.%d\n",height); } diff --git a/src/scheduler.cpp b/src/scheduler.cpp index e085791fc..4229a2efb 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -31,6 +31,17 @@ CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stop CScheduler::~CScheduler() { + int32_t i; + if ( nThreadsServicingQueue != 0 ) + { + for (i=0; i<10; i++) + { + MilliSleep(1000); + fprintf(stderr,"CScheduler nThreadsServicingQueue.%d\n",(int32_t)nThreadsServicingQueue); + if ( nThreadsServicingQueue == 0 ) + break; + } + } assert(nThreadsServicingQueue == 0); } From 29d5c46bcde5ae653e7e6ac75f786ef03faa46b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:22:25 -1100 Subject: [PATCH 02/59] Sleep --- src/scheduler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 4229a2efb..6f9a0d5ba 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -36,7 +36,7 @@ CScheduler::~CScheduler() { for (i=0; i<10; i++) { - MilliSleep(1000); + sleep(1); fprintf(stderr,"CScheduler nThreadsServicingQueue.%d\n",(int32_t)nThreadsServicingQueue); if ( nThreadsServicingQueue == 0 ) break; From 6f78003c0e6a65256cb8b2708d026f1ffa387095 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:29:20 -1100 Subject: [PATCH 03/59] -debug --- src/scheduler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 6f9a0d5ba..08aba3225 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -31,7 +31,7 @@ CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stop CScheduler::~CScheduler() { - int32_t i; + /*int32_t i; if ( nThreadsServicingQueue != 0 ) { for (i=0; i<10; i++) @@ -41,7 +41,7 @@ CScheduler::~CScheduler() if ( nThreadsServicingQueue == 0 ) break; } - } + }*/ assert(nThreadsServicingQueue == 0); } From d47d2dd595891e706fb564269782f6a4e528734d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:49:24 -1100 Subject: [PATCH 04/59] Better way to avoid sync errors --- src/main.cpp | 16 ++++++++-------- src/main.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9df53b2d7..db81c2070 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -512,8 +512,8 @@ namespace { // Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last // linked block we have in common with this peer. The +1 is so we can detect stalling, namely if we would be able to // download that next block if the window were 1 larger. - if ( ASSETCHAINS_CBOPRET != 0 ) - BLOCK_DOWNLOAD_WINDOW = 1; + //if ( ASSETCHAINS_CBOPRET != 0 ) + // BLOCK_DOWNLOAD_WINDOW = 1; int nWindowEnd = state->pindexLastCommonBlock->GetHeight() + BLOCK_DOWNLOAD_WINDOW; int nMaxHeight = std::min(state->pindexBestKnownBlock->GetHeight(), nWindowEnd + 1); NodeId waitingfor = -1; @@ -980,7 +980,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 CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight) +bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight,int32_t validateprices) { // 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) || @@ -1021,7 +1021,7 @@ bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const { } - else if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 && tx.vout.size() > 0 ) + else if ( ASSETCHAINS_CBOPRET != 0 && validateprices != 0 && nHeight > 0 && tx.vout.size() > 0 ) { if ( komodo_opretvalidate(block,previndex,nHeight,tx.vout[tx.vout.size()-1].scriptPubKey) < 0 ) return(false); @@ -1043,7 +1043,7 @@ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const prevind CValidationState &state, const int nHeight, const int dosLevel, - bool (*isInitBlockDownload)()) + bool (*isInitBlockDownload)(),int32_t validateprices) { bool overwinterActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); bool saplingActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING); @@ -1174,7 +1174,7 @@ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const prevind if (tx.IsCoinBase()) { - if (!ContextualCheckCoinbaseTransaction(block,previndex,tx, nHeight)) + if (!ContextualCheckCoinbaseTransaction(block,previndex,tx, nHeight,validateprices)) 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(0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel)) + if (!fSkipExpiry && !ContextualCheckTransaction(0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel,0)) { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } @@ -5151,7 +5151,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(&block,pindexPrev,tx, state, nHeight, 100)) { + if (!ContextualCheckTransaction(&block,pindexPrev,tx, state, nHeight, 100,1)) { return false; // Failure reason has been set in validation state object } diff --git a/src/main.h b/src/main.h index 15e9f5934..7e4c2201a 100644 --- a/src/main.h +++ b/src/main.h @@ -707,7 +707,7 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons /** Check a transaction contextually against a set of consensus rules */ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, - bool (*isInitBlockDownload)() = IsInitialBlockDownload); + bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices); /** Apply the effects of this transaction on the UTXO set represented by view */ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight); From 082aec73ffcf5dfdb50113ebaf76956414b7c2b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:51:44 -1100 Subject: [PATCH 05/59] =0 --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 7e4c2201a..5be021f52 100644 --- a/src/main.h +++ b/src/main.h @@ -707,7 +707,7 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons /** Check a transaction contextually against a set of consensus rules */ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, - bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices); + bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices=0); /** Apply the effects of this transaction on the UTXO set represented by view */ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight); From 3db5e5a8746eb9be334be2c2ab3c56681bacc12f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:52:05 -1100 Subject: [PATCH 06/59] =1 --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 5be021f52..ec36c976b 100644 --- a/src/main.h +++ b/src/main.h @@ -707,7 +707,7 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons /** Check a transaction contextually against a set of consensus rules */ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, - bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices=0); + bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices=1); /** Apply the effects of this transaction on the UTXO set represented by view */ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight); From 77ad8944ca8e7489a9f0fe03ee6ea4c557056ff2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Apr 2019 23:59:33 -1100 Subject: [PATCH 07/59] -,1 --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index db81c2070..5ce7ca46d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5151,7 +5151,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(&block,pindexPrev,tx, state, nHeight, 100,1)) { + if (!ContextualCheckTransaction(&block,pindexPrev,tx, state, nHeight, 100)) { return false; // Failure reason has been set in validation state object } From 9686cdd6cd0500b34f94d141307857c856d9122a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 00:47:02 -1100 Subject: [PATCH 08/59] Shrink lookahead if not initial download --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5ce7ca46d..2176d59b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -512,8 +512,8 @@ namespace { // Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last // linked block we have in common with this peer. The +1 is so we can detect stalling, namely if we would be able to // download that next block if the window were 1 larger. - //if ( ASSETCHAINS_CBOPRET != 0 ) - // BLOCK_DOWNLOAD_WINDOW = 1; + if ( ASSETCHAINS_CBOPRET != 0 && IsInitialBlockDownload() == 0 ) + BLOCK_DOWNLOAD_WINDOW = 1; int nWindowEnd = state->pindexLastCommonBlock->GetHeight() + BLOCK_DOWNLOAD_WINDOW; int nMaxHeight = std::min(state->pindexBestKnownBlock->GetHeight(), nWindowEnd + 1); NodeId waitingfor = -1; From 27083abb20e1822f43f03bf8ccc561e68fd1e6bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:25:01 -1100 Subject: [PATCH 09/59] Auto reconsider --- src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2176d59b7..dd8249362 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5333,6 +5333,15 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; + if ( ASSETCHAINS_CBOPRET != 0 ) + { + CValidationState tmpstate; CBlockIndex *tmpindex; + if ( (tmpindex=komodo_chainactive(tmpptr->GetHeight())) != 0 ) + { + fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()); + ReconsiderBlock(tmpstate,tmpindex); + } + } } if ( *futureblockp == 0 ) { From e9e6e18f0596295217fdf419b0bdd46578aa44a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:29:07 -1100 Subject: [PATCH 10/59] -1 --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dd8249362..b9f6cd9ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5336,9 +5336,9 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if ( ASSETCHAINS_CBOPRET != 0 ) { CValidationState tmpstate; CBlockIndex *tmpindex; - if ( (tmpindex=komodo_chainactive(tmpptr->GetHeight())) != 0 ) + if ( (tmpindex=komodo_chainactive(tmpptr->GetHeight()-1)) != 0 ) { - fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()); + fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()-1); ReconsiderBlock(tmpstate,tmpindex); } } From 5fb80dee40610f5f222f56bd90ad92acbef2cfc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:33:33 -1100 Subject: [PATCH 11/59] Test --- src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index b9f6cd9ed..1537dea1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5340,6 +5340,11 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C { fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()-1); ReconsiderBlock(tmpstate,tmpindex); + if ( (tmpindex=komodo_chainactive(tmpptr->GetHeight())) != 0 ) + { + fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()); + ReconsiderBlock(tmpstate,tmpindex); + } } } } From f9c13b8c60d3135215d368b1e04d134a83c8f132 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:36:33 -1100 Subject: [PATCH 12/59] Reconsider --- src/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1537dea1c..42e2414b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5335,14 +5335,15 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C *futureblockp = 1; if ( ASSETCHAINS_CBOPRET != 0 ) { - CValidationState tmpstate; CBlockIndex *tmpindex; - if ( (tmpindex=komodo_chainactive(tmpptr->GetHeight()-1)) != 0 ) + CValidationState tmpstate; CBlockIndex *tmpindex; int32_t ht; + ht = (int32_t)pindex->GetHeight(); + if ( (tmpindex=komodo_chainactive(ht-1)) != 0 ) { - fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()-1); + fprintf(stderr,"reconsider height.%d\n",(int32_t)ht-1); ReconsiderBlock(tmpstate,tmpindex); - if ( (tmpindex=komodo_chainactive(tmpptr->GetHeight())) != 0 ) + if ( (tmpindex=komodo_chainactive(ht)) != 0 ) { - fprintf(stderr,"reconsider height.%d\n",(int32_t)tmpptr->GetHeight()); + fprintf(stderr,"reconsider height.%d\n",(int32_t)ht); ReconsiderBlock(tmpstate,tmpindex); } } From 0d2d1625bc4b666407d1d3334dadb38666efbb37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:41:33 -1100 Subject: [PATCH 13/59] Test --- src/main.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 42e2414b9..1493409bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5335,17 +5335,13 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C *futureblockp = 1; if ( ASSETCHAINS_CBOPRET != 0 ) { - CValidationState tmpstate; CBlockIndex *tmpindex; int32_t ht; + CValidationState tmpstate; CBlockIndex *tmpindex; int32_t ht,longest; ht = (int32_t)pindex->GetHeight(); - if ( (tmpindex=komodo_chainactive(ht-1)) != 0 ) + longest = komodo_longestchain(); + if ( (longest == 0 || ht < longest-6) && (tmpindex=komodo_chainactive(ht)) != 0 ) { - fprintf(stderr,"reconsider height.%d\n",(int32_t)ht-1); - ReconsiderBlock(tmpstate,tmpindex); - if ( (tmpindex=komodo_chainactive(ht)) != 0 ) - { - fprintf(stderr,"reconsider height.%d\n",(int32_t)ht); - ReconsiderBlock(tmpstate,tmpindex); - } + fprintf(stderr,"reconsider height.%d, longest.%d\n",(int32_t)ht,longest); + InvalidateBlock(tmpstate,tmpindex); } } } From b306b395501bbd0ba9c9a29dc27c6c52904302f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:43:27 -1100 Subject: [PATCH 14/59] -1 --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1493409bb..fdd9d3132 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5336,7 +5336,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if ( ASSETCHAINS_CBOPRET != 0 ) { CValidationState tmpstate; CBlockIndex *tmpindex; int32_t ht,longest; - ht = (int32_t)pindex->GetHeight(); + ht = (int32_t)pindex->GetHeight()-1; longest = komodo_longestchain(); if ( (longest == 0 || ht < longest-6) && (tmpindex=komodo_chainactive(ht)) != 0 ) { From 7ad01e44ed23efdef651df8efa7b7f4749128f9e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:56:16 -1100 Subject: [PATCH 15/59] komodo_reconsiderblock --- src/komodo_bitcoind.h | 12 ++++++++++++ src/komodo_gateway.h | 7 +++++++ src/main.cpp | 7 +++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0ae61356f..327761c00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -448,6 +448,18 @@ int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len, return(-1); } +void komodo_reconsiderblock(uint256 blockhash) +{ + char params[256],*jsonstr,*hexstr; + sprintf(params,"[\"%s\"]",blockhash.ToString().c_str()); + komodo_reconsiderblock(Queued_reconsiderblock); + if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"reconsiderblock",params,KMD_PORT)) != 0 ) + { + fprintf(stderr,"komodo_reconsiderblock.(%s) -> (%s)\n",params,jsonstr); + free(jsonstr); + } +} + int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) { char params[256],*jsonstr,*hexstr; uint8_t *script,_script[8192]; int32_t n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5d5f74155..f23a2ff8f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2625,10 +2625,17 @@ void komodo_pricesinit() } } +extern Queued_reconsiderblock; + void komodo_pricesupdate(int32_t height,CBlock *pblock) { static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf; int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[PRICES_MAXDATAPOINTS*2]; + if ( Queued_reconsiderblock != zeroid ) + { + komodo_reconsiderblock(Queued_reconsiderblock); + Queued_reconsiderblock = zeroid; + } width = PRICES_DAYWINDOW;//(2*PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH); if ( numprices == 0 ) { diff --git a/src/main.cpp b/src/main.cpp index fdd9d3132..d01c9babb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5273,6 +5273,8 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat return true; } +uint256 Queued_reconsiderblock; + bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp) { const CChainParams& chainparams = Params(); @@ -5336,12 +5338,13 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if ( ASSETCHAINS_CBOPRET != 0 ) { CValidationState tmpstate; CBlockIndex *tmpindex; int32_t ht,longest; - ht = (int32_t)pindex->GetHeight()-1; + ht = (int32_t)pindex->GetHeight(); longest = komodo_longestchain(); if ( (longest == 0 || ht < longest-6) && (tmpindex=komodo_chainactive(ht)) != 0 ) { fprintf(stderr,"reconsider height.%d, longest.%d\n",(int32_t)ht,longest); - InvalidateBlock(tmpstate,tmpindex); + if ( Queued_reconsiderblock == zeroid ) + Queued_reconsiderblock = pindex->GetHash(); } } } From c28dcf1a9d078aa465fde009ed24a6c1c7899c64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 01:58:02 -1100 Subject: [PATCH 16/59] Syntax --- src/komodo_bitcoind.h | 1 - src/komodo_gateway.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 327761c00..d771e2af7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -452,7 +452,6 @@ void komodo_reconsiderblock(uint256 blockhash) { char params[256],*jsonstr,*hexstr; sprintf(params,"[\"%s\"]",blockhash.ToString().c_str()); - komodo_reconsiderblock(Queued_reconsiderblock); if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"reconsiderblock",params,KMD_PORT)) != 0 ) { fprintf(stderr,"komodo_reconsiderblock.(%s) -> (%s)\n",params,jsonstr); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f23a2ff8f..bbad40c35 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2625,7 +2625,7 @@ void komodo_pricesinit() } } -extern Queued_reconsiderblock; +extern uint256 Queued_reconsiderblock; void komodo_pricesupdate(int32_t height,CBlock *pblock) { From 541df854ccdad7dd0da4ccaad97e1b3517702229 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:00:08 -1100 Subject: [PATCH 17/59] GetBlockHash() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d01c9babb..e0e40c9a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5344,7 +5344,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C { fprintf(stderr,"reconsider height.%d, longest.%d\n",(int32_t)ht,longest); if ( Queued_reconsiderblock == zeroid ) - Queued_reconsiderblock = pindex->GetHash(); + Queued_reconsiderblock = pindex->GetBlockHash(); } } } From 73dc3374780616d5478fdb82532c36249c79f307 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:09:49 -1100 Subject: [PATCH 18/59] +print --- src/komodo_bitcoind.h | 1 + src/komodo_gateway.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d771e2af7..6485f46a9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -457,6 +457,7 @@ void komodo_reconsiderblock(uint256 blockhash) fprintf(stderr,"komodo_reconsiderblock.(%s) -> (%s)\n",params,jsonstr); free(jsonstr); } + fprintf(stderr,"komodo_reconsiderblock.(%s) -> NULL\n",params); } int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bbad40c35..225dfd5a7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2631,6 +2631,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) { static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf; int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[PRICES_MAXDATAPOINTS*2]; + fprintf(stderr,"Queued_reconsiderblock %s\n",Queued_reconsiderblock.GetHex().c_str()); if ( Queued_reconsiderblock != zeroid ) { komodo_reconsiderblock(Queued_reconsiderblock); From b4cf30250748bab3b400c7dc50d21cf9b9a8dff3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:16:22 -1100 Subject: [PATCH 19/59] Move to right function --- src/komodo_gateway.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 225dfd5a7..274cf426c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2164,11 +2164,19 @@ int32_t komodo_cbopretsize(uint64_t flags) return(size); } +extern uint256 Queued_reconsiderblock; + void komodo_cbopretupdate(int32_t forceflag) { static uint32_t lasttime,lastcrypto,lastbtc,pending; static uint32_t pricebits[4],cryptoprices[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; int32_t size; uint32_t flags=0,now; CBlockIndex *pindex; + fprintf(stderr,"Queued_reconsiderblock %s\n",Queued_reconsiderblock.GetHex().c_str()); + if ( Queued_reconsiderblock != zeroid ) + { + komodo_reconsiderblock(Queued_reconsiderblock); + Queued_reconsiderblock = zeroid; + } if ( forceflag != 0 && pending != 0 ) { while ( pending != 0 ) @@ -2625,18 +2633,10 @@ void komodo_pricesinit() } } -extern uint256 Queued_reconsiderblock; - void komodo_pricesupdate(int32_t height,CBlock *pblock) { static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf; int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[PRICES_MAXDATAPOINTS*2]; - fprintf(stderr,"Queued_reconsiderblock %s\n",Queued_reconsiderblock.GetHex().c_str()); - if ( Queued_reconsiderblock != zeroid ) - { - komodo_reconsiderblock(Queued_reconsiderblock); - Queued_reconsiderblock = zeroid; - } width = PRICES_DAYWINDOW;//(2*PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH); if ( numprices == 0 ) { From 8d672e591c4131f42701d548f8eff90148638136 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:22:35 -1100 Subject: [PATCH 20/59] Test --- src/komodo_bitcoind.h | 4 ++-- src/komodo_gateway.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6485f46a9..d9476c6ff 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -371,7 +371,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); +printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } @@ -454,7 +454,7 @@ void komodo_reconsiderblock(uint256 blockhash) sprintf(params,"[\"%s\"]",blockhash.ToString().c_str()); if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"reconsiderblock",params,KMD_PORT)) != 0 ) { - fprintf(stderr,"komodo_reconsiderblock.(%s) -> (%s)\n",params,jsonstr); + fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,KMDUSERPASS,KMD_PORT,jsonstr); free(jsonstr); } fprintf(stderr,"komodo_reconsiderblock.(%s) -> NULL\n",params); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 274cf426c..54f80a8eb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2171,9 +2171,9 @@ void komodo_cbopretupdate(int32_t forceflag) static uint32_t lasttime,lastcrypto,lastbtc,pending; static uint32_t pricebits[4],cryptoprices[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; int32_t size; uint32_t flags=0,now; CBlockIndex *pindex; - fprintf(stderr,"Queued_reconsiderblock %s\n",Queued_reconsiderblock.GetHex().c_str()); if ( Queued_reconsiderblock != zeroid ) { + fprintf(stderr,"Queued_reconsiderblock %s\n",Queued_reconsiderblock.GetHex().c_str()); komodo_reconsiderblock(Queued_reconsiderblock); Queued_reconsiderblock = zeroid; } From 76e866c24347cac1b598be8cf071c103a21da2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:29:20 -1100 Subject: [PATCH 21/59] Call right daemon --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d9476c6ff..5e2f3a49f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -371,7 +371,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); -printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); +//printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } @@ -452,12 +452,12 @@ void komodo_reconsiderblock(uint256 blockhash) { char params[256],*jsonstr,*hexstr; sprintf(params,"[\"%s\"]",blockhash.ToString().c_str()); - if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"reconsiderblock",params,KMD_PORT)) != 0 ) + if ( (jsonstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"reconsiderblock",params,ASSETCHAINS_RPCPORT)) != 0 ) { - fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,KMDUSERPASS,KMD_PORT,jsonstr); + fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,USERPASS,KMD_PORT,jsonstr); free(jsonstr); } - fprintf(stderr,"komodo_reconsiderblock.(%s) -> NULL\n",params); + fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> NULL\n",params,USERPASS,KMD_PORT); } int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) From 4599d8ced6d28543ba21011b321c9ac7982b95bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:31:32 -1100 Subject: [PATCH 22/59] ASSETCHAINS_RPCPORT --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5e2f3a49f..a89b9db1a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -454,10 +454,10 @@ void komodo_reconsiderblock(uint256 blockhash) sprintf(params,"[\"%s\"]",blockhash.ToString().c_str()); if ( (jsonstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"reconsiderblock",params,ASSETCHAINS_RPCPORT)) != 0 ) { - fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,USERPASS,KMD_PORT,jsonstr); + fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT,jsonstr); free(jsonstr); } - fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> NULL\n",params,USERPASS,KMD_PORT); + fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> NULL\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT); } int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) From 3d3be0492abdd90c3cdce340f6e5ee30138a3c51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 02:40:12 -1100 Subject: [PATCH 23/59] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a89b9db1a..c0917a765 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -454,10 +454,10 @@ void komodo_reconsiderblock(uint256 blockhash) sprintf(params,"[\"%s\"]",blockhash.ToString().c_str()); if ( (jsonstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"reconsiderblock",params,ASSETCHAINS_RPCPORT)) != 0 ) { - fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT,jsonstr); + //fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT,jsonstr); free(jsonstr); } - fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> NULL\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT); + //fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> NULL\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT); } int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID) From 11930668acfb107229a995b324a696548f4c2265 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 06:44:10 -1100 Subject: [PATCH 24/59] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c0917a765..58d984eb7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -371,7 +371,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); -//printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } From f350e6bdad90e3fb4ef9c55f723734eeb7f44868 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:02:18 -1100 Subject: [PATCH 25/59] AAPL --- src/komodo_gateway.h | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 54f80a8eb..4cb803c9e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2014,18 +2014,13 @@ cJSON *get_urljson(char *url) return(json); } -uint32_t get_stockprice(const char *symbol) +uint32_t get_stockprices(std::vector symbols) { - char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; - sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + char url[32768]; cJSON *json,*obj; uint32_t high,low,price = 0; + sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL"); if ( (json= get_urljson(url)) != 0 ) { - if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 ) - { - high = jdouble(jitem(obj,0),(char *)"2. high")*10000 + 0.000049; - low = jdouble(jitem(obj,0),(char *)"3. low")*10000 + 0.000049; - price = (high + low) / 2; - } + fprintf(stderr,"%s -> %s\n",url,jprint(json,0)); free_json(json); } return(price); @@ -2085,6 +2080,23 @@ int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vect return(-errs); } +/*uint32_t oldget_stockprice(const char *symbol) +{ + char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; + sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + if ( (json= get_urljson(url)) != 0 ) + { + if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 ) + { + high = jdouble(jitem(obj,0),(char *)"2. high")*10000 + 0.000049; + low = jdouble(jitem(obj,0),(char *)"3. low")*10000 + 0.000049; + price = (high + low) / 2; + } + free_json(json); + } + return(price); +} + uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; @@ -2109,7 +2121,7 @@ int32_t get_stocks(const char *list[],int32_t n) } fprintf(stderr," errs.%d\n",errs); return(-errs); -} +}*/ // parse the coindesk specific data. yes, if this changes, it will require an update. However, regardless if the format from the data source changes, then the code that extracts it must be changed. One way to mitigate this is to have a large variety of data sources so that there is only a very remote chance that all of them are not available. Certainly the data gathering needs to be made more robust, but it doesnt really affect the proof of concept for the decentralized trustless oracle. The trustlessness is achieved by having all nodes get the oracle data. @@ -2183,6 +2195,8 @@ void komodo_cbopretupdate(int32_t forceflag) fprintf(stderr,"pricewait "), sleep(1); return; } + get_stockprices("AAPL"); + pending = 1; now = (uint32_t)time(NULL); if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) From d3d42bb31c5e14aeef557dbb22c61fb4179ef9bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:05:15 -1100 Subject: [PATCH 26/59] 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 4cb803c9e..5ea46dba3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2195,7 +2195,7 @@ void komodo_cbopretupdate(int32_t forceflag) fprintf(stderr,"pricewait "), sleep(1); return; } - get_stockprices("AAPL"); + get_stockprices(0); pending = 1; now = (uint32_t)time(NULL); From b575d3ac5af3b34860d55c2cabc1e94164b8dc9e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:06:12 -1100 Subject: [PATCH 27/59] 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 5ea46dba3..605afd271 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2014,7 +2014,7 @@ cJSON *get_urljson(char *url) return(json); } -uint32_t get_stockprices(std::vector symbols) +uint32_t get_stockprices()//std::vector symbols) { char url[32768]; cJSON *json,*obj; uint32_t high,low,price = 0; sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL"); @@ -2195,7 +2195,7 @@ void komodo_cbopretupdate(int32_t forceflag) fprintf(stderr,"pricewait "), sleep(1); return; } - get_stockprices(0); + get_stockprices(); pending = 1; now = (uint32_t)time(NULL); From f0dd1cf6cfe8161960240828d6620d97115134b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:08:57 -1100 Subject: [PATCH 28/59] Use files --- 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 605afd271..9a8700c6f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2018,7 +2018,7 @@ uint32_t get_stockprices()//std::vector symbols) { char url[32768]; cJSON *json,*obj; uint32_t high,low,price = 0; sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL"); - if ( (json= get_urljson(url)) != 0 ) + if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { fprintf(stderr,"%s -> %s\n",url,jprint(json,0)); free_json(json); From 9a44dbb94938946e5638a241b3401074f9f29656 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:11:16 -1100 Subject: [PATCH 29/59] 2nd --- 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 9a8700c6f..72ee7e819 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2017,10 +2017,10 @@ cJSON *get_urljson(char *url) uint32_t get_stockprices()//std::vector symbols) { char url[32768]; cJSON *json,*obj; uint32_t high,low,price = 0; - sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL"); + sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL, MSFT"); if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { - fprintf(stderr,"%s -> %s\n",url,jprint(json,0)); + //https://api.iextrading.com/1.0/tops/last?symbols=AAPL -> [{"symbol":"AAPL","price":198.63,"size":100,"time":1555092606076}] free_json(json); } return(price); From 8eccd385490801719cf042b7bd42da09672cab80 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:21:33 -1100 Subject: [PATCH 30/59] Test --- src/komodo_gateway.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 72ee7e819..8612ddbbb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2016,10 +2016,28 @@ cJSON *get_urljson(char *url) uint32_t get_stockprices()//std::vector symbols) { - char url[32768]; cJSON *json,*obj; uint32_t high,low,price = 0; + std::vector symbols; + char url[32768],*symbol; cJSON *json,*obj; int32_t i,n; uint32_t uprice; + symbols.push_back("AAPL"); + symbols.push_back("MSFT"); sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL, MSFT"); if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { + if ( (n= cJSON_GetArraySize(json)) > 0 ) + { + for (i=0; i [{"symbol":"AAPL","price":198.63,"size":100,"time":1555092606076}] free_json(json); } From cf09109439a1beed5e33e439b043871586b7162d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:22:29 -1100 Subject: [PATCH 31/59] (char *) --- 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 8612ddbbb..0bd1476fd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2028,9 +2028,9 @@ uint32_t get_stockprices()//std::vector symbols) for (i=0; i Date: Fri, 12 Apr 2019 07:22:58 -1100 Subject: [PATCH 32/59] Retail --- 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 0bd1476fd..dd9f9a6a7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2014,10 +2014,10 @@ cJSON *get_urljson(char *url) return(json); } -uint32_t get_stockprices()//std::vector symbols) +int32_t get_stockprices()//std::vector symbols) { std::vector symbols; - char url[32768],*symbol; cJSON *json,*obj; int32_t i,n; uint32_t uprice; + char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0; uint32_t uprice; symbols.push_back("AAPL"); symbols.push_back("MSFT"); sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL, MSFT"); @@ -2041,7 +2041,7 @@ uint32_t get_stockprices()//std::vector symbols) //https://api.iextrading.com/1.0/tops/last?symbols=AAPL -> [{"symbol":"AAPL","price":198.63,"size":100,"time":1555092606076}] free_json(json); } - return(price); + return(n); } uint32_t get_dailyfx(uint32_t *prices) From 77afae4f251ccb99e9ef1af94e549c094f7f0ce1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 07:51:28 -1100 Subject: [PATCH 33/59] Support stock prices --- src/komodo_defs.h | 2 +- src/komodo_gateway.h | 95 +++++++++++++++++++++++++++----------------- src/komodo_globals.h | 2 +- src/komodo_utils.h | 19 ++++++++- 4 files changed, 78 insertions(+), 40 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index ebfadee69..a78276fb3 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -60,7 +60,7 @@ extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NO extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; -extern std::vector ASSETCHAINS_PRICES; +extern std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; extern char ASSETCHAINS_SYMBOL[65]; extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dd9f9a6a7..96ce788f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2014,26 +2014,34 @@ cJSON *get_urljson(char *url) return(json); } -int32_t get_stockprices()//std::vector symbols) +int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector symbols) { - std::vector symbols; - char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0; uint32_t uprice; - symbols.push_back("AAPL"); - symbols.push_back("MSFT"); - sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL, MSFT"); + char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; + sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","")); if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { if ( (n= cJSON_GetArraySize(json)) > 0 ) { + retval = n; for (i=0; i now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) + { + fprintf(stderr,"time error.%d\n",timestamp-now); + retval = -1; + } if ( symbols[i] != symbol ) + { + retval = -1; fprintf(stderr,"MISMATCH."); - fprintf(stderr,"(%s %u) ",symbol,uprice); + } + fprintf(stderr,"(%s %u).%d ",symbol,uprice,timestamp-now); } } fprintf(stderr,"numstocks.%d\n",n); @@ -2041,7 +2049,7 @@ int32_t get_stockprices()//std::vector symbols) //https://api.iextrading.com/1.0/tops/last?symbols=AAPL -> [{"symbol":"AAPL","price":198.63,"size":100,"time":1555092606076}] free_json(json); } - return(n); + return(retval); } uint32_t get_dailyfx(uint32_t *prices) @@ -2190,6 +2198,8 @@ int32_t komodo_cbopretsize(uint64_t flags) size += (sizeof(Forex)/sizeof(*Forex)) * sizeof(uint32_t); if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size())*sizeof(uint32_t); + if ( (ASSETCHAINS_CBOPRET & 8) != 0 ) + size += (ASSETCHAINS_STOCKS.size())*sizeof(uint32_t); } return(size); } @@ -2198,8 +2208,8 @@ extern uint256 Queued_reconsiderblock; void komodo_cbopretupdate(int32_t forceflag) { - static uint32_t lasttime,lastcrypto,lastbtc,pending; - static uint32_t pricebits[4],cryptoprices[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; + static uint32_t lasttime,lastbtc,pending; + static uint32_t pricebits[4],pricebuf[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; int32_t size; uint32_t flags=0,now; CBlockIndex *pindex; if ( Queued_reconsiderblock != zeroid ) { @@ -2213,8 +2223,6 @@ void komodo_cbopretupdate(int32_t forceflag) fprintf(stderr,"pricewait "), sleep(1); return; } - get_stockprices(); - pending = 1; now = (uint32_t)time(NULL); if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) @@ -2248,23 +2256,35 @@ void komodo_cbopretupdate(int32_t forceflag) { if ( forceflag != 0 || flags != 0 ) { - get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES); + get_cryptoprices(pricebuf,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES); if ( flags == 0 ) komodo_PriceCache_shift(); - memcpy(&PriceCache[0][size/sizeof(uint32_t)],cryptoprices,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t)); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],pricebuf,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t)); flags |= 4; // very rarely we can see flags == 6 case } size += (sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t); } + now = (uint32_t)time(NULL); + if ( (ASSETCHAINS_CBOPRET & 8) != 0 ) + { + if ( forceflag != 0 || flags != 0 ) + { + if ( get_stockprices(now,pricebuf,ASSETCHAINS_STOCKS) == ASSETCHAINS_STOCKS.size() ) + { + if ( flags == 0 ) + komodo_PriceCache_shift(); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],pricebuf,ASSETCHAINS_STOCKS.size() * sizeof(uint32_t)); + flags |= 8; // very rarely we can see flags == 10 case + } + } + size += (ASSETCHAINS_STOCKS.size()) * sizeof(uint32_t); + } 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); if ( ExtremePrice.dir != 0 && ExtremePrice.ind > 0 && ExtremePrice.ind < size/sizeof(uint32_t) && now < ExtremePrice.timestamp+3600 ) { @@ -2284,19 +2304,6 @@ void komodo_cbopretupdate(int32_t forceflag) // fprintf(stderr,"%02x",Mineropret[i]); //fprintf(stderr," <- set Mineropret[%d] size.%d %ld\n",(int32_t)Mineropret.size(),size,sizeof(PriceCache[0])); } - /* - if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) - { - get_currencies(Metals,(int32_t)(sizeof(Metals)/sizeof(*Metals))); - } - if ( (ASSETCHAINS_CBOPRET & 32) != 0 ) - { - get_stocks(Markets,(int32_t)(sizeof(Markets)/sizeof(*Markets))); - } - if ( (ASSETCHAINS_CBOPRET & 64) != 0 ) - { - get_stocks(Techstocks,(int32_t)(sizeof(Techstocks)/sizeof(*Techstocks))); - }*/ } pending = 0; } @@ -2320,6 +2327,11 @@ int64_t komodo_pricemult(int32_t ind) for (j=0; j ASSETCHAINS_PRICES; +std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 3; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 3ffaf52dd..c5f562b0e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1815,11 +1815,17 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CBOPRET != 0 ) { SplitStr(GetArg("-ac_prices",""), ASSETCHAINS_PRICES); - for (i=0; i 0 ) ASSETCHAINS_CBOPRET |= 4; + SplitStr(GetArg("-ac_stocks",""), ASSETCHAINS_STOCKS); + if ( ASSETCHAINS_STOCKS.size() > 0 ) + ASSETCHAINS_CBOPRET |= 8; + for (i=0; i Date: Fri, 12 Apr 2019 07:57:20 -1100 Subject: [PATCH 34/59] c_Str --- 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 96ce788f9..36ebce74a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2017,7 +2017,7 @@ cJSON *get_urljson(char *url) int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector symbols) { char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; - sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","")); + sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { if ( (n= cJSON_GetArraySize(json)) > 0 ) From d1af8415a895b8fc17c235d2ad39f95c5c42b5b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:08:48 -1100 Subject: [PATCH 35/59] Pricing --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 36ebce74a..2575df1ac 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2392,6 +2392,7 @@ char *komodo_pricename(char *name,int32_t ind) return(0); if ( ind < ASSETCHAINS_STOCKS.size() ) { + fprintf(stderr,"ind.%d vs size.%d\n",ind,(int32_t)ASSETCHAINS_PRICES.size()); strcpy(name,ASSETCHAINS_PRICES[ind].c_str()); strcat(name,"/USD"); return(name); @@ -2669,6 +2670,7 @@ void komodo_pricesinit() { if ( komodo_pricename(PRICES[i].symbol,i) == 0 ) break; + fprintf(stderr,"i.%d %s\n",i,PRICES[i].symbol); if ( i == 0 ) strcpy(PRICES[i].symbol,"rawprices"); pricefname = pricesdir / PRICES[i].symbol; From eb2b06ba62a446767fa1ac1087bf1a0dfc97b604 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:14:32 -1100 Subject: [PATCH 36/59] +print --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2575df1ac..e2981a856 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2033,7 +2033,7 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s prices[i] = uprice; if ( timestamp > now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) { - fprintf(stderr,"time error.%d\n",timestamp-now); + fprintf(stderr,"time error.%d (%u vs %u)\n",timestamp-now,timestamp,now); retval = -1; } if ( symbols[i] != symbol ) @@ -2392,8 +2392,7 @@ char *komodo_pricename(char *name,int32_t ind) return(0); if ( ind < ASSETCHAINS_STOCKS.size() ) { - fprintf(stderr,"ind.%d vs size.%d\n",ind,(int32_t)ASSETCHAINS_PRICES.size()); - strcpy(name,ASSETCHAINS_PRICES[ind].c_str()); + strcpy(name,ASSETCHAINS_STOCKS[ind].c_str()); strcat(name,"/USD"); return(name); } else ind -= ASSETCHAINS_STOCKS.size(); From e6eddb7a70992a5d1b6dc3708db9e0dbc8c21762 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:17:28 -1100 Subject: [PATCH 37/59] -print --- 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 e2981a856..73df3a546 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2028,7 +2028,7 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s obj = jitem(json,i); if ( (symbol= jstr(obj,(char *)"symbol")) != 0 ) { - timestamp = juint(obj,(char *)"time"); + timestamp = jdouble(obj,(char *)"time"); uprice = jdouble(obj,(char *)"price")*100 + 0.0049; prices[i] = uprice; if ( timestamp > now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) @@ -2669,7 +2669,6 @@ void komodo_pricesinit() { if ( komodo_pricename(PRICES[i].symbol,i) == 0 ) break; - fprintf(stderr,"i.%d %s\n",i,PRICES[i].symbol); if ( i == 0 ) strcpy(PRICES[i].symbol,"rawprices"); pricefname = pricesdir / PRICES[i].symbol; From 06157628eb1c80225b93a25cb35362d36663a0ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:21:55 -1100 Subject: [PATCH 38/59] Atol --- 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 73df3a546..f03d74c11 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2016,7 +2016,7 @@ cJSON *get_urljson(char *url) int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector symbols) { - char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; + char url[32768],*symbol,*timestr; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { @@ -2026,9 +2026,9 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s for (i=0; i now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) From 7d487d3ea3d27d3c34f394fefa27c65e38cc0b36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:28:56 -1100 Subject: [PATCH 39/59] 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 f03d74c11..e30ee8d00 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2026,9 +2026,9 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s for (i=0; i now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) From 26dddaac894c0fff7ae2e316cdc46ddc955fd83a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:31:44 -1100 Subject: [PATCH 40/59] Skip timestamp for now --- 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 e30ee8d00..4dfba5392 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2028,20 +2028,20 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s obj = jitem(json,i); if ( (symbol= jstr(obj,(char *)"symbol")) != 0 ) { - timestamp = j64bits(obj,(char *)"time"); uprice = jdouble(obj,(char *)"price")*100 + 0.0049; prices[i] = uprice; + /*timestamp = j64bits(obj,(char *)"time"); if ( timestamp > now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) { fprintf(stderr,"time error.%d (%u vs %u)\n",timestamp-now,timestamp,now); retval = -1; - } + }*/ if ( symbols[i] != symbol ) { retval = -1; fprintf(stderr,"MISMATCH."); } - fprintf(stderr,"(%s %u).%d ",symbol,uprice,timestamp-now); + fprintf(stderr,"(%s %u) ",symbol,uprice); } } fprintf(stderr,"numstocks.%d\n",n); From 325e914ce846b6e6e0498db2e02a60db34eb4bd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:38:43 -1100 Subject: [PATCH 41/59] Test --- src/bitcoind.cpp | 4 ++-- src/komodo_gateway.h | 9 +++++++++ src/komodo_utils.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 68e0da8b3..dc85547a9 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -70,8 +70,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) { int32_t i; bool fShutdown = ShutdownRequested(); // Tell the main threads to shutdown. - if ( ASSETCHAINS_CBOPRET != 0 ) - komodo_pricesinit(); + //if ( ASSETCHAINS_CBOPRET != 0 ) + // komodo_pricesinit(); while (!fShutdown) { //fprintf(stderr,"call passport iteration\n"); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4dfba5392..3a3dba00e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2660,7 +2660,11 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) void komodo_pricesinit() { + static int32_t didinit; int32_t i,createflag = 0; + if ( didinit != 0 ) + return; + didinit = 1; boost::filesystem::path pricefname,pricesdir = GetDataDir() / "prices"; fprintf(stderr,"pricesinit (%s)\n",pricesdir.string().c_str()); if (!boost::filesystem::exists(pricesdir)) @@ -2720,6 +2724,11 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) rngval = seed; for (ind=1; ind 0 ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c5f562b0e..363eb73ce 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2100,6 +2100,7 @@ void komodo_args(char *argv0) extralen += symbol.size(); } } + komodo_pricesinit(); komodo_cbopretupdate(1); // will set Mineropret fprintf(stderr,"This blockchain uses data produced from CoinDesk Bitcoin Price Index\n"); } From d0fd337b2565b11e8cb683b4acdaf9edfb1449c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:44:54 -1100 Subject: [PATCH 42/59] Revert --- src/bitcoind.cpp | 4 ++-- src/komodo_defs.h | 2 +- src/komodo_gateway.h | 6 ++++-- src/komodo_utils.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index dc85547a9..68e0da8b3 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -70,8 +70,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) { int32_t i; bool fShutdown = ShutdownRequested(); // Tell the main threads to shutdown. - //if ( ASSETCHAINS_CBOPRET != 0 ) - // komodo_pricesinit(); + if ( ASSETCHAINS_CBOPRET != 0 ) + komodo_pricesinit(); while (!fShutdown) { //fprintf(stderr,"call passport iteration\n"); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index a78276fb3..4fd357ac1 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -87,6 +87,6 @@ void komodo_netevent(std::vector payload); #define PRICES_SMOOTHWIDTH 1 int32_t komodo_priceind(char *symbol); -void komodo_pricesinit(); +int32_t komodo_pricesinit(); #endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3a3dba00e..cebe152ff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2658,12 +2658,12 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) return((price*7 + halfave*5 + thirdave*3 + fourthave*2 + decayprice + buf[PRICES_DAYWINDOW-1]) / 19); } -void komodo_pricesinit() +int32_t komodo_pricesinit() { static int32_t didinit; int32_t i,createflag = 0; if ( didinit != 0 ) - return; + return(-1); didinit = 1; boost::filesystem::path pricefname,pricesdir = GetDataDir() / "prices"; fprintf(stderr,"pricesinit (%s)\n",pricesdir.string().c_str()); @@ -2690,6 +2690,8 @@ void komodo_pricesinit() fputc(0,PRICES[0].fp); fflush(PRICES[0].fp); } + fprintf(stderr,"pricesinit done\n"); + return(0); } void komodo_pricesupdate(int32_t height,CBlock *pblock) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 363eb73ce..a3d611f9f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2100,7 +2100,7 @@ void komodo_args(char *argv0) extralen += symbol.size(); } } - komodo_pricesinit(); + //komodo_pricesinit(); komodo_cbopretupdate(1); // will set Mineropret fprintf(stderr,"This blockchain uses data produced from CoinDesk Bitcoin Price Index\n"); } From f3056d48294524939219c33750daad8fe85ad6b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 08:56:44 -1100 Subject: [PATCH 43/59] +print --- src/komodo_gateway.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cebe152ff..792e2b5ab 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2197,9 +2197,9 @@ int32_t komodo_cbopretsize(uint64_t flags) if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) size += (sizeof(Forex)/sizeof(*Forex)) * sizeof(uint32_t); if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) - size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size())*sizeof(uint32_t); + size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size()) * sizeof(uint32_t); if ( (ASSETCHAINS_CBOPRET & 8) != 0 ) - size += (ASSETCHAINS_STOCKS.size())*sizeof(uint32_t); + size += (ASSETCHAINS_STOCKS.size() * sizeof(uint32_t)); } return(size); } @@ -2661,7 +2661,7 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip) int32_t komodo_pricesinit() { static int32_t didinit; - int32_t i,createflag = 0; + int32_t i,num=0,createflag = 0; if ( didinit != 0 ) return(-1); didinit = 1; @@ -2676,12 +2676,15 @@ int32_t komodo_pricesinit() if ( i == 0 ) strcpy(PRICES[i].symbol,"rawprices"); pricefname = pricesdir / PRICES[i].symbol; - PRICES[i].fp = fopen(pricefname.string().c_str(), createflag != 0 ? "wb+" : "rb+"); - if ( createflag != 0 ) + if ( (PRICES[i].fp= fopen(pricefname.string().c_str(), createflag != 0 ? "wb+" : "rb+")) != 0 ) { - fseek(PRICES[i].fp,(2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH) * sizeof(int64_t) * PRICES_MAXDATAPOINTS,SEEK_SET); - fputc(0,PRICES[i].fp); - fflush(PRICES[i].fp); + num++; + if ( createflag != 0 ) + { + fseek(PRICES[i].fp,(2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH) * sizeof(int64_t) * PRICES_MAXDATAPOINTS,SEEK_SET); + fputc(0,PRICES[i].fp); + fflush(PRICES[i].fp); + } } } if ( i > 0 && PRICES[0].fp != 0 && createflag != 0 ) @@ -2690,7 +2693,7 @@ int32_t komodo_pricesinit() fputc(0,PRICES[0].fp); fflush(PRICES[0].fp); } - fprintf(stderr,"pricesinit done\n"); + fprintf(stderr,"pricesinit done i.%d num.%d numprices.%d\n",i,num,(int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET)/sizeof(uint32_t))); return(0); } From 149ce304f62cc63085e0161089cddd4e56126659 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 09:00:06 -1100 Subject: [PATCH 44/59] pricefname.string().c_str(), createflag --- 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 792e2b5ab..d941699dd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2673,6 +2673,7 @@ int32_t komodo_pricesinit() { if ( komodo_pricename(PRICES[i].symbol,i) == 0 ) break; + fprintf(stderr,"%s.%d ",PRICES[i].symbol,i); if ( i == 0 ) strcpy(PRICES[i].symbol,"rawprices"); pricefname = pricesdir / PRICES[i].symbol; @@ -2685,7 +2686,7 @@ int32_t komodo_pricesinit() fputc(0,PRICES[i].fp); fflush(PRICES[i].fp); } - } + } else fprintf(stderr,"error operning %s createflag.%d\n",pricefname.string().c_str(), createflag); } if ( i > 0 && PRICES[0].fp != 0 && createflag != 0 ) { From 0c3582c06a0aad460897cc144607f76b579d5ca1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 09:03:08 -1100 Subject: [PATCH 45/59] Fix names --- src/komodo_gateway.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d941699dd..b0e8b391d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2348,9 +2348,9 @@ char *komodo_pricename(char *name,int32_t ind) switch ( ind ) { case 0: strcpy(name,"timestamp"); break; - case 1: strcpy(name,"BTC/USD"); break; - case 2: strcpy(name,"BTC/GBP"); break; - case 3: strcpy(name,"BTC/EUR"); break; + case 1: strcpy(name,"BTCUSD"); break; + case 2: strcpy(name,"BTCGBP"); break; + case 3: strcpy(name,"BTCEUR"); break; default: return(0); break; } return(name); @@ -2364,8 +2364,8 @@ char *komodo_pricename(char *name,int32_t ind) return(0); if ( ind < sizeof(Forex)/sizeof(*Forex) ) { - name[0] = 'U', name[1] = 'S', name[2] = 'D', name[3] = '/'; - strcpy(name+4,Forex[ind]); + name[0] = 'U', name[1] = 'S', name[2] = 'D'; + strcpy(name+3,Forex[ind]); return(name); } else ind -= sizeof(Forex)/sizeof(*Forex); } @@ -2382,7 +2382,7 @@ char *komodo_pricename(char *name,int32_t ind) ind -= (sizeof(Cryptos)/sizeof(*Cryptos)); strcpy(name,ASSETCHAINS_PRICES[ind].c_str()); } - strcat(name,"/BTC"); + strcat(name,"BTC"); return(name); } else ind -= (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size()); } @@ -2393,7 +2393,7 @@ char *komodo_pricename(char *name,int32_t ind) if ( ind < ASSETCHAINS_STOCKS.size() ) { strcpy(name,ASSETCHAINS_STOCKS[ind].c_str()); - strcat(name,"/USD"); + strcat(name,"USD"); return(name); } else ind -= ASSETCHAINS_STOCKS.size(); } @@ -2673,7 +2673,7 @@ int32_t komodo_pricesinit() { if ( komodo_pricename(PRICES[i].symbol,i) == 0 ) break; - fprintf(stderr,"%s.%d ",PRICES[i].symbol,i); + //fprintf(stderr,"%s.%d ",PRICES[i].symbol,i); if ( i == 0 ) strcpy(PRICES[i].symbol,"rawprices"); pricefname = pricesdir / PRICES[i].symbol; From 456ccc25644de46a78a1ce8c8dd0d29405a3d162 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 09:07:22 -1100 Subject: [PATCH 46/59] Shutdown if can't open prices --- src/komodo_gateway.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b0e8b391d..dc00c2391 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2695,6 +2695,11 @@ int32_t komodo_pricesinit() fflush(PRICES[0].fp); } fprintf(stderr,"pricesinit done i.%d num.%d numprices.%d\n",i,num,(int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET)/sizeof(uint32_t))); + if ( i != num || i != komodo_cbopretsize(ASSETCHAINS_CBOPRET)/sizeof(uint32_t) ) + { + fprintf(stderr,"fatal error opening prices files, start shutdown\n"); + StartShutdown(); + } return(0); } From 45f8c77b79175d7f0b7a67e4933de695da547b57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 09:10:47 -1100 Subject: [PATCH 47/59] Handle prices directory there, but missing file --- src/komodo_gateway.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dc00c2391..09af54bc4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2677,7 +2677,11 @@ int32_t komodo_pricesinit() if ( i == 0 ) strcpy(PRICES[i].symbol,"rawprices"); pricefname = pricesdir / PRICES[i].symbol; - if ( (PRICES[i].fp= fopen(pricefname.string().c_str(), createflag != 0 ? "wb+" : "rb+")) != 0 ) + if ( createflag != 0 ) + PRICES[i].fp = fopen(pricefname.string().c_str(),"wb+"); + else if ( (PRICES[i].fp= fopen(pricefname.string().c_str(),"rb+")) == 0 ) + PRICES[i].fp = fopen(pricefname.string().c_str(),"wb+"); + if ( PRICES[i].fp != 0 ) { num++; if ( createflag != 0 ) @@ -2686,7 +2690,7 @@ int32_t komodo_pricesinit() fputc(0,PRICES[i].fp); fflush(PRICES[i].fp); } - } else fprintf(stderr,"error operning %s createflag.%d\n",pricefname.string().c_str(), createflag); + } else fprintf(stderr,"error opening %s createflag.%d\n",pricefname.string().c_str(), createflag); } if ( i > 0 && PRICES[0].fp != 0 && createflag != 0 ) { From a05149ce8ef2204d89a5660a11d6cf4ce8f250b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 09:13:30 -1100 Subject: [PATCH 48/59] Test --- 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 09af54bc4..20e473ad6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2348,9 +2348,9 @@ char *komodo_pricename(char *name,int32_t ind) switch ( ind ) { case 0: strcpy(name,"timestamp"); break; - case 1: strcpy(name,"BTCUSD"); break; - case 2: strcpy(name,"BTCGBP"); break; - case 3: strcpy(name,"BTCEUR"); break; + case 1: strcpy(name,"BTC_USD"); break; + case 2: strcpy(name,"BTC_GBP"); break; + case 3: strcpy(name,"BTC_EUR"); break; default: return(0); break; } return(name); @@ -2364,8 +2364,8 @@ char *komodo_pricename(char *name,int32_t ind) return(0); if ( ind < sizeof(Forex)/sizeof(*Forex) ) { - name[0] = 'U', name[1] = 'S', name[2] = 'D'; - strcpy(name+3,Forex[ind]); + name[0] = 'U', name[1] = 'S', name[2] = 'D', name[3] = '_'; + strcpy(name+4,Forex[ind]); return(name); } else ind -= sizeof(Forex)/sizeof(*Forex); } @@ -2382,7 +2382,7 @@ char *komodo_pricename(char *name,int32_t ind) ind -= (sizeof(Cryptos)/sizeof(*Cryptos)); strcpy(name,ASSETCHAINS_PRICES[ind].c_str()); } - strcat(name,"BTC"); + strcat(name,"_BTC"); return(name); } else ind -= (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size()); } @@ -2393,7 +2393,7 @@ char *komodo_pricename(char *name,int32_t ind) if ( ind < ASSETCHAINS_STOCKS.size() ) { strcpy(name,ASSETCHAINS_STOCKS[ind].c_str()); - strcat(name,"USD"); + strcat(name,"_USD"); return(name); } else ind -= ASSETCHAINS_STOCKS.size(); } From bceb29eb2b62dd862f1a710e8cbb226b54903b23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Apr 2019 21:55:55 -1100 Subject: [PATCH 49/59] New refs --- src/cc/CCPrices.h | 1 + src/komodo_defs.h | 27 +++++++++++++++++++++++---- src/komodo_gateway.h | 24 ++++++++++++++++++++++++ src/rpc/blockchain.cpp | 33 ++------------------------------- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 1ecaebb2c..633cc32e2 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -19,6 +19,7 @@ #include "CCinclude.h" int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind); +int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) #define PRICES_TXFEE 10000 diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 4fd357ac1..4db390494 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -57,25 +57,21 @@ extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY extern const char *ASSETCHAINS_ALGORITHMS[]; extern int32_t VERUS_MIN_STAKEAGE; extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; extern std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; -extern char ASSETCHAINS_SYMBOL[65]; extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; -extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror,ASSETCHAINS_CCLIB; extern uint8_t ASSETCHAINS_CCDISABLES[256]; extern int32_t USE_EXTERNAL_PUBKEY; extern std::string NOTARY_PUBKEY; extern int32_t KOMODO_EXCHANGEWALLET; -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern int32_t VERUS_MIN_STAKEAGE; extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; @@ -85,8 +81,31 @@ int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; void komodo_netevent(std::vector payload); +#define IGUANA_MAXSCRIPTSIZE 10001 +#define KOMODO_KVDURATION 1440 +#define KOMODO_KVBINARY 2 #define PRICES_SMOOTHWIDTH 1 +uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); +int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); +char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); +int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); +int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); + +int32_t komodo_longestchain(); +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); +int8_t komodo_segid(int32_t nocache,int32_t height); +int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); +char *komodo_pricename(char *name,int32_t ind); int32_t komodo_priceind(char *symbol); int32_t komodo_pricesinit(); +int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); +int32_t komodo_nextheight(); +uint32_t komodo_heightstamp(int32_t height); +int64_t komodo_pricemult(int32_t ind); +int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); + #endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 20e473ad6..b1860dbc1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2707,6 +2707,14 @@ int32_t komodo_pricesinit() return(0); } +pthread_mutex_t pricemutex; + +// PRICES file layouts +// [0] rawprice32 / timestamp +// [1] correlated +// [2] 24hr ave +// [3] to [7] reserved + void komodo_pricesupdate(int32_t height,CBlock *pblock) { static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf; @@ -2714,6 +2722,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) width = PRICES_DAYWINDOW;//(2*PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH); if ( numprices == 0 ) { + pthread_mutex_init(&pricemutex,0); numprices = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t)); ptr32 = (uint32_t *)calloc(sizeof(uint32_t),numprices * width); ptr64 = (int64_t *)calloc(sizeof(int64_t),PRICES_DAYWINDOW*PRICES_MAXDATAPOINTS); @@ -2727,6 +2736,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) //fprintf(stderr,"numprices.%d\n",numprices); if ( PRICES[0].fp != 0 ) { + pthread_mutex_lock(&pricemutex); fseek(PRICES[0].fp,height * numprices * sizeof(uint32_t),SEEK_SET); if ( fwrite(rawprices,sizeof(uint32_t),numprices,PRICES[0].fp) != numprices ) fprintf(stderr,"error writing rawprices for ht.%d\n",height); @@ -2774,8 +2784,22 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock) fprintf(stderr,"height.%d\n",height); } else fprintf(stderr,"error reading rawprices for ht.%d\n",height); } else fprintf(stderr,"height.%d <= width.%d\n",height,width); + pthread_mutex_unlock(&pricemutex); } else fprintf(stderr,"null PRICES[0].fp\n"); } else fprintf(stderr,"numprices mismatch, height.%d\n",height); } +int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks) +{ + FILE *fp; int32_t retval = PRICES_MAXDATAPOINTS; + pthread_mutex_lock(&pricemutex); + if ( ind < KOMODO_MAXPRICES && (fp= PRICES[ind].fp) != 0 ) + { + fseek(fp,height * PRICES_MAXDATAPOINTS * sizeof(int64_t),SEEK_SET); + if ( fread(buf64,sizeof(int64_t),numblocks*PRICES_MAXDATAPOINTS,fp) != numblocks*PRICES_MAXDATAPOINTS ) + retval = -1; + } + pthread_mutex_unlock(&pricemutex); + return(retval); +} diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 83fcd8cad..84bdfd02e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -47,10 +47,8 @@ using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); -int32_t komodo_longestchain(); -int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); -extern int8_t komodo_segid(int32_t nocache,int32_t height); -extern int32_t KOMODO_LONGESTCHAIN; +#include "komodo_defs.h" +#include "komodo_structs.h" double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty) { @@ -628,8 +626,6 @@ UniValue getblockhash(const UniValue& params, bool fHelp) return pblockindex->GetBlockHash().GetHex(); } -extern int32_t ASSETCHAINS_STAKED; - UniValue getlastsegidstakes(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -915,20 +911,6 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) return ret; } -#include "komodo_defs.h" -#include "komodo_structs.h" - -#define IGUANA_MAXSCRIPTSIZE 10001 -#define KOMODO_KVDURATION 1440 -#define KOMODO_KVBINARY 2 -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern int32_t ASSETCHAINS_LWMAPOS; -uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); -int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); -int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); -char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); -int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); -int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); UniValue kvsearch(const UniValue& params, bool fHelp) { @@ -1174,15 +1156,6 @@ UniValue paxprice(const UniValue& params, bool fHelp) return ret; } -int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); -char *komodo_pricename(char *name,int32_t ind); -int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip); -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); -int32_t komodo_nextheight(); -uint32_t komodo_heightstamp(int32_t height); -int64_t komodo_pricemult(int32_t ind); -#define PRICES_SMOOTHWIDTH 1 - int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) { int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; int64_t *tmpbuf; @@ -1324,8 +1297,6 @@ UniValue prices(const UniValue& params, bool fHelp) return ret; } -uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); - UniValue gettxout(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) From 9d0a39dbd742239850ec3d62a2e5c395245ac645 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Apr 2019 19:19:00 -1100 Subject: [PATCH 50/59] coinsupply inflation calc --- src/rpc/blockchain.cpp | 1 + src/rpc/misc.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 84bdfd02e..18f7b0fc0 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1255,6 +1255,7 @@ UniValue prices(const UniValue& params, bool fHelp) rngval = (rngval*11109 + 13849); if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],1,0,PRICES_SMOOTHWIDTH)) < 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price"); + } tmpbuf = (int64_t *)calloc(sizeof(int64_t),2*PRICES_DAYWINDOW); for (i=0; i 1) throw runtime_error("coinsupply \n" "\nReturn coin supply information at a given block height. If no height is given, the current height is used.\n" @@ -448,6 +448,26 @@ UniValue coinsupply(const UniValue& params, bool fHelp) result.push_back(Pair("zfunds", ValueFromAmount(zfunds))); result.push_back(Pair("sprout", ValueFromAmount(sproutfunds))); result.push_back(Pair("total", ValueFromAmount(zfunds + supply))); + if ( ASSETCHAINS_BLOCKTIME > 0 ) + { + blocks_per_year = 24*3600*365 / ASSETCHAINS_BLOCKTIME; + if ( height > blocks_per_year ) + { + supply1 = komodo_coinsupply(&zf,&sf,height - blocks_per_year/12); + supply3 = komodo_coinsupply(&zf,&sf,height - blocks_per_year/4); + supply12 = komodo_coinsupply(&zf,&sf,height - blocks_per_year); + if ( supply1 != 0 && supply3 != 0 && supply12 != 0 ) + { + result.push_back(Pair("lastmonth", ValueFromAmount(supply1))); + result.push_back(Pair("monthcoins", ValueFromAmount(supply - supply1))); + result.push_back(Pair("lastquarter", ValueFromAmount(supply3))); + result.push_back(Pair("quartercoins", ValueFromAmount(supply - supply3))); + result.push_back(Pair("lastyear", ValueFromAmount(supply12))); + result.push_back(Pair("yearcoins", ValueFromAmount(supply - supply12))); + result.push_back(Pair("inflation", 100. * (((double)supply/supply12)-1.))); + } + } + } } else result.push_back(Pair("error", "couldnt calculate supply")); } else { result.push_back(Pair("error", "invalid height")); From 8c27ef7372d2dacddb3d69ef30453e349a688172 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Apr 2019 20:41:40 -1100 Subject: [PATCH 51/59] Coin supply changes to include funds --- src/rpc/misc.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 48914cce1..0d741422f 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -413,7 +413,7 @@ public: UniValue coinsupply(const UniValue& params, bool fHelp) { - int32_t height = 0; int32_t currentHeight; int64_t blocks_per_year,zf,sf,sproutfunds,zfunds,supply1,supply3,supply12,supply = 0; UniValue result(UniValue::VOBJ); + int32_t height = 0; int32_t currentHeight; int64_t blocks_per_year,zf1,zf3,zf12,sf1,sf3,sf12,sproutfunds,zfunds,supply1,supply3,supply12,supply = 0; UniValue result(UniValue::VOBJ); if (fHelp || params.size() > 1) throw runtime_error("coinsupply \n" "\nReturn coin supply information at a given block height. If no height is given, the current height is used.\n" @@ -453,18 +453,19 @@ UniValue coinsupply(const UniValue& params, bool fHelp) blocks_per_year = 24*3600*365 / ASSETCHAINS_BLOCKTIME; if ( height > blocks_per_year ) { - supply1 = komodo_coinsupply(&zf,&sf,height - blocks_per_year/12); - supply3 = komodo_coinsupply(&zf,&sf,height - blocks_per_year/4); - supply12 = komodo_coinsupply(&zf,&sf,height - blocks_per_year); + supply1 = komodo_coinsupply(&zf1,&sf1,height - blocks_per_year/12); + supply3 = komodo_coinsupply(&zf3,&sf3,height - blocks_per_year/4); + supply12 = komodo_coinsupply(&zf12,&sf12,height - blocks_per_year); if ( supply1 != 0 && supply3 != 0 && supply12 != 0 ) { - result.push_back(Pair("lastmonth", ValueFromAmount(supply1))); - result.push_back(Pair("monthcoins", ValueFromAmount(supply - supply1))); - result.push_back(Pair("lastquarter", ValueFromAmount(supply3))); - result.push_back(Pair("quartercoins", ValueFromAmount(supply - supply3))); - result.push_back(Pair("lastyear", ValueFromAmount(supply12))); - result.push_back(Pair("yearcoins", ValueFromAmount(supply - supply12))); - result.push_back(Pair("inflation", 100. * (((double)supply/supply12)-1.))); + result.push_back(Pair("lastmonth", ValueFromAmount(supply1+zf1))); + result.push_back(Pair("monthcoins", ValueFromAmount(zfunds + supply - supply1-zf1))); + result.push_back(Pair("lastquarter", ValueFromAmount(supply3+zf3))); + result.push_back(Pair("quartercoins", ValueFromAmount(zfunds + supply - supply3-zf3))); + result.push_back(Pair("lastyear", ValueFromAmount(supply12+zf12))); + result.push_back(Pair("yearcoins", ValueFromAmount(zfunds + supply - supply12-zf12))); + result.push_back(Pair("inflation", 100. * (((double)(zfunds + supply)/(supply12+zf12))-1.))); + result.push_back(Pair("blocksperyear", (int64_t)blocks_per_year))); } } } From 1ca7ee28e008fa32e54b232d9a7a2050690ca979 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Apr 2019 20:49:31 -1100 Subject: [PATCH 52/59] -) --- src/rpc/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 0d741422f..4e21ab9e9 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -465,7 +465,7 @@ UniValue coinsupply(const UniValue& params, bool fHelp) result.push_back(Pair("lastyear", ValueFromAmount(supply12+zf12))); result.push_back(Pair("yearcoins", ValueFromAmount(zfunds + supply - supply12-zf12))); result.push_back(Pair("inflation", 100. * (((double)(zfunds + supply)/(supply12+zf12))-1.))); - result.push_back(Pair("blocksperyear", (int64_t)blocks_per_year))); + result.push_back(Pair("blocksperyear", (int64_t)blocks_per_year)); } } } From 7c56d034748a2eb1596ba7078d7fd1fbbedfa203 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 14 Apr 2019 15:51:26 +0800 Subject: [PATCH 53/59] try wallet fix --- src/wallet/walletdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 83a79821f..3428b8b75 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -961,7 +961,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) if (GetTransaction(hash,tx,blockhash,true)) { CWalletTx wtx(pwallet,tx); - pwallet->AddToWallet(wtx, true, NULL); + pwallet->AddToWallet(wtx, false, NULL); reAdded++; } } From aec18840703dbea6a38bcaa98b3e34312308bd10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Apr 2019 02:15:56 -1100 Subject: [PATCH 54/59] StartShutdown(); instead of exit() --- src/cc/dice.cpp | 2 +- src/cryptoconditions/src/secp256k1.c | 2 +- src/komodo_bitcoind.h | 4 ++-- src/komodo_gateway.h | 2 +- src/komodo_utils.h | 27 ++++++++++++++++----------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 76d68e090..20f7a0567 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1662,7 +1662,7 @@ void *dealer0_loop(void *_arg) if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { fprintf(stderr,"error initializing dealer0_loop\n"); - exit(-1); + StartShutdown(); } fprintf(stderr,"dealer0 node running\n"); height = lastht = 0; diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 31bab06e5..aa82376a3 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -68,7 +68,7 @@ void lockSign() { } if (!secp256k1_context_randomize(ec_ctx_sign, ent)) { fprintf(stderr, "Could not randomize secp256k1 context\n"); - exit(1); + StartShutdown(); } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58d984eb7..2f9c1a8d7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -57,7 +57,7 @@ void init_string(struct return_string *s) if ( s->ptr == NULL ) { fprintf(stderr,"init_string malloc() failed\n"); - exit(-1); + StartShutdown(); } s->ptr[0] = '\0'; } @@ -94,7 +94,7 @@ size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string * if ( s->ptr == NULL ) { fprintf(stderr, "accumulate realloc() failed\n"); - exit(-1); + StartShutdown(); } memcpy(s->ptr+s->len,ptr,size*nmemb); s->ptr[new_len] = '\0'; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b1860dbc1..a6b5b4566 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -653,7 +653,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) if ( sizeof(banned_txids)/sizeof(*banned_txids) > max ) { fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max); - exit(-1); + StartShutdown(); } for (i=0; i (uint64_t)90*1000*1000000 ) { fprintf(stderr,"-ac_supply must be less than 90 billion\n"); - exit(0); + StartShutdown(); } fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY); @@ -1839,7 +1839,7 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_FOUNDERS_REWARD != 0 ) { fprintf(stderr,"cannot use founders reward and commission on the same chain.\n"); - exit(0); + StartShutdown(); } if ( ASSETCHAINS_CC != 0 ) { @@ -1879,7 +1879,7 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); - exit(0); + StartShutdown(); } ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) @@ -1887,18 +1887,18 @@ void komodo_args(char *argv0) if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) { fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); - exit(0); + StartShutdown(); } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); - exit(0); + StartShutdown(); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) { fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); - exit(0); + StartShutdown(); } // else it can be gateway coin @@ -1926,12 +1926,12 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_SUPPLY > 10000000000 ) { printf("ac_pubkey or ac_script wont work with ac_supply over 10 billion\n"); - exit(0); + StartShutdown(); } if ( ASSETCHAINS_NOTARY_PAY[0] != 0 ) { printf("Assetchains NOTARY PAY cannot be used with ac_pubkey or ac_script.\n"); - exit(0); + StartShutdown(); } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) { @@ -1972,7 +1972,7 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_SCRIPTPUB.size() > 1 && ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); - exit(0); + StartShutdown(); } if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 ) { @@ -2150,7 +2150,7 @@ void komodo_args(char *argv0) if ( strcmp(ASSETCHAINS_SYMBOL,"KMD") == 0 ) { fprintf(stderr,"cant have assetchain named KMD\n"); - exit(0); + StartShutdown(); } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; @@ -2232,6 +2232,11 @@ void komodo_args(char *argv0) } else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) dpowconfs = 0; + else if ( ASSETCHAINS_PRIVATE != 0 ) + { + fprintf(stderr,"-ac_private for a non-PIRATE chain is not supported. The only reason to have an -ac_private chain is for total privacy and that is best achieved with the largest anon set. PIRATE has that and it is recommended to just use PIRATE\n"); + StartShutdown(); + } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 ) From 9d208da4b64e21ab800fed677361d5651b777ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Apr 2019 02:17:58 -1100 Subject: [PATCH 55/59] void StartShutdown() --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 08d466411..5b6d575f3 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -164,6 +164,7 @@ UniValue CClib_info(struct CCcontract_info *cp); CBlockIndex *komodo_blockindex(uint256 hash); CBlockIndex *komodo_chainactive(int32_t height); int32_t komodo_blockheight(uint256 hash); +void StartShutdown(); static const uint256 zeroid; static uint256 ignoretxid; From edfaea0c64be6a08c01a89609f199e37e7214690 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Apr 2019 02:45:06 -1100 Subject: [PATCH 56/59] Revert to exit --- src/cryptoconditions/src/secp256k1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index aa82376a3..7cb557fb0 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -68,7 +68,7 @@ void lockSign() { } if (!secp256k1_context_randomize(ec_ctx_sign, ent)) { fprintf(stderr, "Could not randomize secp256k1 context\n"); - StartShutdown(); + exit(-1); } } From f7e94b113e97df29a67cea5e965e5d4cb93c8226 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 14 Apr 2019 18:29:28 +0200 Subject: [PATCH 57/59] init.cpp : Help message for -whitelistaddress= Few days ago, on discord, blackjok3r said that he hopes that somebody will add a help message for -whitelistaddress= --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index 042d1d9fd..89390b5ed 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -399,6 +399,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-spentindex", strprintf(_("Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u)"), DEFAULT_SPENTINDEX)); strUsage += HelpMessageGroup(_("Connection options:")); strUsage += HelpMessageOpt("-addnode=", _("Add a node to connect to and attempt to keep the connection open")); + strUsage += HelpMessageOpt("-whitelistaddress=", _("Enable the wallet filter for notary nodes and add one Raddress to the whitelist of the wallet filter. If -whitelistaddress= is used, then the wallet filter is automatically activated. Several Raddresses can be defined using several -whitelistaddress= (similar to -addnode). The wallet filter will filter the utxo to only ones coming from my own Raddress (derived from pubkey) and each Raddress defined using -whitelistaddress= this option is mostly for Notary Nodes).")); strUsage += HelpMessageOpt("-banscore=", strprintf(_("Threshold for disconnecting misbehaving peers (default: %u)"), 100)); strUsage += HelpMessageOpt("-bantime=", strprintf(_("Number of seconds to keep misbehaving peers from reconnecting (default: %u)"), 86400)); strUsage += HelpMessageOpt("-bind=", _("Bind to given address and always listen on it. Use [host]:port notation for IPv6")); From 35ad4a6bc329541a7539316145c4db25bf900af7 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 14 Apr 2019 19:24:29 +0200 Subject: [PATCH 58/59] init.cpp : move help message -whitelistaddress= Move the help message of -whitelistaddress= to the section related to "Wallet options:" --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 89390b5ed..4003f9ced 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -399,7 +399,6 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-spentindex", strprintf(_("Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u)"), DEFAULT_SPENTINDEX)); strUsage += HelpMessageGroup(_("Connection options:")); strUsage += HelpMessageOpt("-addnode=", _("Add a node to connect to and attempt to keep the connection open")); - strUsage += HelpMessageOpt("-whitelistaddress=", _("Enable the wallet filter for notary nodes and add one Raddress to the whitelist of the wallet filter. If -whitelistaddress= is used, then the wallet filter is automatically activated. Several Raddresses can be defined using several -whitelistaddress= (similar to -addnode). The wallet filter will filter the utxo to only ones coming from my own Raddress (derived from pubkey) and each Raddress defined using -whitelistaddress= this option is mostly for Notary Nodes).")); strUsage += HelpMessageOpt("-banscore=", strprintf(_("Threshold for disconnecting misbehaving peers (default: %u)"), 100)); strUsage += HelpMessageOpt("-bantime=", strprintf(_("Number of seconds to keep misbehaving peers from reconnecting (default: %u)"), 86400)); strUsage += HelpMessageOpt("-bind=", _("Bind to given address and always listen on it. Use [host]:port notation for IPv6")); @@ -452,6 +451,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-wallet=", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat")); strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), true)); strUsage += HelpMessageOpt("-walletnotify=", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)")); + strUsage += HelpMessageOpt("-whitelistaddress=", _("Enable the wallet filter for notary nodes and add one Raddress to the whitelist of the wallet filter. If -whitelistaddress= is used, then the wallet filter is automatically activated. Several Raddresses can be defined using several -whitelistaddress= (similar to -addnode). The wallet filter will filter the utxo to only ones coming from my own Raddress (derived from pubkey) and each Raddress defined using -whitelistaddress= this option is mostly for Notary Nodes).")); strUsage += HelpMessageOpt("-zapwallettxes=", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") + " " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)")); #endif From c9f395f241503c75205be8d91d80ee86d9c1ae05 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 15 Apr 2019 12:08:58 +0800 Subject: [PATCH 59/59] revert miner change. Causes crash when staking. --- src/miner.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 54b18195a..f131bc90e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -224,7 +224,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 CBlockIndex* pindexPrev = 0; { - LOCK2(cs_main,mempool.cs); + ENTER_CRITICAL_SECTION(cs_main); + ENTER_CRITICAL_SECTION(mempool.cs); pindexPrev = chainActive.LastTip(); const int nHeight = pindexPrev->GetHeight() + 1; const Consensus::Params &consensusParams = chainparams.GetConsensus(); @@ -563,10 +564,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x stake.%i\n", nBlockSize,blocktime,pblock->nBits,isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { - uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr; - CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight); LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); + uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr; + CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight); + if (ASSETCHAINS_LWMAPOS != 0) { uint32_t nBitsPOS; @@ -591,7 +593,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { sleep(1); if ( (rand() % 100) < 1 ) - fprintf(stderr, "%u seconds until elegible, waiting...\n", blocktime-((uint32_t)GetAdjustedTime()+57)); + fprintf(stderr, "%u seconds until elegible, waiting.\n", blocktime-((uint32_t)GetAdjustedTime()+57)); if ( chainActive.LastTip()->GetHeight() >= stakeHeight ) { fprintf(stderr, "Block Arrived, reset staking loop.\n"); @@ -601,8 +603,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 return(0); } } - ENTER_CRITICAL_SECTION(cs_main); - ENTER_CRITICAL_SECTION(mempool.cs); + if ( siglen > 0 ) { CAmount txfees; @@ -615,7 +616,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nFees += txfees; pblock->nTime = blocktime; //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); - } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); + } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } // Create coinbase tx @@ -687,6 +688,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) { fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } return 0; } @@ -708,6 +714,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( totalsats == 0 ) { fprintf(stderr, "Could not create notary payment, trying again.\n"); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } return(0); } fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats); @@ -778,6 +789,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 else { fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n"); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } return(0); } } @@ -792,6 +808,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"valid\n"); } } + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } //fprintf(stderr,"done new block\n"); return pblocktemplate.release(); }