-
Notifications
You must be signed in to change notification settings - Fork 17
/
block_verifiers_functions.c
executable file
·2468 lines (2046 loc) · 116 KB
/
block_verifiers_functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <time.h>
#include <mongoc/mongoc.h>
#include <bson/bson.h>
#include "define_macro_functions.h"
#include "define_macros.h"
#include "define_macros_test.h"
#include "structures.h"
#include "variables.h"
#include "blockchain_functions.h"
#include "block_verifiers_functions.h"
#include "block_verifiers_synchronize_check_functions.h"
#include "block_verifiers_synchronize_server_functions.h"
#include "block_verifiers_synchronize_functions.h"
#include "block_verifiers_thread_server_functions.h"
#include "block_verifiers_update_functions.h"
#include "database_functions.h"
#include "count_database_functions.h"
#include "insert_database_functions.h"
#include "read_database_functions.h"
#include "update_database_functions.h"
#include "delete_database_functions.h"
#include "file_functions.h"
#include "network_daemon_functions.h"
#include "network_functions.h"
#include "network_security_functions.h"
#include "network_wallet_functions.h"
#include "organize_functions.h"
#include "string_functions.h"
#include "thread_functions.h"
#include "convert.h"
#include "vrf.h"
#include "crypto_vrf.h"
#include "VRF_functions.h"
#include "sha512EL.h"
/*
-----------------------------------------------------------------------------------------------------------
Functions
-----------------------------------------------------------------------------------------------------------
*/
int start_new_round(void)
{
// Variables
char data[SMALL_BUFFER_SIZE];
char data2[SMALL_BUFFER_SIZE];
time_t current_date_and_time;
struct tm current_UTC_date_and_time;
size_t count;
int count2;
// threads
pthread_t thread_id;
// define macros
#define START_NEW_ROUND_ERROR(settings) \
memcpy(error_message.function[error_message.total],"start_new_round",15); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
sleep(1); \
return 0;
#define RESET_VARIABLES \
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++) \
{ \
memset(VRF_data.block_verifiers_vrf_secret_key_data[count],0,strlen(VRF_data.block_verifiers_vrf_secret_key_data[count])); \
memset(VRF_data.block_verifiers_vrf_secret_key[count],0,strlen((const char*)VRF_data.block_verifiers_vrf_secret_key[count])); \
memset(VRF_data.block_verifiers_vrf_public_key_data[count],0,strlen(VRF_data.block_verifiers_vrf_public_key_data[count])); \
memset(VRF_data.block_verifiers_vrf_public_key[count],0,strlen((const char*)VRF_data.block_verifiers_vrf_public_key[count])); \
memset(VRF_data.block_verifiers_random_data[count],0,strlen(VRF_data.block_verifiers_random_data[count])); \
memset(VRF_data.block_blob_signature[count],0,strlen(VRF_data.block_blob_signature[count])); \
} \
memset(VRF_data.vrf_secret_key_data,0,strlen(VRF_data.vrf_secret_key_data)); \
memset(VRF_data.vrf_secret_key,0,strlen((const char*)VRF_data.vrf_secret_key)); \
memset(VRF_data.vrf_public_key_data,0,strlen(VRF_data.vrf_public_key_data)); \
memset(VRF_data.vrf_public_key,0,strlen((const char*)VRF_data.vrf_public_key)); \
memset(VRF_data.vrf_alpha_string_data,0,strlen(VRF_data.vrf_alpha_string_data)); \
memset(VRF_data.vrf_alpha_string,0,strlen((const char*)VRF_data.vrf_alpha_string)); \
memset(VRF_data.vrf_proof_data,0,strlen(VRF_data.vrf_proof_data)); \
memset(VRF_data.vrf_proof,0,strlen((const char*)VRF_data.vrf_proof)); \
memset(VRF_data.vrf_beta_string_data,0,strlen(VRF_data.vrf_beta_string_data)); \
memset(VRF_data.vrf_beta_string,0,strlen((const char*)VRF_data.vrf_beta_string)); \
memset(VRF_data.reserve_bytes_data_hash,0,strlen(VRF_data.reserve_bytes_data_hash)); \
memset(VRF_data.block_blob,0,strlen(VRF_data.block_blob));
memset(data,0,sizeof(data));
memset(data2,0,sizeof(data2));
// check if there are any updates that need to be downloaded, and if so update and wait 1 hour so all block verifiers restart at the same time
/*if (production_settings == 1)
{
check_for_updates();
}*/
// get the delegates online status
if (registration_settings == 0)
{
color_print("Getting the delegates online status","blue");
get_delegates_online_status();
}
// wait so everyone has got the online status
sync_block_verifiers_minutes_and_seconds(0,20);
// start a new round
if (get_current_block_height(current_block_height) == 0)
{
START_NEW_ROUND_ERROR("Could not get the current block height");
}
// check if it is running in registration mode only
if (registration_settings == 0)
{
memcpy(data,"A new round is starting for block ",34);
memcpy(data+34,current_block_height,strnlen(current_block_height,sizeof(current_block_height)));
print_start_message(current_date_and_time,current_UTC_date_and_time,data,data2);
}
// get the current block height
sscanf(current_block_height,"%zu", &count);
// reload the initial previous, current and next block verifiers list if its the first block or if you had to restart
if (count <= XCASH_PROOF_OF_STAKE_BLOCK_HEIGHT || sync_previous_current_next_block_verifiers_settings == 1)
{
sync_previous_current_next_block_verifiers_settings = 0;
count2 = get_network_data_nodes_online_status();
sync_all_block_verifiers_list(0,count2);
}
// check if it is running in registration mode only
if (registration_settings == 1)
{
color_print("Registration mode is on, checking to make sure all network data nodes databases are synced","yellow");
sync_network_data_nodes_database();
// update the previous, current and next block verifiers after syncing the database
if (update_block_verifiers_list() == 0)
{
START_NEW_ROUND_ERROR("Could not update the previous, current and next block verifiers list");
}
// start the reserve proofs timer
pthread_create(&thread_id, NULL, &check_reserve_proofs_timer_thread, NULL);
pthread_detach(thread_id);
sync_block_verifiers_minutes_and_seconds((BLOCK_TIME-1),SUBMIT_NETWORK_BLOCK_TIME_SECONDS);
// check if the start time is 1 hour away
get_current_UTC_time(current_date_and_time,current_UTC_date_and_time);
if (current_UTC_date_and_time.tm_year == block_height_start_time.block_height_start_time_year && current_UTC_date_and_time.tm_mon == block_height_start_time.block_height_start_time_month && current_UTC_date_and_time.tm_mday == block_height_start_time.block_height_start_time_day && current_UTC_date_and_time.tm_hour == block_height_start_time.block_height_start_time_hour-1 && abs(current_UTC_date_and_time.tm_min - block_height_start_time.block_height_start_time_minute) <= 5)
{
color_print("Stoping registration mode","green");
registration_settings = 0;
return 10;
}
return 2;
}
if (count == XCASH_PROOF_OF_STAKE_BLOCK_HEIGHT)
{
// this is the first block of the network
color_print("The current block is the first block on the network, meaning that the main network node will create this block","yellow");
RESET_VARIABLES;
// set the main_network_data_node_create_block so the main network data node can create the block
main_network_data_node_create_block = 1;
if (start_current_round_start_blocks() == 0)
{
START_NEW_ROUND_ERROR("start_current_round_start_blocks error");
}
}
else
{
// this is a X-CASH proof of stake block so this is not the start blocks of the network
if (strncmp(VRF_data.block_blob,"",1) != 0)
{
// update all of the databases
color_print("Updating the previous rounds data in the databases","blue");
update_databases();
}
RESET_VARIABLES;
// reset the current_round_part and current_round_part_backup_node after the databases have been updated for the previous rounds statistics
memset(current_round_part,0,sizeof(current_round_part));
memcpy(current_round_part,"1",sizeof(char));
memset(current_round_part_backup_node,0,sizeof(current_round_part_backup_node));
memcpy(current_round_part_backup_node,"0",sizeof(char));
// check if it is time to remove the inactive delegates
get_current_UTC_time(current_date_and_time,current_UTC_date_and_time);
if (current_UTC_date_and_time.tm_hour == 23 && current_UTC_date_and_time.tm_min < BLOCK_TIME)
{
/*color_print("Removing inactive delegates\n","blue");
remove_inactive_delegates();*/
}
// all block verifiers will sync and make sure they have the same database
color_print("\nChecking to make sure all block verifiers databases are synced\n","blue");
sync_block_verifiers_database();
// wait for all block verifiers to sync
sync_block_verifiers_minutes_and_seconds(1,40);
// update the previous, current and next block verifiers after syncing the database
if (update_block_verifiers_list() == 0)
{
START_NEW_ROUND_ERROR("Could not update the previous, current and next block verifiers list");
}
// check if it is running in registration mode only
if (registration_settings == 1)
{
// start the reserve proofs timer
pthread_create(&thread_id, NULL, &check_reserve_proofs_timer_thread, NULL);
pthread_detach(thread_id);
sync_block_verifiers_minutes_and_seconds((BLOCK_TIME-1),SUBMIT_NETWORK_BLOCK_TIME_SECONDS);
return 2;
}
// wait for all block verifiers to sync, as this will ensure when we calculate the main node roles we have the same buffer
sync_block_verifiers_minutes_and_seconds(1,45);
if (calculate_main_nodes_roles() == 0)
{
print_error_message(current_date_and_time,current_UTC_date_and_time,data);
START_NEW_ROUND_ERROR("Error calculating the next block producer.\nYour block verifier will wait until the next round\n");
}
// check if the syncing time is over the start time of the round
get_current_UTC_time(current_date_and_time,current_UTC_date_and_time);
if (current_UTC_date_and_time.tm_min % BLOCK_TIME >= 2)
{
color_print("Your block verifier took longer to sync and the next round has already started, so your block verifier will sit out for the remainder of the round\n","yellow");
sync_block_verifiers_minutes_and_seconds((BLOCK_TIME-1),SUBMIT_NETWORK_BLOCK_TIME_SECONDS);
return 2;
}
// check if your delegate is a current block verifier, and sit out the round if not since you have already synced the database
for (count2 = 0; count2 < BLOCK_VERIFIERS_AMOUNT; count2++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count2],xcash_wallet_public_address,XCASH_WALLET_LENGTH) == 0)
{
break;
}
}
if (count2 == BLOCK_VERIFIERS_AMOUNT && strncmp(xcash_wallet_public_address,OFFICIAL_SHARED_DELEGATE_PUBLIC_ADDRESS_PRODUCTION,BUFFER_SIZE) != 0)
{
color_print("Your delegate is not a current block verifier, waiting until the next round","yellow");
print_block_producer();
sync_block_verifiers_minutes_and_seconds((BLOCK_TIME-1),SUBMIT_NETWORK_BLOCK_TIME_SECONDS);
return 2;
}
if (block_verifiers_create_block() == 0)
{
START_NEW_ROUND_ERROR("Your block verifier will wait until the next round\n");
}
}
count2 = 2;
return count2;
#undef START_NEW_ROUND_ERROR
#undef RESET_VARIABLES
}
/*
-----------------------------------------------------------------------------------------------------------
Name: start_blocks_create_vrf_data
Description: Creates the VRF data for the start block
Return: 0 if an error has occured, 1 if successfull
-----------------------------------------------------------------------------------------------------------
*/
int start_blocks_create_vrf_data(void)
{
// Variables
size_t count;
size_t count2;
// define macros
#define START_BLOCKS_CREATE_VRF_DATA_ERROR(settings) \
memcpy(error_message.function[error_message.total],"start_blocks_create_vrf_data",28); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
return 0;
if (create_random_VRF_keys(VRF_data.vrf_public_key,VRF_data.vrf_secret_key) == 1 && crypto_vrf_is_valid_key((const unsigned char*)VRF_data.vrf_public_key) != 1)
{
START_BLOCKS_CREATE_VRF_DATA_ERROR("Could not create the vrf_public_key or vrf_secret_key");
}
memset(blockchain_data.blockchain_reserve_bytes.previous_block_hash_data,0,strlen(blockchain_data.blockchain_reserve_bytes.previous_block_hash_data));
memset(blockchain_data.previous_block_hash_data,0,strlen(blockchain_data.previous_block_hash_data));
memset(VRF_data.vrf_alpha_string,0,strlen((char*)VRF_data.vrf_alpha_string));
memcpy(blockchain_data.blockchain_reserve_bytes.previous_block_hash_data,previous_block_hash,BLOCK_HASH_LENGTH);
memcpy(blockchain_data.previous_block_hash_data,previous_block_hash,BLOCK_HASH_LENGTH);
memcpy(VRF_data.vrf_alpha_string,previous_block_hash,BLOCK_HASH_LENGTH);
blockchain_data.previous_block_hash_data_length = BLOCK_HASH_LENGTH;
blockchain_data.blockchain_reserve_bytes.previous_block_hash_data_length = BLOCK_HASH_LENGTH;
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
memcpy(VRF_data.vrf_alpha_string+strlen((const char*)VRF_data.vrf_alpha_string),GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING)-1);
}
// convert the vrf alpha string to a string
for (count2 = 0, count = 0; count2 < (((RANDOM_STRING_LENGTH*2)*BLOCK_VERIFIERS_AMOUNT) + (BLOCK_HASH_LENGTH*2)) / 2; count2++, count += 2)
{
snprintf(VRF_data.vrf_alpha_string_data+count,BUFFER_SIZE-1,"%02x",VRF_data.vrf_alpha_string[count2] & 0xFF);
}
if (crypto_vrf_prove(VRF_data.vrf_proof,(const unsigned char*)VRF_data.vrf_secret_key,(const unsigned char*)VRF_data.vrf_alpha_string_data,(unsigned long long)strlen((const char*)VRF_data.vrf_alpha_string_data)) != 0)
{
START_BLOCKS_CREATE_VRF_DATA_ERROR("Could not create the vrf proof");
}
if (crypto_vrf_proof_to_hash(VRF_data.vrf_beta_string,(const unsigned char*)VRF_data.vrf_proof) != 0)
{
START_BLOCKS_CREATE_VRF_DATA_ERROR("Could not create the vrf beta string");
}
if (crypto_vrf_verify(VRF_data.vrf_beta_string,(const unsigned char*)VRF_data.vrf_public_key,(const unsigned char*)VRF_data.vrf_proof,(const unsigned char*)VRF_data.vrf_alpha_string_data,(unsigned long long)strlen((const char*)VRF_data.vrf_alpha_string_data)) != 0)
{
START_BLOCKS_CREATE_VRF_DATA_ERROR("Could not create the VRF data");
}
// convert all of the VRF data to a string
for (count2 = 0, count = 0; count2 < crypto_vrf_SECRETKEYBYTES; count2++, count += 2)
{
snprintf(VRF_data.vrf_secret_key_data+count,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_secret_key[count2] & 0xFF);
}
for (count2 = 0, count = 0; count2 < crypto_vrf_PUBLICKEYBYTES; count2++, count += 2)
{
snprintf(VRF_data.vrf_public_key_data+count,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_public_key[count2] & 0xFF);
}
for (count2 = 0, count = 0; count2 < crypto_vrf_PROOFBYTES; count2++, count += 2)
{
snprintf(VRF_data.vrf_proof_data+count,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_proof[count2] & 0xFF);
}
for (count2 = 0, count = 0; count2 < crypto_vrf_OUTPUTBYTES; count2++, count += 2)
{
snprintf(VRF_data.vrf_beta_string_data+count,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_beta_string[count2] & 0xFF);
}
// add all of the VRF data to the blockchain_data struct
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_secret_key,VRF_data.vrf_secret_key,crypto_vrf_SECRETKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_secret_key_data,VRF_data.vrf_secret_key_data,VRF_SECRET_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_public_key,VRF_data.vrf_public_key,crypto_vrf_PUBLICKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_public_key_data,VRF_data.vrf_public_key_data,VRF_PUBLIC_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_alpha_string,VRF_data.vrf_alpha_string,strnlen((const char*)VRF_data.vrf_alpha_string,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_alpha_string_data,VRF_data.vrf_alpha_string_data,strnlen(VRF_data.vrf_alpha_string_data,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_proof,VRF_data.vrf_proof,crypto_vrf_PROOFBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_proof_data,VRF_data.vrf_proof_data,VRF_PROOF_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_beta_string,VRF_data.vrf_beta_string,crypto_vrf_OUTPUTBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_beta_string_data,VRF_data.vrf_beta_string_data,VRF_BETA_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_secret_key[0],blockchain_data.blockchain_reserve_bytes.vrf_secret_key,crypto_vrf_SECRETKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_secret_key_data[0],blockchain_data.blockchain_reserve_bytes.vrf_secret_key_data,VRF_SECRET_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_public_key[0],blockchain_data.blockchain_reserve_bytes.vrf_public_key,crypto_vrf_PUBLICKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_public_key_data[0],blockchain_data.blockchain_reserve_bytes.vrf_public_key_data,VRF_PUBLIC_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_random_data[0],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING)-1);
for (count = 1; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_secret_key_data[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_SECRET_KEY_DATA,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_SECRET_KEY_DATA)-1);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_public_key_data[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_PUBLIC_KEY_DATA,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_PUBLIC_KEY_DATA)-1);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_random_data[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING)-1);
}
return 1;
#undef START_BLOCKS_CREATE_VRF_DATA_ERROR
}
/*
-----------------------------------------------------------------------------------------------------------
Name: start_blocks_create_data
Description: Creates the data for the start block
Parameters:
message - The data
network_block_string - The network_block_string
Return: 0 if an error has occured, 1 if successfull
-----------------------------------------------------------------------------------------------------------
*/
int start_blocks_create_data(char* message, char* network_block_string)
{
// Variables
char data[BUFFER_SIZE];
char data2[BUFFER_SIZE];
char data3[BUFFER_SIZE];
size_t count;
// define macros
#define DATABASE_COLLECTION "reserve_bytes_1"
#define START_BLOCKS_CREATE_DATA_ERROR(settings) \
memcpy(error_message.function[error_message.total],"start_blocks_create_data",24); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
return 0;
memset(data,0,sizeof(data));
memset(data2,0,sizeof(data2));
memset(data3,0,sizeof(data3));
// get a block template
if (get_block_template(data) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not get a block template");
}
// convert the network_block_string to blockchain_data
if (network_block_string_to_blockchain_data((const char*)data,"0",BLOCK_VERIFIERS_AMOUNT) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not convert the network_block_string to blockchain_data");
}
// change the nonce to the CONSENSUS_NODE_NETWORK_BLOCK_NONCE
memcpy(blockchain_data.nonce_data,CONSENSUS_NODE_NETWORK_BLOCK_NONCE,sizeof(CONSENSUS_NODE_NETWORK_BLOCK_NONCE)-1);
// add the delegates data to the network_block_string
memset(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,0,strnlen(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,"network_data_node_1",19);
memset(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,0,strnlen(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,network_data_nodes_list.network_data_nodes_public_address[0],XCASH_WALLET_LENGTH);
memset(blockchain_data.blockchain_reserve_bytes.block_producer_node_backup_count,0,strnlen(blockchain_data.blockchain_reserve_bytes.block_producer_node_backup_count,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_node_backup_count,"0",sizeof(char));
memset(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names,0,strnlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names,"network_data_node_1,network_data_node_1,network_data_node_1,network_data_node_1,network_data_node_1",99);
// add the VRF data
if (start_blocks_create_vrf_data() == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not add the VRF data");
}
// add the next block verifiers and add 0`s for the block_validation_node_signature
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
memcpy(blockchain_data.blockchain_reserve_bytes.next_block_verifiers_public_address[count],next_block_verifiers_list.block_verifiers_public_key[count],VRF_PUBLIC_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_validation_node_signature_data[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE_DATA,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE_DATA)-1);
memcpy(blockchain_data.blockchain_reserve_bytes.block_validation_node_signature[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE)-1);
}
// convert the blockchain_data to a network_block_string
memset(data,0,sizeof(data));
if (blockchain_data_to_network_block_string(data,BLOCK_VERIFIERS_AMOUNT) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not convert the blockchain_data to a network_block_string");
}
// sign the network block string
if (sign_network_block_string(blockchain_data.blockchain_reserve_bytes.block_validation_node_signature[0],data) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not sign the network block string");
}
// convert the blockchain_data to a network_block_string
memset(VRF_data.block_blob,0,strlen(VRF_data.block_blob));
if (blockchain_data_to_network_block_string(VRF_data.block_blob,BLOCK_VERIFIERS_AMOUNT) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not convert the blockchain_data to a network_block_string");
}
// add the data hash to the network block string
memset(network_block_string,0,strlen(network_block_string));
if (add_data_hash_to_network_block_string(VRF_data.block_blob,network_block_string) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not add the network block string data hash");
}
// update the reserve bytes database
memset(data2,0,sizeof(data2));
memcpy(data2,"{\"block_height\":\"",17);
memcpy(data2+17,current_block_height,strnlen(current_block_height,sizeof(current_block_height)));
memcpy(data2+strlen(data2),"\",\"reserve_bytes_data_hash\":\"",29);
memcpy(data2+strlen(data2),VRF_data.reserve_bytes_data_hash,DATA_HASH_LENGTH);
memcpy(data2+strlen(data2),"\",\"reserve_bytes\":\"",19);
memcpy(data2+strlen(data2),VRF_data.block_blob,strnlen(VRF_data.block_blob,sizeof(data2)));
memcpy(data2+strlen(data2),"\"}",2);
// add the network block string to the database
if (insert_document_into_collection_json(database_name,DATABASE_COLLECTION,data2) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not add the new block to the database");
}
// create the message
memset(message,0,strlen(message));
memcpy(message,"{\r\n \"message_settings\": \"MAIN_NETWORK_DATA_NODE_TO_BLOCK_VERIFIERS_START_BLOCK\",\r\n \"database_data\": \"",101);
memcpy(message+101,data2,strnlen(data2,BUFFER_SIZE));
memcpy(message+strlen(message),"\",\r\n \"reserve_bytes_data_hash\": \"",33);
memcpy(message+strlen(message),VRF_data.reserve_bytes_data_hash,DATA_HASH_LENGTH);
memcpy(message+strlen(message),"\",\r\n}",5);
// sign_data
if (sign_data(message) == 0)
{
START_BLOCKS_CREATE_DATA_ERROR("Could not sign_data");
}
// clear the VRF_data.block_blob so at the start of the next round, the main network data node does not try to update the databases
memset(VRF_data.block_blob,0,strlen(VRF_data.block_blob));
return 1;
#undef DATABASE_COLLECTION
#undef START_BLOCKS_CREATE_DATA_ERROR
}
/*
-----------------------------------------------------------------------------------------------------------
Name: start_current_round_start_blocks
Description: Runs the round where the network data node will create the first block of the X-CASH proof of stake block on the network
Return: 0 if an error has occured, 1 if successfull
-----------------------------------------------------------------------------------------------------------
*/
int start_current_round_start_blocks(void)
{
// Variables
char data[BUFFER_SIZE];
char data2[BUFFER_SIZE];
// define macros
#define DATABASE_COLLECTION "reserve_bytes_1"
#define START_CURRENT_ROUND_START_BLOCKS_ERROR(settings) \
memcpy(error_message.function[error_message.total],"start_current_round_start_blocks",32); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
return 0;
memset(data,0,sizeof(data));
memset(data2,0,sizeof(data2));
// set the main_network_data_node_create_block so the main network data node can create the block
main_network_data_node_create_block = 1;
// check if the block verifier is the main network data node
if (strncmp(network_data_nodes_list.network_data_nodes_public_address[0],xcash_wallet_public_address,XCASH_WALLET_LENGTH) != 0)
{
color_print("Your block verifier is not the main data network node so your block verifier will sit out for the remainder of the round\n","yellow");
sync_block_verifiers_minutes_and_seconds((BLOCK_TIME-1),SUBMIT_NETWORK_BLOCK_TIME_SECONDS);
return 1;
}
color_print("Your block verifier is the main data network node so your block verifier will create the block\n","yellow");
// wait until the non network data nodes have synced the previous current and next block verifiers list
sleep(30);
// create the data
if (start_blocks_create_data(data,data2) == 0)
{
START_CURRENT_ROUND_START_BLOCKS_ERROR("Could not create the start blocks data");
}
// send the database data to all block verifiers
sleep(BLOCK_VERIFIERS_SETTINGS);
block_verifiers_send_data_socket((const char*)data);
color_print("Waiting for the block producer to submit the block to the network\n","blue");
sync_block_verifiers_minutes_and_seconds((BLOCK_TIME-1),SUBMIT_NETWORK_BLOCK_TIME_SECONDS);
// have the main network data node submit the block to the network
submit_block_template(data2);
return 1;
#undef DATABASE_COLLECTION
#undef START_CURRENT_ROUND_START_BLOCKS_ERROR
}
/*
-----------------------------------------------------------------------------------------------------------
Name: block_verifiers_create_VRF_secret_key_and_VRF_public_key
Description: The block verifiers will create a VRF secret key and a VRF public key
Parameters:
message - The message to send to the block verifiers
Return: 0 if an error has occured, 1 if successfull
-----------------------------------------------------------------------------------------------------------
*/
int block_verifiers_create_VRF_secret_key_and_VRF_public_key(char* message)
{
// Variables
char data[SMALL_BUFFER_SIZE];
size_t count;
size_t counter;
// define macros
#define BLOCK_VERIFIERS_CREATE_VRF_SECRET_KEY_AND_VRF_PUBLIC_KEY_ERROR(settings) \
memcpy(error_message.function[error_message.total],"block_verifiers_create_VRF_secret_key_and_VRF_public_key",56); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
return 0;
memset(data,0,sizeof(data));
// create a random VRF public key and secret key
if (create_random_VRF_keys(VRF_data.vrf_public_key,VRF_data.vrf_secret_key) != 1 || crypto_vrf_is_valid_key((const unsigned char*)VRF_data.vrf_public_key) != 1)
{
BLOCK_VERIFIERS_CREATE_VRF_SECRET_KEY_AND_VRF_PUBLIC_KEY_ERROR("Could not create the VRF secret key or VRF public key for the VRF data");
}
// convert the VRF secret key to hexadecimal
for (count = 0, counter = 0; count < crypto_vrf_SECRETKEYBYTES; count++, counter += 2)
{
snprintf(VRF_data.vrf_secret_key_data+counter,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_secret_key[count] & 0xFF);
}
// convert the VRF public key to hexadecimal
for (count = 0, counter = 0; count < crypto_vrf_PUBLICKEYBYTES; count++, counter += 2)
{
snprintf(VRF_data.vrf_public_key_data+counter,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_public_key[count] & 0xFF);
}
// create the message
memset(message,0,strlen(message));
memcpy(message,"{\r\n \"message_settings\": \"BLOCK_VERIFIERS_TO_BLOCK_VERIFIERS_VRF_DATA\",\r\n \"vrf_secret_key\": \"",92);
memcpy(message+92,VRF_data.vrf_secret_key_data,VRF_SECRET_KEY_LENGTH);
memcpy(message+220,"\",\r\n \"vrf_public_key\": \"",24);
memcpy(message+244,VRF_data.vrf_public_key_data,VRF_PUBLIC_KEY_LENGTH);
memcpy(message+308,"\",\r\n \"random_data\": \"",21);
// create random data to use in the alpha string of the VRF data
if (random_string(data,RANDOM_STRING_LENGTH) == 0)
{
BLOCK_VERIFIERS_CREATE_VRF_SECRET_KEY_AND_VRF_PUBLIC_KEY_ERROR("Could not create random data for the VRF data");
}
memcpy(message+329,data,RANDOM_STRING_LENGTH);
memcpy(message+429,"\",\r\n}",5);
// add the VRF data to the block verifiers VRF data copy
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],xcash_wallet_public_address,XCASH_WALLET_LENGTH) == 0)
{
memcpy(VRF_data.block_verifiers_vrf_secret_key[count],VRF_data.vrf_secret_key,crypto_vrf_SECRETKEYBYTES);
memcpy(VRF_data.block_verifiers_vrf_secret_key_data[count],VRF_data.vrf_secret_key_data,VRF_SECRET_KEY_LENGTH);
memcpy(VRF_data.block_verifiers_vrf_public_key[count],VRF_data.vrf_public_key,crypto_vrf_PUBLICKEYBYTES);
memcpy(VRF_data.block_verifiers_vrf_public_key_data[count],VRF_data.vrf_public_key_data,VRF_PUBLIC_KEY_LENGTH);
memcpy(VRF_data.block_verifiers_random_data[count],data,RANDOM_STRING_LENGTH);
}
}
return 1;
#undef BLOCK_VERIFIERS_CREATE_VRF_SECRET_KEY_AND_VRF_PUBLIC_KEY_ERROR
}
/*
-----------------------------------------------------------------------------------------------------------
Name: block_verifiers_create_VRF_data
Description: The block verifiers will create all of the VRF data
Return: 0 if an error has occured, 1 if successfull
-----------------------------------------------------------------------------------------------------------
*/
int block_verifiers_create_VRF_data(void)
{
// Variables
char data[SMALL_BUFFER_SIZE];
char data2[SMALL_BUFFER_SIZE];
size_t count;
size_t count2;
size_t counter;
// define macros
#define BLOCK_VERIFIERS_CREATE_VRF_DATA_ERROR(settings) \
memcpy(error_message.function[error_message.total],"block_verifiers_create_VRF_data",31); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
return 0;
memset(data,0,sizeof(data));
memset(data2,0,sizeof(data2));
// create the VRF alpha string using all of the random data from the block verifiers
memset(VRF_data.vrf_alpha_string,0,strlen((const char*)VRF_data.vrf_alpha_string));
memcpy(VRF_data.vrf_alpha_string,previous_block_hash,BLOCK_HASH_LENGTH);
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strlen((const char*)VRF_data.block_verifiers_vrf_secret_key[count]) == crypto_vrf_SECRETKEYBYTES && strlen((const char*)VRF_data.block_verifiers_vrf_public_key[count]) == crypto_vrf_PUBLICKEYBYTES && strlen(VRF_data.block_verifiers_random_data[count]) == RANDOM_STRING_LENGTH)
{
memcpy(VRF_data.vrf_alpha_string+strlen((const char*)VRF_data.vrf_alpha_string),VRF_data.block_verifiers_random_data[count],RANDOM_STRING_LENGTH);
}
else
{
memcpy(VRF_data.vrf_alpha_string+strlen((const char*)VRF_data.vrf_alpha_string),GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING)-1);
}
}
// convert the vrf alpha string to a string
for (count2 = 0, count = 0; count2 < (((RANDOM_STRING_LENGTH*2)*BLOCK_VERIFIERS_AMOUNT) + (BLOCK_HASH_LENGTH*2)) / 2; count2++, count += 2)
{
snprintf(VRF_data.vrf_alpha_string_data+count,BUFFER_SIZE-1,"%02x",VRF_data.vrf_alpha_string[count2] & 0xFF);
}
crypto_hash_sha512((unsigned char*)data,(const unsigned char*)VRF_data.vrf_alpha_string_data,strlen(VRF_data.vrf_alpha_string_data));
// convert the SHA512 data hash to a string
for (count2 = 0, count = 0; count2 < DATA_HASH_LENGTH / 2; count2++, count += 2)
{
snprintf(data2+count,sizeof(data2)-1,"%02x",data[count2] & 0xFF);
}
// check what block verifiers vrf secret key and vrf public key to use
for (count = 0; count < DATA_HASH_LENGTH; count += 2)
{
memset(data,0,sizeof(data));
memcpy(data,&data2[count],2);
counter = (int)strtol(data, NULL, 16);
/* if it is not in the range of 01 - FA or it has already been calculated then skip the byte
This number needs to be evenly divisible by how many maximum block verifiers there will be
This is so block verifiers in specific spots do not have more of a chance to be the block producer than others
The goal is to use as many bytes as possible, since the more unused bytes, the more chance that it will run out of bytes when selecting the block producer
*/
if (counter >= MINIMUM_BYTE_RANGE && counter <= MAXIMUM_BYTE_RANGE)
{
counter = counter % BLOCK_VERIFIERS_AMOUNT;
// check if the block verifier created the data
if (strncmp(VRF_data.block_verifiers_vrf_secret_key_data[counter],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_SECRET_KEY_DATA,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_SECRET_KEY_DATA)-1) != 0 && strncmp(VRF_data.block_verifiers_vrf_public_key_data[counter],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_PUBLIC_KEY_DATA,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_VRF_PUBLIC_KEY_DATA)-1) != 0 && strncmp(VRF_data.block_verifiers_random_data[counter],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_RANDOM_STRING)-1) != 0)
{
break;
}
}
}
// create all of the VRF data
memcpy(VRF_data.vrf_secret_key_data,VRF_data.block_verifiers_vrf_secret_key_data[counter],VRF_SECRET_KEY_LENGTH);
memcpy(VRF_data.vrf_secret_key,VRF_data.block_verifiers_vrf_secret_key[counter],crypto_vrf_SECRETKEYBYTES);
memcpy(VRF_data.vrf_public_key_data,VRF_data.block_verifiers_vrf_public_key_data[counter],VRF_PUBLIC_KEY_LENGTH);
memcpy(VRF_data.vrf_public_key,VRF_data.block_verifiers_vrf_public_key[counter],crypto_vrf_PUBLICKEYBYTES);
if (crypto_vrf_prove(VRF_data.vrf_proof,(const unsigned char*)VRF_data.vrf_secret_key,(const unsigned char*)VRF_data.vrf_alpha_string_data,(unsigned long long)strlen((const char*)VRF_data.vrf_alpha_string_data)) != 0)
{
BLOCK_VERIFIERS_CREATE_VRF_DATA_ERROR("Could not create the vrf proof");
}
if (crypto_vrf_proof_to_hash(VRF_data.vrf_beta_string,(const unsigned char*)VRF_data.vrf_proof) != 0)
{
BLOCK_VERIFIERS_CREATE_VRF_DATA_ERROR("Could not create the vrf beta string");
}
if (crypto_vrf_verify(VRF_data.vrf_beta_string,(const unsigned char*)VRF_data.vrf_public_key,(const unsigned char*)VRF_data.vrf_proof,(const unsigned char*)VRF_data.vrf_alpha_string_data,(unsigned long long)strlen((const char*)VRF_data.vrf_alpha_string_data)) != 0)
{
BLOCK_VERIFIERS_CREATE_VRF_DATA_ERROR("Could not create the VRF data");
}
// convert the vrf proof and vrf beta string to a string
for (counter = 0, count = 0; counter < crypto_vrf_PROOFBYTES; counter++, count += 2)
{
snprintf(VRF_data.vrf_proof_data+count,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_proof[counter] & 0xFF);
}
for (counter = 0, count = 0; counter < crypto_vrf_OUTPUTBYTES; counter++, count += 2)
{
snprintf(VRF_data.vrf_beta_string_data+count,BUFFER_SIZE_NETWORK_BLOCK_DATA-1,"%02x",VRF_data.vrf_beta_string[counter] & 0xFF);
}
return 1;
#undef BLOCK_VERIFIERS_CREATE_VRF_DATA_ERROR
}
/*
-----------------------------------------------------------------------------------------------------------
Name: block_verifiers_create_block_signature
Description: The block verifiers will create the block signature
Parameters:
message - The message to send to the block verifiers
Return: 0 if an error has occured, 1 if successfull
-----------------------------------------------------------------------------------------------------------
*/
int block_verifiers_create_block_signature(char* message)
{
// Variables
char data[BUFFER_SIZE];
size_t count;
size_t count2;
size_t counter;
int block_producer_backup_settings[BLOCK_PRODUCERS_BACKUP_AMOUNT] = {0,0,0,0,0};
// define macros
#define BLOCK_VERIFIERS_CREATE_BLOCK_SIGNATURE_ERROR(settings) \
memcpy(error_message.function[error_message.total],"block_verifiers_create_block_signature",38); \
memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \
error_message.total++; \
return 0;
memset(data,0,sizeof(data));
// convert the network block string to a blockchain data
if (network_block_string_to_blockchain_data(VRF_data.block_blob,"0",BLOCK_VERIFIERS_AMOUNT) == 0)
{
BLOCK_VERIFIERS_CREATE_BLOCK_SIGNATURE_ERROR("Could not convert the network block string to a blockchain data");
}
// change the network block nonce to the block producer network block nonce
memcpy(blockchain_data.nonce_data,BLOCK_PRODUCER_NETWORK_BLOCK_NONCE,sizeof(BLOCK_PRODUCER_NETWORK_BLOCK_NONCE)-1);
// get the current block producer
if (strncmp(current_round_part_backup_node,"0",1) == 0)
{
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],main_nodes_list.block_producer_public_address,sizeof(main_nodes_list.block_producer_public_address)) == 0)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,current_block_verifiers_list.block_verifiers_name[count],strnlen(current_block_verifiers_list.block_verifiers_name[count],sizeof(current_block_verifiers_list.block_verifiers_name[count])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH);
break;
}
}
}
else if (strncmp(current_round_part_backup_node,"1",1) == 0)
{
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],main_nodes_list.block_producer_backup_block_verifier_1_public_address,sizeof(current_block_verifiers_list.block_verifiers_public_address[count])) == 0)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,current_block_verifiers_list.block_verifiers_name[count],strnlen(current_block_verifiers_list.block_verifiers_name[count],sizeof(current_block_verifiers_list.block_verifiers_name[count])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH);
break;
}
}
}
else if (strncmp(current_round_part_backup_node,"2",1) == 0)
{
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],main_nodes_list.block_producer_backup_block_verifier_2_public_address,sizeof(current_block_verifiers_list.block_verifiers_public_address[count])) == 0)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,current_block_verifiers_list.block_verifiers_name[count],strnlen(current_block_verifiers_list.block_verifiers_name[count],sizeof(current_block_verifiers_list.block_verifiers_name[count])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH);
break;
}
}
}
else if (strncmp(current_round_part_backup_node,"3",1) == 0)
{
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],main_nodes_list.block_producer_backup_block_verifier_3_public_address,sizeof(current_block_verifiers_list.block_verifiers_public_address[count])) == 0)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,current_block_verifiers_list.block_verifiers_name[count],strnlen(current_block_verifiers_list.block_verifiers_name[count],sizeof(current_block_verifiers_list.block_verifiers_name[count])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH);
break;
}
}
}
else if (strncmp(current_round_part_backup_node,"4",1) == 0)
{
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],main_nodes_list.block_producer_backup_block_verifier_4_public_address,sizeof(current_block_verifiers_list.block_verifiers_public_address[count])) == 0)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,current_block_verifiers_list.block_verifiers_name[count],strnlen(current_block_verifiers_list.block_verifiers_name[count],sizeof(current_block_verifiers_list.block_verifiers_name[count])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH);
break;
}
}
}
else if (strncmp(current_round_part_backup_node,"5",1) == 0)
{
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],main_nodes_list.block_producer_backup_block_verifier_5_public_address,sizeof(current_block_verifiers_list.block_verifiers_public_address[count])) == 0)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_delegates_name,current_block_verifiers_list.block_verifiers_name[count],strnlen(current_block_verifiers_list.block_verifiers_name[count],sizeof(current_block_verifiers_list.block_verifiers_name[count])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH);
break;
}
}
}
// add all of the VRF data to the blockchain_data struct
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(main_nodes_list.block_producer_backup_block_verifier_1_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH) == 0)
{
block_producer_backup_settings[0] = (int)count;
}
if (strncmp(main_nodes_list.block_producer_backup_block_verifier_2_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH) == 0)
{
block_producer_backup_settings[1] = (int)count;
}
if (strncmp(main_nodes_list.block_producer_backup_block_verifier_3_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH) == 0)
{
block_producer_backup_settings[2] = (int)count;
}
if (strncmp(main_nodes_list.block_producer_backup_block_verifier_4_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH) == 0)
{
block_producer_backup_settings[3] = (int)count;
}
if (strncmp(main_nodes_list.block_producer_backup_block_verifier_5_public_address,current_block_verifiers_list.block_verifiers_public_address[count],XCASH_WALLET_LENGTH) == 0)
{
block_producer_backup_settings[4] = (int)count;
}
}
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_node_backup_count,current_round_part_backup_node,sizeof(char));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[0]],strnlen(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[0]],sizeof(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[0]])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),",",sizeof(char));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[1]],strnlen(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[1]],sizeof(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[1]])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),",",sizeof(char));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[2]],strnlen(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[2]],sizeof(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[2]])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),",",sizeof(char));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[3]],strnlen(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[3]],sizeof(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[3]])));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),",",sizeof(char));
memcpy(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names+strlen(blockchain_data.blockchain_reserve_bytes.block_producer_backup_nodes_names),current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[4]],strnlen(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[4]],sizeof(current_block_verifiers_list.block_verifiers_name[block_producer_backup_settings[4]])));
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_secret_key,VRF_data.vrf_secret_key,crypto_vrf_SECRETKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_secret_key_data,VRF_data.vrf_secret_key_data,VRF_SECRET_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_public_key,VRF_data.vrf_public_key,crypto_vrf_PUBLICKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_public_key_data,VRF_data.vrf_public_key_data,VRF_PUBLIC_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_alpha_string,VRF_data.vrf_alpha_string,strnlen((const char*)VRF_data.vrf_alpha_string,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_alpha_string_data,VRF_data.vrf_alpha_string_data,strnlen(VRF_data.vrf_alpha_string_data,BUFFER_SIZE));
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_proof,VRF_data.vrf_proof,crypto_vrf_PROOFBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_proof_data,VRF_data.vrf_proof_data,VRF_PROOF_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_beta_string,VRF_data.vrf_beta_string,crypto_vrf_OUTPUTBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.vrf_beta_string_data,VRF_data.vrf_beta_string_data,VRF_BETA_LENGTH);
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_secret_key[count],VRF_data.block_verifiers_vrf_secret_key[count],crypto_vrf_SECRETKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_public_key[count],VRF_data.block_verifiers_vrf_public_key[count],crypto_vrf_PUBLICKEYBYTES);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_secret_key_data[count],VRF_data.block_verifiers_vrf_secret_key_data[count],VRF_SECRET_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_vrf_public_key_data[count],VRF_data.block_verifiers_vrf_public_key_data[count],VRF_PUBLIC_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_verifiers_random_data_text[count],VRF_data.block_verifiers_random_data[count],RANDOM_STRING_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.next_block_verifiers_public_address[count],next_block_verifiers_list.block_verifiers_public_key[count],VRF_PUBLIC_KEY_LENGTH);
memcpy(blockchain_data.blockchain_reserve_bytes.block_validation_node_signature_data[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE_DATA,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE_DATA)-1);
memcpy(blockchain_data.blockchain_reserve_bytes.block_validation_node_signature[count],GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE,sizeof(GET_BLOCK_TEMPLATE_BLOCK_VERIFIERS_SIGNATURE)-1);
for (counter = 0, count2 = 0; counter < RANDOM_STRING_LENGTH; counter++, count2 += 2)
{
snprintf(blockchain_data.blockchain_reserve_bytes.block_verifiers_random_data[count]+count2,RANDOM_STRING_LENGTH,"%02x",VRF_data.block_verifiers_random_data[count][counter] & 0xFF);
}
}
memcpy(blockchain_data.blockchain_reserve_bytes.previous_block_hash_data,blockchain_data.previous_block_hash_data,BLOCK_HASH_LENGTH);
// convert the blockchain_data to a network_block_string
if (blockchain_data_to_network_block_string(VRF_data.block_blob,BLOCK_VERIFIERS_AMOUNT) == 0)
{
BLOCK_VERIFIERS_CREATE_BLOCK_SIGNATURE_ERROR("Could not convert the blockchain_data to a network_block_string");
}
// sign the network block string
memset(data,0,sizeof(data));
if (sign_network_block_string(data,VRF_data.block_blob) == 0)
{
BLOCK_VERIFIERS_CREATE_BLOCK_SIGNATURE_ERROR("Could not sign the network block string");
}
// add the block verifier signature to the VRF data and the blockchain_data struct
for (count = 0; count < BLOCK_VERIFIERS_AMOUNT; count++)
{
if (strncmp(current_block_verifiers_list.block_verifiers_public_address[count],xcash_wallet_public_address,XCASH_WALLET_LENGTH) == 0)
{
memcpy(VRF_data.block_blob_signature[count],data,strnlen(data,BUFFER_SIZE));
}
}
// create the message
memset(message,0,strlen(message));
memcpy(message,"{\r\n \"message_settings\": \"BLOCK_VERIFIERS_TO_BLOCK_VERIFIERS_BLOCK_BLOB_SIGNATURE\",\r\n \"block_blob_signature\": \"",110);
memcpy(message+110,data,strnlen(data,BUFFER_SIZE));
memcpy(message+strlen(message),"\",\r\n}",5);