-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestoptions.go
784 lines (734 loc) · 29.6 KB
/
testoptions.go
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
/*
github.com/tcrain/cons - Experimental project for testing and scaling consensus algorithms.
Copyright (C) 2020 The project authors - tcrain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package types
import (
"encoding/json"
"fmt"
"github.com/tcrain/cons/config"
"github.com/tcrain/cons/consensus/logging"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
)
// TestOptions are given as input to consensus tests to describe the test behaviour
type TestOptions struct {
UseFixedSeed bool // If true then use a fix seed to generate proposals/coin
OrderingType OrderingType // Total order or causal order
FailRounds uint64 // The round faulty processes will crash
FailDuration uint64 // How long to sleep before restarting a failure in milliseconds
MaxRounds uint64 // The number of consensus instances run by the test
NumFailProcs int // The number of faulty processes
NumTotalProcs int // The total number of processes
NumNonMembers int // How many of the processes are just listening/forwarding, but are not allowed to participate in consensus
StorageType StorageType // The type of storage to use
ClearDiskOnRestart bool // If when faulty processes crash they should also lose their disk storage
NetworkType NetworkPropagationType // The network type to use (all to all or gossip)
FanOut int // How many neighbors a process has (when not using an all to all network)
ConnectionType NetworkProtocolType // The connection type being used (UDP/TCP)
ByzType ByzType // The behaviour of the byzantine processes
NumByz int // The number of byzantine processes
CheckDecisions bool // Check all processes have decided the same values at the end of the test
MsgDropPercent int // Percentage of messages to be artificially dropped by the network
IncludeProofs bool // Include signatures as part of messages that prove you are sending a valid message (see protocol description)
SigType SigType // The type of signature to use
UsePubIndex bool // Identify processes just by their index in the list of pub keys (otherwise use the whole pub key as the id)
SleepValidate bool // If true we dont validate sigs, just sleep
SleepCrypto bool // If true all signature based crypto is done using sleeps
MCType MemberCheckerType // if TestMemberCheckers is false, then test a specific type
BufferForwardType BufferForwardType // Buffer several messages before forwarding them (in a gossip network)
UseMultisig bool // Use multi-signautres
BlsMultiNew bool // Use the new type of BLS multi-signatures (see https://crypto.stanford.edu/~dabo/pubs/papers/BLSmultisig.html)
MemCheckerBitIDType BitIDType // If using multi-sigs the type of bit ID to use in the member checker
SigBitIDType BitIDType // If using multi-sigs the type of bit ID to use with the signatures
StateMachineType StateMachineType // The application being implemented by the state machines
PartialMessageType PartialMessageType // The type of partial messsages to use during broadcasts
AllowConcurrent uint64 // Number of concurrent consensus indecies to allow to run.
LocalRandMemberChange uint64 // On consensus index mod this value, the local rand member checker will change.
RotateCord bool // If true then the coordinator will rotate each consensus index, if supported by the member checker.
AllowSupportCoin bool // True if AuxProofMessages can support the coin directly instead of a bin value.
ConsType ConsType // The type of the consensus being used for the test.
// UseFullBinaryState will (if true) keep the consensus state as the list of all valid messages received appended together,
// if false stores only different messages with all the signatures at the end
UseFullBinaryState bool
StorageBuffer int // byte size of buffer for writing to disk
IncludeCurrentSigs bool // When forwarding a message (for non all-to-all networks) will include all sigs received so far
CPUProfile bool // If true will profile CPU usage
MemProfile bool // If true will profile mem usage
NumMsgProcessThreads int // Number of threads that will process messages
MvProposalSizeBytes int // Size of proposals when using MvCons1ProposalInfo to propose random bytes
BinConsPercentOnes int // When using binary consensus number of proposals that will be 1 vs 0 (randomly chosen) for testing
CollectBroadcast CollectBroadcastType // If true, when sending the commit message, will send it to the leader
StopOnCommit StopOnCommitType // If true then the consensus will not execute rounds after deciding (the eventual message propagation will ensure termination)
ByzStartIndex uint64 // Index to start faulty behaviour
TestID uint64 // unique identifier for the test
AdditionalP2PNetworks int // Generate additional P2P connection networks, used when sending the same message type multiple times when using buffer forwarder
EncryptChannels bool // True if network channels should be encrypted using nacl secretbox
NoSignatures bool // Use encrypted channels for message authentification instead of signatures
CoinType CoinType // The type of coin being used
UseFixedCoinPresets bool // If true then will use predefined coins for the initial rounds of randomized consensus
SharePubsRPC bool // If true then during RPC tests nodes on the same machine will share public key objects for external nodes
WarmUpInstances int // Number of consensus instances to run before recording results
KeepPast int // Number of previously decided consensus instances to keep in memory
ForwardTimeout int // milliseconds // for msg forwarder when you dont receive enough messages to foward a buffer automatically
RandForwardTimeout int // amount of time to randomly add to Forward timeout
ProgressTimeout int // milliseconds, if no progress in this time, let neighbors know
MvConsTimeout int // millseconds timeout when taking an action in the MV consensus algorithms
MvConsVRFTimeout int // millseconds timeout for waiting for a proposal when VRFs are enabled (only used by MVCons3)
MvConsRequestRecoverTimeout int // millseconds timeout before requesting the full proposal after delivering the hash
NodeChoiceVRFRelaxation int // Additional chance to chose a node as a member when using VRF.
CoordChoiceVRF int // Chance of each node being chosen as a coordinator when using VRF.
GenRandBytes bool // If true the state machine shouldn generate random bytes each decision.
RndMemberCount int // Only works if GenRandBytes is ture. This chooses RndMemberCount members to randomly decide which nodes will participate, if 0 random selection is not used.
RndMemberType RndMemberType // Type of random membeship selection, RndMemberCount must be > 0 for this.
UseRandCoord bool // If true round coordinators will be chosen using VRFs note, that these are only calculated from within the existing random members
// so the coordinator relaxation may need to be higher
MvCons4BcastType MvCons4BcastType // the type of message broadcast used by MvCons4
}
// UsesVRFs returns true if this test configuration uses VRFs.
func (to TestOptions) UsesVRFs() bool {
switch to.RndMemberType {
case KnownPerCons, VRFPerCons, VRFPerMessage:
return true
}
return to.UseRandCoord
}
func (to TestOptions) String() string {
return fmt.Sprintf("{ConsType: %v, Rounds: %v, Fail round: %v, Total procs: %v, Nonmember procs: %v, Fail procs: %v, "+
"\n\tConnection: %s, Msg Drop%%: %v, Network: %s, Nw fan out: %v, Storage type: %s, Clear disk on restart: %v,"+
"\n\tInclude proofs: %v, Sig type: %s, Use multisig: %v, Use pub index: %v, Buffer Forwarder: %v,"+
"\n\tState machine: %v, Allow concurrent: %v, Rotate cord: %v, Gen rand bytes: %v, Ordering: %v,"+
"\n\tRand member type: %v, Rand coord: %v, Rand members %v, LocalRandMemberChange: %v, AllowSupportCoin: %v,"+
"\n\tUseFullBinaryState %v, StorageBuffer %v, IncludeCurrentSigs %v, CPUProfile %v, MemProfile %v,"+
"\n\tNumMsgProcessThreads %v, MvProposalSizeBytes %v, BinConsPercentOnes %v, CollectBroadcast: %v,"+
"\n\tStopOnCommit: %v, FixedSeed: %v, EncryptChannels: %v, NoSignatures: %v, Byz procs: %v, ByzType: %s,"+
"\n\tCoinType: %v, UseFixedCoinPresets: %v, Sleep Crypto: %v, Share Pubs: %v, MCType: %v,"+
"\n\tSig BitID: %v, MC BitID: %v, WarmUp: %v, KeepPast %v, FwdTimeout: %v, RndFwdTimeout: %v,"+
"\n\t ProgressTimeout: %v, MVTimeout: %v, MVVRFTimeout: %v, MVRecoverTimeout: %v, NodeVRFRelax: %v,"+
"\n\tCoordVRF: %v, MvCons4Bcast: %v, TestID %v}",
to.ConsType, to.MaxRounds, to.FailRounds, to.NumTotalProcs, to.NumNonMembers, to.NumFailProcs,
to.ConnectionType, to.MsgDropPercent, to.NetworkType, to.FanOut, to.StorageType,
to.ClearDiskOnRestart, to.IncludeProofs, to.SigType, to.UseMultisig, to.UsePubIndex, to.BufferForwardType,
to.StateMachineType, to.AllowConcurrent, to.RotateCord, to.GenRandBytes, to.OrderingType, to.RndMemberType,
to.UseRandCoord, to.RndMemberCount, to.LocalRandMemberChange, to.AllowSupportCoin,
to.UseFullBinaryState, to.StorageBuffer, to.IncludeCurrentSigs, to.CPUProfile, to.MemProfile,
to.NumMsgProcessThreads, to.MvProposalSizeBytes, to.BinConsPercentOnes, to.CollectBroadcast, to.StopOnCommit, to.UseFixedSeed,
to.EncryptChannels, to.NoSignatures, to.NumByz, to.ByzType, to.CoinType, to.UseFixedCoinPresets,
to.SleepCrypto, to.SharePubsRPC, to.MCType,
to.SigBitIDType, to.MemCheckerBitIDType, to.WarmUpInstances, to.KeepPast, to.ForwardTimeout, to.RandForwardTimeout, to.ProgressTimeout,
to.MvConsTimeout, to.MvConsVRFTimeout, to.MvConsRequestRecoverTimeout, to.NodeChoiceVRFRelaxation,
to.CoordChoiceVRF, to.MvCons4BcastType, to.TestID)
}
func AllowsGetRandBytes(smType StateMachineType) bool {
switch smType {
case CounterProposer, BytesProposer, CounterTxProposer, CurrencyTxProposer:
return true
}
return false
}
func makeStr(id string, val, newVal interface{}) string {
return fmt.Sprintf("%v: %v -> %v, ", id, val, newVal)
}
// FieldDiff returns a list of the fields that differ between the test options.
func (to TestOptions) FieldDiff(other TestOptions) (ret []string) {
toV := reflect.ValueOf(to)
otherV := reflect.ValueOf(other)
for i := 0; i < toV.NumField(); i++ {
v1 := toV.Field(i).Interface()
v2 := otherV.Field(i).Interface()
if v1 != v2 {
ret = append(ret, toV.Type().Field(i).Name)
}
}
return ret
}
// StringDiff returns a human readable string of the differences between the test options.
func (to TestOptions) StringDiff(other TestOptions) string {
b := strings.Builder{}
b.WriteString("Config difference: ")
toV := reflect.ValueOf(to)
otherV := reflect.ValueOf(other)
for i := 0; i < toV.NumField(); i++ {
v1 := toV.Field(i).Interface()
v2 := otherV.Field(i).Interface()
if v1 != v2 {
if _, err := b.WriteString(makeStr(toV.Type().Field(i).Name, v1, v2)); err != nil {
panic(err)
}
}
}
return b.String()
}
func (to TestOptions) AllowsRandMembers(checkerType MemberCheckerType) bool {
if !to.GenRandBytes && to.RndMemberType != LocalRandMember {
return false
}
switch checkerType {
case CurrentTrueMC, LaterMC, CurrencyMC:
return true
}
return false
}
// AllowsOutOfOrderProposals should return true if proposals might not see the state of the previous commited when they are made.
func (to TestOptions) AllowsOutOfOrderProposals(consType ConsType) bool {
switch to.StateMachineType {
case CurrencyTxProposer:
return false
}
switch consType {
case BinCons1Type, BinConsRnd1Type, BinConsRnd2Type, BinConsRnd3Type, BinConsRnd4Type, BinConsRnd5Type, BinConsRnd6Type:
return false
case MvBinCons1Type, MvBinConsRnd1Type, MvBinConsRnd2Type:
if to.AllowConcurrent > 1 {
return true
}
return false
case MvCons2Type:
if to.AllowConcurrent > 1 {
return true
}
return false
case MvCons3Type:
return false
case MvCons4Type:
return true
case SimpleConsType:
if to.AllowConcurrent > 1 {
return true
}
return false
case RbBcast1Type, RbBcast2Type:
if to.AllowConcurrent > 1 {
return true
}
return false
default:
panic("unknown cons type")
}
}
func GetOrderForSM(smt StateMachineType) OrderingType {
for _, nxt := range TotalOrderProposerTypes {
if smt == nxt {
return Total
}
}
for _, nxt := range CausalProposerTypes {
if smt == nxt {
return Causal
}
}
if smt == TestProposer {
return Total
}
panic(smt)
}
// SanitizeTO will clean certain parts of the test configuration, so that it is valid.
// Should only be used during benchmarks when using the same config for multiple
// node counts.
func (to TestOptions) SanitizeTO() (newTO TestOptions) {
newTO = to
switch newTO.RndMemberType {
case NonRandom:
if newTO.RndMemberCount != 0 {
logging.Printf("setting RndMemberCount to 0")
newTO.RndMemberCount = 0
}
}
switch newTO.NetworkType {
case AllToAll:
if newTO.FanOut != 0 {
logging.Printf("setting FanOut to 0")
newTO.FanOut = 0
}
}
return
}
// CheckValid returns an error if the generalconfig in invalid
func (to TestOptions) CheckValid(consType ConsType, isMv bool) (newTo TestOptions, err error) {
newTo = to
consProcs := to.NumTotalProcs - to.NumNonMembers // consensus participants
if !to.AllowsOutOfOrderProposals(consType) && consType == MvCons4Type {
err = fmt.Errorf("%v supports out of order proposals, which is not compatalbe with %v", consType, to.StateMachineType)
return
}
if to.AllowSupportCoin {
switch to.CoinType {
case KnownCoinType, LocalCoinType, FlipCoinType:
err = fmt.Errorf("cannot support coin when using known, flip, or local coin type")
return
}
if consType == MvBinConsRnd1Type || consType == MvBinConsRnd2Type {
err = fmt.Errorf("TODO allow support coin with reduction")
return
}
}
if to.RndMemberType != NonRandom {
switch to.CoinType {
case NoCoinType, KnownCoinType, FlipCoinType, LocalCoinType:
default:
err = fmt.Errorf("coin %v not supported with %v", to.CoinType, to.RndMemberType)
return
}
}
if to.CoinType != NoCoinType {
switch UseTp1CoinThresh(to) {
case true:
switch to.CoinType {
case StrongCoin2EchoType, StrongCoin1EchoType:
// ok
case StrongCoin2Type:
// must be rndcons 4
if to.ConsType != BinConsRnd4Type && to.ConsType != BinConsRnd6Type {
err = fmt.Errorf("if using t+1 threshold coins and StrongCoin2, must use BinConsRnd4/6")
return
}
case StrongCoin1Type:
if to.ConsType != BinConsRnd4Type && to.ConsType != BinConsRnd6Type {
err = fmt.Errorf("if using t+1 threshold coins and StrongCoin1, must use BinConsRnd4/6")
return
}
}
case false:
}
}
if to.CoinType == StrongCoin1Type || to.CoinType == StrongCoin1EchoType {
if to.SigType != TBLS && to.SigType != TBLSDual && to.SigType != CoinDual {
err = fmt.Errorf("StrongCoin1Type must be used with TBLS or TBLSDual")
return
}
}
if to.CoinType == StrongCoin2Type || to.CoinType == StrongCoin2EchoType {
if to.SigType != EDCOIN {
err = fmt.Errorf("StrongCoin2Type must be used with EDCOIN")
return
}
}
if to.RndMemberType != NonRandom {
if to.RndMemberCount > to.NumTotalProcs-to.NumNonMembers {
err = fmt.Errorf("must have at least as many members as rand members, rnd members: %v, non members: %v, total mem: %v",
to.RndMemberCount, to.NumTotalProcs, to.NumNonMembers)
return
}
}
if to.UseRandCoord {
if to.RndMemberType == VRFPerCons {
err = fmt.Errorf("rand coord not supported with VRFPerCons")
return
}
if to.RotateCord {
err = fmt.Errorf("cannot have random and rotate coord enabled together")
return
}
}
if to.NoSignatures {
switch to.RndMemberType {
case VRFPerCons, VRFPerMessage, KnownPerCons:
err = fmt.Errorf("must use signatures with %v", to.RndMemberType)
return
}
if to.CollectBroadcast != Full {
err = fmt.Errorf("no signatures only support full broadcasts")
return
}
if to.NetworkType != AllToAll && to.NetworkType != RequestForwarder {
err = fmt.Errorf("must use either all to all network or request forward network with no signatures")
return
}
if !to.EncryptChannels {
err = fmt.Errorf("if not using signatures, must encrypt channels")
return
}
if to.StopOnCommit == SendProof {
err = fmt.Errorf("cannot send proofs if not using signatures")
return
}
if to.IncludeProofs {
err = fmt.Errorf("cannot use proofs if not using signatures")
return
}
}
if to.EncryptChannels {
var found bool
for _, nxt := range EncryptChannelsSigTypes {
if nxt == to.SigType {
found = true
break
}
}
if !found {
err = fmt.Errorf("sig type %d does not support encrypted channels", to.SigType)
return
}
}
if to.BufferForwardType != NoBufferForward {
switch to.NetworkType {
case P2p, Random:
// ok
default:
err = fmt.Errorf("buffer forward can only be used with p2p or random network type")
return
}
}
if to.ConnectionType == UDP && to.EncryptChannels {
err = fmt.Errorf("UDP and encrypted channels currently not supported")
return
}
if to.BufferForwardType != ThresholdBufferForward && to.AdditionalP2PNetworks > 0 {
err = fmt.Errorf("additional P2P networks not needed if buffer forwarder is being used")
return
}
if to.BufferForwardType == ThresholdBufferForward && !to.IncludeCurrentSigs {
err = fmt.Errorf("if using buffer forwarder must include current signatures")
return
}
if to.CollectBroadcast != Full && (to.RndMemberType != NonRandom || to.OrderingType == Causal) {
err = fmt.Errorf("collect broadcast only supported for total order and non-random membership")
return
}
if to.SigType == TBLS && (to.UseMultisig || to.BlsMultiNew || !to.UsePubIndex) {
err = fmt.Errorf("for bls thrsh (TBLS) must not use multi sig or bls multi new and must use put index, useMultiSig: %v, BlsMultiNew: %v, UsePubIndex %v",
to.UseMultisig, to.BlsMultiNew, to.UsePubIndex)
return
}
if to.SigType == QSAFE && !config.AllowQsafe {
err = fmt.Errorf("qsafe signatures disabled in config.go")
return
}
if to.MCType == CurrencyMC {
if to.StateMachineType != CurrencyTxProposer {
err = fmt.Errorf("if using CurrencySM, then must use SimpleCurrencyTxProposer state machie")
return
}
if to.CollectBroadcast != Full {
err = fmt.Errorf("TODO allow collect broadcast the currency proposer (we need to be able to tenatively predict the next coordinator from the current proposal state)")
return
}
}
if consProcs < 4 {
err = fmt.Errorf("must have at least 4 consensus participants")
return
}
if to.AllowConcurrent > 1 && (to.MCType != TrueMC || to.RndMemberType != NonRandom) {
err = fmt.Errorf("must use static membership for concurrent consensus")
return
}
if to.UseMultisig && to.SigType != BLS {
err = fmt.Errorf("multisig and sig type %v not valid", to.SigType)
return
}
if to.OrderingType != GetOrderForSM(to.StateMachineType) {
err = fmt.Errorf("sm type %v not valid for order type %v", to.OrderingType, to.StateMachineType)
return
}
switch to.ConsType {
case SimpleConsType:
if to.StateMachineType != TestProposer {
err = fmt.Errorf("must use SimpleProposalInfo with SimpleCons")
return
}
default:
if to.StateMachineType == TestProposer {
err = fmt.Errorf("must use SimpleProposalInfo with SimpleCons")
return
}
switch isMv {
case true:
if to.StateMachineType == BinaryProposer {
err = fmt.Errorf("must not use binary proposer for multi value cons")
return
}
case false:
if to.StateMachineType != BinaryProposer {
err = fmt.Errorf("must use binary proposer for non-multi value cons")
return
}
}
}
switch to.SigType {
case EDCOIN, TBLS, TBLSDual, CoinDual:
if !to.UsePubIndex {
err = fmt.Errorf("must use pub index with threshold signatures")
return
}
if to.RndMemberType != NonRandom {
err = fmt.Errorf("must use static membership for threhosld or coin signatures")
return
}
switch to.MCType {
case TrueMC, CurrentTrueMC:
default:
err = fmt.Errorf("must use static membership for threhosld or coin signatures")
return
}
}
switch consType {
case BinConsRnd1Type, BinConsRnd2Type, BinConsRnd3Type, BinConsRnd4Type, BinConsRnd5Type,
BinConsRnd6Type, MvBinConsRnd1Type, MvBinConsRnd2Type:
switch to.CoinType {
case NoCoinType:
err = fmt.Errorf("must use a coin type when using a randomized consensus")
return
case FlipCoinType, KnownCoinType, LocalCoinType:
// ok
default:
if !to.UsePubIndex {
err = fmt.Errorf("must use pub index for BinConsRnd1Type/MvBinConsRnd1Type")
return
}
switch to.SigType {
case EDCOIN, TBLS, TBLSDual, CoinDual:
default:
err = fmt.Errorf("must use threshold or coin sigs for BinConsRnd1")
return
}
switch to.RndMemberType {
case NonRandom:
default:
err = fmt.Errorf("BinConsRnd1 does not support random membership")
return
}
}
default:
if to.UseFixedCoinPresets {
err = fmt.Errorf("UseFixedCoinPresets not used for non-randomized consensus types")
return
}
}
if to.RndMemberCount > 0 && to.NumNonMembers > 0 {
if consProcs < to.RndMemberCount {
err = fmt.Errorf("must have at least as many normal members as random members")
return
}
// panic(1)
// return fmt.Errorf("currently not supported to have non-members and rand members") // TODO fix this.
}
if to.RndMemberType != NonRandom && to.RndMemberCount < 4 {
err = fmt.Errorf("if using random membership selection, must have a RndMemberCout at least 4")
return
}
if (consType == RbBcast1Type || consType == RbBcast2Type) && (to.RndMemberType == VRFPerCons ||
to.RndMemberType == VRFPerMessage || to.UseRandCoord) {
err = fmt.Errorf("cons type RbBcast does not support VRFPerCons or VRFPerMessage (because there will be differnt coordinators, and will block termination)")
return
}
if to.NetworkType == RequestForwarder && (to.RndMemberType != LocalRandMember || to.BufferForwardType != NoBufferForward) {
err = fmt.Errorf("request forwarder and local random mebership must be used together, and without BufferForwarder")
return
}
if to.RndMemberType == LocalRandMember {
if to.NetworkType != RequestForwarder {
err = fmt.Errorf("localRandMember must be used with RequestForwarder network")
return
}
//if to.RndMemberCount < to.FanOut {
// return fmt.Errorf("with request forwarder, must have ran out at least as large as rand member count")
//}
}
if to.RndMemberType == NonRandom && to.RndMemberCount > 0 {
err = fmt.Errorf("if > 0 RndMemberCount then must use a random member type")
return
}
if !(to.GenRandBytes || to.RndMemberType == LocalRandMember) && to.RndMemberCount > 0 {
err = fmt.Errorf("if ChooseRandMembers, then GenRandBytes must be true")
return
}
if !to.GenRandBytes && to.UseRandCoord {
err = fmt.Errorf("GenRandBytes must be true if using random coordinator")
}
if !to.AllowsRandMembers(to.MCType) && to.RndMemberCount > 0 {
err = fmt.Errorf("member checker type %v does not support random membership", to.MCType)
return
}
if to.NumFailProcs > 0 && to.ByzType != NonFaulty {
err = fmt.Errorf("cannot have both byzantine and crash processes in the same test")
return
}
if to.UseMultisig {
switch to.RndMemberType {
case NonRandom, KnownPerCons:
// multisig allowed
default:
err = fmt.Errorf("multisig and random member selection not currently supported")
return
}
}
if to.NumNonMembers >= to.NumTotalProcs {
err = fmt.Errorf("need to have some members")
return
}
if to.ByzType != NonFaulty && to.NumByz == 0 {
logging.Info("if byz type them must have at least 1 byz faulty process, updating the test config to use" +
" 1/3 of the number of nodes")
newTo.NumByz = GetOneThirdBottom(consProcs)
}
if (consProcs%3 == 0 && to.NumByz >= consProcs/3) || (consProcs%3 != 0 && to.NumByz > consProcs/3) {
logging.Error("if byz type them must have less than 1/3 byz faulty process, updating the test config to use" +
"1/3 of the number of nodes")
newTo.NumByz = GetOneThirdBottom(consProcs)
}
if to.FanOut >= to.NumTotalProcs {
err = fmt.Errorf("use all to all connection if network fan out is the same as the number of processes")
return
}
if to.FanOut < 1 && (to.NetworkType == P2p || to.NetworkType == Random || to.NetworkType == RequestForwarder) {
err = fmt.Errorf("Must have fan out of at least 1 for p2p network")
return
}
if to.UseMultisig && !to.UsePubIndex {
err = fmt.Errorf("Multisig must be used with use pub index")
return
}
if consType == MvCons3Type || consType == MvCons4Type {
if config.KeepFuture < 5 {
err = fmt.Errorf("when using MvCons3/4 generalconfig.KeepFuture must be at least 5")
return
}
}
if consType == MvCons4Type {
if to.AllowConcurrent < 4 {
err = fmt.Errorf("when using MvCons4 AllowConcurrent must be at least 4")
return
}
if to.RotateCord {
err = fmt.Errorf("MvCons4 does not support rotate coord")
return
}
if to.MCType != TrueMC {
err = fmt.Errorf("TrueMC must be used with MvCons4")
return
}
if to.RndMemberType != NonRandom {
err = fmt.Errorf("MvCons4 must not have random members")
return
}
if to.UseMultisig {
err = fmt.Errorf("MvCons4 does not support mulit-sig")
return
}
if config.MvBroadcastInitForBufferForwarder {
panic("unsupported")
}
switch to.MvCons4BcastType {
case Normal:
switch to.NetworkType {
case AllToAll, P2p, Random: // ok
default:
err = fmt.Errorf("MvCons4 broadcast type %v does not support network type %v",
to.MvCons4BcastType, to.NetworkType)
return
}
case Direct, Indices:
if to.IncludeProofs {
err = fmt.Errorf("MvCons4 does not support mulit-sig with broadcast type %v",
to.MvCons4BcastType)
return
}
if to.NetworkType != AllToAll {
err = fmt.Errorf("MvCons4 broadcast type %v does not support network type %v",
to.MvCons4BcastType, to.NetworkType)
return
}
}
//if to.NumNonMembers != 0 {
// err = fmt.Errorf("all participants must be members in MvCons4Type")
//}
}
if consType == MvCons3Type {
if to.AllowConcurrent != 0 {
err = fmt.Errorf("when using MvCons3 AllowConcurrent must be 0")
return
}
switch to.MCType {
case TrueMC, LaterMC: // ok
default:
err = fmt.Errorf("when using MvCons3 must use true memberchecker TrueMC or LaterMC")
return
}
if to.CollectBroadcast != Full && (to.RotateCord || to.RndMemberType != NonRandom || to.UseRandCoord) {
err = fmt.Errorf("must set rotateCord to false and disable random membership when using MvCons3")
return
}
}
if to.OrderingType == Causal {
if to.RotateCord {
err = fmt.Errorf("must set rotateCord to false when using causal order")
return
}
if to.UseRandCoord {
err = fmt.Errorf("UseRandCoord must be fale when using causal ordering")
return
}
if to.ByzType != NonFaulty {
err = fmt.Errorf("TODO") // TODO
return
}
if to.MCType == LaterMC {
err = fmt.Errorf("LaterMC only compatible with total ordering")
return
}
}
if to.GenRandBytes {
switch to.SigType {
case TBLS, BLS, TBLSDual, EC: // OK
default:
err = fmt.Errorf("signatures type %v do not support generating random bytes", to.SigType)
return
}
}
return
}
// GetTestOptions generates a types.TestOptions object from a json formatted file.
func GetTestOptions(optionsPath string) (to TestOptions, err error) {
var raw []byte
raw, err = ioutil.ReadFile(filepath.Join(optionsPath))
if err != nil {
return
}
err = json.Unmarshal(raw, &to)
return
}
// ToToDisk stores the test options to disk in folderPath, using TestID as the file name.
func TOToDisk(folderPath string, to TestOptions) error {
toByt, err := json.MarshalIndent(to, "", "\t")
if err != nil {
return err
}
if err := ioutil.WriteFile(filepath.Join(folderPath, fmt.Sprintf("%v.json", to.TestID)),
toByt, os.ModePerm); err != nil {
return err
}
return nil
}
// ToToDisk stores the test options to disk in folderPath, using TestID as the file name.
func TOConsToDisk(folderPath string, to TestOptionsCons) error {
toByt, err := json.MarshalIndent(to, "", "\t")
if err != nil {
return err
}
if err := ioutil.WriteFile(filepath.Join(folderPath, fmt.Sprintf("%v.json", to.TestID)),
toByt, os.ModePerm); err != nil {
return err
}
return nil
}
func GetOneThirdBottom(n int) int {
switch n % 3 {
case 0:
return n/3 - 1
default:
return n / 3
}
}