From 435454954488472b9f3a96c4eb0cd2436f53267b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 14 Dec 2018 17:36:15 +0800 Subject: [PATCH 1/3] Add ac_period --- src/komodo_bitcoind.h | 35 +++++++++++++++++++---------------- src/komodo_globals.h | 11 +++++------ src/komodo_utils.h | 13 +++++++++---- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c99a5f1a6..9ec1b20e8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -167,7 +167,7 @@ try_again: curl_handle = curl_easy_init(); init_string(&s); headers = curl_slist_append(0,"Expect:"); - + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); @@ -196,7 +196,7 @@ try_again: bracket0 = (char *)"["; bracket1 = (char *)"]"; } - + databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); @@ -236,7 +236,7 @@ try_again: free(s.ptr); sleep((1<= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] */ +extern int32_t ASSETCHAINS_FOUNDERS_PERIOD; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); @@ -1123,11 +1124,14 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) { nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); - return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); - n = pblock->vtx[0].vout.size(); - for (j=0; jvtx[0].vout[j].nValue; + commission = ((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); + if ( ASSETCHAINS_FOUNDERS_PERIOD != 0 ) + { + if ( height % ASSETCHAINS_FOUNDERS_PERIOD == 0 ) + commission = commission * ASSETCHAINS_FOUNDERS_PERIOD; + else + commission = 0; + } } else { @@ -1141,9 +1145,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } - //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); if ( commission < 10000 ) commission = 0; return(commission); @@ -1545,7 +1548,7 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) { fprintf(stderr,"ERROR: chain not fully loaded or invalid PoS block %s - no past block found\n",blkHash.ToString().c_str()); } - else + else #ifndef KOMODO_ZCASH if (!GetTransaction(txid, tx, Params().GetConsensus(), blkHash, true)) #else @@ -1578,7 +1581,7 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) { BlockMap::const_iterator it = mapBlockIndex.find(blkHash); if ((it == mapBlockIndex.end()) || - !(pastBlockIndex = it->second) || + !(pastBlockIndex = it->second) || (height - pastBlockIndex->GetHeight()) < VERUS_MIN_STAKEAGE) { fprintf(stderr,"ERROR: invalid PoS block %s - stake source too new or not found\n",blkHash.ToString().c_str()); @@ -1695,7 +1698,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) // fprintf(stderr,"%02x",script[i]); //fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); return(-1); - + } if ( pblock->vtx[0].vout[1].nValue != checktoshis ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2590a4a21..0c69322e3 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS_PERIOD; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; @@ -131,7 +131,7 @@ int64_t komodo_current_supply(uint32_t nHeight) if ( (baseid = komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 ) cur_money = ASSETCHAINS_GENESISTXVAL + ASSETCHAINS_SUPPLY + nHeight * ASSETCHAINS_REWARD[0] / SATOSHIDEN; - else + else { // figure out max_money by adding up supply to a maximum of 10,000,000 blocks cur_money = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + (ASSETCHAINS_MAGIC & 0xffffff) + ASSETCHAINS_GENESISTXVAL; @@ -144,7 +144,7 @@ int64_t komodo_current_supply(uint32_t nHeight) for ( int j = 0; j <= ASSETCHAINS_LASTERA; j++ ) { // if any condition means we have no more rewards, break - if (j != 0 && (nHeight <= ASSETCHAINS_ENDSUBSIDY[j - 1] || (ASSETCHAINS_ENDSUBSIDY[j - 1] == 0 && + if (j != 0 && (nHeight <= ASSETCHAINS_ENDSUBSIDY[j - 1] || (ASSETCHAINS_ENDSUBSIDY[j - 1] == 0 && (ASSETCHAINS_REWARD[j] == 0 && (j == ASSETCHAINS_LASTERA || ASSETCHAINS_DECAY[j] != SATOSHIDEN))))) break; @@ -180,7 +180,7 @@ int64_t komodo_current_supply(uint32_t nHeight) lowestSubsidy = 0; } else - { + { // Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0 subsidyDifference = reward - ASSETCHAINS_REWARD[j + 1]; if (subsidyDifference < 0) @@ -234,7 +234,7 @@ int64_t komodo_current_supply(uint32_t nHeight) // if negative slope, the minor triangle is the full number of steps, as the highest // level step is full. lowest subsidy is just the lowest so far lowestSubsidy = reward - (stepDifference * nSteps); - + // add the step triangles, one per step cur_money += stepTriangle * nSteps; @@ -261,4 +261,3 @@ int64_t komodo_current_supply(uint32_t nHeight) } return((int64_t)(cur_money + (cur_money * ASSETCHAINS_COMMISSION))); } - diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0b6704752..9e8856dae 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1068,7 +1068,7 @@ uint64_t komodo_block_prg(uint32_t nHeight) // given a block height, this returns the unlock time for that block height, derived from // the ASSETCHAINS_MAGIC number as well as the block height, providing different random numbers -// for corresponding blocks across chains, but the same sequence in each chain +// for corresponding blocks across chains, but the same sequence in each chain int64_t komodo_block_unlocktime(uint32_t nHeight) { uint64_t fromTime, toTime, unlocktime; @@ -1604,7 +1604,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) subsidyDifference = subsidy; } else - { + { // Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0 subsidyDifference = subsidy - ASSETCHAINS_REWARD[curEra + 1]; if (subsidyDifference < 0) @@ -1770,6 +1770,8 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); + ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); + if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; @@ -1777,7 +1779,7 @@ void komodo_args(char *argv0) // other values if ( (ASSETCHAINS_LWMAPOS = GetArg("-ac_veruspos",0)) != 0 ) ASSETCHAINS_LWMAPOS = 50; - + ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) { @@ -1870,7 +1872,11 @@ void komodo_args(char *argv0) val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) + { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); + if ( ASSETCHAINS_FOUNDERS_PERIOD != 0 ) + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_PERIOD),(void *)&ASSETCHAINS_FOUNDERS_PERIOD); + } if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); } @@ -2051,4 +2057,3 @@ void komodo_prefetch(FILE *fp) } fseek(fp,fpos,SEEK_SET); } - From bbb4d05af522b5312d05ab2ef6566ce552d8f735 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 14 Dec 2018 17:43:33 +0800 Subject: [PATCH 2/3] fix formatting --- src/komodo_utils.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9e8856dae..2a93d261c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1770,7 +1770,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); - ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); + ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; @@ -1872,13 +1872,13 @@ void komodo_args(char *argv0) val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) - { + { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); - if ( ASSETCHAINS_FOUNDERS_PERIOD != 0 ) - extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_PERIOD),(void *)&ASSETCHAINS_FOUNDERS_PERIOD); - } + if ( ASSETCHAINS_FOUNDERS_PERIOD != 0 ) + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_PERIOD),(void *)&ASSETCHAINS_FOUNDERS_PERIOD); + } if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) - extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); + extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); } addn = GetArg("-seednode",""); From 9d9974442de11a7ee8d0483159c80dc6a6cfe150 Mon Sep 17 00:00:00 2001 From: blackjok3rtt <30971146+blackjok3rtt@users.noreply.github.com> Date: Fri, 14 Dec 2018 17:49:23 +0800 Subject: [PATCH 3/3] fix formatting again... --- src/komodo_utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2a93d261c..dd133cd02 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1872,11 +1872,11 @@ void komodo_args(char *argv0) val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) - { + { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); - if ( ASSETCHAINS_FOUNDERS_PERIOD != 0 ) - extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_PERIOD),(void *)&ASSETCHAINS_FOUNDERS_PERIOD); - } + if ( ASSETCHAINS_FOUNDERS_PERIOD != 0 ) + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_PERIOD),(void *)&ASSETCHAINS_FOUNDERS_PERIOD); + } if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); }