From 129aa1345ade02decd228d96e2020eb5d8234864 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Apr 2018 23:57:39 +0300 Subject: [PATCH 01/58] Compensate for processblock --- src/main.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8d09ffcb6..f4a7eed43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1615,14 +1615,17 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos) return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString()); } // Check the header - komodo_block2pubkey33(pubkey33,(CBlock *)&block); - if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime))) + if ( 0 ) { - int32_t i; for (i=0; i<33; i++) - fprintf(stderr,"%02x",pubkey33[i]); - fprintf(stderr," warning unexpected diff at ht.%d\n",height); - - return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); + komodo_block2pubkey33(pubkey33,(CBlock *)&block); + if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime))) + { + int32_t i; for (i=0; i<33; i++) + fprintf(stderr,"%02x",pubkey33[i]); + fprintf(stderr," warning unexpected diff at ht.%d\n",height); + + return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); + } } return true; } From e6c99a7ab9834d2ba74ea2d0f681e595b3f26fe8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 23:06:56 +0300 Subject: [PATCH 02/58] Split out no previndex from invalid prevblock --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 03262b0fe..ca86aa5e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4001,14 +4001,17 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } // Get prev block index CBlockIndex* pindexPrev = NULL; - if (hash != chainparams.GetConsensus().hashGenesisBlock) { + if (hash != chainparams.GetConsensus().hashGenesisBlock) + { BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; - if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) + if (pindexPrev == 0 ) + return(false); + if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) From 8999ab66f1028847e3871cff7a0c1fdb6d37f1b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 23:18:52 +0300 Subject: [PATCH 03/58] Test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ca86aa5e9..16a04e654 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3759,7 +3759,10 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) + { + fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + } else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime < pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); From d6eb511b21965fbe5d0e742101d51a28b6684dd8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 00:08:08 +0300 Subject: [PATCH 04/58] -print --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 16a04e654..0913f2608 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1294,10 +1294,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa COutPoint outpoint = tx.vin[i].prevout; if (pool.mapNextTx.count(outpoint)) { - static uint32_t counter; + //static uint32_t counter; // Disable replacement feature for now //if ( counter++ < 100 ) - fprintf(stderr,"Disable replacement feature for now\n"); + //fprintf(stderr,"Disable replacement feature for now\n"); return false; } } From f307157143a2fea4ca6a048505e4f533db7425dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 11:07:39 +0300 Subject: [PATCH 05/58] Reduce prev block not found to return false from state.DoS error --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0913f2608..e634142ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3763,7 +3763,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); } - else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime < pindex->pprev->nTime ) + else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); @@ -4009,7 +4009,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); + fprintf(stderr,"AcceptBlockHeader prev block not found\n"); + return(false); + //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; if (pindexPrev == 0 ) From bbd0d75a7eb09bd83a2b5951bc7e4187c1ea816b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 12:54:38 +0300 Subject: [PATCH 06/58] prohibit same timestamps for staked blocks --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ca86aa5e9..ae9aa4367 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3760,7 +3760,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); - else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime < pindex->pprev->nTime ) + else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); From 3ac6a0a66d46e153d9f09d27ac9215537a2fa61e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 15:33:38 +0300 Subject: [PATCH 07/58] Debug --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5e3a04e9a..80983cfa8 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1581,7 +1581,7 @@ void komodo_args(char *argv0) addn = GetArg("-seednode",""); if ( strlen(addn.c_str()) > 0 ) ASSETCHAINS_SEED = 1; - strncpy(ASSETCHAINS_SYMBOL,name.c_str(),sizeof(ASSETCHAINS_SYMBOL)-1); + strncpy(ASSETCHAINS_SYMBOL,name.c_str(),64); if ( (baseid= komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 ) MAX_MONEY = komodo_maxallowed(baseid); else if ( ASSETCHAINS_REWARD == 0 ) @@ -1607,7 +1607,7 @@ void komodo_args(char *argv0) komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL); COINBASE_MATURITY = 1; - //fprintf(stderr,"ASSETCHAINS_PORT %s %u (%s)\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_USERPASS); + fprintf(stderr,"ASSETCHAINS_PORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); } //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); From 9edf27ec053597178bcf178624c9a296a754f34d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:05:56 +0300 Subject: [PATCH 08/58] +print --- src/deprecation.cpp | 2 +- src/komodo_utils.h | 3 ++- src/policy/fees.cpp | 2 +- src/pow.cpp | 2 +- src/qt/transactiondesc.cpp | 2 +- src/rpcmisc.cpp | 5 +++-- src/rpcserver.cpp | 2 +- src/txmempool.cpp | 2 +- src/util.h | 3 +++ 9 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/deprecation.cpp b/src/deprecation.cpp index 8898e049a..73ff8046d 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -11,7 +11,7 @@ #include "chainparams.h" static const std::string CLIENT_VERSION_STR = FormatVersion(CLIENT_VERSION); -extern char ASSETCHAINS_SYMBOL[]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; void EnforceNodeDeprecation(int nHeight, bool forceLogging) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 80983cfa8..e6dcd2889 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1663,7 +1663,8 @@ void komodo_args(char *argv0) } } BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); - //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT); } void komodo_nameset(char *symbol,char *dest,char *source) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 014b97cc3..e4ff99246 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -53,7 +53,7 @@ void TxConfirmStats::ClearCurrent(unsigned int nBlockHeight) unsigned int TxConfirmStats::FindBucketIndex(double val) { - extern char ASSETCHAINS_SYMBOL[]; + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; auto it = bucketMap.lower_bound(val); if ( it != bucketMap.end() ) { diff --git a/src/pow.cpp b/src/pow.cpp index 310e9721b..bd2410616 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -123,7 +123,7 @@ CBlockIndex *komodo_chainactive(int32_t height); void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height); extern int32_t KOMODO_CHOSEN_ONE; extern uint64_t ASSETCHAINS_STAKED; -extern char ASSETCHAINS_SYMBOL[]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; #define KOMODO_ELECTION_GAP 2000 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index d8a0a184b..170e45d59 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -264,7 +264,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco if (wtx.IsCoinBase()) { - extern char ASSETCHAINS_SYMBOL[]; + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; if ( ASSETCHAINS_SYMBOL[0] == 0 ) COINBASE_MATURITY = _COINBASE_MATURITY; quint32 numBlocksToMaturity = COINBASE_MATURITY + 1; diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index cab292571..39ca817e5 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -50,7 +50,7 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); uint32_t komodo_chainactive_timestamp(); int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE; -extern char ASSETCHAINS_SYMBOL[]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_PORT; @@ -155,9 +155,10 @@ UniValue getinfo(const UniValue& params, bool fHelp) } if ( ASSETCHAINS_CC != 0 ) obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC)); + obj.push_back(Pair("name", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - obj.push_back(Pair("name", ASSETCHAINS_SYMBOL)); + //obj.push_back(Pair("name", ASSETCHAINS_SYMBOL)); obj.push_back(Pair("port", ASSETCHAINS_PORT)); obj.push_back(Pair("magic", (int)ASSETCHAINS_MAGIC)); if ( ASSETCHAINS_SUPPLY != 0 ) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 55dcabbb5..d3e08a935 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -238,7 +238,7 @@ UniValue help(const UniValue& params, bool fHelp) return tableRPC.help(strCommand); } -extern char ASSETCHAINS_SYMBOL[]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; UniValue stop(const UniValue& params, bool fHelp) { diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 164d5bb47..d14de08b9 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -315,7 +315,7 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list& rem void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags) { // Remove transactions spending a coinbase which are now immature - extern char ASSETCHAINS_SYMBOL[]; + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; if ( ASSETCHAINS_SYMBOL[0] == 0 ) COINBASE_MATURITY = _COINBASE_MATURITY; // Remove transactions spending a coinbase which are now immature and no-longer-final transactions diff --git a/src/util.h b/src/util.h index faf741409..a9f5ba1f8 100644 --- a/src/util.h +++ b/src/util.h @@ -257,4 +257,7 @@ template void TraceThread(const char* name, Callable func) } } +#define KOMODO_ASSETCHAIN_MAXLEN 65 + + #endif // BITCOIN_UTIL_H From 3a19bc18f53eedadf9eacb084afa48c1927039cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:14:19 +0300 Subject: [PATCH 09/58] Test --- src/komodo_utils.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e6dcd2889..2ba2c92e1 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1503,7 +1503,7 @@ char *argv0names[] = void komodo_args(char *argv0) { extern int64_t MAX_MONEY; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; int32_t i,baseid,len,n,extralen = 0; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); @@ -1605,7 +1605,8 @@ void komodo_args(char *argv0) int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); - komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL); + if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) + ASSETCHAINS_PORT = port; COINBASE_MATURITY = 1; fprintf(stderr,"ASSETCHAINS_PORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); } @@ -1662,9 +1663,11 @@ void komodo_args(char *argv0) break; } } - BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + BITCOIND_PORT = GetArg("-rpcport", ASSETCHAINS_PORT); fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT); + } else BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); } void komodo_nameset(char *symbol,char *dest,char *source) From 5cf29e5bfd77215986e078697d8383568612d3b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:16:14 +0300 Subject: [PATCH 10/58] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2ba2c92e1..3d895fef3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1280,7 +1280,7 @@ uint16_t komodo_userpass(char *username,char *password,FILE *fp) else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) { port = atoi(parse_conf_line(str,(char *)"rpcport")); - //printf("rpcport.%u in file\n",port); + printf("rpcport.%u in file\n",port); } } if ( rpcuser != 0 && rpcpassword != 0 ) From 4735f5b2016c0d1b6ad0fed9663a070b7680a4aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:16:27 +0300 Subject: [PATCH 11/58] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 3d895fef3..62df64f1e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1280,7 +1280,7 @@ uint16_t komodo_userpass(char *username,char *password,FILE *fp) else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) { port = atoi(parse_conf_line(str,(char *)"rpcport")); - printf("rpcport.%u in file\n",port); + fprintf(stderr,"rpcport.%u in file\n",port); } } if ( rpcuser != 0 && rpcpassword != 0 ) From 9c117b3df7e2a169765f220a8d6f37b4a8124cd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:19:51 +0300 Subject: [PATCH 12/58] Test --- src/komodo_utils.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 62df64f1e..8219f96fc 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1280,7 +1280,7 @@ uint16_t komodo_userpass(char *username,char *password,FILE *fp) else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) { port = atoi(parse_conf_line(str,(char *)"rpcport")); - fprintf(stderr,"rpcport.%u in file\n",port); + //fprintf(stderr,"rpcport.%u in file\n",port); } } if ( rpcuser != 0 && rpcpassword != 0 ) @@ -1288,7 +1288,7 @@ uint16_t komodo_userpass(char *username,char *password,FILE *fp) strcpy(username,rpcuser); strcpy(password,rpcpassword); } - //printf("rpcuser.(%s) rpcpassword.(%s) KMDUSERPASS.(%s) %u\n",rpcuser,rpcpassword,KMDUSERPASS,port); + printf("rpcuser.(%s) rpcpassword.(%s) KMDUSERPASS.(%s) %u\n",rpcuser,rpcpassword,KMDUSERPASS,port); if ( rpcuser != 0 ) free(rpcuser); if ( rpcpassword != 0 ) @@ -1606,7 +1606,10 @@ void komodo_args(char *argv0) extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) + { ASSETCHAINS_PORT = port; + fprintf(stderr,"komodo_userpass returns %u %u\n",port,ASSETCHAINS_PORT); + } COINBASE_MATURITY = 1; fprintf(stderr,"ASSETCHAINS_PORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); } From 34775d996cb13adbeee3467a08e7c3724de802b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:36:00 +0300 Subject: [PATCH 13/58] Test --- src/komodo_utils.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8219f96fc..7db807ac3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1263,7 +1263,7 @@ void iguana_initQ(queue_t *Q,char *name) free(item); } -uint16_t komodo_userpass(char *username,char *password,FILE *fp) +uint16_t _komodo_userpass(char *username,char *password,FILE *fp) { char *rpcuser,*rpcpassword,*str,line[8192]; uint16_t port = 0; rpcuser = rpcpassword = 0; @@ -1373,7 +1373,7 @@ void komodo_configfile(char *symbol,uint16_t port) } else { - komodo_userpass(myusername,mypassword,fp); + _komodo_userpass(myusername,mypassword,fp); mapArgs["-rpcpassword"] = mypassword; mapArgs["-rpcusername"] = myusername; //fprintf(stderr,"myusername.(%s)\n",myusername); @@ -1396,7 +1396,7 @@ void komodo_configfile(char *symbol,uint16_t port) #endif if ( (fp= fopen(fname,"rb")) != 0 ) { - if ( (kmdport= komodo_userpass(username,password,fp)) != 0 ) + if ( (kmdport= _komodo_userpass(username,password,fp)) != 0 ) KMD_PORT = kmdport; sprintf(KMDUSERPASS,"%s:%s",username,password); fclose(fp); @@ -1420,12 +1420,11 @@ uint16_t komodo_userpass(char *userpass,char *symbol) komodo_statefname(fname,symbol,confname); if ( (fp= fopen(fname,"rb")) != 0 ) { - port = komodo_userpass(username,password,fp); + port = _komodo_userpass(username,password,fp); sprintf(userpass,"%s:%s",username,password); if ( strcmp(symbol,ASSETCHAINS_SYMBOL) == 0 ) strcpy(ASSETCHAINS_USERPASS,userpass); fclose(fp); - return((int32_t)strlen(userpass)); } return(port); } From 59490d6f232caf74aae98fc4cbbe70177641f2f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:39:33 +0300 Subject: [PATCH 14/58] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7db807ac3..b7e1aca6e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1656,7 +1656,7 @@ void komodo_args(char *argv0) #endif if ( (fp= fopen(fname,"rb")) != 0 ) { - komodo_userpass(username,password,fp); + _komodo_userpass(username,password,fp); sprintf(iter == 0 ? KMDUSERPASS : BTCUSERPASS,"%s:%s",username,password); fclose(fp); //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); From 67899f2e2c0071b1c2ee9fbbacab3d12e1ae5f1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 16:44:35 +0300 Subject: [PATCH 15/58] -prints --- src/komodo_utils.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index b7e1aca6e..7ed7db9f6 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1288,7 +1288,7 @@ uint16_t _komodo_userpass(char *username,char *password,FILE *fp) strcpy(username,rpcuser); strcpy(password,rpcpassword); } - printf("rpcuser.(%s) rpcpassword.(%s) KMDUSERPASS.(%s) %u\n",rpcuser,rpcpassword,KMDUSERPASS,port); + //printf("rpcuser.(%s) rpcpassword.(%s) KMDUSERPASS.(%s) %u\n",rpcuser,rpcpassword,KMDUSERPASS,port); if ( rpcuser != 0 ) free(rpcuser); if ( rpcpassword != 0 ) @@ -1605,12 +1605,9 @@ void komodo_args(char *argv0) extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) - { ASSETCHAINS_PORT = port; - fprintf(stderr,"komodo_userpass returns %u %u\n",port,ASSETCHAINS_PORT); - } COINBASE_MATURITY = 1; - fprintf(stderr,"ASSETCHAINS_PORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); + //fprintf(stderr,"ASSETCHAINS_PORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); } //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); @@ -1667,8 +1664,8 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - BITCOIND_PORT = GetArg("-rpcport", ASSETCHAINS_PORT); - fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT); + BITCOIND_PORT = GetArg("-rpcport", ASSETCHAINS_PORT+1); + //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT); } else BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); } From 05c2ba6371243d82eda7050672299c1e808cc908 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 17:10:35 +0300 Subject: [PATCH 16/58] split out asset chain p2p port from roc port --- src/bitcoin-cli.cpp | 2 +- src/chainparams.cpp | 12 +++++++----- src/komodo_bitcoind.h | 2 +- src/komodo_globals.h | 4 ++-- src/komodo_utils.h | 25 ++++++++++++++----------- src/rpcmisc.cpp | 5 +++-- src/util.cpp | 5 ++--- src/wallet-utility.cpp | 4 ++-- src/zcash/CreateJoinSplit.cpp | 2 +- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 178f0baed..bf189e483 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -202,7 +202,7 @@ UniValue CallRPC(const string& strMethod, const UniValue& params) { std::string host = GetArg("-rpcconnect", "127.0.0.1"); int port = GetArg("-rpcport", BaseParams().RPCPort()); - BITCOIND_PORT = port; + BITCOIND_RPCPORT = port; // Obtain event base raii_event_base base = obtain_event_base(); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 49c4a2244..df258d782 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -79,7 +79,7 @@ void *chainparams_commandline(void *ptr); #include "komodo_defs.h" extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern uint16_t ASSETCHAINS_PORT; +extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAIN_INIT; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_SUPPLY; @@ -209,7 +209,7 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat void *chainparams_commandline(void *ptr) { CChainParams::CCheckpointData checkpointData; - while ( ASSETCHAINS_PORT == 0 ) + while ( ASSETCHAINS_P2PPORT == 0 ) { #ifdef _WIN32 boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); @@ -217,15 +217,17 @@ void *chainparams_commandline(void *ptr) sleep(1); #endif } - //fprintf(stderr,">>>>>>>> port.%u\n",ASSETCHAINS_PORT); + //fprintf(stderr,">>>>>>>> port.%u\n",ASSETCHAINS_P2PPORT); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - mainParams.SetDefaultPort(ASSETCHAINS_PORT); + mainParams.SetDefaultPort(ASSETCHAINS_P2PPORT); + if ( ASSETCHAINS_RPCPORT == 0 ) + ASSETCHAINS_RPCPORT = ASSETCHAINS_P2PPORT + 1; mainParams.pchMessageStart[0] = ASSETCHAINS_MAGIC & 0xff; mainParams.pchMessageStart[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; mainParams.pchMessageStart[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; mainParams.pchMessageStart[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; - fprintf(stderr,">>>>>>>>>> %s: port.%u/%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_PORT+1,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY); + fprintf(stderr,">>>>>>>>>> %s: p2p.%u rpc.%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY); checkpointData = //(Checkpoints::CCheckpointData) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bdc5bdecc..b9680f9fd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -504,7 +504,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32]; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); - if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,BITCOIND_PORT)) != 0 ) + if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,BITCOIND_RPCPORT)) != 0 ) { if ( (result= cJSON_Parse(jsonstr)) != 0 ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index ca2145e0f..8472ddb8f 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -51,13 +51,13 @@ std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; -uint16_t ASSETCHAINS_PORT; +uint16_t ASSETCHAINS_P2PPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_PORT = 7771; +char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7ed7db9f6..9d455ce08 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1333,7 +1333,7 @@ void komodo_statefname(char *fname,char *symbol,char *str) //printf("test.(%s) -> [%s] statename.(%s) %s\n",test,ASSETCHAINS_SYMBOL,symbol,fname); } -void komodo_configfile(char *symbol,uint16_t port) +void komodo_configfile(char *symbol,uint16_t rpcport) { static char myusername[512],mypassword[8192]; FILE *fp; uint16_t kmdport; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; @@ -1354,7 +1354,7 @@ void komodo_configfile(char *symbol,uint16_t port) sprintf(&password[i*2],"%02x",buf2[i]); password[i*2] = 0; sprintf(buf,"%s.conf",symbol); - BITCOIND_PORT = port; + BITCOIND_RPCPORT = port; #ifdef _WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); #else @@ -1588,7 +1588,7 @@ void komodo_args(char *argv0) else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { fprintf(stderr,"waiting for datadir\n"); @@ -1603,12 +1603,14 @@ void komodo_args(char *argv0) { int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; - komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) - ASSETCHAINS_PORT = port; + ASSETCHAINS_RPCPORT = port; + else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); COINBASE_MATURITY = 1; - //fprintf(stderr,"ASSETCHAINS_PORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); + //fprintf(stderr,"ASSETCHAINS_RPCPORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_RPCPORT); } + if ( ASSETCHAINS_RPCPORT == 0 ) + ASSETCHAINS_RPCPORT = ASSETCHAINS_P2PPORT + 1; //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); iguana_rwnum(1,magic,sizeof(ASSETCHAINS_MAGIC),(void *)&ASSETCHAINS_MAGIC); @@ -1619,7 +1621,7 @@ void komodo_args(char *argv0) sprintf(fname,"gen%s",ASSETCHAINS_SYMBOL); if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),name.c_str(),name.c_str(),magicstr,ASSETCHAINS_PORT,ASSETCHAINS_PORT+1,"78.47.196.146"); + fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),name.c_str(),name.c_str(),magicstr,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,"78.47.196.146"); fclose(fp); //printf("created (%s)\n",fname); } else printf("error creating (%s)\n",fname); @@ -1628,7 +1630,8 @@ void komodo_args(char *argv0) else { char fname[512],username[512],password[4096]; int32_t iter; FILE *fp; - ASSETCHAINS_PORT = 8777; + ASSETCHAINS_P2PPORT = 7770; + ASSETCHAINS_RPCPORT = 7771; for (iter=0; iter<2; iter++) { strcpy(fname,GetDataDir().string().c_str()); @@ -1664,9 +1667,9 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - BITCOIND_PORT = GetArg("-rpcport", ASSETCHAINS_PORT+1); - //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT); - } else BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); + BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); + //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_RPCPORT); + } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } void komodo_nameset(char *symbol,char *dest,char *source) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 39ca817e5..5b117d03f 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,7 +53,7 @@ extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" -extern uint16_t ASSETCHAINS_PORT; +extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY; @@ -159,7 +159,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) if ( ASSETCHAINS_SYMBOL[0] != 0 ) { //obj.push_back(Pair("name", ASSETCHAINS_SYMBOL)); - obj.push_back(Pair("port", ASSETCHAINS_PORT)); + obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT)); + obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT)); obj.push_back(Pair("magic", (int)ASSETCHAINS_MAGIC)); if ( ASSETCHAINS_SUPPLY != 0 ) obj.push_back(Pair("premine", ASSETCHAINS_SUPPLY)); diff --git a/src/util.cpp b/src/util.cpp index dd9b709a2..c9d831a18 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -644,9 +644,8 @@ void ReadConfigFile(map& mapSettingsRet, } // If datadir is changed in .conf file: ClearDatadirCache(); - extern uint16_t BITCOIND_PORT; - BITCOIND_PORT = GetArg("-rpcport",BaseParams().RPCPort()); - //fprintf(stderr,"from conf file %s RPC %u, used to be %u\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT,BITCOIND_PORT); + extern uint16_t BITCOIND_RPCPORT; + BITCOIND_RPCPORT = GetArg("-rpcport",BaseParams().RPCPort()); } #ifndef _WIN32 diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index 04b9edf45..a0adc8684 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -12,8 +12,8 @@ char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int64_t MAX_MONEY = 200000000 * 100000000LL; uint64_t ASSETCHAINS_SUPPLY; -uint16_t BITCOIND_PORT = 7771; -uint16_t ASSETCHAINS_PORT; +uint16_t BITCOIND_RPCPORT = 7771; +uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; uint32_t ASSETCHAINS_MAGIC = 2387029918; diff --git a/src/zcash/CreateJoinSplit.cpp b/src/zcash/CreateJoinSplit.cpp index 166b4fac7..94b0241b3 100644 --- a/src/zcash/CreateJoinSplit.cpp +++ b/src/zcash/CreateJoinSplit.cpp @@ -10,7 +10,7 @@ #include "komodo_defs.h" char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int64_t MAX_MONEY = 200000000 * 100000000LL; -uint16_t BITCOIND_PORT = 7771; +uint16_t BITCOIND_RPCPORT = 7771; uint32_t ASSETCHAINS_CC = 0; using namespace libzcash; From 307d443cca478e57cb9a45651d716063569110a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 17:11:35 +0300 Subject: [PATCH 17/58] Test --- src/komodo_jumblr.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index e033306b4..f36bb441a 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -83,7 +83,7 @@ char *jumblr_importaddress(char *address) { char params[1024]; sprintf(params,"[\"%s\", \"%s\", false]",address,address); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"importaddress",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"importaddress",params,BITCOIND_RPCPORT)); } char *jumblr_validateaddress(char *addr) @@ -91,7 +91,7 @@ char *jumblr_validateaddress(char *addr) char params[1024]; sprintf(params,"[\"%s\"]",addr); printf("validateaddress.%s\n",params); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"validateaddress",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"validateaddress",params,BITCOIND_RPCPORT)); } int32_t Jumblr_secretaddrfind(char *searchaddr) @@ -222,28 +222,28 @@ char *jumblr_zgetnewaddress() { char params[1024]; sprintf(params,"[]"); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getnewaddress",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getnewaddress",params,BITCOIND_RPCPORT)); } char *jumblr_zlistoperationids() { char params[1024]; sprintf(params,"[]"); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_listoperationids",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_listoperationids",params,BITCOIND_RPCPORT)); } char *jumblr_zgetoperationresult(char *opid) { char params[1024]; sprintf(params,"[[\"%s\"]]",opid); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getoperationresult",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getoperationresult",params,BITCOIND_RPCPORT)); } char *jumblr_zgetoperationstatus(char *opid) { char params[1024]; sprintf(params,"[[\"%s\"]]",opid); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getoperationstatus",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getoperationstatus",params,BITCOIND_RPCPORT)); } char *jumblr_sendt_to_z(char *taddr,char *zaddr,double amount) @@ -253,7 +253,7 @@ char *jumblr_sendt_to_z(char *taddr,char *zaddr,double amount) return(clonestr((char *)"{\"error\":\"illegal address in t to z\"}")); sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",taddr,zaddr,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE); printf("t -> z: %s\n",params); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_sendmany",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_sendmany",params,BITCOIND_RPCPORT)); } char *jumblr_sendz_to_z(char *zaddrS,char *zaddrD,double amount) @@ -264,7 +264,7 @@ char *jumblr_sendz_to_z(char *zaddrS,char *zaddrD,double amount) //sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddrS,zaddrD,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE); sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddrS,zaddrD,amount-fee-JUMBLR_TXFEE,JUMBLR_TXFEE); printf("z -> z: %s\n",params); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_sendmany",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_sendmany",params,BITCOIND_RPCPORT)); } char *jumblr_sendz_to_t(char *zaddr,char *taddr,double amount) @@ -274,56 +274,56 @@ char *jumblr_sendz_to_t(char *zaddr,char *taddr,double amount) return(clonestr((char *)"{\"error\":\"illegal address in z to t\"}")); sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddr,taddr,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE); printf("z -> t: %s\n",params); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_sendmany",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_sendmany",params,BITCOIND_RPCPORT)); } char *jumblr_zlistaddresses() { char params[1024]; sprintf(params,"[]"); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_listaddresses",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_listaddresses",params,BITCOIND_RPCPORT)); } char *jumblr_zlistreceivedbyaddress(char *addr) { char params[1024]; sprintf(params,"[\"%s\", 1]",addr); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_listreceivedbyaddress",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_listreceivedbyaddress",params,BITCOIND_RPCPORT)); } char *jumblr_getreceivedbyaddress(char *addr) { char params[1024]; sprintf(params,"[\"%s\", 1]",addr); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"getreceivedbyaddress",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"getreceivedbyaddress",params,BITCOIND_RPCPORT)); } char *jumblr_importprivkey(char *wifstr) { char params[1024]; sprintf(params,"[\"%s\", \"\", false]",wifstr); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"importprivkey",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"importprivkey",params,BITCOIND_RPCPORT)); } char *jumblr_zgetbalance(char *addr) { char params[1024]; sprintf(params,"[\"%s\", 1]",addr); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getbalance",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"z_getbalance",params,BITCOIND_RPCPORT)); } char *jumblr_listunspent(char *coinaddr) { char params[1024]; sprintf(params,"[1, 99999999, [\"%s\"]]",coinaddr); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"listunspent",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"listunspent",params,BITCOIND_RPCPORT)); } char *jumblr_gettransaction(char *txidstr) { char params[1024]; sprintf(params,"[\"%s\", 1]",txidstr); - return(jumblr_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,BITCOIND_PORT)); + return(jumblr_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,BITCOIND_RPCPORT)); } int32_t jumblr_numvins(bits256 txid) From 346d96b956f9d9b4a8ae42a76ac313acf46a0010 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 17:13:18 +0300 Subject: [PATCH 18/58] Test --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 8472ddb8f..f9e0f6688 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -51,7 +51,7 @@ std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; -uint16_t ASSETCHAINS_P2PPORT; +uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9d455ce08..74eefd417 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1354,7 +1354,7 @@ void komodo_configfile(char *symbol,uint16_t rpcport) sprintf(&password[i*2],"%02x",buf2[i]); password[i*2] = 0; sprintf(buf,"%s.conf",symbol); - BITCOIND_RPCPORT = port; + BITCOIND_RPCPORT = rpcport; #ifdef _WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); #else @@ -1365,7 +1365,7 @@ void komodo_configfile(char *symbol,uint16_t rpcport) #ifndef FROM_CLI if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=256\nrpcallowip=127.0.0.1\n",crc,password,port); + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=256\nrpcallowip=127.0.0.1\n",crc,password,rpcport); fclose(fp); printf("Created (%s)\n",fname); } else printf("Couldnt create (%s)\n",fname); From 3ede6dd335b02c75e4d245ada14db9bc435392b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Apr 2018 17:14:27 +0300 Subject: [PATCH 19/58] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 74eefd417..24be6a0dc 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1337,7 +1337,7 @@ void komodo_configfile(char *symbol,uint16_t rpcport) { static char myusername[512],mypassword[8192]; FILE *fp; uint16_t kmdport; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; - if ( symbol != 0 && port != 0 ) + if ( symbol != 0 && rpcport != 0 ) { r = (uint32_t)time(NULL); r2 = OS_milliseconds(); From f8a07170af77660b3d598ede0442d43f8d88623c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 10:28:16 +0300 Subject: [PATCH 20/58] Revert half of windows headers filter --- src/main.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e634142ba..9e954324c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3855,7 +3855,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(tx,height == 0 ? komodo_block2height((CBlock *)&block) : height,block.nTime,1) < 0 ) + if ( komodo_validate_interest(tx,height == 0 ? komodo_block2height((CBlock *)&block) : height,block.nTime,0) < 0 ) return error("CheckBlock: komodo_validate_interest failed"); if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock: CheckTransaction failed"); @@ -4009,7 +4009,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader prev block not found\n"); + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found %p\n",block.hashPrevBlock.ToString().c_str,pindex); + // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } @@ -4137,6 +4138,15 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) miSelf->second = AddToBlockIndex(*pblock); //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); } + if ( hash != chainparams.GetConsensus().hashGenesisBlock ) + { + miSelf = mapBlockIndex.find(pblock->hashPrevBlock); + if ( miSelf == mapBlockIndex.end() ) + { + miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); + fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } + } } } @@ -5845,7 +5855,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, vector vHeaders; int nLimit = MAX_HEADERS_RESULTS; LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id); - if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) ) + //if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) )// no need to ever suppress this { pfrom->lasthdrsreq = (int32_t)(pindex ? pindex->nHeight : -1); for (; pindex; pindex = chainActive.Next(pindex)) @@ -5856,12 +5866,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } pfrom->PushMessage("headers", vHeaders); } - else if ( NOTARY_PUBKEY33[0] != 0 ) + /*else if ( NOTARY_PUBKEY33[0] != 0 ) { static uint32_t counter; if ( counter++ < 3 ) fprintf(stderr,"you can ignore redundant getheaders from peer.%d %d prev.%d\n",(int32_t)pfrom->id,(int32_t)(pindex ? pindex->nHeight : -1),pfrom->lasthdrsreq); - } + }*/ } From 882c4cfeef9d02a9ecb6953994b83447057b7662 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 10:38:44 +0300 Subject: [PATCH 21/58] Syntax --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9e954324c..67a67310d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4138,7 +4138,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) miSelf->second = AddToBlockIndex(*pblock); //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); } - if ( hash != chainparams.GetConsensus().hashGenesisBlock ) + /*if ( hash != chainparams.GetConsensus().hashGenesisBlock ) { miSelf = mapBlockIndex.find(pblock->hashPrevBlock); if ( miSelf == mapBlockIndex.end() ) @@ -4146,7 +4146,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); } - } + }*/ } } From 1e57ae08cac47f315c4616c0645e58e22b0124da Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 10:40:06 +0300 Subject: [PATCH 22/58] Fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 67a67310d..a436fefd2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4009,7 +4009,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found %p\n",block.hashPrevBlock.ToString().c_str,pindex); + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str); // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); From 7cae836aa82d9c316cf61fb9c9e10c4cac91c918 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 10:42:14 +0300 Subject: [PATCH 23/58] Fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a436fefd2..829d443ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4009,7 +4009,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str); + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); From 3099c9ca230f546a0d47ac240a9e792f8b135d3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 11:17:36 +0300 Subject: [PATCH 24/58] Tweak sync constants --- src/main.cpp | 2 +- src/main.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 829d443ef..03e05dbad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4064,7 +4064,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, // blocks which are too close in height to the tip. Apply this test // regardless of whether pruning is enabled; it should generally be safe to // not process unrequested blocks. - bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); + bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW));//MIN_BLOCKS_TO_KEEP)); // TODO: deal better with return value and error conditions for duplicate // and unrequested blocks. diff --git a/src/main.h b/src/main.h index f52fa222d..221077acb 100644 --- a/src/main.h +++ b/src/main.h @@ -94,7 +94,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 160; * Larger windows tolerate larger download speed differences between peer, but increase the potential * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning * harder). We'll probably want to make this a per-peer adaptive value at some point. */ -static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024; +static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024*16; /** Time to wait (in seconds) between writing blocks/block index to disk. */ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60; /** Time to wait (in seconds) between flushing chainstate to disk. */ From 71f2c6969cc6eed6dc35d06d569a2d0792fc7250 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 11:23:05 +0300 Subject: [PATCH 25/58] Revert --- src/main.cpp | 2 +- src/main.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 03e05dbad..829d443ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4064,7 +4064,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, // blocks which are too close in height to the tip. Apply this test // regardless of whether pruning is enabled; it should generally be safe to // not process unrequested blocks. - bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW));//MIN_BLOCKS_TO_KEEP)); + bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); // TODO: deal better with return value and error conditions for duplicate // and unrequested blocks. diff --git a/src/main.h b/src/main.h index 221077acb..f52fa222d 100644 --- a/src/main.h +++ b/src/main.h @@ -94,7 +94,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 160; * Larger windows tolerate larger download speed differences between peer, but increase the potential * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning * harder). We'll probably want to make this a per-peer adaptive value at some point. */ -static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024*16; +static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024; /** Time to wait (in seconds) between writing blocks/block index to disk. */ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60; /** Time to wait (in seconds) between flushing chainstate to disk. */ From 161f617de49123ef2046fd45b869c3102dd58a99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 19:58:16 +0300 Subject: [PATCH 26/58] komodo_requestedhash request --- src/main.cpp | 21 +++++++++++++++++++-- src/miner.cpp | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 829d443ef..1afb622a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3977,8 +3977,11 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return true; } +static uint256 komodo_requestedhash; + bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { + static uint256 zero; const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); // Check for duplicate @@ -4009,7 +4012,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found req %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_cstr()); + if ( komodo_requestedhash == zero ) + komodo_requestedhash = block.hashPrevBlock; // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); @@ -4034,6 +4039,11 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (ppindex) *ppindex = pindex; + if ( pindex != 0 && hash == komodo_requestedhash ) + { + fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); + memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + } return true; } @@ -6671,6 +6681,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // // Message: getdata (blocks) // + static uint256 zero; vector vGetData; if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { vector vToDownload; @@ -6689,7 +6700,13 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } } - + if ( komodo_requestedhash != zero ) + { + fprintf(stderr,"request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); + vGetData.push_back(CInv(MSG_BLOCK, komodo_requestedhash)); + MarkBlockAsInFlight(pto->GetId(), komodo_requestedhash, consensusParams, pindex); + } + // // Message: getdata (non-blocks) // diff --git a/src/miner.cpp b/src/miner.cpp index a8569980d..fed17a652 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -212,7 +212,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) continue; - if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) { //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); continue; From e450b1ceaf2c49bfc7c04dbb6e93d50ab90e8465 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:02:40 +0300 Subject: [PATCH 27/58] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1afb622a6..456ed9b22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4012,7 +4012,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found req %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_cstr()); + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found req %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); if ( komodo_requestedhash == zero ) komodo_requestedhash = block.hashPrevBlock; // request block.hashPrevBlock @@ -6700,7 +6700,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } } - if ( komodo_requestedhash != zero ) + if ( komodo_requestedhash != zero && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) { fprintf(stderr,"request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); vGetData.push_back(CInv(MSG_BLOCK, komodo_requestedhash)); From 99dd19d43e2490e9a325c458fa0ede8ed3d472ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:04:54 +0300 Subject: [PATCH 28/58] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 456ed9b22..8681bf44a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6700,8 +6700,10 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } } + CBlockIndex *pindex; if ( komodo_requestedhash != zero && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) { + LogPrint("net","request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); fprintf(stderr,"request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); vGetData.push_back(CInv(MSG_BLOCK, komodo_requestedhash)); MarkBlockAsInFlight(pto->GetId(), komodo_requestedhash, consensusParams, pindex); From b80fef6f77c05b7028079e13f6e566b70ac151a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:18:46 +0300 Subject: [PATCH 29/58] Test --- src/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8681bf44a..64e19f01d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3996,6 +3996,11 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + if ( pindex != 0 && hash == komodo_requestedhash ) + { + fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); + memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + } //if ( pindex == 0 ) // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; @@ -4044,6 +4049,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); } + else if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) + komodo_requestedhash = hash; return true; } From ecc342b6da7522744aa721dffb4baf78fe8822ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:25:32 +0300 Subject: [PATCH 30/58] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 64e19f01d..124e92e3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4173,7 +4173,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo bool checked; uint256 hash; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - //fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); +fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); if ( chainActive.Tip() != 0 ) komodo_currentheight_set(chainActive.Tip()->nHeight); checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); @@ -4207,7 +4207,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo CheckBlockIndex(); if (!ret) return error("%s: AcceptBlock FAILED", __func__); - //else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); + else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); } if (!ActivateBestChain(state, pblock)) From 367265ab29447d633d6ac42084257793828eeec9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:32:50 +0300 Subject: [PATCH 31/58] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 124e92e3c..245ca21e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,7 +3761,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); - return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); } else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { From 027cfdce1547cb5548f1d31513c73b5c097f94fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:49:28 +0300 Subject: [PATCH 32/58] Test --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 245ca21e0..c1cb61fdd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4017,7 +4017,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found req %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); if ( komodo_requestedhash == zero ) komodo_requestedhash = block.hashPrevBlock; // request block.hashPrevBlock @@ -4050,7 +4050,10 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); } else if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) + { + fprintf(stderr,"random komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); komodo_requestedhash = hash; + } return true; } @@ -6711,7 +6714,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if ( komodo_requestedhash != zero && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) { LogPrint("net","request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); - fprintf(stderr,"request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); + fprintf(stderr,"komodo_requestedhash request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); vGetData.push_back(CInv(MSG_BLOCK, komodo_requestedhash)); MarkBlockAsInFlight(pto->GetId(), komodo_requestedhash, consensusParams, pindex); } From d9cf73430644ff6728c4c8895f26cc8d5b910777 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 20:56:24 +0300 Subject: [PATCH 33/58] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c1cb61fdd..4eaf46eca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4049,7 +4049,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); } - else if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) + else //if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) { fprintf(stderr,"random komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); komodo_requestedhash = hash; From bddeaf5e44cc9661565f3cfcae14164599141596 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 21:09:47 +0300 Subject: [PATCH 34/58] Detect missing prevblock and request it. On some systems, the chain can get into a state where it has the hash for a prevblock, but not the prevblock itself. This condition was treated as a horrible error, but since it can happen, it is better to return a simple error and let the block get processed when it comes back again. --- src/main.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4eaf46eca..23d8d65c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3978,6 +3978,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn } static uint256 komodo_requestedhash; +static int32_t komodo_requestedcount; bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { @@ -4000,6 +4001,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc { fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + komodo_requestedcount = 0; } //if ( pindex == 0 ) // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); @@ -4019,7 +4021,10 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc { fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); if ( komodo_requestedhash == zero ) + { komodo_requestedhash = block.hashPrevBlock; + komodo_requestedcount = 0; + } // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); @@ -4048,12 +4053,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc { fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + komodo_requestedcount = 0; } - else //if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) + /*else //if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) { fprintf(stderr,"random komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); komodo_requestedhash = hash; - } + }*/ return true; } @@ -4176,7 +4182,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo bool checked; uint256 hash; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); -fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); +//fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); if ( chainActive.Tip() != 0 ) komodo_currentheight_set(chainActive.Tip()->nHeight); checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); @@ -4210,7 +4216,7 @@ fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); CheckBlockIndex(); if (!ret) return error("%s: AcceptBlock FAILED", __func__); - else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); + //else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); } if (!ActivateBestChain(state, pblock)) @@ -6711,12 +6717,18 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } CBlockIndex *pindex; - if ( komodo_requestedhash != zero && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) + if ( komodo_requestedhash != zero && komodo_requestedcount < 16 && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) { - LogPrint("net","request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); - fprintf(stderr,"komodo_requestedhash request %s to nodeid.%d\n",komodo_requestedhash.ToString().c_str(),pto->GetId()); + LogPrint("net","komodo_requestedhash.%d request %s to nodeid.%d\n",komodo_requestedcount,komodo_requestedhash.ToString().c_str(),pto->GetId()); + fprintf(stderr,"komodo_requestedhash.%d request %s to nodeid.%d\n",komodo_requestedcount,komodo_requestedhash.ToString().c_str(),pto->GetId()); vGetData.push_back(CInv(MSG_BLOCK, komodo_requestedhash)); MarkBlockAsInFlight(pto->GetId(), komodo_requestedhash, consensusParams, pindex); + komodo_requestedcount++; + if ( komodo_requestedcount > 16 ) + { + memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + komodo_requestedcount = 0; + } } // From 37091e704e998ea252ff39f926a7cf306cb20357 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 21:33:18 +0300 Subject: [PATCH 35/58] 30 seconds margin for notary mining --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index fed17a652..02327522a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -463,7 +463,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) { pblock->nTime = pindexPrev->nTime + 60; - while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 ) + while ( pblock->GetBlockTime() > GetAdjustedTime() + 30 ) sleep(1); //fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60)); } From f65a34b970a4509a67e147d222c31cd51abdb2a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:32:35 +0300 Subject: [PATCH 36/58] Test --- src/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 23d8d65c4..acf898246 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4009,7 +4009,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { - //fprintf(stderr,"CheckBlockHeader failed\n"); + fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); return false; } // Get prev block index @@ -4025,26 +4025,33 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; } - // request block.hashPrevBlock return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; if (pindexPrev == 0 ) + { + fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); + if ( komodo_requestedhash == zero ) + { + komodo_requestedhash = block.hashPrevBlock; + komodo_requestedcount = 0; + } return(false); + } if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - //fprintf(stderr,"ContextualCheckBlockHeader failed\n"); + fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); return false; } if (pindex == NULL) { if ( (pindex= AddToBlockIndex(block)) == 0 ) { - //fprintf(stderr,"couldnt add to block index\n"); + fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n"); } } if (ppindex) From 5d9f111967b5d06beb44c03914f24fe8fc67aac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:52:16 +0300 Subject: [PATCH 37/58] Test --- src/main.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index acf898246..47f6e2485 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,9 +3761,19 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); - return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + if ( (tipindex= chainActive().Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) + { + fprintf(stderr,"it is the next block, let's wait a bit\n"); + while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) + sleep(1); + fprintf(stderr,"now its valid\n"); + } + else + { + return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + } } - else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) + if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); From 82b4714bee6f6211d9d5329fb13d91c4a8cf96c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:55:27 +0300 Subject: [PATCH 38/58] Test --- src/main.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 47f6e2485..6b15ea775 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3760,6 +3760,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { + CBlockIndex *tipindex; fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); if ( (tipindex= chainActive().Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { @@ -4072,11 +4073,6 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; } - /*else //if ( (rand() % 100) == 0 && komodo_requestedhash == zero ) - { - fprintf(stderr,"random komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); - komodo_requestedhash = hash; - }*/ return true; } From d1cd2af5f4a690f989dcd160a71f2d9da0604c4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:56:28 +0300 Subject: [PATCH 39/58] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6b15ea775..951558e52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3762,7 +3762,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl { CBlockIndex *tipindex; fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); - if ( (tipindex= chainActive().Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) + if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { fprintf(stderr,"it is the next block, let's wait a bit\n"); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) From 8d725ab46ff31e50d34dbc6714b833715ff68b06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 22:59:51 +0300 Subject: [PATCH 40/58] -komodo_requesthash --- src/main.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 951558e52..b2962565d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3988,8 +3988,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return true; } -static uint256 komodo_requestedhash; -static int32_t komodo_requestedcount; +//static uint256 komodo_requestedhash; +//static int32_t komodo_requestedcount; bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { @@ -4008,12 +4008,12 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - if ( pindex != 0 && hash == komodo_requestedhash ) + /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; - } + }*/ //if ( pindex == 0 ) // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; @@ -4030,24 +4030,24 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); - if ( komodo_requestedhash == zero ) + fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); + /*if ( komodo_requestedhash == zero ) { komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; - } + }*/ return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; if (pindexPrev == 0 ) { - fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s komodo_requestedhash %s\n",block.hashPrevBlock.ToString().c_str(),komodo_requestedhash.ToString().c_str()); - if ( komodo_requestedhash == zero ) + fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str()); + /*if ( komodo_requestedhash == zero ) { komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; - } + }*/ return(false); } if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) @@ -4067,12 +4067,12 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (ppindex) *ppindex = pindex; - if ( pindex != 0 && hash == komodo_requestedhash ) + /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; - } + }*/ return true; } @@ -6729,7 +6729,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } } - CBlockIndex *pindex; + /*CBlockIndex *pindex; if ( komodo_requestedhash != zero && komodo_requestedcount < 16 && (pindex= mapBlockIndex[komodo_requestedhash]) != 0 ) { LogPrint("net","komodo_requestedhash.%d request %s to nodeid.%d\n",komodo_requestedcount,komodo_requestedhash.ToString().c_str(),pto->GetId()); @@ -6742,7 +6742,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); komodo_requestedcount = 0; } - } + }*/ // // Message: getdata (non-blocks) From 43ef3068d139d449c198f7a8598288a1dd8bbc8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 23:47:48 +0300 Subject: [PATCH 41/58] 10 second window for notary mining --- src/main.cpp | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b2962565d..2ac1e416c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,10 +3761,10 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { CBlockIndex *tipindex; - fprintf(stderr,"future block %u vs time.%u + 60\n",(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); + fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { - fprintf(stderr,"it is the next block, let's wait a bit\n"); + fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) sleep(1); fprintf(stderr,"now its valid\n"); diff --git a/src/miner.cpp b/src/miner.cpp index 02327522a..d9da98f3c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -463,7 +463,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) { pblock->nTime = pindexPrev->nTime + 60; - while ( pblock->GetBlockTime() > GetAdjustedTime() + 30 ) + while ( pblock->GetBlockTime() > GetAdjustedTime() + 10 ) sleep(1); //fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60)); } From 2fea1c97239ac17f65346aa8790ef98685437580 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 00:00:45 +0300 Subject: [PATCH 42/58] -print --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2ac1e416c..87e14bbaa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3761,13 +3761,13 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { CBlockIndex *tipindex; - fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); + //fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { - fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); + //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) sleep(1); - fprintf(stderr,"now its valid\n"); + //fprintf(stderr,"now its valid\n"); } else { @@ -4020,7 +4020,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { - fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); + //fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); return false; } // Get prev block index @@ -4055,7 +4055,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); + //fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); return false; } if (pindex == NULL) From 9f6cb8f05e2514a3d075633e893b46352614ea67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 10:49:04 +0300 Subject: [PATCH 43/58] futureblock flag --- src/gtest/test_checkblock.cpp | 5 +++-- src/main.cpp | 29 +++++++++++++++++------------ src/main.h | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/gtest/test_checkblock.cpp b/src/gtest/test_checkblock.cpp index e098cfdae..284cff134 100644 --- a/src/gtest/test_checkblock.cpp +++ b/src/gtest/test_checkblock.cpp @@ -22,6 +22,7 @@ public: MOCK_CONST_METHOD0(GetRejectReason, std::string()); }; +int32_t futureblock; TEST(CheckBlock, VersionTooLow) { auto verifier = libzcash::ProofVerifier::Strict(); @@ -30,7 +31,7 @@ TEST(CheckBlock, VersionTooLow) { MockCValidationState state; EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "version-too-low", false)).Times(1); - EXPECT_FALSE(CheckBlock(0,0,block, state, verifier, false, false)); + EXPECT_FALSE(CheckBlock(&futureblock,0,0,block, state, verifier, false, false)); } @@ -230,4 +231,4 @@ TEST(ContextualCheckBlock, BlockOverwinterRulesRejectSproutTx) { // Revert to default UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 87e14bbaa..be5cbb5d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2583,9 +2583,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } auto verifier = libzcash::ProofVerifier::Strict(); auto disabledVerifier = libzcash::ProofVerifier::Disabled(); - + int32_t futureblock; // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in - if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) + if (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) { fprintf(stderr,"checkblock failure in connectblock\n"); return false; @@ -3740,7 +3740,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne return true; } -bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& blockhdr, CValidationState& state, bool fCheckPOW) +bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, const CBlockHeader& blockhdr, CValidationState& state, bool fCheckPOW) { // Check timestamp if ( 0 ) @@ -3758,6 +3758,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl fprintf(stderr," <- chainTip\n"); } } + *futureblockp = 0; if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { CBlockIndex *tipindex; @@ -3771,6 +3772,8 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } else { + if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600) + *futureblockp = 1; return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); } } @@ -3799,7 +3802,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime); int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height); -bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, +bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, libzcash::ProofVerifier& verifier, bool fCheckPOW, bool fCheckMerkleRoot) { @@ -3809,7 +3812,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. - if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW)) + if (!CheckBlockHeader(futureblockp,height,pindex,block,state,fCheckPOW)) { //fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); return false; @@ -4117,9 +4120,9 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, // See method docstring for why this is always disabled auto verifier = libzcash::ProofVerifier::Disabled(); - if ((!CheckBlock(pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) + if ((!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { - if (state.IsInvalid() && !state.CorruptionPossible()) { + if (futureblock == 0 && state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex); } @@ -4192,13 +4195,13 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks - bool checked; uint256 hash; + bool checked; uint256 hash; int32_t futureblock; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); //fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); if ( chainActive.Tip() != 0 ) komodo_currentheight_set(chainActive.Tip()->nHeight); - checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); + checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); { LOCK(cs_main); bool fRequested = MarkBlockAsReceived(hash); @@ -4208,7 +4211,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo checked = 0; fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0); } - if (!checked) + if (!checked && futureblock == 0) { if ( pfrom != 0 ) { @@ -4255,7 +4258,8 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex //fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); return false; } - if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) + int32_t futureblock; + if (!CheckBlock(&futureblock,indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { //fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; @@ -4665,7 +4669,8 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth if (!ReadBlockFromDisk(block, pindex,0)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity - if (nCheckLevel >= 1 && !CheckBlock(pindex->nHeight,pindex,block, state, verifier,0)) + int32_t futureblock; + if (nCheckLevel >= 1 && !CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) return error("VerifyDB(): *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 2: verify undo validity if (nCheckLevel >= 2 && pindex) { diff --git a/src/main.h b/src/main.h index f52fa222d..6c590ea01 100644 --- a/src/main.h +++ b/src/main.h @@ -797,7 +797,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin /** Context-independent validity checks */ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); -bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, +bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, libzcash::ProofVerifier& verifier, bool fCheckPOW = true, bool fCheckMerkleRoot = true); From e5301556873d046de78bb2a668594360bf1d9ef6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 10:53:04 +0300 Subject: [PATCH 44/58] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index be5cbb5d6..a2237d75d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4033,7 +4033,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); + //fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); /*if ( komodo_requestedhash == zero ) { komodo_requestedhash = block.hashPrevBlock; @@ -4119,6 +4119,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, } // See method docstring for why this is always disabled + int32_t futureblock; auto verifier = libzcash::ProofVerifier::Disabled(); if ((!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { From 2a5ffc0486d8f2e828a354d355127320468e8bc9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 11:02:09 +0300 Subject: [PATCH 45/58] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a2237d75d..7b9d0819e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3999,6 +3999,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc static uint256 zero; const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); + int32_t futureblock; // Check for duplicate uint256 hash = block.GetHash(); BlockMap::iterator miSelf = mapBlockIndex.find(hash); @@ -4021,7 +4022,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; } - if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) + if (!CheckBlockHeader(&futureblock,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { //fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); return false; From 531b92932aafd157195c3059c0ff0fd11fde5c29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 14:47:21 +0300 Subject: [PATCH 46/58] Allow future block to not trigger severe rejection --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 32 ++++++++++++++++---------------- src/main.h | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b9680f9fd..72136427c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1035,7 +1035,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - if ( tx.nLockTime != 1477258935 || dispflag != 0 ) + if ( tx.nLockTime != 1477258935 && dispflag != 0 ) { fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); } diff --git a/src/main.cpp b/src/main.cpp index 7b9d0819e..0952609c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3762,7 +3762,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { CBlockIndex *tipindex; - //fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); + fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); @@ -3994,12 +3994,12 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn //static uint256 komodo_requestedhash; //static int32_t komodo_requestedcount; -bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) +bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { static uint256 zero; const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); - int32_t futureblock; + // Check for duplicate uint256 hash = block.GetHash(); BlockMap::iterator miSelf = mapBlockIndex.find(hash); @@ -4022,7 +4022,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; } - if (!CheckBlockHeader(&futureblock,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) + if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { //fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); return false; @@ -4046,8 +4046,8 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc pindexPrev = (*mi).second; if (pindexPrev == 0 ) { - fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str()); - /*if ( komodo_requestedhash == zero ) + /*fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str()); + if ( komodo_requestedhash == zero ) { komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; @@ -4080,13 +4080,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc return true; } -bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp) +bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp) { const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); CBlockIndex *&pindex = *ppindex; - if (!AcceptBlockHeader(block, state, &pindex)) + if (!AcceptBlockHeader(futureblockp,block, state, &pindex)) { //fprintf(stderr,"AcceptBlockHeader rejected\n"); return false; @@ -4120,9 +4120,8 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, } // See method docstring for why this is always disabled - int32_t futureblock; auto verifier = libzcash::ProofVerifier::Disabled(); - if ((!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) + if ((!CheckBlock(futureblockp,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { if (futureblock == 0 && state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus |= BLOCK_FAILED_VALID; @@ -4197,7 +4196,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks - bool checked; uint256 hash; int32_t futureblock; + bool checked; uint256 hash; int32_t futureblock=0; auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); //fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); @@ -4227,17 +4226,17 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); } - bool ret = AcceptBlock(*pblock, state, &pindex, fRequested, dbp); + bool ret = AcceptBlock(&futureblock,*pblock, state, &pindex, fRequested, dbp); if (pindex && pfrom) { mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId(); } CheckBlockIndex(); - if (!ret) + if (!ret && futureblock == 0) return error("%s: AcceptBlock FAILED", __func__); //else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); } - if (!ActivateBestChain(state, pblock)) + if (futureblock == 0 && !ActivateBestChain(state, pblock)) return error("%s: ActivateBestChain failed", __func__); return true; @@ -6081,12 +6080,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 20); return error("non-continuous headers sequence"); } + int32_t futureblock; //fprintf(stderr,"headers msg nCount.%d\n",(int32_t)nCount); - if (!AcceptBlockHeader(header, state, &pindexLast)) { + if (!AcceptBlockHeader(&futureblock,header, state, &pindexLast)) { int nDoS; if (state.IsInvalid(nDoS)) { - if (nDoS > 0) + if (nDoS > 0 && futureblock == 0) Misbehaving(pfrom->GetId(), nDoS/nDoS); return error("invalid header received"); } diff --git a/src/main.h b/src/main.h index 6c590ea01..ef46cd83d 100644 --- a/src/main.h +++ b/src/main.h @@ -796,7 +796,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false,bool fCheckPOW = false); /** Context-independent validity checks */ -bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); +bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, libzcash::ProofVerifier& verifier, bool fCheckPOW = true, bool fCheckMerkleRoot = true); @@ -815,8 +815,8 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex * - The only caller of AcceptBlock verifies JoinSplit proofs elsewhere. * If dbp is non-NULL, the file is known to already reside on disk */ -bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp); -bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL); +bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp); +bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL); From e868c9ea245ebc2e264f9609ae8340ebd4f709f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 14:49:41 +0300 Subject: [PATCH 47/58] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0952609c7..4ae407c8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4123,7 +4123,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C auto verifier = libzcash::ProofVerifier::Disabled(); if ((!CheckBlock(futureblockp,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { - if (futureblock == 0 && state.IsInvalid() && !state.CorruptionPossible()) { + if (*futureblockp == 0 && state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex); } From 20e0bc85a86d580ff8a032a09fab07e61fd9269b Mon Sep 17 00:00:00 2001 From: SHossain Date: Tue, 24 Apr 2018 12:53:13 +0100 Subject: [PATCH 48/58] Update README.md --- README.md | 112 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e766870a5..5d85d013d 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,46 @@ ## Komodo with Bitcore This version of Komodo contains Bitcore support for komodo and all its assetchains. + ## Komodod This software is Komodo client, generally you will use this if you want to mine KMD or setup a full node. It downloads and stores the entire history of Komodo transactions; depending on the speed of your computer and network connection, the synchronization process could take a day or more once the blockchain has reached a significant size. + ## Development Resources - Komodo Web: [https://komodoplatform.com/](https://komodoplatform.com/) -- Organization web: [https://www.supernet.org](https://www.supernet.org) -- Forum: [https://forum.supernet.org/](https://forum.supernet.org/) -- Mail: [info@supernet.org](mailto:info@supernet.org) -- Support & Guides: [https://support.supernet.org/support/home](https://support.supernet.org/support/home) +- Organization web: [https://komodoplatform.com/](https://komodoplatform.com/) +- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) +- Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) +- Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) +- Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) - API references: [http://docs.supernet.org/](http://docs.supernet.org/) #Not up to date. +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) + ## List of Komodo Platform Technologies -Delayed Proof of Work (dPoW) - Additional security layer. -zk-SNARKs - Komodo Platform's privacy technology -Jumblr - Decentralized tumbler for KMD and other cryptocurrencies -Assetchains - Easy way to fork Komodo coin -Pegged Assets - Chains that maintain a peg to fiat currencies -Peerchains - Scalability solution where sibling chains form a network of blockchains -More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) -Also note you receive 5% APR on your holdings. -[See this article for more details](https://supernet.org/en/resources/articles/receive-free-coins-quaranteed-kmd-interest) +- Delayed Proof of Work (dPoW) - Additional security layer. +- zk-SNARKs - Komodo Platform's privacy technology +- Jumblr - Decentralized tumbler for KMD and other cryptocurrencies +- Assetchains - Easy way to fork Komodo coin +- Pegged Assets - Chains that maintain a peg to fiat currencies +- Peerchains - Scalability solution where sibling chains form a network of blockchains +- More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) +- Also note you receive 5% APR on your holdings. +[See this article for more details](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages/20480015/Claim+KMD+Interest+in+Agama) + ## Tech Specification -Max Supply: 200 million KMD. -Block Time: 1M 2s -Block Reward: 3KMD -Mining Algorithm: Equihash +- Max Supply: 200 million KMD. +- Block Time: 1M 2s +- Block Reward: 3KMD +- Mining Algorithm: Equihash + ## About this Project Komodo is based on Zcash and has been by our innovative consensus algorithm called dPoW which utilizes Bitcoin's hashrate to store Komodo blockchain information into the Bitcoin blockchain. Other new and native Komodo features are the privacy technology called JUMBLR or our assetchain capabilities (one click plug and play blockchain solutions). More details are available under https://komodoplatform.com/. + ## Getting started Dependencies ------------ -``` +```shell #The following packages are needed: sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-openssl-dev bsdmainutils automake curl ``` @@ -54,7 +62,7 @@ dPoW branch: autobuild into GUI installers, unix, osx, windows beta branch: notary nodes, command line unix dev branch: bleeding edge, possibly wont even compile, multiple updates per hour -``` +```shell git clone https://github.com/jl777/komodo cd komodo #you might want to: git checkout ; git pull @@ -64,7 +72,6 @@ cd komodo #This can take some time. ``` - **komodo is experimental and a work-in-progress.** Use at your own risk. Deprecation Policy @@ -76,11 +83,14 @@ time after this one year period. The automatic feature is based on block height and can be explicitly disabled. -# to update an existing version, git checkout dPoW if not on that branch already +# to update an existing version, `git checkout dPoW` if not on that branch already +```shell git pull ./zcutil/fetch-params.sh ./zcutil/build.sh -j8 -To reset the blockchain, from ~/.komodo rm -rf blocks chainstate debug.log komodostate db.log +``` +To reset the blockchain, from *~/.komodo* `rm -rf blocks chainstate debug.log komodostate db.log` + Create komodo.conf ------------------ @@ -105,7 +115,7 @@ addnode=89.248.166.91 Start mining ------------ -``` +```shell #iguana documentation shows how to get the btcpubkey and wifstrs that need to be used #bitcoin also need to be installed with txindex=1 and with rpc enabled cd ~ @@ -136,59 +146,89 @@ Both komodod and komodo-cli recognize -ac_name=option so you can create fork fro ``` ======= **Zcash is unfinished and highly experimental.** Use at your own risk. + Where do I begin? ----------------- We have a guide for joining the main Zcash network: https://github.com/zcash/zcash/wiki/1.0-User-Guide + ### Need Help? * See the documentation at the [Zcash Wiki](https://github.com/zcash/zcash/wiki) for help and more information. * Ask for help on the [Zcash](https://forum.z.cash/) forum. Participation in the Zcash project is subject to a [Code of Conduct](code_of_conduct.md). + Building -------- Build Zcash along with most dependencies from source by running -./zcutil/build.sh. Currently only Linux is officially supported. +`./zcutil/build.sh`. Currently only Linux is officially supported. + License ------- For license information see the file [COPYING](COPYING). -NOTE TO EXCHANGES: + +**NOTE TO EXCHANGES:** https://bitcointalk.org/index.php?topic=1605144.msg17732151#msg17732151 There is a small chance that an outbound transaction will give an error due to mismatched values in wallet calculations. There is a -exchange option that you can run komodod with, but make sure to have the entire transaction history under the same -exchange mode. Otherwise you will get wallet conflicts. -To change modes: -a) backup all privkeys (launch komodod with -exportdir= and dumpwallet) -b) start a totally new sync including wallet.dat, launch with same exportdir -c) stop it before it gets too far and import all the privkeys from a) using komodo-cli importwallet filename + +**To change modes:** + +a) backup all privkeys (launch komodod with `-exportdir=` and `dumpwallet`) + +b) start a totally new sync including `wallet.dat`, launch with same `exportdir` + +c) stop it before it gets too far and import all the privkeys from a) using `komodo-cli importwallet filename` + d) resume sync till it gets to chaintip + For example: +```shell ./komodod -exportdir=/tmp & ./komodo-cli dumpwallet example ./komodo-cli stop mv ~/.komodo ~/.komodo.old && mkdir ~/.komodo && cp ~/.komodo.old/komodo.conf ~/.komodo.old/peers.dat ~/.komodo ./komodod -exchange -exportdir=/tmp & ./komodo-cli importwallet /tmp/example -############## JUMBLR -komodod now has jumblr_deposit and jumblr_secret RPC calls. +``` + +## JUMBLR +komodod now has `jumblr_deposit` and `jumblr_secret` RPC calls. + Jumblr works like described previously where all the nodes with jumblr active synchronize their tx activity during the same block to maximize the mixing effect. However, unlike all other mixers/tumblers, you never give up control of your coins to anybody else. JUMBLR uses a one to many allocation of funds, ie. one deposit address and many secret addresses. You can always run multiple komodod daemons to get multiple active deposit addresses. + JUMBLR implements t -> z, z -> z and z -> t transactions to maximize privacy of the destination t (transparent) address. So while it is transparent, its first activity is funds coming from an untracable z address. + Which of the three stages is done is randomly selected at each turn. Also when there is more than one possible transaction at the selected stage, a random one is selected. This randomization prevents analyzing incoming z ->t transactions by its size to correlate it to the originating address. -jumblr_deposit designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. -There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. -jumblr_secret notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. -Practical Advice: + +`jumblr_deposit ` designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. + +There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. + +`jumblr_secret ` notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. + +#### Practical Advice: Obtaining privacy used to be very difficult. JUMBLR makes it as simple as issuing two command line calls. Higher level layers can be added to help manage the addresses, ie. linking them at the passphrase level. Such matters are left to each implementation. + Once obtained, it is very easy to lose all the privacy. With a single errant transaction that combines some previously used address and the secretaddress, well, the secretaddress is no longer so private. + The advice is to setup a totally separate node! + This might seem a bit drastic, but if you want to maintain privacy, it is best to make it look like all the transactions are coming from a different node. The easiest way for most people to do this is to actually have a different node. -It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. + +It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. + Of course, don't send emails that link the two accounts together! Dont use secret address funds for home delivery purchases! Etc. There are many ways to lose the privacy, just think about what linkages can be dont at the IP and blockchain level and that should be a useful preparation. + What if you have 100,000 KMD and you dont want others to know you are such a whale? Instead of generating 1 secret address, generate 100 and make a script file with: +```shell ./komodo-cli jumblr_secret ./komodo-cli jumblr_secret ... ./komodo-cli jumblr_secret +``` And make sure to delete all traces of this when the JUMBLR is finished. You will end up with 100 addresses that have an average of 1000 KMD each. So as long as you are careful and dont do a 10,000 KMD transaction (that will link 10 of your secret addresses together), you can appear as 100 different people each with 1000 KMD. + From aa03edda8a6ee774db81ef88bd554ace3cf96e70 Mon Sep 17 00:00:00 2001 From: SHossain Date: Tue, 24 Apr 2018 13:09:31 +0100 Subject: [PATCH 49/58] Update README.md --- README.md | 111 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e766870a5..31cc880ab 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,46 @@ ## Komodo with Bitcore This version of Komodo contains Bitcore support for komodo and all its assetchains. + ## Komodod This software is Komodo client, generally you will use this if you want to mine KMD or setup a full node. It downloads and stores the entire history of Komodo transactions; depending on the speed of your computer and network connection, the synchronization process could take a day or more once the blockchain has reached a significant size. + ## Development Resources - Komodo Web: [https://komodoplatform.com/](https://komodoplatform.com/) -- Organization web: [https://www.supernet.org](https://www.supernet.org) -- Forum: [https://forum.supernet.org/](https://forum.supernet.org/) -- Mail: [info@supernet.org](mailto:info@supernet.org) -- Support & Guides: [https://support.supernet.org/support/home](https://support.supernet.org/support/home) +- Organization web: [https://komodoplatform.com/](https://komodoplatform.com/) +- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) +- Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) +- Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) +- Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) - API references: [http://docs.supernet.org/](http://docs.supernet.org/) #Not up to date. +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) + ## List of Komodo Platform Technologies -Delayed Proof of Work (dPoW) - Additional security layer. -zk-SNARKs - Komodo Platform's privacy technology -Jumblr - Decentralized tumbler for KMD and other cryptocurrencies -Assetchains - Easy way to fork Komodo coin -Pegged Assets - Chains that maintain a peg to fiat currencies -Peerchains - Scalability solution where sibling chains form a network of blockchains -More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) -Also note you receive 5% APR on your holdings. -[See this article for more details](https://supernet.org/en/resources/articles/receive-free-coins-quaranteed-kmd-interest) +- Delayed Proof of Work (dPoW) - Additional security layer. +- zk-SNARKs - Komodo Platform's privacy technology +- Jumblr - Decentralized tumbler for KMD and other cryptocurrencies +- Assetchains - Easy way to fork Komodo coin +- Pegged Assets - Chains that maintain a peg to fiat currencies +- Peerchains - Scalability solution where sibling chains form a network of blockchains +- More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) +- Also note you receive 5% APR on your holdings. +[See this article for more details](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages/20480015/Claim+KMD+Interest+in+Agama) + ## Tech Specification -Max Supply: 200 million KMD. -Block Time: 1M 2s -Block Reward: 3KMD -Mining Algorithm: Equihash +- Max Supply: 200 million KMD. +- Block Time: 1M 2s +- Block Reward: 3KMD +- Mining Algorithm: Equihash + ## About this Project Komodo is based on Zcash and has been by our innovative consensus algorithm called dPoW which utilizes Bitcoin's hashrate to store Komodo blockchain information into the Bitcoin blockchain. Other new and native Komodo features are the privacy technology called JUMBLR or our assetchain capabilities (one click plug and play blockchain solutions). More details are available under https://komodoplatform.com/. + ## Getting started Dependencies ------------ -``` +```shell #The following packages are needed: sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-openssl-dev bsdmainutils automake curl ``` @@ -54,7 +62,7 @@ dPoW branch: autobuild into GUI installers, unix, osx, windows beta branch: notary nodes, command line unix dev branch: bleeding edge, possibly wont even compile, multiple updates per hour -``` +```shell git clone https://github.com/jl777/komodo cd komodo #you might want to: git checkout ; git pull @@ -64,7 +72,6 @@ cd komodo #This can take some time. ``` - **komodo is experimental and a work-in-progress.** Use at your own risk. Deprecation Policy @@ -76,11 +83,14 @@ time after this one year period. The automatic feature is based on block height and can be explicitly disabled. -# to update an existing version, git checkout dPoW if not on that branch already +# to update an existing version, `git checkout dPoW` if not on that branch already +```shell git pull ./zcutil/fetch-params.sh ./zcutil/build.sh -j8 -To reset the blockchain, from ~/.komodo rm -rf blocks chainstate debug.log komodostate db.log +``` +To reset the blockchain, from *~/.komodo* `rm -rf blocks chainstate debug.log komodostate db.log` + Create komodo.conf ------------------ @@ -105,7 +115,7 @@ addnode=89.248.166.91 Start mining ------------ -``` +```shell #iguana documentation shows how to get the btcpubkey and wifstrs that need to be used #bitcoin also need to be installed with txindex=1 and with rpc enabled cd ~ @@ -136,59 +146,88 @@ Both komodod and komodo-cli recognize -ac_name=option so you can create fork fro ``` ======= **Zcash is unfinished and highly experimental.** Use at your own risk. + Where do I begin? ----------------- We have a guide for joining the main Zcash network: https://github.com/zcash/zcash/wiki/1.0-User-Guide + ### Need Help? * See the documentation at the [Zcash Wiki](https://github.com/zcash/zcash/wiki) for help and more information. * Ask for help on the [Zcash](https://forum.z.cash/) forum. Participation in the Zcash project is subject to a [Code of Conduct](code_of_conduct.md). + Building -------- Build Zcash along with most dependencies from source by running -./zcutil/build.sh. Currently only Linux is officially supported. +`./zcutil/build.sh`. Currently only Linux is officially supported. + License ------- For license information see the file [COPYING](COPYING). -NOTE TO EXCHANGES: + +**NOTE TO EXCHANGES:** https://bitcointalk.org/index.php?topic=1605144.msg17732151#msg17732151 There is a small chance that an outbound transaction will give an error due to mismatched values in wallet calculations. There is a -exchange option that you can run komodod with, but make sure to have the entire transaction history under the same -exchange mode. Otherwise you will get wallet conflicts. -To change modes: -a) backup all privkeys (launch komodod with -exportdir= and dumpwallet) -b) start a totally new sync including wallet.dat, launch with same exportdir -c) stop it before it gets too far and import all the privkeys from a) using komodo-cli importwallet filename + +**To change modes:** + +a) backup all privkeys (launch komodod with `-exportdir=` and `dumpwallet`) + +b) start a totally new sync including `wallet.dat`, launch with same `exportdir` + +c) stop it before it gets too far and import all the privkeys from a) using `komodo-cli importwallet filename` + d) resume sync till it gets to chaintip + For example: +```shell ./komodod -exportdir=/tmp & ./komodo-cli dumpwallet example ./komodo-cli stop mv ~/.komodo ~/.komodo.old && mkdir ~/.komodo && cp ~/.komodo.old/komodo.conf ~/.komodo.old/peers.dat ~/.komodo ./komodod -exchange -exportdir=/tmp & ./komodo-cli importwallet /tmp/example -############## JUMBLR -komodod now has jumblr_deposit and jumblr_secret RPC calls. +``` + +## JUMBLR +komodod now has `jumblr_deposit` and `jumblr_secret` RPC calls. + Jumblr works like described previously where all the nodes with jumblr active synchronize their tx activity during the same block to maximize the mixing effect. However, unlike all other mixers/tumblers, you never give up control of your coins to anybody else. JUMBLR uses a one to many allocation of funds, ie. one deposit address and many secret addresses. You can always run multiple komodod daemons to get multiple active deposit addresses. + JUMBLR implements t -> z, z -> z and z -> t transactions to maximize privacy of the destination t (transparent) address. So while it is transparent, its first activity is funds coming from an untracable z address. + Which of the three stages is done is randomly selected at each turn. Also when there is more than one possible transaction at the selected stage, a random one is selected. This randomization prevents analyzing incoming z ->t transactions by its size to correlate it to the originating address. -jumblr_deposit designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. -There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. -jumblr_secret notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. -Practical Advice: + +`jumblr_deposit ` designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. + +There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. + +`jumblr_secret ` notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. + +#### Practical Advice: Obtaining privacy used to be very difficult. JUMBLR makes it as simple as issuing two command line calls. Higher level layers can be added to help manage the addresses, ie. linking them at the passphrase level. Such matters are left to each implementation. + Once obtained, it is very easy to lose all the privacy. With a single errant transaction that combines some previously used address and the secretaddress, well, the secretaddress is no longer so private. + The advice is to setup a totally separate node! + This might seem a bit drastic, but if you want to maintain privacy, it is best to make it look like all the transactions are coming from a different node. The easiest way for most people to do this is to actually have a different node. -It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. + +It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. + Of course, don't send emails that link the two accounts together! Dont use secret address funds for home delivery purchases! Etc. There are many ways to lose the privacy, just think about what linkages can be dont at the IP and blockchain level and that should be a useful preparation. + What if you have 100,000 KMD and you dont want others to know you are such a whale? Instead of generating 1 secret address, generate 100 and make a script file with: +```shell ./komodo-cli jumblr_secret ./komodo-cli jumblr_secret ... ./komodo-cli jumblr_secret +``` And make sure to delete all traces of this when the JUMBLR is finished. You will end up with 100 addresses that have an average of 1000 KMD each. So as long as you are careful and dont do a 10,000 KMD transaction (that will link 10 of your secret addresses together), you can appear as 100 different people each with 1000 KMD. From 4825cbeb683085ac6040ce94607bba2265088146 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 15:32:10 +0300 Subject: [PATCH 50/58] komodo_validate_interest expiration in CTxMemPool::removeExpired --- src/txmempool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index d14de08b9..9dcfab346 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -409,7 +409,8 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight) for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - if (IsExpiredTx(tx, nBlockHeight)) { + if (IsExpiredTx(tx, nBlockHeight) || komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0) + { transactionsToRemove.push_back(tx); } } From f045635ebc4987e553fcf55fd27cf0a8f4686213 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 15:35:48 +0300 Subject: [PATCH 51/58] Fix --- src/txmempool.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 9dcfab346..26926ae16 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -401,15 +401,19 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list } } +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); + void CTxMemPool::removeExpired(unsigned int nBlockHeight) { + CBlockIndex *tipindex; // Remove expired txs from the mempool LOCK(cs); list transactionsToRemove; for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - if (IsExpiredTx(tx, nBlockHeight) || komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0) + tipindex = chainActive.Tip(); + if (IsExpiredTx(tx, nBlockHeight) || (tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,1) < 0) { transactionsToRemove.push_back(tx); } From ed67a29bcdb5d66f04df1e7633696368478722df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 15:36:34 +0300 Subject: [PATCH 52/58] Fix --- src/txmempool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 26926ae16..d9eb9debc 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -413,7 +413,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight) { const CTransaction& tx = it->GetTx(); tipindex = chainActive.Tip(); - if (IsExpiredTx(tx, nBlockHeight) || (tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,1) < 0) + if (IsExpiredTx(tx, nBlockHeight) || (tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,1)) < 0) { transactionsToRemove.push_back(tx); } From 924afa4c3f255ac792d56916fbc13a7445e99400 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 15:54:52 +0300 Subject: [PATCH 53/58] Test config --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4ae407c8e..45a31f140 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3759,11 +3759,11 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, } } *futureblockp = 0; - if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) + if (blockhdr.GetBlockTime() > GetAdjustedTime() - 60) // test, usually +60 { CBlockIndex *tipindex; fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); - if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) + if ( 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) { //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) From 599c2c5f4d216bb57117913d95a07f01c550d2a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 16:19:15 +0300 Subject: [PATCH 54/58] Allow a block from the future to be rejected without being permabanned --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 45a31f140..c69cb7e6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3759,11 +3759,11 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, } } *futureblockp = 0; - if (blockhdr.GetBlockTime() > GetAdjustedTime() - 60) // test, usually +60 + if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { CBlockIndex *tipindex; fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); - if ( 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60*2 ) + if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60 + 5 ) { //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) From 5794aafc486b6de598d4e5f3033732ca9ffbf8f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 16:39:04 +0300 Subject: [PATCH 55/58] +printout --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c69cb7e6d..8f430b6e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3317,8 +3317,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo pindexOldTip->phashBlock->GetHex(), pindexOldTip->nHeight, pindexOldTip->nChainWork.GetHex()) + "\n" + "- " + strprintf(_("New tip: %s, height %d, work %s"), pindexMostWork->phashBlock->GetHex(), pindexMostWork->nHeight, pindexMostWork->nChainWork.GetHex()) + "\n" + - "- " + strprintf(_("Fork point: %s, height %d"), - pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + + "- " + strprintf(_("Fork point: %s %s, height %d"), + ASSECHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + _("Please help, human!"); LogPrintf("*** %s\n", msg); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); From a17a8c5200a766fc95900acfe4d0ff67e4c0b071 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 17:15:34 +0300 Subject: [PATCH 56/58] Typo --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8f430b6e8..d0e16b354 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3318,7 +3318,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo "- " + strprintf(_("New tip: %s, height %d, work %s"), pindexMostWork->phashBlock->GetHex(), pindexMostWork->nHeight, pindexMostWork->nChainWork.GetHex()) + "\n" + "- " + strprintf(_("Fork point: %s %s, height %d"), - ASSECHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + + ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + _("Please help, human!"); LogPrintf("*** %s\n", msg); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); From 9840ae39219b052fdb65f8c561beeeaf31dd5364 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 17:42:46 +0300 Subject: [PATCH 57/58] Test --- src/main.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d0e16b354..65fb56c2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2585,9 +2585,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin auto disabledVerifier = libzcash::ProofVerifier::Disabled(); int32_t futureblock; // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in - if (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) + if (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck) || futureblock != 0 ) { - fprintf(stderr,"checkblock failure in connectblock\n"); + fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } @@ -3814,8 +3814,9 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // redundant with the call in AcceptBlockHeader. if (!CheckBlockHeader(futureblockp,height,pindex,block,state,fCheckPOW)) { - //fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); - return false; + if ( *futureblockp == 0 ) + return false; + else fprintf(stderr,"checkblockheader PoW.%d got futureblock\n",fCheckPOW); } if ( fCheckPOW ) { @@ -4024,8 +4025,9 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat } if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { - //fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader failed\n"); - return false; + if ( *futureblockp == 0 ) + return false; + else fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader got future block\n"); } // Get prev block index CBlockIndex* pindexPrev = NULL; @@ -4088,8 +4090,9 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C CBlockIndex *&pindex = *ppindex; if (!AcceptBlockHeader(futureblockp,block, state, &pindex)) { - //fprintf(stderr,"AcceptBlockHeader rejected\n"); - return false; + if ( *futureblockp == 0 ) + return false; + else fprintf(stderr,"AcceptBlock AcceptBlockHeader got future block\n"); } if ( pindex == 0 ) { @@ -4123,12 +4126,14 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C auto verifier = libzcash::ProofVerifier::Disabled(); if ((!CheckBlock(futureblockp,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { - if (*futureblockp == 0 && state.IsInvalid() && !state.CorruptionPossible()) { - pindex->nStatus |= BLOCK_FAILED_VALID; - setDirtyBlockIndex.insert(pindex); - } - //fprintf(stderr,"CheckBlock or ContextualCheckBlock failed\n"); - return false; + if ( *futureblockp == 0 ) + { + if (state.IsInvalid() && !state.CorruptionPossible()) { + pindex->nStatus |= BLOCK_FAILED_VALID; + setDirtyBlockIndex.insert(pindex); + } + return false; + } else fprintf(stderr,"CheckBlock or ContextualCheckBlock got futureblock\n"); } int nHeight = pindex->nHeight; @@ -4152,8 +4157,9 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if (fCheckForPruning) FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files - - return true; + if ( *futureblockp == 0 ) + return true; + else return false; } static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams) @@ -4276,7 +4282,8 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex return false; } assert(state.IsValid()); - + if ( futureblock != 0 ) + return(false); return true; } @@ -4671,7 +4678,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity int32_t futureblock; - if (nCheckLevel >= 1 && !CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) + if (nCheckLevel >= 1 && (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0) || futureblock != 0) ) return error("VerifyDB(): *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 2: verify undo validity if (nCheckLevel >= 2 && pindex) { From 4342e69bf4852547ef0b9cb17dd475f872685b14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 18:38:07 +0300 Subject: [PATCH 58/58] -print and tweak error triggers --- src/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 65fb56c2b..7b746c3d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1665,7 +1665,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos,bo if (filein.IsNull()) { //fprintf(stderr,"readblockfromdisk err A\n"); - return false;//error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString()); + return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString()); } // Read block @@ -2587,7 +2587,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in if (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck) || futureblock != 0 ) { - fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); + //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } @@ -3816,7 +3816,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { if ( *futureblockp == 0 ) return false; - else fprintf(stderr,"checkblockheader PoW.%d got futureblock\n",fCheckPOW); + //else fprintf(stderr,"checkblockheader PoW.%d got futureblock\n",fCheckPOW); } if ( fCheckPOW ) { @@ -4027,7 +4027,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat { if ( *futureblockp == 0 ) return false; - else fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader got future block\n"); + //else fprintf(stderr,"AcceptBlockHeader: CheckBlockHeader got future block\n"); } // Get prev block index CBlockIndex* pindexPrev = NULL; @@ -4092,7 +4092,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C { if ( *futureblockp == 0 ) return false; - else fprintf(stderr,"AcceptBlock AcceptBlockHeader got future block\n"); + //else fprintf(stderr,"AcceptBlock AcceptBlockHeader got future block\n"); } if ( pindex == 0 ) { @@ -4678,7 +4678,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity int32_t futureblock; - if (nCheckLevel >= 1 && (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0) || futureblock != 0) ) + if (nCheckLevel >= 1 && !CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0) ) return error("VerifyDB(): *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 2: verify undo validity if (nCheckLevel >= 2 && pindex) {