]> Git Repo - VerusCoin.git/blame - src/komodo_globals.h
Optimized miner for wallet
[VerusCoin.git] / src / komodo_globals.h
CommitLineData
98f2e433 1/******************************************************************************
713c2a94 2 * Copyright © 2014-2018 The SuperNET Developers. *
98f2e433 3 * *
4 * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
5 * the top-level directory of this distribution for the individual copyright *
6 * holder information and the developer policies on copyright and licensing. *
7 * *
8 * Unless otherwise agreed in a custom licensing agreement, no part of the *
9 * SuperNET software, including this file may be copied, modified, propagated *
10 * or distributed except according to the terms contained in the LICENSE file *
11 * *
12 * Removal or modification of this copyright notice is prohibited. *
13 * *
14 ******************************************************************************/
15
5416af1d 16#include "komodo_defs.h"
17
cf53fd7c 18void komodo_prefetch(FILE *fp);
709a9861 19uint32_t komodo_heightstamp(int32_t height);
c88fa588 20void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint32_t ktime,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout,uint256 MoM,int32_t MoMdepth);
cf0ace4a 21void komodo_init(int32_t height);
51dab149 22int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
cf0ace4a 23int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp);
0ded57c8 24char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port);
cf0ace4a 25void komodo_init(int32_t height);
8683bd8d 26int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
48a3cd18 27int32_t komodo_isrealtime(int32_t *kmdheightp);
b4116bb6 28uint64_t komodo_paxtotal();
439e76ae 29int32_t komodo_longestchain();
afacf361 30uint64_t komodo_maxallowed(int32_t baseid);
c2123afe 31int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max);
cf0ace4a 32
3face669 33pthread_mutex_t komodo_mutex;
0db8cd28 34
335f2ea7 35#define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
7c130297 36#define KOMODO_ASSETCHAIN_MAXLEN 65
0db8cd28 37
0db8cd28 38struct pax_transaction *PAX;
39int32_t NUM_PRICES; uint32_t *PVALS;
40struct knotaries_entry *Pubkeys;
0db8cd28 41
2d116f01 42struct komodo_state KOMODO_STATES[34];
0db8cd28 43
7e2cbee1 44#define _COINBASE_MATURITY 100
7a90b9dd 45int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
1290fc05 46
5f63373e 47int32_t KOMODO_MININGTHREADS = 0,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;
e0f78699 48int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
10214558 49std::string VERUS_CHEATCATCHER, NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
36f9e6d6 50uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
5f63373e 51bool VERUS_MINTBLOCKS;
98f2e433 52
dfb57be5 53char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096];
346d96b9 54uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
6d2fc290 55uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT;
98f2e433 56uint32_t ASSETCHAINS_MAGIC = 2387029918;
a0dd01bc 57int64_t ASSETCHAINS_GENESISTXVAL = 5000000000;
36647d52 58
9feb4b9e 59int64_t MAX_MONEY = 200000000 * 100000000LL;
60
29bd53a1
MT
61// consensus variables for coinbase timelock control and timelock transaction support
62// time locks are specified enough to enable their use initially to lock specific coinbase transactions for emission control
63// to be verifiable, timelocks require additional data that enables them to be validated and their ownership and
64// release time determined from the blockchain. to do this, every time locked output according to this
65// spec will use an op_return with CLTV at front and anything after |OP_RETURN|PUSH of rest|OPRETTYPE_TIMELOCK|script|
0a962eb9 66#define _ASSETCHAINS_TIMELOCKOFF 0xffffffffffffffff
67uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF;
42181656 68uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0;
d121e75b 69
6b78e01d 70uint32_t ASSETCHAINS_LASTERA = 1;
26a8d194 71uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS];
98f2e433 72
42181656 73#define _ASSETCHAINS_EQUIHASH 0
74uint32_t ASSETCHAINS_NUMALGOS = 2;
75uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH;
76uint32_t ASSETCHAINS_VERUSHASH = 1;
77const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "verushash"};
4dcb64c0
MT
78uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff,0xfffffff};
79uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16};
fa7fdbc6 80uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,0x10000};
42181656 81uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH;
82
1f722359
MT
83// Verus proof of stake controls
84int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS
dbe656fe 85int32_t VERUS_BLOCK_POSUNITS = 1024; // one block is 1000 units
1fae37f6 86int32_t VERUS_MIN_STAKEAGE = 150; // 1/2 this should also be a cap on the POS averaging window, or startup could be too easy
3c8a1c9d 87int32_t VERUS_CONSECUTIVE_POS_THRESHOLD = 7;
dbe656fe 88int32_t VERUS_NOPOS_THRESHHOLD = 150; // if we have no POS blocks in this many blocks, set to default difficulty
1f722359 89
4b729ec5 90int32_t ASSETCHAINS_SAPLING;
91int32_t ASSETCHAINS_OVERWINTER;
92
94d3d09d 93uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
48d800c2 94uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10;
98f2e433 95
ab918767 96uint32_t KOMODO_INITDONE;
4d068367 97char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;
f846a857 98uint64_t PENDING_KOMODO_TX;
e28e0df9 99extern int32_t KOMODO_LOADINGBLOCKS;
9d657620 100unsigned int MAX_BLOCK_SIGOPS = 20000;
15d0fbd4 101
102struct komodo_kv *KOMODO_KV;
fb9c3652 103pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex;
48d800c2 104
105#define MAX_CURRENCIES 32
106char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies
107 "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK",
108 "KMD" };
109
110int32_t komodo_baseid(char *origbase)
111{
112 int32_t i; char base[64];
113 for (i=0; origbase[i]!=0&&i<sizeof(base); i++)
114 base[i] = toupper((int32_t)(origbase[i] & 0xff));
115 base[i] = 0;
116 for (i=0; i<=MAX_CURRENCIES; i++)
117 if ( strcmp(CURRENCIES[i],base) == 0 )
118 return(i);
119 //printf("illegal base.(%s) %s\n",origbase,base);
120 return(-1);
121}
122
123#ifndef SATOSHIDEN
124#define SATOSHIDEN ((uint64_t)100000000L)
125#endif
126int64_t komodo_current_supply(uint32_t nHeight)
127{
128 uint64_t cur_money;
129 int32_t baseid;
130
131 if ( (baseid = komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 )
e980a26d 132 cur_money = ASSETCHAINS_GENESISTXVAL + ASSETCHAINS_SUPPLY + nHeight * ASSETCHAINS_REWARD[0] / SATOSHIDEN;
48d800c2 133 else
134 {
135 // figure out max_money by adding up supply to a maximum of 10,000,000 blocks
136 cur_money = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + (ASSETCHAINS_MAGIC & 0xffffff) + ASSETCHAINS_GENESISTXVAL;
137 if ( ASSETCHAINS_LASTERA == 0 && ASSETCHAINS_REWARD[0] == 0 )
138 {
e980a26d 139 cur_money += (nHeight * 10000) / SATOSHIDEN;
48d800c2 140 }
141 else
142 {
143 for ( int j = 0; j <= ASSETCHAINS_LASTERA; j++ )
144 {
145 // if any condition means we have no more rewards, break
146 if (j != 0 && (nHeight <= ASSETCHAINS_ENDSUBSIDY[j - 1] || (ASSETCHAINS_ENDSUBSIDY[j - 1] == 0 &&
147 (ASSETCHAINS_REWARD[j] == 0 && (j == ASSETCHAINS_LASTERA || ASSETCHAINS_DECAY[j] != SATOSHIDEN)))))
148 break;
149
150 // add rewards from this era, up to nHeight
151 int64_t reward = ASSETCHAINS_REWARD[j];
152 if ( reward > 0 )
153 {
154 uint64_t lastEnd = j == 0 ? 0 : ASSETCHAINS_ENDSUBSIDY[j - 1];
155 uint64_t curEnd = ASSETCHAINS_ENDSUBSIDY[j] == 0 ? nHeight : nHeight > ASSETCHAINS_ENDSUBSIDY[j] ? ASSETCHAINS_ENDSUBSIDY[j] : nHeight;
156 uint64_t period = ASSETCHAINS_HALVING[j];
157 uint32_t nSteps = (curEnd - lastEnd) / period;
158 uint32_t modulo = (curEnd - lastEnd) % period;
159 uint64_t decay = ASSETCHAINS_DECAY[j];
160
161 // if exactly SATOSHIDEN, linear decay to zero or to next era, same as:
162 // (next_era_reward + (starting reward - next_era_reward) / 2) * num_blocks
163 if ( decay == SATOSHIDEN )
164 {
165 int64_t lowestSubsidy, subsidyDifference, stepDifference, stepTriangle;
166 int64_t denominator, modulo;
167 int32_t sign = 1;
168
169 if ( j == ASSETCHAINS_LASTERA )
170 {
171 subsidyDifference = reward;
172 lowestSubsidy = 0;
173 }
174 else
175 {
176 // Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0
177 subsidyDifference = reward - ASSETCHAINS_REWARD[j + 1];
178 if (subsidyDifference < 0)
179 {
180 sign = -1;
181 subsidyDifference *= sign;
182 lowestSubsidy = reward;
183 }
184 else
185 {
186 lowestSubsidy = ASSETCHAINS_REWARD[j + 1];
187 }
188 }
189
190 // if we have not finished the current era, we need to caluclate a total as if we are at the end, with the current
191 // subsidy. we will calculate the total of a linear era as follows. Each item represents an area calculation:
192 // a) the rectangle from 0 to the lowest reward in the era * the number of blocks
193 // b) the rectangle of the remainder of blocks from the lowest point of the era to the highest point of the era if any remainder
194 // c) the minor triangle from the start of transition from the lowest point to the start of transition to the highest point
195 // d) one halving triangle (half area of one full step)
196 //
197 // we also need:
198 // e) number of steps = (n - erastart) / halving interval
199 //
200 // the total supply from era start up to height is:
201 // a + b + c + (d * e)
202
203 // calculate amount in one step's triangular protrusion over minor triangle's hypotenuse
204 denominator = nSteps * period;
205
206 // difference of one step vs. total
207 stepDifference = (period * subsidyDifference) / denominator;
208
209 // area == coin holding of one step triangle, protruding from minor triangle's hypotenuse
210 stepTriangle = (period * stepDifference) >> 1;
211
212 // sign is negative if slope is positive (start is less than end)
213 if (sign < 0)
214 {
215 // use steps minus one for our calculations, and add the potentially partial rectangle
216 // at the end
217 cur_money += stepTriangle * (nSteps - 1);
218 cur_money += stepTriangle * (nSteps - 1) * (nSteps - 1);
219
220 // difference times number of steps is height of rectangle above lowest subsidy
221 cur_money += modulo * stepDifference * nSteps;
222 }
223 else
224 {
225 // if negative slope, the minor triangle is the full number of steps, as the highest
226 // level step is full. lowest subsidy is just the lowest so far
227 lowestSubsidy = reward - (stepDifference * nSteps);
228
229 // add the step triangles, one per step
230 cur_money += stepTriangle * nSteps;
231
232 // add the minor triangle
233 cur_money += stepTriangle * nSteps * nSteps;
234 }
235
236 // add more for the base rectangle if lowest subsidy is not 0
237 cur_money += lowestSubsidy * (curEnd - lastEnd);
238 }
239 else
240 {
241 for ( int k = lastEnd; k < curEnd; k += period )
242 {
243 cur_money += period * reward;
244 // if zero, we do straight halving
245 reward = decay ? (reward * decay) / SATOSHIDEN : reward >> 1;
246 }
247 cur_money += modulo * reward;
248 }
249 }
250 }
251 }
252 }
253 return((int64_t)(cur_money + (cur_money * ASSETCHAINS_COMMISSION) / SATOSHIDEN));
254}
255
This page took 0.30618 seconds and 4 git commands to generate.