]>
Commit | Line | Data |
---|---|---|
d019c447 | 1 | /****************************************************************************** |
2 | * Copyright © 2014-2016 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 | ******************************************************************************/ | |
2ea62dae | 15 | |
1e9d15c6 | 16 | const char *Notaries_genesis[][2] = |
2ea62dae | 17 | { |
18 | { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, | |
19 | { "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, | |
20 | { "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" }, | |
21 | { "crackers_EU", "0340c66cf2c41c41efb420af57867baa765e8468c12aa996bfd816e1e07e410728" }, | |
22 | { "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" }, | |
23 | { "locomb_EU", "025c6d26649b9d397e63323d96db42a9d3caad82e1d6076970efe5056c00c0779b" }, | |
24 | { "fullmoon_AE", "0204a908350b8142698fdb6fabefc97fe0e04f537adc7522ba7a1e8f3bec003d4a" }, | |
25 | { "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" }, | |
26 | { "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, | |
27 | { "crackers_NA", "029e1c01131974f4cd3f564cc0c00eb87a0f9721043fbc1ca60f9bd0a1f73f64a1" }, | |
28 | { "proto_EU", "03681ffdf17c8f4f0008cefb7fa0779c5e888339cdf932f0974483787a4d6747c1" }, | |
29 | { "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, | |
30 | { "farl4web_EU", "035caa40684ace968677dca3f09098aa02b70e533da32390a7654c626e0cf908e1" }, | |
31 | { "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" }, | |
32 | { "traderbill_EU", "03196e8de3e2e5d872f31d79d6a859c8704a2198baf0af9c7b21e29656a7eb455f" }, | |
33 | { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, | |
34 | { "titomane_EU", "03517fcac101fed480ae4f2caf775560065957930d8c1facc83e30077e45bdd199" }, | |
35 | { "supernet_AE", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" }, | |
36 | { "supernet_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" }, | |
37 | { "supernet_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" }, | |
38 | { "yassin_EU", "033fb7231bb66484081952890d9a03f91164fb27d392d9152ec41336b71b15fbd0" }, | |
39 | { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" }, | |
40 | { "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" }, | |
41 | { "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, | |
42 | { "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" }, | |
43 | { "rnr_EU", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" }, | |
44 | { "crackers_SH", "02313d72f9a16055737e14cfc528dcd5d0ef094cfce23d0348fe974b6b1a32e5f0" }, | |
45 | { "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" }, | |
46 | { "polycryptoblock_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" }, | |
47 | { "titomane_NA", "0387046d9745414fb58a0fa3599078af5073e10347e4657ef7259a99cb4f10ad47" }, | |
48 | { "titomane_AE", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" }, | |
49 | { "kolo_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" }, | |
50 | { "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" }, | |
51 | { "eclips_EU", "0339369c1f5a2028d44be7be6f8ec3b907fdec814f87d2dead97cab4edb71a42e9" }, | |
52 | { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, | |
53 | }; | |
54 | ||
3eea72f2 | 55 | void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) |
56 | { | |
57 | struct nutxo_entry *np; | |
58 | if ( numvouts > 1 && notaryid < 64 ) | |
59 | { | |
60 | pthread_mutex_lock(&komodo_mutex); | |
61 | np = (struct nutxo_entry *)calloc(1,sizeof(*np)); | |
62 | np->height = height; | |
63 | np->txhash = txhash; | |
64 | np->voutmask = voutmask; | |
65 | np->notaryid = notaryid; | |
66 | HASH_ADD_KEYPTR(hh,NUTXOS,&np->txhash,sizeof(np->txhash),np); | |
1e9d15c6 | 67 | //printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask); |
3eea72f2 | 68 | Num_nutxos++; |
69 | pthread_mutex_unlock(&komodo_mutex); | |
70 | } | |
71 | } | |
72 | ||
73 | int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout) | |
74 | { | |
75 | struct nutxo_entry *np; | |
76 | pthread_mutex_lock(&komodo_mutex); | |
77 | HASH_FIND(hh,NUTXOS,&txhash,sizeof(txhash),np); | |
78 | pthread_mutex_unlock(&komodo_mutex); | |
79 | if ( np != 0 && ((1LL << vout) & np->voutmask) != 0 ) | |
80 | return(np->notaryid); | |
81 | return(-1); | |
82 | } | |
83 | ||
1e9d15c6 | 84 | int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) |
85 | { | |
86 | int32_t htind,numnotaries,i,wt = 0; | |
b1c130e3 | 87 | if ( ASSETCHAINS_SYMBOL[0] != 0 ) |
88 | return(2); | |
27fa4f8c | 89 | htind = height / KOMODO_ELECTION_GAP; |
1e9d15c6 | 90 | numnotaries = Pubkeys[htind].numnotaries; |
91 | for (i=0; i<numnotaries; i++) | |
92 | if ( ((1LL << i) & signedmask) != 0 ) | |
93 | wt++; | |
94 | if ( wt > (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) ) | |
95 | return(1); | |
96 | else return(0); | |
97 | } | |
98 | ||
99 | int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) | |
100 | { | |
101 | int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; | |
27fa4f8c | 102 | htind = height / KOMODO_ELECTION_GAP; |
1e9d15c6 | 103 | pthread_mutex_lock(&komodo_mutex); |
ef5b15b0 | 104 | n = Pubkeys[htind].numnotaries; |
1e9d15c6 | 105 | HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp) |
106 | { | |
107 | if ( kp->notaryid < n ) | |
108 | { | |
109 | mask |= (1LL << kp->notaryid); | |
110 | memcpy(pubkeys[kp->notaryid],kp->pubkey,33); | |
98622aa7 | 111 | } else printf("illegal notaryid.%d vs n.%d\n",kp->notaryid,n); |
1e9d15c6 | 112 | } |
113 | pthread_mutex_unlock(&komodo_mutex); | |
114 | if ( mask == ((1LL << n)-1) ) | |
115 | return(n); | |
116 | printf("error retrieving notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); | |
117 | return(-1); | |
118 | } | |
119 | ||
c75c18fc | 120 | void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) |
3eea72f2 | 121 | { |
df027c81 | 122 | static int32_t hwmheight; |
e4e76989 | 123 | int32_t k,i,htind,nonz,height; struct knotary_entry *kp; struct knotaries_entry N; |
c75c18fc | 124 | if ( Pubkeys == 0 ) |
125 | Pubkeys = (struct knotaries_entry *)calloc(KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP,sizeof(*Pubkeys)); | |
3eea72f2 | 126 | memset(&N,0,sizeof(N)); |
97417354 | 127 | if ( height > 0 ) |
128 | { | |
c75c18fc | 129 | height = (origheight + KOMODO_ELECTION_GAP/2); |
97417354 | 130 | height /= KOMODO_ELECTION_GAP; |
131 | height = ((height + 1) * KOMODO_ELECTION_GAP); | |
132 | htind = (height / KOMODO_ELECTION_GAP); | |
c75c18fc | 133 | printf("htind.%d activation %d from %d\n",htind,height,origheight); |
97417354 | 134 | } else htind = 0; |
3eea72f2 | 135 | pthread_mutex_lock(&komodo_mutex); |
136 | for (k=0; k<num; k++) | |
137 | { | |
138 | kp = (struct knotary_entry *)calloc(1,sizeof(*kp)); | |
139 | memcpy(kp->pubkey,pubkeys[k],33); | |
140 | kp->notaryid = k; | |
141 | HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); | |
27a7b467 | 142 | //if ( height > 0 ) |
7a4c01c9 | 143 | { |
144 | for (i=0; i<33; i++) | |
145 | printf("%02x",pubkeys[k][i]); | |
bf484c7a | 146 | printf(" notarypubs.[%d] ht.%d active at %d\n",k,height,htind*KOMODO_ELECTION_GAP); |
7a4c01c9 | 147 | } |
3eea72f2 | 148 | } |
149 | N.numnotaries = num; | |
97417354 | 150 | for (i=htind; i<sizeof(Pubkeys)/sizeof(*Pubkeys); i++) |
3eea72f2 | 151 | { |
2a881c3e | 152 | if ( Pubkeys[i].height != 0 && height < hwmheight ) |
153 | break; | |
3eea72f2 | 154 | Pubkeys[i] = N; |
155 | Pubkeys[i].height = i * KOMODO_ELECTION_GAP; | |
156 | } | |
157 | pthread_mutex_unlock(&komodo_mutex); | |
2a881c3e | 158 | if ( height > hwmheight ) |
159 | hwmheight = height; | |
3eea72f2 | 160 | } |
161 | ||
162 | int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) | |
163 | { | |
164 | // -1 if not notary, 0 if notary, 1 if special notary | |
1e9d15c6 | 165 | struct knotary_entry *kp; int32_t numnotaries,htind,modval = -1; |
3eea72f2 | 166 | *notaryidp = -1; |
050cb9a3 | 167 | if ( height < 0 || height >= KOMODO_MAXBLOCKS ) |
b5f08ccf | 168 | return(-1); |
27fa4f8c | 169 | htind = height / KOMODO_ELECTION_GAP; |
3eea72f2 | 170 | pthread_mutex_lock(&komodo_mutex); |
1e9d15c6 | 171 | HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); |
3eea72f2 | 172 | pthread_mutex_unlock(&komodo_mutex); |
173 | if ( kp != 0 ) | |
174 | { | |
1e9d15c6 | 175 | if ( (numnotaries= Pubkeys[htind].numnotaries) > 0 ) |
3eea72f2 | 176 | { |
177 | *notaryidp = kp->notaryid; | |
178 | modval = ((height % numnotaries) == kp->notaryid); | |
179 | //printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval); | |
180 | } else printf("unexpected zero notaries at height.%d\n",height); | |
181 | } | |
182 | //int32_t i; for (i=0; i<33; i++) | |
183 | // printf("%02x",pubkey33[i]); | |
184 | //printf(" ht.%d notary.%d special.%d\n",height,*notaryidp,modval); | |
185 | return(modval); | |
186 | } | |
187 | ||
c75c18fc | 188 | void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid) |
3eea72f2 | 189 | { |
190 | struct notarized_checkpoint *np; | |
191 | if ( notarized_height > nHeight ) | |
192 | { | |
193 | printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); | |
194 | return; | |
195 | } | |
196 | NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS)); | |
197 | np = &NPOINTS[NUM_NPOINTS++]; | |
198 | memset(np,0,sizeof(*np)); | |
199 | np->nHeight = nHeight; | |
c75c18fc | 200 | sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height; |
201 | sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash; | |
202 | sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; | |
203 | } | |
204 | ||
5a630fc3 | 205 | struct komodo_state *komodo_stateptr(char *symbol,char *dest); |
c75c18fc | 206 | int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) |
207 | { | |
208 | char symbol[16],dest[16]; struct komodo_state *sp; | |
209 | if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) | |
210 | { | |
211 | *hashp = sp->NOTARIZED_HASH; | |
212 | *txidp = sp->NOTARIZED_DESTTXID; | |
213 | return(sp->NOTARIZED_HEIGHT); | |
214 | } | |
215 | else | |
216 | { | |
217 | memset(hashp,0,sizeof(*hashp)); | |
218 | memset(txidp,0,sizeof(*txidp)); | |
219 | return(0); | |
220 | } | |
3eea72f2 | 221 | } |
222 | ||
223 | int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) | |
224 | { | |
225 | struct notarized_checkpoint *np = 0; int32_t i; | |
226 | if ( NUM_NPOINTS > 0 ) | |
227 | { | |
228 | for (i=0; i<NUM_NPOINTS; i++) | |
229 | { | |
230 | if ( NPOINTS[i].nHeight >= nHeight ) | |
231 | break; | |
232 | np = &NPOINTS[i]; | |
233 | } | |
234 | } | |
235 | if ( np != 0 ) | |
236 | { | |
237 | *notarized_hashp = np->notarized_hash; | |
238 | *notarized_desttxidp = np->notarized_desttxid; | |
239 | return(np->notarized_height); | |
240 | } | |
241 | memset(notarized_hashp,0,sizeof(*notarized_hashp)); | |
242 | return(0); | |
243 | } | |
3b34b59c | 244 | |
c93dc546 | 245 | void komodo_init(int32_t height) |
3b34b59c | 246 | { |
e6f6a829 | 247 | static int didinit; uint256 zero; int32_t i,k,n; uint8_t pubkeys[64][33]; |
725800f9 | 248 | if ( didinit == 0 ) |
3b34b59c | 249 | { |
725800f9 | 250 | pthread_mutex_init(&komodo_mutex,NULL); |
251 | decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); | |
4a4e912b | 252 | if ( height >= 0 ) |
3b34b59c | 253 | { |
4a4e912b | 254 | n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); |
255 | for (k=0; k<n; k++) | |
256 | { | |
257 | if ( Notaries_genesis[k][0] == 0 || Notaries_genesis[k][1] == 0 || Notaries_genesis[k][0][0] == 0 || Notaries_genesis[k][1][0] == 0 ) | |
258 | break; | |
259 | decode_hex(pubkeys[k],33,(char *)Notaries_genesis[k][1]); | |
260 | } | |
261 | komodo_notarysinit(0,pubkeys,k); | |
3b34b59c | 262 | } |
725800f9 | 263 | memset(&zero,0,sizeof(zero)); |
4a4e912b | 264 | for (i=0; i<sizeof(Minerids); i++) |
265 | Minerids[i] = -2; | |
afab4692 | 266 | didinit = 1; |
3b34b59c | 267 | } |
725800f9 | 268 | komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0); |
3b34b59c | 269 | } |
727e05f6 | 270 | |
271 | void komodo_assetchain_pubkeys(char *jsonstr) | |
272 | { | |
273 | cJSON *array; int32_t i,n; uint8_t pubkeys[64][33]; char *hexstr; | |
274 | memset(pubkeys,0,sizeof(pubkeys)); | |
275 | if ( (array= cJSON_Parse(jsonstr)) != 0 ) | |
276 | { | |
277 | if ( (n= cJSON_GetArraySize(array)) > 0 ) | |
278 | { | |
279 | for (i=0; i<n; i++) | |
280 | { | |
281 | if ( (hexstr= jstri(array,i)) != 0 && is_hexstr(hexstr,0) == 66 ) | |
6a8e70a9 | 282 | { |
727e05f6 | 283 | decode_hex(pubkeys[i],33,hexstr); |
a2ce1e0f | 284 | fprintf(stderr,"i.%d of n.%d pubkey.(%s)\n",i,n,hexstr); |
6a8e70a9 | 285 | } |
727e05f6 | 286 | else |
287 | { | |
6a8e70a9 | 288 | fprintf(stderr,"illegal hexstr.(%s) i.%d of n.%d\n",hexstr,i,n); |
727e05f6 | 289 | break; |
290 | } | |
291 | } | |
292 | if ( i == n ) | |
293 | { | |
4a4e912b | 294 | komodo_init(-1); |
727e05f6 | 295 | komodo_notarysinit(0,pubkeys,n); |
2a881c3e | 296 | //printf("initialize pubkeys[%d]\n",n); |
6a8e70a9 | 297 | } else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n); |
298 | } else fprintf(stderr,"assetchain pubkeys n.%d\n",n); | |
727e05f6 | 299 | } |
b6a7cb2c | 300 | //else if ( jsonstr != 0 ) |
301 | // fprintf(stderr,"assetchain pubkeys couldnt parse.(%s)\n",jsonstr); | |
727e05f6 | 302 | } |