]> Git Repo - VerusCoin.git/blob - src/komodo_globals.h
Update root chain name
[VerusCoin.git] / src / komodo_globals.h
1 /******************************************************************************
2  * Copyright © 2014-2018 The SuperNET Developers.                             *
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
16 #include "komodo_structs.h"
17
18 void komodo_prefetch(FILE *fp);
19 uint32_t komodo_heightstamp(int32_t height);
20 void 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);
21 void komodo_init(int32_t height);
22 int32_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);
23 int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp);
24 char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port);
25 void komodo_init(int32_t height);
26 int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
27 int32_t komodo_isrealtime(int32_t *kmdheightp);
28 uint64_t komodo_paxtotal();
29 int32_t komodo_longestchain();
30 uint64_t komodo_maxallowed(int32_t baseid);
31 int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max);
32
33 pthread_mutex_t komodo_mutex;
34
35 #define KOMODO_ELECTION_GAP 2000    //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
36 #define KOMODO_ASSETCHAIN_MAXLEN 65
37
38 struct pax_transaction *PAX;
39 int32_t NUM_PRICES; uint32_t *PVALS;
40 struct knotaries_entry *Pubkeys;
41
42 struct komodo_state KOMODO_STATES[34];
43
44 #define _COINBASE_MATURITY 100
45 int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
46
47 int32_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;
48 int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
49 std::string VERUS_CHEATCATCHER, NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
50 uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
51 bool VERUS_MINTBLOCKS;
52
53 char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096];
54
55 bool PBAAS_TESTMODE;
56 std::string PBAAS_HOST;
57 int32_t PBAAS_PORT;
58 std::string PBAAS_USERPASS;
59
60 uint160 ASSETCHAINS_CHAINID;
61 uint160 VERUS_CHAINID;
62 std::string VERUS_CHAINNAME;
63 uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
64 uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT;
65 uint32_t ASSETCHAINS_MAGIC = 2387029918;
66 int64_t ASSETCHAINS_GENESISTXVAL = 5000000000;
67
68 int64_t MAX_MONEY = 200000000 * 100000000LL;
69
70 // consensus variables for coinbase timelock control and timelock transaction support
71 // time locks are specified enough to enable their use initially to lock specific coinbase transactions for emission control
72 // to be verifiable, timelocks require additional data that enables them to be validated and their ownership and
73 // release time determined from the blockchain. to do this, every time locked output according to this
74 // spec will use an op_return with CLTV at front and anything after |OP_RETURN|PUSH of rest|OPRETTYPE_TIMELOCK|script|
75 #define _ASSETCHAINS_TIMELOCKOFF 0xffffffffffffffff
76 uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF;
77 int32_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0;
78
79 uint32_t ASSETCHAINS_LASTERA = 1;
80 uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS];
81
82 #define _ASSETCHAINS_EQUIHASH 0
83 uint32_t ASSETCHAINS_NUMALGOS = 2;
84 uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH;
85 uint32_t ASSETCHAINS_VERUSHASH = 1;
86 const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "verushash"};
87 uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff,0xfffffff};
88 uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16};
89 uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,0x10000};
90 uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH;
91
92 // Verus proof of stake controls
93 int32_t ASSETCHAINS_LWMAPOS = 0;        // percentage of blocks should be PoS
94 int32_t VERUS_BLOCK_POSUNITS = 1024;    // one block is 1000 units
95 int32_t VERUS_MIN_STAKEAGE = 150;       // 1/2 this should also be a cap on the POS averaging window, or startup could be too easy
96 int32_t VERUS_CONSECUTIVE_POS_THRESHOLD = 7;
97 int32_t VERUS_NOPOS_THRESHHOLD = 150;   // if we have no POS blocks in this many blocks, set to default difficulty
98 int32_t PBAAS_STARTBLOCK = 0;           // the parent blockchain must be notarized at this value in block 1 for it to be accepted
99 int32_t PBAAS_ENDBLOCK = 0;             // end of life block for the PBaaS blockchain
100
101 int32_t ASSETCHAINS_SAPLING;
102 int32_t ASSETCHAINS_OVERWINTER;
103
104 uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
105 uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10;
106
107 uint32_t KOMODO_INITDONE;
108 char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;
109 uint64_t PENDING_KOMODO_TX;
110 extern int32_t KOMODO_LOADINGBLOCKS;
111 unsigned int MAX_BLOCK_SIGOPS = 20000;
112
113 struct komodo_kv *KOMODO_KV;
114 pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex;
115
116 #define MAX_CURRENCIES 32
117 char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies
118     "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK",
119     "KMD" };
120
121 int32_t komodo_baseid(char *origbase)
122 {
123     int32_t i; char base[64];
124     for (i=0; origbase[i]!=0&&i<sizeof(base); i++)
125         base[i] = toupper((int32_t)(origbase[i] & 0xff));
126     base[i] = 0;
127     for (i=0; i<=MAX_CURRENCIES; i++)
128         if ( strcmp(CURRENCIES[i],base) == 0 )
129             return(i);
130     //printf("illegal base.(%s) %s\n",origbase,base);
131     return(-1);
132 }
133
134 #ifndef SATOSHIDEN
135 #define SATOSHIDEN ((uint64_t)100000000L)
136 #endif
137 int64_t komodo_current_supply(uint32_t nHeight)
138 {
139     uint64_t cur_money;
140     int32_t baseid;
141
142     if ( (baseid = komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 )
143         cur_money = ASSETCHAINS_GENESISTXVAL + ASSETCHAINS_SUPPLY + nHeight * ASSETCHAINS_REWARD[0] / SATOSHIDEN;
144     else 
145     {
146         // figure out max_money by adding up supply to a maximum of 10,000,000 blocks
147         cur_money = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + (ASSETCHAINS_MAGIC & 0xffffff) + ASSETCHAINS_GENESISTXVAL;
148         if ( ASSETCHAINS_LASTERA == 0 && ASSETCHAINS_REWARD[0] == 0 )
149         {
150             cur_money += (nHeight * 10000) / SATOSHIDEN;
151         }
152         else
153         {
154             for ( int j = 0; j <= ASSETCHAINS_LASTERA; j++ )
155             {
156                 // if any condition means we have no more rewards, break
157                 if (j != 0 && (nHeight <= ASSETCHAINS_ENDSUBSIDY[j - 1] || (ASSETCHAINS_ENDSUBSIDY[j - 1] == 0 && 
158                     (ASSETCHAINS_REWARD[j] == 0 && (j == ASSETCHAINS_LASTERA || ASSETCHAINS_DECAY[j] != SATOSHIDEN)))))
159                     break;
160
161                 // add rewards from this era, up to nHeight
162                 int64_t reward = ASSETCHAINS_REWARD[j];
163                 if ( reward > 0 )
164                 {
165                     uint64_t lastEnd = j == 0 ? 0 : ASSETCHAINS_ENDSUBSIDY[j - 1];
166                     uint64_t curEnd = ASSETCHAINS_ENDSUBSIDY[j] == 0 ? nHeight : nHeight > ASSETCHAINS_ENDSUBSIDY[j] ? ASSETCHAINS_ENDSUBSIDY[j] : nHeight;
167                     uint64_t period = ASSETCHAINS_HALVING[j];
168                     if (period == 0)
169                     {
170                         period = curEnd - lastEnd;
171                     }
172                     uint32_t nSteps = (curEnd - lastEnd) / period;
173                     uint32_t modulo = (curEnd - lastEnd) % period;
174                     uint64_t decay = ASSETCHAINS_DECAY[j];
175
176                     // if exactly SATOSHIDEN, linear decay to zero or to next era, same as:
177                     // (next_era_reward + (starting reward - next_era_reward) / 2) * num_blocks
178                     if ( decay == SATOSHIDEN )
179                     {
180                         int64_t lowestSubsidy, subsidyDifference, stepDifference, stepTriangle;
181                         int64_t denominator, modulo;
182                         int32_t sign = 1;
183
184                         if ( j == ASSETCHAINS_LASTERA )
185                         {
186                             subsidyDifference = reward;
187                             lowestSubsidy = 0;
188                         }
189                         else
190                         {    
191                             // Ex: -ac_eras=3 -ac_reward=0,384,24 -ac_end=1440,260640,0 -ac_halving=1,1440,2103840 -ac_decay 100000000,97750000,0
192                             subsidyDifference = reward - ASSETCHAINS_REWARD[j + 1];
193                             if (subsidyDifference < 0)
194                             {
195                                 sign = -1;
196                                 subsidyDifference *= sign;
197                                 lowestSubsidy = reward;
198                             }
199                             else
200                             {
201                                 lowestSubsidy = ASSETCHAINS_REWARD[j + 1];
202                             }
203                         }
204
205                         // if we have not finished the current era, we need to caluclate a total as if we are at the end, with the current
206                         // subsidy. we will calculate the total of a linear era as follows. Each item represents an area calculation:
207                         // a) the rectangle from 0 to the lowest reward in the era * the number of blocks
208                         // 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
209                         // c) the minor triangle from the start of transition from the lowest point to the start of transition to the highest point
210                         // d) one halving triangle (half area of one full step)
211                         //
212                         // we also need:
213                         // e) number of steps = (n - erastart) / halving interval
214                         //
215                         // the total supply from era start up to height is:
216                         // a + b + c + (d * e)
217
218                         // calculate amount in one step's triangular protrusion over minor triangle's hypotenuse
219                         denominator = nSteps * period;
220
221                         // difference of one step vs. total
222                         stepDifference = (period * subsidyDifference) / denominator;
223
224                         // area == coin holding of one step triangle, protruding from minor triangle's hypotenuse
225                         stepTriangle = (period * stepDifference) >> 1;
226
227                         // sign is negative if slope is positive (start is less than end)
228                         if (sign < 0)
229                         {
230                             // use steps minus one for our calculations, and add the potentially partial rectangle
231                             // at the end
232                             cur_money += stepTriangle * (nSteps - 1);
233                             cur_money += stepTriangle * (nSteps - 1) * (nSteps - 1);
234
235                             // difference times number of steps is height of rectangle above lowest subsidy
236                             cur_money += modulo * stepDifference * nSteps;
237                         }
238                         else
239                         {
240                             // if negative slope, the minor triangle is the full number of steps, as the highest
241                             // level step is full. lowest subsidy is just the lowest so far
242                             lowestSubsidy = reward - (stepDifference * nSteps);
243                             
244                             // add the step triangles, one per step
245                             cur_money += stepTriangle * nSteps;
246
247                             // add the minor triangle
248                             cur_money += stepTriangle * nSteps * nSteps;
249                         }
250
251                         // add more for the base rectangle if lowest subsidy is not 0
252                         cur_money += lowestSubsidy * (curEnd - lastEnd);
253                     }
254                     else
255                     {
256                         if (period == 0)
257                         {
258
259                         }
260                         else
261                         {
262                             /* code */
263                         }
264                         
265                         for ( int k = lastEnd; k < curEnd; k += period )
266                         {
267                             cur_money += period * reward;
268                             // if zero, we do straight halving
269                             reward = decay ? (reward * decay) / SATOSHIDEN : reward >> 1;
270                         }
271                         cur_money += modulo * reward;
272                     }
273                 }
274             }
275         }
276     }
277     return((int64_t)(cur_money + (cur_money * ASSETCHAINS_COMMISSION) / SATOSHIDEN));
278 }
279
This page took 0.040156 seconds and 4 git commands to generate.