This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainchainBMMDIFF.html
5534 lines (5336 loc) · 307 KB
/
mainchainBMMDIFF.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
body .hll { background-color: #ffffcc }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .ch { color: #999988; font-style: italic } /* Comment.Hashbang */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .cpf { color: #999988; font-style: italic } /* Comment.PreprocFile */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kn { font-weight: bold } /* Keyword.Namespace */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mb { color: #009999 } /* Literal.Number.Bin */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sa { color: #bb8844 } /* Literal.String.Affix */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .dl { color: #bb8844 } /* Literal.String.Delimiter */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .fm { color: #990000; font-weight: bold } /* Name.Function.Magic */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .vm { color: #008080 } /* Name.Variable.Magic */
body .il { color: #009999 } /* Literal.Number.Integer.Long */
</style>
</head>
<body>
<h2></h2>
<div class="highlight"><pre><span></span><span class="gh">diff --git a/src/base58.cpp b/src/base58.cpp</span>
<span class="gh">index 499afbe38..72b51eed5 100644</span>
<span class="gd">--- a/src/base58.cpp</span>
<span class="gi">+++ b/src/base58.cpp</span>
<span class="gu">@@ -121,6 +121,29 @@ bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)</span>
return DecodeBase58(str.c_str(), vchRet);
}
<span class="gi">+bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const</span>
<span class="gi">+ {</span>
<span class="gi">+ if (!IsValid() || vchVersion != Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))</span>
<span class="gi">+ return false;</span>
<span class="gi">+ uint160 id;</span>
<span class="gi">+ memcpy(&id, vchData.data(), 20);</span>
<span class="gi">+ keyID = CKeyID(id);</span>
<span class="gi">+ return true;</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ bool CBitcoinAddress::IsValid() const</span>
<span class="gi">+{</span>
<span class="gi">+ return IsValid(Params());</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+bool CBitcoinAddress::IsValid(const CChainParams& params) const</span>
<span class="gi">+{</span>
<span class="gi">+ bool fCorrectSize = vchData.size() == 20;</span>
<span class="gi">+ bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::PUBKEY_ADDRESS) ||</span>
<span class="gi">+ vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);</span>
<span class="gi">+ return fCorrectSize && fKnownVersion;</span>
<span class="gi">+}</span>
<span class="gi">+</span>
std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn)
{
// add 4-byte hash check to the end
<span class="gu">@@ -213,6 +236,60 @@ int CBase58Data::CompareTo(const CBase58Data& b58) const</span>
return 0;
}
<span class="gi">+bool CSidechainAddress::Set(const CKeyID& id)</span>
<span class="gi">+{</span>
<span class="gi">+ SetData(Params().Base58Prefix(CChainParams::SIDECHAIN_PUBKEY_ADDRESS), &id, 20);</span>
<span class="gi">+ return true;</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+bool CSidechainAddress::Set(const CScriptID& id)</span>
<span class="gi">+{</span>
<span class="gi">+ SetData(Params().Base58Prefix(CChainParams::SIDECHAIN_SCRIPT_ADDRESS), &id, 20);</span>
<span class="gi">+ return true;</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+bool CSidechainAddress::IsValid() const</span>
<span class="gi">+{</span>
<span class="gi">+ return IsValid(Params());</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+bool CSidechainAddress::IsValid(const CChainParams& params) const</span>
<span class="gi">+{</span>
<span class="gi">+ bool fCorrectSize = vchData.size() == 20;</span>
<span class="gi">+ bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::SIDECHAIN_PUBKEY_ADDRESS) ||</span>
<span class="gi">+ vchVersion == params.Base58Prefix(CChainParams::SIDECHAIN_SCRIPT_ADDRESS);</span>
<span class="gi">+ return fCorrectSize && fKnownVersion;</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+CTxDestination CSidechainAddress::Get() const</span>
<span class="gi">+{</span>
<span class="gi">+ if (!IsValid())</span>
<span class="gi">+ return CNoDestination();</span>
<span class="gi">+ uint160 id;</span>
<span class="gi">+ memcpy(&id, &vchData[0], 20);</span>
<span class="gi">+ if (vchVersion == Params().Base58Prefix(CChainParams::SIDECHAIN_PUBKEY_ADDRESS))</span>
<span class="gi">+ return CKeyID(id);</span>
<span class="gi">+ else if (vchVersion == Params().Base58Prefix(CChainParams::SIDECHAIN_SCRIPT_ADDRESS))</span>
<span class="gi">+ return CScriptID(id);</span>
<span class="gi">+ else</span>
<span class="gi">+ return CNoDestination();</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+bool CSidechainAddress::GetKeyID(CKeyID& keyID) const</span>
<span class="gi">+{</span>
<span class="gi">+ if (!IsValid() || vchVersion != Params().Base58Prefix(CChainParams::SIDECHAIN_PUBKEY_ADDRESS))</span>
<span class="gi">+ return false;</span>
<span class="gi">+ uint160 id;</span>
<span class="gi">+ memcpy(&id, &vchData[0], 20);</span>
<span class="gi">+ keyID = CKeyID(id);</span>
<span class="gi">+ return true;</span>
<span class="gi">+}</span>
<span class="gi">+</span>
<span class="gi">+bool CSidechainAddress::IsScript() const</span>
<span class="gi">+{</span>
<span class="gi">+ return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SIDECHAIN_SCRIPT_ADDRESS);</span>
<span class="gi">+}</span>
<span class="gi">+</span>
namespace
{
class DestinationEncoder : public boost::static_visitor<std::string>
<span class="gh">diff --git a/src/base58.h b/src/base58.h</span>
<span class="gh">index 39eb4eacc..a8e285a63 100644</span>
<span class="gd">--- a/src/base58.h</span>
<span class="gi">+++ b/src/base58.h</span>
<span class="gu">@@ -94,6 +94,47 @@ public:</span>
bool operator> (const CBase58Data& b58) const { return CompareTo(b58) > 0; }
};
<span class="gi">+/** Base58 encoded Sidechain address */</span>
<span class="gi">+class CSidechainAddress : public CBase58Data {</span>
<span class="gi">+public:</span>
<span class="gi">+ bool Set(const CKeyID &id);</span>
<span class="gi">+ bool Set(const CScriptID &id);</span>
<span class="gi">+ bool IsValid() const;</span>
<span class="gi">+ bool IsValid(const CChainParams &params) const;</span>
<span class="gi">+</span>
<span class="gi">+ CSidechainAddress() {}</span>
<span class="gi">+ CSidechainAddress(const std::string& strAddress) { SetString(strAddress); }</span>
<span class="gi">+ CSidechainAddress(const char* pszAddress) { SetString(pszAddress); }</span>
<span class="gi">+</span>
<span class="gi">+ CTxDestination Get() const;</span>
<span class="gi">+ bool GetKeyID(CKeyID &keyID) const;</span>
<span class="gi">+ bool IsScript() const;</span>
<span class="gi">+};</span>
<span class="gi">+</span>
<span class="gi">+/** base58-encoded Bitcoin addresses.</span>
<span class="gi">+ * Public-key-hash-addresses have version 0 (or 111 testnet).</span>
<span class="gi">+ * The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key.</span>
<span class="gi">+ * Script-hash-addresses have version 5 (or 196 testnet).</span>
<span class="gi">+ * The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.</span>
<span class="gi">+ */</span>
<span class="gi">+class CBitcoinAddress : public CBase58Data {</span>
<span class="gi">+public:</span>
<span class="gi">+ bool Set(const CKeyID &id);</span>
<span class="gi">+ bool Set(const CScriptID &id);</span>
<span class="gi">+ bool Set(const CTxDestination &dest);</span>
<span class="gi">+ bool IsValid() const;</span>
<span class="gi">+ bool IsValid(const CChainParams &params) const;</span>
<span class="gi">+</span>
<span class="gi">+ CBitcoinAddress() {}</span>
<span class="gi">+ CBitcoinAddress(const CTxDestination &dest) { Set(dest); }</span>
<span class="gi">+ CBitcoinAddress(const std::string& strAddress) { SetString(strAddress); }</span>
<span class="gi">+ CBitcoinAddress(const char* pszAddress) { SetString(pszAddress); }</span>
<span class="gi">+</span>
<span class="gi">+ CTxDestination Get() const;</span>
<span class="gi">+ bool GetKeyID(CKeyID &keyID) const;</span>
<span class="gi">+ bool IsScript() const;</span>
<span class="gi">+};</span>
<span class="gi">+</span>
/**
* A base58-encoded secret key
*/
<span class="gh">diff --git a/src/chain.cpp b/src/chain.cpp</span>
<span class="gh">index 79e8bdfa4..435ef6d6b 100644</span>
<span class="gd">--- a/src/chain.cpp</span>
<span class="gi">+++ b/src/chain.cpp</span>
<span class="gu">@@ -5,6 +5,8 @@</span>
#include <chain.h>
<span class="gi">+int nCoinbaseCached = 0;</span>
<span class="gi">+</span>
/**
* CChain implementation
*/
<span class="gh">diff --git a/src/chain.h b/src/chain.h</span>
old mode 100644
new mode 100755
<span class="gh">index 3728f768c..af770bbb7</span>
<span class="gd">--- a/src/chain.h</span>
<span class="gi">+++ b/src/chain.h</span>
<span class="gu">@@ -8,12 +8,23 @@</span>
#include <arith_uint256.h>
#include <primitives/block.h>
<span class="gi">+#include <primitives/transaction.h></span>
#include <pow.h>
<span class="gi">+#include <sidechain.h></span>
#include <tinyformat.h>
#include <uint256.h>
#include <vector>
<span class="gi">+//! Number of coinbase(s) chainActive has cached</span>
<span class="gi">+extern int nCoinbaseCached;</span>
<span class="gi">+</span>
<span class="gi">+/** Target size limit of coinbase cache */</span>
<span class="gi">+static const int COINBASE_CACHE_TARGET = SIDECHAIN_VERIFICATION_PERIOD;</span>
<span class="gi">+</span>
<span class="gi">+/** How many blocks to wait between pruning cache */</span>
<span class="gi">+static const int COINBASE_CACHE_PRUNE_INTERVAL = 50;</span>
<span class="gi">+</span>
/**
* Maximum amount of time that a block timestamp is allowed to exceed the
* current network-adjusted time before the block will be accepted.
<span class="gu">@@ -219,6 +230,12 @@ public:</span>
//! (memory only) Maximum nTime in the chain up to and including this block.
unsigned int nTimeMax;
<span class="gi">+ //! Should a coinbase be cached for this block?</span>
<span class="gi">+ bool fCoinbase;</span>
<span class="gi">+</span>
<span class="gi">+ //! Cached coinbase for this block</span>
<span class="gi">+ CTransactionRef coinbase;</span>
<span class="gi">+</span>
void SetNull()
{
phashBlock = nullptr;
<span class="gu">@@ -240,6 +257,9 @@ public:</span>
nTime = 0;
nBits = 0;
nNonce = 0;
<span class="gi">+</span>
<span class="gi">+ fCoinbase = false;</span>
<span class="gi">+ coinbase = NULL;</span>
}
CBlockIndex()
<span class="gu">@@ -405,6 +425,18 @@ public:</span>
READWRITE(nTime);
READWRITE(nBits);
READWRITE(nNonce);
<span class="gi">+</span>
<span class="gi">+ // Coinbase cache</span>
<span class="gi">+ READWRITE(fCoinbase);</span>
<span class="gi">+ if (fCoinbase)</span>
<span class="gi">+ READWRITE(coinbase);</span>
<span class="gi">+ else</span>
<span class="gi">+ if (coinbase && !ser_action.ForRead()) {</span>
<span class="gi">+ // TODO improve</span>
<span class="gi">+ // Reduce size on disk by replacing coinbase with blank tx</span>
<span class="gi">+ CTransactionRef tx = MakeTransactionRef(CTransaction());</span>
<span class="gi">+ READWRITE(tx);</span>
<span class="gi">+ }</span>
}
uint256 GetBlockHash() const
<span class="gh">diff --git a/src/chainparams.cpp b/src/chainparams.cpp</span>
old mode 100644
new mode 100755
<span class="gh">index 6eb223171..e2f7f66d1</span>
<span class="gd">--- a/src/chainparams.cpp</span>
<span class="gi">+++ b/src/chainparams.cpp</span>
<span class="gu">@@ -101,6 +101,11 @@ public:</span>
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
<span class="gi">+ // Deployment of Drivechains (BIPX, BIPY)</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].bit = 4;</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].nStartTime = 1515974401; // January 15th, 2018.</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].nTimeout = 1547510401; // January 15th, 2019.</span>
<span class="gi">+</span>
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000f91c579d57cad4bc5278cc");
<span class="gu">@@ -138,6 +143,8 @@ public:</span>
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
<span class="gi">+ base58Prefixes[SIDECHAIN_PUBKEY_ADDRESS] = std::vector<unsigned char>(1,8);</span>
<span class="gi">+ base58Prefixes[SIDECHAIN_SCRIPT_ADDRESS] = std::vector<unsigned char>(1,63);</span>
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,128);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
<span class="gu">@@ -212,6 +219,11 @@ public:</span>
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
<span class="gi">+ // Deployment of Drivechains (BIPX, BIPY)</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].bit = 4;</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].nStartTime = 1515974401; // January 15th, 2018.</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].nTimeout = 1547510401; // January 15th, 2019.</span>
<span class="gi">+</span>
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000002830dab7f76dbb7d63");
<span class="gu">@@ -240,6 +252,8 @@ public:</span>
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
<span class="gi">+ base58Prefixes[SIDECHAIN_PUBKEY_ADDRESS] = std::vector<unsigned char>(1,8);</span>
<span class="gi">+ base58Prefixes[SIDECHAIN_SCRIPT_ADDRESS] = std::vector<unsigned char>(1,63);</span>
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
<span class="gu">@@ -299,6 +313,10 @@ public:</span>
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].bit = 4;</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;</span>
<span class="gi">+ consensus.vDeployments[Consensus::DEPLOYMENT_DRIVECHAINS].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;</span>
<span class="gi">+</span>
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
<span class="gu">@@ -338,6 +356,8 @@ public:</span>
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
<span class="gi">+ base58Prefixes[SIDECHAIN_PUBKEY_ADDRESS] = std::vector<unsigned char>(1,8);</span>
<span class="gi">+ base58Prefixes[SIDECHAIN_SCRIPT_ADDRESS] = std::vector<unsigned char>(1,63);</span>
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
<span class="gh">diff --git a/src/chainparams.h b/src/chainparams.h</span>
<span class="gh">index d478da989..5c7f863d8 100644</span>
<span class="gd">--- a/src/chainparams.h</span>
<span class="gi">+++ b/src/chainparams.h</span>
<span class="gu">@@ -44,6 +44,8 @@ public:</span>
enum Base58Type {
PUBKEY_ADDRESS,
SCRIPT_ADDRESS,
<span class="gi">+ SIDECHAIN_PUBKEY_ADDRESS,</span>
<span class="gi">+ SIDECHAIN_SCRIPT_ADDRESS,</span>
SECRET_KEY,
EXT_PUBLIC_KEY,
EXT_SECRET_KEY,
<span class="gh">diff --git a/src/coins.cpp b/src/coins.cpp</span>
old mode 100644
new mode 100755
<span class="gh">index 8dfb35c2e..d1703d0f6</span>
<span class="gd">--- a/src/coins.cpp</span>
<span class="gi">+++ b/src/coins.cpp</span>
<span class="gu">@@ -6,6 +6,8 @@</span>
#include <consensus/consensus.h>
#include <random.h>
<span class="gi">+#include <sidechain.h></span>
<span class="gi">+#include <utilstrencodings.h></span>
bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
<span class="gu">@@ -91,7 +93,17 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool</span>
bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
// Always set the possible_overwrite flag to AddCoin for coinbase txn, in order to correctly
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
<span class="gd">- cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);</span>
<span class="gi">+ if (tx.criticalData.IsNull()) {</span>
<span class="gi">+ cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase, false), overwrite);</span>
<span class="gi">+ } else {</span>
<span class="gi">+ uint8_t nSidechain;</span>
<span class="gi">+ uint16_t nPrevBlockRef;</span>
<span class="gi">+ if (tx.criticalData.IsBMMRequest(nSidechain, nPrevBlockRef)) {</span>
<span class="gi">+ cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase, true, nSidechain, nPrevBlockRef, tx.criticalData.hashCritical), overwrite);</span>
<span class="gi">+ } else {</span>
<span class="gi">+ cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase, true), overwrite);</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
}
}
<span class="gu">@@ -232,13 +244,25 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const</span>
return nResult;
}
<span class="gd">-bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const</span>
<span class="gi">+bool CCoinsViewCache::HaveInputs(const CTransaction& tx, bool* fSidechainInputs, uint8_t* nSidechain) const</span>
{
if (!tx.IsCoinBase()) {
for (unsigned int i = 0; i < tx.vin.size(); i++) {
if (!HaveCoin(tx.vin[i].prevout)) {
return false;
}
<span class="gi">+</span>
<span class="gi">+ // Optionally check for Sidechain UTXO inputs</span>
<span class="gi">+ if (fSidechainInputs && nSidechain) {</span>
<span class="gi">+ const Coin &coin = AccessCoin(tx.vin[i].prevout);</span>
<span class="gi">+</span>
<span class="gi">+ auto vsf = ValidSidechainField.find(HexStr(coin.out.scriptPubKey));</span>
<span class="gi">+ if (vsf != ValidSidechainField.end()) {</span>
<span class="gi">+ *fSidechainInputs = true;</span>
<span class="gi">+ *nSidechain = vsf->second;</span>
<span class="gi">+ break;</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
}
}
return true;
<span class="gh">diff --git a/src/coins.h b/src/coins.h</span>
old mode 100644
new mode 100755
<span class="gh">index c6850947e..9b1e7b908</span>
<span class="gd">--- a/src/coins.h</span>
<span class="gi">+++ b/src/coins.h</span>
<span class="gu">@@ -32,34 +32,54 @@ public:</span>
//! unspent transaction output
CTxOut out;
<span class="gi">+ //! at which height this containing transaction was included in the active block chain</span>
<span class="gi">+ uint32_t nHeight : 31;</span>
<span class="gi">+</span>
//! whether containing transaction was a coinbase
unsigned int fCoinBase : 1;
<span class="gd">- //! at which height this containing transaction was included in the active block chain</span>
<span class="gd">- uint32_t nHeight : 31;</span>
<span class="gi">+ //! whether containing transaction has critical data</span>
<span class="gi">+ bool fCriticalData;</span>
<span class="gi">+</span>
<span class="gi">+ //! TODO Memory Only</span>
<span class="gi">+ uint8_t nSidechain;</span>
<span class="gi">+ uint16_t nPrevBlockRef;</span>
<span class="gi">+ uint256 hashCritical;</span>
//! construct a Coin from a CTxOut and height/coinbase information.
<span class="gd">- Coin(CTxOut&& outIn, int nHeightIn, bool fCoinBaseIn) : out(std::move(outIn)), fCoinBase(fCoinBaseIn), nHeight(nHeightIn) {}</span>
<span class="gd">- Coin(const CTxOut& outIn, int nHeightIn, bool fCoinBaseIn) : out(outIn), fCoinBase(fCoinBaseIn),nHeight(nHeightIn) {}</span>
<span class="gi">+ Coin(CTxOut&& outIn, int nHeightIn, bool fCoinBaseIn, bool fCriticalDataIn, uint8_t nSidechainIn = 0, uint16_t nPrevBlockRefIn = 0, uint256 hashCriticalIn = uint256()) : out(std::move(outIn)), nHeight(nHeightIn), fCoinBase(fCoinBaseIn), fCriticalData(fCriticalDataIn), nSidechain(nSidechainIn), nPrevBlockRef(nPrevBlockRefIn), hashCritical(hashCriticalIn) {}</span>
<span class="gi">+ Coin(const CTxOut& outIn, int nHeightIn, bool fCoinBaseIn, bool fCriticalDataIn, uint8_t nSidechainIn = 0, uint16_t nPrevBlockRefIn = 0, uint256 hashCriticalIn = uint256()) : out(outIn), nHeight(nHeightIn), fCoinBase(fCoinBaseIn), fCriticalData(fCriticalDataIn), nSidechain(nSidechainIn), nPrevBlockRef(nPrevBlockRefIn), hashCritical(hashCriticalIn) {}</span>
void Clear() {
out.SetNull();
fCoinBase = false;
<span class="gi">+ fCriticalData = false;</span>
<span class="gi">+ nSidechain = 0;</span>
<span class="gi">+ nPrevBlockRef = 0;</span>
<span class="gi">+ hashCritical.SetNull();</span>
nHeight = 0;
}
//! empty constructor
<span class="gd">- Coin() : fCoinBase(false), nHeight(0) { }</span>
<span class="gi">+ Coin() : nHeight(0), fCoinBase(false), fCriticalData(false), nSidechain(0), nPrevBlockRef(0), hashCritical(uint256()) { }</span>
bool IsCoinBase() const {
return fCoinBase;
}
<span class="gi">+ bool IsCriticalData() const {</span>
<span class="gi">+ return fCriticalData;</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
template<typename Stream>
void Serialize(Stream &s) const {
assert(!IsSpent());
uint32_t code = nHeight * 2 + fCoinBase;
::Serialize(s, VARINT(code));
<span class="gi">+ ::Serialize(s, fCriticalData);</span>
<span class="gi">+ ::Serialize(s, VARINT(nSidechain));</span>
<span class="gi">+ ::Serialize(s, VARINT(nPrevBlockRef));</span>
<span class="gi">+ ::Serialize(s, hashCritical);</span>
::Serialize(s, CTxOutCompressor(REF(out)));
}
<span class="gu">@@ -69,6 +89,10 @@ public:</span>
::Unserialize(s, VARINT(code));
nHeight = code >> 1;
fCoinBase = code & 1;
<span class="gi">+ ::Unserialize(s, fCriticalData);</span>
<span class="gi">+ ::Unserialize(s, VARINT(nSidechain));</span>
<span class="gi">+ ::Unserialize(s, VARINT(nPrevBlockRef));</span>
<span class="gi">+ ::Unserialize(s, hashCritical);</span>
::Unserialize(s, REF(CTxOutCompressor(out)));
}
<span class="gu">@@ -203,7 +227,7 @@ class CCoinsViewCache : public CCoinsViewBacked</span>
protected:
/**
* Make mutable so that we can "fill the cache" even from Get-methods
<span class="gd">- * declared as "const". </span>
<span class="gi">+ * declared as "const".</span>
*/
mutable uint256 hashBlock;
mutable CCoinsMap cacheCoins;
<span class="gu">@@ -280,7 +304,7 @@ public:</span>
//! Calculate the size of the cache (in bytes)
size_t DynamicMemoryUsage() const;
<span class="gd">- /** </span>
<span class="gi">+ /**</span>
* Amount of bitcoins coming in to a transaction
* Note that lightweight clients may not know anything besides the hash of previous transactions,
* so may not be able to calculate this.
<span class="gu">@@ -291,7 +315,8 @@ public:</span>
CAmount GetValueIn(const CTransaction& tx) const;
//! Check whether all prevouts of the transaction are present in the UTXO set represented by this view
<span class="gd">- bool HaveInputs(const CTransaction& tx) const;</span>
<span class="gi">+ // Optionally return whether or not any sidechain UTXO inputs are spent by the tx.</span>
<span class="gi">+ bool HaveInputs(const CTransaction& tx, bool* fSidechainInputs = NULL, uint8_t* nSidechain = NULL) const;</span>
private:
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const;
<span class="gh">diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h</span>
old mode 100644
new mode 100755
<span class="gh">index 650635a76..111a1c930</span>
<span class="gd">--- a/src/consensus/consensus.h</span>
<span class="gi">+++ b/src/consensus/consensus.h</span>
<span class="gu">@@ -23,6 +23,10 @@ static const int WITNESS_SCALE_FACTOR = 4;</span>
static const size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is the lower bound for the size of a valid serialized CTransaction
static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction
<span class="gi">+static const int BMM_MAX_LD = 4000;</span>
<span class="gi">+static const int BMM_MAX_PREVBLOCK = 100;</span>
<span class="gi">+static const int CRITICAL_DATA_MATURITY = 100;</span>
<span class="gi">+</span>
/** Flags for nSequence and nLockTime locks */
/** Interpret sequence numbers as relative lock-time constraints. */
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0);
<span class="gh">diff --git a/src/consensus/params.h b/src/consensus/params.h</span>
old mode 100644
new mode 100755
<span class="gh">index 4ef808c85..3b842faea</span>
<span class="gd">--- a/src/consensus/params.h</span>
<span class="gi">+++ b/src/consensus/params.h</span>
<span class="gu">@@ -18,6 +18,7 @@ enum DeploymentPos</span>
DEPLOYMENT_TESTDUMMY,
DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
DEPLOYMENT_SEGWIT, // Deployment of BIP141, BIP143, and BIP147.
<span class="gi">+ DEPLOYMENT_DRIVECHAINS, // Deployment of BIPX and BIPY.</span>
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
MAX_VERSION_BITS_DEPLOYMENTS
};
<span class="gh">diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp</span>
old mode 100644
new mode 100755
<span class="gh">index be73d0a2f..0d601d799</span>
<span class="gd">--- a/src/consensus/tx_verify.cpp</span>
<span class="gi">+++ b/src/consensus/tx_verify.cpp</span>
<span class="gu">@@ -4,15 +4,16 @@</span>
#include <consensus/tx_verify.h>
<span class="gd">-#include <consensus/consensus.h></span>
<span class="gd">-#include <primitives/transaction.h></span>
<span class="gd">-#include <script/interpreter.h></span>
<span class="gd">-#include <consensus/validation.h></span>
<span class="gi">+#include "consensus.h"</span>
<span class="gi">+#include "primitives/transaction.h"</span>
<span class="gi">+#include "script/interpreter.h"</span>
<span class="gi">+#include "sidechaindb.h"</span>
<span class="gi">+#include "validation.h"</span>
// TODO remove the following dependencies
<span class="gd">-#include <chain.h></span>
<span class="gd">-#include <coins.h></span>
<span class="gd">-#include <utilmoneystr.h></span>
<span class="gi">+#include "chain.h"</span>
<span class="gi">+#include "coins.h"</span>
<span class="gi">+#include "utilmoneystr.h"</span>
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
{
<span class="gu">@@ -210,11 +211,13 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c</span>
// are the actual inputs available?
if (!inputs.HaveInputs(tx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-missingorspent", false,
<span class="gd">- strprintf("%s: inputs missing/spent", __func__));</span>
<span class="gi">+ strprintf("%s: inputs missing/spent", __func__));</span>
}
CAmount nValueIn = 0;
<span class="gd">- for (unsigned int i = 0; i < tx.vin.size(); ++i) {</span>
<span class="gi">+ CAmount nFees = 0;</span>
<span class="gi">+ for (unsigned int i = 0; i < tx.vin.size(); i++)</span>
<span class="gi">+ {</span>
const COutPoint &prevout = tx.vin[i].prevout;
const Coin& coin = inputs.AccessCoin(prevout);
assert(!coin.IsSpent());
<span class="gh">diff --git a/src/init.cpp b/src/init.cpp</span>
old mode 100644
new mode 100755
<span class="gh">index 84398d978..58f1c2fac</span>
<span class="gd">--- a/src/init.cpp</span>
<span class="gi">+++ b/src/init.cpp</span>
<span class="gu">@@ -7,46 +7,49 @@</span>
#include <config/bitcoin-config.h>
#endif
<span class="gd">-#include <init.h></span>
<span class="gd">-</span>
<span class="gd">-#include <addrman.h></span>
<span class="gd">-#include <amount.h></span>
<span class="gd">-#include <chain.h></span>
<span class="gd">-#include <chainparams.h></span>
<span class="gd">-#include <checkpoints.h></span>
<span class="gd">-#include <compat/sanity.h></span>
<span class="gd">-#include <consensus/validation.h></span>
<span class="gd">-#include <fs.h></span>
<span class="gd">-#include <httpserver.h></span>
<span class="gd">-#include <httprpc.h></span>
<span class="gd">-#include <key.h></span>
<span class="gd">-#include <validation.h></span>
<span class="gd">-#include <miner.h></span>
<span class="gd">-#include <netbase.h></span>
<span class="gd">-#include <net.h></span>
<span class="gd">-#include <net_processing.h></span>
<span class="gd">-#include <policy/feerate.h></span>
<span class="gd">-#include <policy/fees.h></span>
<span class="gd">-#include <policy/policy.h></span>
<span class="gd">-#include <rpc/server.h></span>
<span class="gd">-#include <rpc/register.h></span>
<span class="gd">-#include <rpc/safemode.h></span>
<span class="gd">-#include <rpc/blockchain.h></span>
<span class="gd">-#include <script/standard.h></span>
<span class="gd">-#include <script/sigcache.h></span>
<span class="gd">-#include <scheduler.h></span>
<span class="gd">-#include <timedata.h></span>
<span class="gd">-#include <txdb.h></span>
<span class="gd">-#include <txmempool.h></span>
<span class="gd">-#include <torcontrol.h></span>
<span class="gd">-#include <ui_interface.h></span>
<span class="gd">-#include <util.h></span>
<span class="gd">-#include <utilmoneystr.h></span>
<span class="gd">-#include <validationinterface.h></span>
<span class="gi">+#include "init.h"</span>
<span class="gi">+</span>
<span class="gi">+#include "addrman.h"</span>
<span class="gi">+#include "amount.h"</span>
<span class="gi">+#include "chain.h"</span>
<span class="gi">+#include "chainparams.h"</span>
<span class="gi">+#include "checkpoints.h"</span>
<span class="gi">+#include "compat/sanity.h"</span>
<span class="gi">+#include "consensus/validation.h"</span>
<span class="gi">+#include "fs.h"</span>
<span class="gi">+#include "httpserver.h"</span>
<span class="gi">+#include "httprpc.h"</span>
<span class="gi">+#include "key.h"</span>
<span class="gi">+#include "validation.h"</span>
<span class="gi">+#include "miner.h"</span>
<span class="gi">+#include "netbase.h"</span>
<span class="gi">+#include "net.h"</span>
<span class="gi">+#include "net_processing.h"</span>
<span class="gi">+#include "policy/feerate.h"</span>
<span class="gi">+#include "policy/fees.h"</span>
<span class="gi">+#include "policy/policy.h"</span>
<span class="gi">+#include "rpc/server.h"</span>
<span class="gi">+#include "rpc/register.h"</span>
<span class="gi">+#include "rpc/blockchain.h"</span>
<span class="gi">+#include "script/standard.h"</span>
<span class="gi">+#include "script/sigcache.h"</span>
<span class="gi">+#include "scheduler.h"</span>
<span class="gi">+#include "sidechain.h"</span>
<span class="gi">+#include "sidechaindb.h"</span>
<span class="gi">+#include "timedata.h"</span>
<span class="gi">+#include "txdb.h"</span>
<span class="gi">+#include "txmempool.h"</span>
<span class="gi">+#include "torcontrol.h"</span>
<span class="gi">+#include "ui_interface.h"</span>
<span class="gi">+#include "util.h"</span>
<span class="gi">+#include "utilmoneystr.h"</span>
<span class="gi">+#include "validationinterface.h"</span>
#ifdef ENABLE_WALLET
#include <wallet/init.h>
<span class="gi">+#include <wallet/wallet.h></span>
#endif
<span class="gd">-#include <warnings.h></span>
<span class="gi">+#include "warnings.h"</span>
<span class="gi">+#include <algorithm></span>
#include <stdint.h>
#include <stdio.h>
#include <memory>
<span class="gu">@@ -71,6 +74,7 @@ bool fFeeEstimatesInitialized = false;</span>
static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
<span class="gi">+static const bool DEFAULT_DISABLE_SAFEMODE = false;</span>
std::unique_ptr<CConnman> g_connman;
std::unique_ptr<PeerLogicValidation> peerLogic;
<span class="gu">@@ -1570,6 +1574,47 @@ bool AppInitMain()</span>
}
}
<span class="gi">+ bool drivechainsEnabled = IsDrivechainEnabled(chainActive.Tip(), chainparams.GetConsensus());</span>
<span class="gi">+</span>
<span class="gi">+ // Synchronize SCDB</span>
<span class="gi">+ if (drivechainsEnabled && chainActive.Tip() && (chainActive.Tip()->GetBlockHash() != scdb.GetHashBlockLastSeen()))</span>
<span class="gi">+ {</span>
<span class="gi">+ // Find out how many blocks we need to update SCDB</span>
<span class="gi">+ const int nHeight = chainActive.Height();</span>
<span class="gi">+ int nTail = nHeight;</span>
<span class="gi">+ for (const Sidechain& s : ValidSidechains) {</span>
<span class="gi">+ int nLastPeriod = s.GetLastVerificationPeriod(nHeight);</span>
<span class="gi">+ if (nLastPeriod < nTail)</span>
<span class="gi">+ nTail = nLastPeriod;</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ // Update SCDB</span>
<span class="gi">+ for (int i = nTail; i <= nHeight; i++) {</span>
<span class="gi">+ // Skip genesis block</span>
<span class="gi">+ if (i == 0)</span>
<span class="gi">+ continue;</span>
<span class="gi">+</span>
<span class="gi">+ CBlockIndex* pindex = chainActive[i];</span>
<span class="gi">+ // Check that block index exists</span>
<span class="gi">+ if (!pindex) {</span>
<span class="gi">+ LogPrintf("SCDB cannot read null block index. Exiting.\n");</span>
<span class="gi">+ return false;</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ // Check that coinbase is cached</span>
<span class="gi">+ if (!pindex->fCoinbase || !pindex->coinbase)</span>
<span class="gi">+ return InitError("Cannot initalize SCDB. Corrupt coinbase cache.\n");</span>
<span class="gi">+</span>
<span class="gi">+ // Update SCDB</span>
<span class="gi">+ std::string strError = "";</span>
<span class="gi">+ if (!scdb.Update(i, pindex->GetBlockHash(), pindex->coinbase->vout, strError)) {</span>
<span class="gi">+ if (strError != "")</span>
<span class="gi">+ LogPrintf("SCDB update error: %s\n", strError);</span>
<span class="gi">+ return InitError("Failed to initialize SCDB.\n");</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
// As LoadBlockIndex can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
// As the program has not fully started yet, Shutdown() is possibly overkill.
<span class="gu">@@ -1741,7 +1786,29 @@ bool AppInitMain()</span>
#ifdef ENABLE_WALLET
StartWallets(scheduler);
<span class="gi">+</span>
<span class="gi">+ if (drivechainsEnabled) {</span>
<span class="gi">+ for (CWalletRef pwallet : vpwallets) {</span>
<span class="gi">+ LOCK2(cs_main, pwallet->cs_wallet);</span>
<span class="gi">+ pwallet->MarkDirty();</span>
<span class="gi">+</span>
<span class="gi">+ // Watch sidechain deposit addresses</span>
<span class="gi">+ for (const Sidechain& sidechain : ValidSidechains) {</span>
<span class="gi">+ std::vector<unsigned char> data(ParseHex(std::string(sidechain.sidechainHex)));</span>
<span class="gi">+ CScript script(data.begin(), data.end());</span>
<span class="gi">+ if (!pwallet->HaveWatchOnly(script)) {</span>
<span class="gi">+ pwallet->AddWatchOnly(script, 0 /* nCreateTime */);</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ CTxDestination destination;</span>
<span class="gi">+ if (ExtractDestination(script, destination)) {</span>
<span class="gi">+ pwallet->SetAddressBook(destination, sidechain.GetSidechainName(), "receive");</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ }</span>
#endif
<span class="gd">- return true;</span>
<span class="gi">+ return !fRequestShutdown;</span>
}
<span class="gh">diff --git a/src/miner.cpp b/src/miner.cpp</span>
old mode 100644
new mode 100755
<span class="gh">index dda52790c..f81d7a02f</span>
<span class="gd">--- a/src/miner.cpp</span>
<span class="gi">+++ b/src/miner.cpp</span>
<span class="gu">@@ -3,28 +3,37 @@</span>
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
<span class="gd">-#include <miner.h></span>
<span class="gd">-</span>
<span class="gd">-#include <amount.h></span>
<span class="gd">-#include <chain.h></span>
<span class="gd">-#include <chainparams.h></span>
<span class="gd">-#include <coins.h></span>
<span class="gd">-#include <consensus/consensus.h></span>
<span class="gd">-#include <consensus/tx_verify.h></span>
<span class="gd">-#include <consensus/merkle.h></span>
<span class="gd">-#include <consensus/validation.h></span>
<span class="gd">-#include <hash.h></span>
<span class="gd">-#include <validation.h></span>
<span class="gd">-#include <net.h></span>
<span class="gd">-#include <policy/feerate.h></span>
<span class="gd">-#include <policy/policy.h></span>
<span class="gd">-#include <pow.h></span>
<span class="gd">-#include <primitives/transaction.h></span>
<span class="gd">-#include <script/standard.h></span>
<span class="gd">-#include <timedata.h></span>
<span class="gd">-#include <util.h></span>
<span class="gd">-#include <utilmoneystr.h></span>
<span class="gd">-#include <validationinterface.h></span>
<span class="gi">+#include "miner.h"</span>
<span class="gi">+</span>
<span class="gi">+#include "amount.h"</span>
<span class="gi">+#include "base58.h"</span>
<span class="gi">+#include "chain.h"</span>
<span class="gi">+#include "chainparams.h"</span>
<span class="gi">+#include "coins.h"</span>
<span class="gi">+#include "consensus/consensus.h"</span>
<span class="gi">+#include "consensus/tx_verify.h"</span>
<span class="gi">+#include "consensus/merkle.h"</span>
<span class="gi">+#include "consensus/validation.h"</span>
<span class="gi">+#include "hash.h"</span>
<span class="gi">+#include "validation.h"</span>
<span class="gi">+#include "net.h"</span>
<span class="gi">+#include "policy/feerate.h"</span>
<span class="gi">+#include "policy/policy.h"</span>
<span class="gi">+#include "pow.h"</span>
<span class="gi">+#include "primitives/transaction.h"</span>
<span class="gi">+#include "script/standard.h"</span>
<span class="gi">+#include "sidechain.h"</span>
<span class="gi">+#include "sidechaindb.h"</span>
<span class="gi">+#include "timedata.h"</span>
<span class="gi">+#include "txmempool.h"</span>
<span class="gi">+#include "util.h"</span>
<span class="gi">+#include "utilmoneystr.h"</span>
<span class="gi">+#include "utilstrencodings.h"</span>
<span class="gi">+#include "validationinterface.h"</span>
<span class="gi">+</span>
<span class="gi">+#ifdef ENABLE_WALLET</span>
<span class="gi">+#include "wallet/wallet.h"</span>
<span class="gi">+#endif</span>
#include <algorithm>
#include <queue>
<span class="gu">@@ -163,9 +172,31 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc</span>
coinbaseTx.vin[0].prevout.SetNull();
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
<span class="gi">+</span>
<span class="gi">+ bool drivechainsEnabled = IsDrivechainEnabled(pindexPrev, chainparams.GetConsensus());</span>
<span class="gi">+</span>
<span class="gi">+ if (drivechainsEnabled) {</span>
<span class="gi">+ // Add WT^(s) which have been validated</span>
<span class="gi">+ for (const Sidechain& s : ValidSidechains) {</span>
<span class="gi">+ CTransaction wtx = CreateWTPrimePayout(s.nSidechain);</span>
<span class="gi">+ if (wtx.vout.size() && wtx.vin.size())</span>
<span class="gi">+ pblock->vtx.push_back(MakeTransactionRef(std::move(wtx)));</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
<span class="gi">+</span>
<span class="gi">+ if (drivechainsEnabled) {</span>
<span class="gi">+ // We're generating the block, and will upvote the last WT^ by default.</span>
<span class="gi">+ if (scdb.HasState())</span>
<span class="gi">+ scdb.UpdateSCDBIndex(scdb.GetUpvotes());</span>
<span class="gi">+ GenerateSCDBHashMerkleRootCommitment(*pblock, chainparams.GetConsensus());</span>
<span class="gi">+ GenerateBMMHashMerkleRootCommitment(*pblock, chainparams.GetConsensus());</span>
<span class="gi">+ GenerateCriticalHashCommitment(*pblock, chainparams.GetConsensus());</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
pblocktemplate->vTxFees[0] = -nFees;
<span class="gu">@@ -273,6 +304,139 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already</span>
return nDescendantsUpdated;
}
<span class="gi">+CTransaction BlockAssembler::CreateWTPrimePayout(uint8_t nSidechain)</span>
<span class="gi">+{</span>
<span class="gi">+ // The WT^ that will be created</span>
<span class="gi">+ CMutableTransaction mtx;</span>
<span class="gi">+</span>
<span class="gi">+ if (!IsDrivechainEnabled(chainActive.Tip(), chainparams.GetConsensus()))</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+</span>
<span class="gi">+#ifdef ENABLE_WALLET</span>
<span class="gi">+ if (!scdb.HasState())</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+ if (!IsSidechainNumberValid(nSidechain))</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+</span>
<span class="gi">+ const Sidechain& sidechain = ValidSidechains[nSidechain];</span>
<span class="gi">+</span>
<span class="gi">+ // TODO remove</span>
<span class="gi">+ if (nSidechain == SIDECHAIN_TEST) {</span>
<span class="gi">+ if (nHeight % SIDECHAIN_TEST_VERIFICATION_PERIOD != 0)</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+ } else {</span>
<span class="gi">+ if (nHeight % SIDECHAIN_VERIFICATION_PERIOD != 0)</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+</span>
<span class="gi">+ // Select the highest scoring B-WT^ for sidechain during verification period</span>
<span class="gi">+ uint256 hashBest = uint256();</span>
<span class="gi">+ uint16_t scoreBest = 0;</span>
<span class="gi">+ std::vector<SidechainWTPrimeState> vState = scdb.GetState(nSidechain);</span>
<span class="gi">+ for (const SidechainWTPrimeState& state : vState) {</span>
<span class="gi">+ if (state.nWorkScore > scoreBest || scoreBest == 0) {</span>
<span class="gi">+ hashBest = state.hashWTPrime;</span>
<span class="gi">+ scoreBest = state.nWorkScore;</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+ if (hashBest == uint256())</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+</span>
<span class="gi">+ // Is the selected B-WT^ verified?</span>
<span class="gi">+ // Different MIN_WORKSCORE requirement for test sidechain (for testing..)</span>
<span class="gi">+ if (nSidechain == SIDECHAIN_TEST) {</span>
<span class="gi">+ if (scoreBest < SIDECHAIN_TEST_MIN_WORKSCORE)</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+ } else {</span>
<span class="gi">+ if (scoreBest < SIDECHAIN_MIN_WORKSCORE)</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ // Copy outputs from B-WT^</span>
<span class="gi">+ // Note that this shouldn't be changed to be more efficient by just copying</span>
<span class="gi">+ // the entire transaction. We should copy the outputs only.</span>
<span class="gi">+ std::vector<CTransaction> vWTPrime = scdb.GetWTPrimeCache();</span>
<span class="gi">+ for (const CTransaction& tx : vWTPrime) {</span>
<span class="gi">+ if (tx.GetHash() == hashBest) {</span>
<span class="gi">+ for (const CTxOut& out : tx.vout)</span>
<span class="gi">+ mtx.vout.push_back(out);</span>
<span class="gi">+ break;</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+ if (!mtx.vout.size())</span>
<span class="gi">+ return mtx;</span>
<span class="gi">+</span>
<span class="gi">+ // Calculate the amount to be withdrawn by WT^</span>
<span class="gi">+ CAmount amtBWT = CAmount(0);</span>
<span class="gi">+ for (const CTxOut& out : mtx.vout) {</span>
<span class="gi">+ const CScript scriptPubKey = out.scriptPubKey;</span>
<span class="gi">+ if (HexStr(scriptPubKey) != sidechain.sidechainHex) {</span>
<span class="gi">+ amtBWT += out.nValue;</span>
<span class="gi">+ }</span>
<span class="gi">+ }</span>
<span class="gi">+</span>
<span class="gi">+ // Format sidechain change return script</span>
<span class="gi">+ CKeyID sidechainKey;</span>
<span class="gi">+ sidechainKey.SetHex(sidechain.sidechainKey);</span>
<span class="gi">+ CScript sidechainScript;</span>
<span class="gi">+ sidechainScript << OP_DUP << OP_HASH160 << ToByteVector(sidechainKey) << OP_EQUALVERIFY << OP_CHECKSIG;</span>
<span class="gi">+</span>