From 2ad1557300b579b7d453bd32398e97d727b667c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 27 May 2018 20:21:15 -1100 Subject: [PATCH 01/19] Fix ;; --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 70a5488f8..fce556d33 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4519,7 +4519,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) txNew.vin.resize(1); txNew.vout.resize(1); - txfee = utxovalue / 2;; + txfee = utxovalue / 2; //for (i=0; i<32; i++) // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; txNew.vin[0].prevout.hash = utxotxid; //revtxid; From 6fd79871df7933ec65b05362f26b84954471b32c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:03:48 -1100 Subject: [PATCH 02/19] wallet/rpcwallet.cpp:2701: uint64_t komodo_interestsum(): Assertion` pwalletMain != NULL' failed.` --- src/wallet/rpcwallet.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fce556d33..0b3b45a80 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2696,6 +2696,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { +#ifdef ENABLE_WALLET uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; assert(pwalletMain != NULL); @@ -2719,6 +2720,9 @@ uint64_t komodo_interestsum() KOMODO_INTERESTSUM = sum; KOMODO_WALLETBALANCE = pwalletMain->GetBalance(); return(sum); +#else + return(0); +#endif } UniValue fundrawtransaction(const UniValue& params, bool fHelp) From d9f176ac7ef5abc7f8af299a7a69d015f50f0f8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:43:08 -1100 Subject: [PATCH 03/19] Support -ac_pubkey without -ac_perc If ac_pubkey is set, then height 1 out must go to that pub key --- src/komodo_bitcoind.h | 27 ++++++++++++++++++--------- src/komodo_port.c | 2 +- src/komodo_utils.h | 2 +- src/miner.cpp | 13 +++++++++---- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c434e33a3..2ef99c5e3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1333,20 +1333,29 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( is_PoSblock < 0 ) return(-1); } - if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { - checktoshis = komodo_commission(pblock); - if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) - return(-1); - else if ( checktoshis != 0 ) + if ( height == 1 ) { - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); - if ( pblock->vtx[0].vout[1].nValue != checktoshis ) - { - fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); + } + if ( ASSETCHAINS_COMMISSION != 0 ) + { + checktoshis = komodo_commission(pblock); + if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) return(-1); + else if ( checktoshis != 0 ) + { + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + if ( pblock->vtx[0].vout[1].nValue != checktoshis ) + { + fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); + return(-1); + } } } } diff --git a/src/komodo_port.c b/src/komodo_port.c index e92da3af1..991be2013 100644 --- a/src/komodo_port.c +++ b/src/komodo_port.c @@ -809,7 +809,7 @@ uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t decay = 0; printf("decay cant be more than 100000000\n"); } - if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || commission != 0 || cc != 0 || staked != 0 ) + if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || commission != 0 || cc != 0 || staked != 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { //printf("end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,(long long)commission); extraptr = extrabuf; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 36766a1f7..119c4d6f4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1559,7 +1559,7 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = 0; printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); } - if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 100000000 ) + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); else if ( ASSETCHAINS_COMMISSION != 0 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 264a6e2d4..ff93ca91c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -108,7 +108,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern std::string NOTARY_PUBKEY; +extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; + extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; uint32_t Mining_start,Mining_height; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); @@ -582,10 +583,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& // Internal miner // -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - if ( USE_EXTERNAL_PUBKEY != 0 ) + if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + { + scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + } + else if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; @@ -787,7 +792,7 @@ void static BitcoinMiner() sleep(3); } #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From cf1b8419d426e7a7d1c65ce887249a167f6b5d4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:56:05 -1100 Subject: [PATCH 04/19] Add nHeight --- src/rpcmining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index bd9c45f5d..e3341144a 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -214,7 +214,7 @@ UniValue generate(const UniValue& params, bool fHelp) lastTime = GetTime(); #ifdef ENABLE_WALLET - std::unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey)); + std::unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight)); #else std::unique_ptr pblocktemplate(CreateNewBlockWithKey()); #endif @@ -639,7 +639,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } #ifdef ENABLE_WALLET CReserveKey reservekey(pwalletMain); - pblocktemplate = CreateNewBlockWithKey(reservekey); + pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1); #else pblocktemplate = CreateNewBlockWithKey(); #endif From 1afc2472d073a6e6907051f85a057fd912f8aa6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:56:49 -1100 Subject: [PATCH 05/19] Create block with nHeight --- src/miner.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.h b/src/miner.h index bf1a088f0..684b10187 100644 --- a/src/miner.h +++ b/src/miner.h @@ -30,7 +30,7 @@ struct CBlockTemplate CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn); #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey); -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey); +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight); #else boost::optional GetMinerScriptPubKey(); CBlockTemplate* CreateNewBlockWithKey(); From 525c7b98a9c62d54b7f1c29e12be343eccd5df8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:01:05 -1100 Subject: [PATCH 06/19] Skip equihash test for regrets --- src/pow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index 817dcc1fe..e942883f2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -86,6 +86,8 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param unsigned int n = params.EquihashN(); unsigned int k = params.EquihashK(); + if ( Params().NetworkIDString() == "regtest" ) + return(true); // Hash state crypto_generichash_blake2b_state state; EhInitialiseState(n, k, state); From e2c2eec41a29794dea0f65c9f1eb3f89b63cffd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:06:13 -1100 Subject: [PATCH 07/19] Guard null it->second --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 119967a46..fa402338a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5147,7 +5147,8 @@ void static CheckBlockIndex() // Build forward-pointing map of the entire block tree. std::multimap forward; for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); it++) { - forward.insert(std::make_pair(it->second->pprev, it->second)); + if ( it->second != 0 ) + forward.insert(std::make_pair(it->second->pprev, it->second)); } assert(forward.size() == mapBlockIndex.size()); From d916630e3a267452ab0a3700fe2e1bc5de8079a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:08:43 -1100 Subject: [PATCH 08/19] Bypass assert in regrets --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fa402338a..34d939431 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5150,8 +5150,8 @@ void static CheckBlockIndex() if ( it->second != 0 ) forward.insert(std::make_pair(it->second->pprev, it->second)); } - - assert(forward.size() == mapBlockIndex.size()); + if ( Params().NetworkIDString() != "regtest" ) + assert(forward.size() == mapBlockIndex.size()); std::pair::iterator,std::multimap::iterator> rangeGenesis = forward.equal_range(NULL); CBlockIndex *pindex = rangeGenesis.first->second; From 528f340601cd6aca31341623a27d291b8ea6a0ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:15:29 -1100 Subject: [PATCH 09/19] -print --- src/komodo.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 36c7c2ef3..d01de9553 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -201,8 +201,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); - } - else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); + } // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); return(func); } else return(-1); } @@ -342,8 +341,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); - } - else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); + } // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); *fposp = fpos; return(func); } From 2d79309f33ed4fdb819170f2db15e856de62d16d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:25:26 -1100 Subject: [PATCH 10/19] unburn Notary vin txfee --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index ff93ca91c..e86902a92 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -479,11 +479,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nTime = pindexPrev->nTime + 65; if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) { - CAmount txfees = 0; + CAmount txfees = 5000; pblock->vtx.push_back(txNotary); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary)); nFees += txfees; + pblocktemplate->vTxFees[0] = -nFees; + pblock->vtx[0].vout[0].nValue += txfees; //fprintf(stderr,"added notaryvin\n"); } else From c255db29b37e1ac2d35e1e6477c7603b2f6f93d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:29:06 -1100 Subject: [PATCH 11/19] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e86902a92..9863c8139 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -485,7 +485,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary)); nFees += txfees; pblocktemplate->vTxFees[0] = -nFees; - pblock->vtx[0].vout[0].nValue += txfees; + *(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; //fprintf(stderr,"added notaryvin\n"); } else From c881e52b6ef23c1dc0df6a95d13ebe5429270a91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:41:03 -1100 Subject: [PATCH 12/19] Revert --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9863c8139..c789eb41d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -485,7 +485,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary)); nFees += txfees; pblocktemplate->vTxFees[0] = -nFees; - *(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; + //*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; //fprintf(stderr,"added notaryvin\n"); } else From fb6bb4e82ebbaee6cf1ebbbd3c9de6ff0bc68ecd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 04:18:31 -1100 Subject: [PATCH 13/19] fix -ac_perc --- src/komodo_bitcoind.h | 42 +++++++++++++++++++++++++----------------- src/komodo_gateway.h | 19 ++++++++++++++----- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2ef99c5e3..b48c40442 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1265,6 +1265,29 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ return(isPoS); } +int64_t komodo_checkcommission(CBlock *pblock,int32_t height) +{ + int64_t checktoshis=0; uint8_t *script; + if ( ASSETCHAINS_COMMISSION != 0 ) + { + checktoshis = komodo_commission(pblock); + if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) + return(-1); + else if ( checktoshis != 0 ) + { + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + if ( pblock->vtx[0].vout[1].nValue != checktoshis ) + { + fprintf(stderr,"ht.%d checktoshis %.8f vs actual vout[1] %.8f\n",height,dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); + return(-1); + } + } + } + return(checktoshis); +} + int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; @@ -1341,23 +1364,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } - if ( ASSETCHAINS_COMMISSION != 0 ) - { - checktoshis = komodo_commission(pblock); - if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) - return(-1); - else if ( checktoshis != 0 ) - { - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) - return(-1); - if ( pblock->vtx[0].vout[1].nValue != checktoshis ) - { - fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); - return(-1); - } - } - } + if ( komodo_checkcommission(pblock,height) < 0 ) + return(-1); } //fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed); if ( failed != 0 && possible == 0 && notaryid < 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 410e106ae..283c2ef0c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -653,7 +653,7 @@ void komodo_passport_iteration(); int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; - int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,notmatched=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; CTransaction tx; + int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,notmatched=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,seed; int64_t checktoshis,values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; CTransaction tx; activation = 235300; if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); @@ -743,11 +743,20 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( overflow != 0 || total > 0 || strangeout != 0 ) + checktoshis = 0; + if ( ASSETCHAINS_COMMISSION != 0 ) { - if ( strangeout != 0 ) - fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); - return(-1); + if ( (checktoshis= komodo_checkcommission(&block,height)) < 0 ) + return(-1); + } + else + { + if ( overflow != 0 || total > checktoshis || strangeout != 0 ) + { + if ( strangeout != 0 ) + fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); + return(-1); + } } } return(0); From 44bbf01edf6b4f522132cfe4e52c973d901c93bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 04:22:02 -1100 Subject: [PATCH 14/19] Fix --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 283c2ef0c..55ab8b477 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -746,7 +746,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim checktoshis = 0; if ( ASSETCHAINS_COMMISSION != 0 ) { - if ( (checktoshis= komodo_checkcommission(&block,height)) < 0 ) + if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) return(-1); } else From dc241f13d0460b094f911d0f58d5b04325e72d7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 05:30:21 -1100 Subject: [PATCH 15/19] Special case ht.1 --- src/komodo_gateway.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 55ab8b477..3b2922a7b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -744,7 +744,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim else { checktoshis = 0; - if ( ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_COMMISSION != 0 && height > 1 ) { if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) return(-1); diff --git a/src/miner.cpp b/src/miner.cpp index c789eb41d..081796aaa 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -440,7 +440,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); From c9855c14864df71b7cfc332c1af02b9941c67137 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 08:34:47 -1100 Subject: [PATCH 16/19] Height 1 exclusion -ac_pubkey --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b48c40442..5b19dfb6f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1364,8 +1364,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } - if ( komodo_checkcommission(pblock,height) < 0 ) - return(-1); + else + { + if ( komodo_checkcommission(pblock,height) < 0 ) + return(-1); + } } //fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed); if ( failed != 0 && possible == 0 && notaryid < 0 ) From 44b541d92fd5f84a7c1470836d38e72e8b44b03f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 10:52:43 -1100 Subject: [PATCH 17/19] Add VRSC to assetchains.old --- src/assetchains.old | 65 +-------------------------------------------- 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/src/assetchains.old b/src/assetchains.old index cf46922de..af9361746 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -34,68 +34,5 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & -#sleep $delay +~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & -#./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 & From b6e71fe96c8bc1518ab58a8c48f488095de07e5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 12:30:16 -1100 Subject: [PATCH 18/19] Encode Ccid into upper MoMdepth --- src/komodo.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d01de9553..efb59dee1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -113,7 +113,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) ) errs++; if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) - printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth); + printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else { @@ -258,7 +258,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) ) errs++; if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) - printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth); + printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else { @@ -480,7 +480,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); if ( sp != 0 ) { - if ( sp->MoMdepth > 0 && sp->MoM != zero ) + if ( sp->MoMdepth != 0 && sp->MoM != zero ) fputc('M',fp); else fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) @@ -491,7 +491,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) errs++; - if ( sp->MoMdepth > 0 && sp->MoM != zero ) + if ( sp->MoMdepth != 0 && sp->MoM != zero ) { if ( fwrite(&sp->MoM,1,sizeof(sp->MoM),fp) != sizeof(sp->MoM) ) errs++; @@ -641,10 +641,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); len += iguana_rwnum(0,&scriptbuf[len],sizeof(MoMdepth),(uint8_t *)&MoMdepth); ccdata.MoMdata.MoM = MoM; - ccdata.MoMdata.MoMdepth = MoMdepth; + ccdata.MoMdata.MoMdepth = MoMdepth & 0xffff; if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen ) { len += iguana_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid); + if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) + fprintf(stderr,"%s CCid mismatch %u != %u\n",ASSETCHAINS_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); ccdata.len = sizeof(ccdata.CCid); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { @@ -670,7 +672,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else ccdata.len = MoMoMdata.len = 0; } } - if ( MoM == zero || MoMdepth > *notarizedheightp || MoMdepth < 0 ) + if ( MoM == zero || (MoMdepth&0xffff) > *notarizedheightp || (MoMdepth&0xffff) < 0 ) { memset(&MoM,0,sizeof(MoM)); MoMdepth = 0; @@ -679,7 +681,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata); if ( matched != 0 ) - printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth); + printf("[%s] matched.%d VALID (%s) MoM.%s [%d] CCid.%u\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } if ( MoMoMdata.pairs != 0 ) free(MoMoMdata.pairs); @@ -693,7 +695,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; - if ( MoM != zero && MoMdepth > 0 ) + if ( MoM != zero && (MoMdepth&0xffff) > 0 ) { sp->MoM = MoM; sp->MoMdepth = MoMdepth; From 1b9f98cd1980493f995c5c1bef0f12d8b81c0397 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 12:57:21 -1100 Subject: [PATCH 19/19] Truncate MoMdepth --- src/komodo_bitcoind.h | 2 +- src/komodo_ccdata.h | 1 + src/komodo_notary.h | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5b19dfb6f..24f510b8b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -932,7 +932,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in memset(MoMp,0,sizeof(*MoMp)); memset(kmdtxidp,0,sizeof(*kmdtxidp)); *notarized_heightp = 0; - if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht ) + if ( depth != 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht ) { *MoMp = MoM; *notarized_heightp = notarized_ht; diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 058e38cee..6e7d0fabe 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -45,6 +45,7 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count) uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth) { static uint256 zero; bits256 MoM,*tree; CBlockIndex *pindex; int32_t i; + MoMdepth &= 0xffff; if ( MoMdepth >= height ) return(zero); tree = (bits256 *)calloc(MoMdepth * 3,sizeof(*tree)); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 25a03f83b..f83f85afe 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -392,7 +392,7 @@ struct notarized_checkpoint *komodo_npptr(int32_t height) for (i=sp->NUM_NPOINTS-1; i>=0; i--) { np = &sp->NPOINTS[i]; - if ( np->MoMdepth > 0 && height > np->notarized_height-np->MoMdepth && height <= np->notarized_height ) + if ( np->MoMdepth != 0 && height > np->notarized_height-(np->MoMdepth&0xffff) && height <= np->notarized_height ) return(np); } } @@ -447,7 +447,7 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in *MoMoMdepthp = np->MoMoMdepth; *kmdstartip = np->kmdstarti; *kmdendip = np->kmdendi; - return(np->MoMdepth); + return(np->MoMdepth & 0xffff); } *notarized_htp = *MoMoMoffsetp = *MoMoMdepthp = *kmdstartip = *kmdendip = 0; memset(MoMp,0,sizeof(*MoMp));