-
Notifications
You must be signed in to change notification settings - Fork 669
/
parameters.go
86 lines (77 loc) · 4.13 KB
/
parameters.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowball
import (
"fmt"
"time"
)
const (
errMsg = "" +
`__________ .___` + "\n" +
`\______ \____________ __| _/__.__.` + "\n" +
` | | _/\_ __ \__ \ / __ < | |` + "\n" +
` | | \ | | \// __ \_/ /_/ |\___ |` + "\n" +
` |______ / |__| (____ /\____ |/ ____|` + "\n" +
` \/ \/ \/\/` + "\n" +
"\n" +
` 🏆 🏆 🏆 🏆 🏆 🏆 🏆` + "\n" +
` ________ ________ ________________` + "\n" +
` / _____/ \_____ \ / _ \__ ___/` + "\n" +
`/ \ ___ / | \ / /_\ \| |` + "\n" +
`\ \_\ \/ | \/ | \ |` + "\n" +
` \______ /\_______ /\____|__ /____|` + "\n" +
` \/ \/ \/` + "\n"
)
// Parameters required for snowball consensus
type Parameters struct {
K int `json:"k" yaml:"k"`
Alpha int `json:"alpha" yaml:"alpha"`
BetaVirtuous int `json:"betaVirtuous" yaml:"betaVirtuous"`
BetaRogue int `json:"betaRogue" yaml:"betaRogue"`
ConcurrentRepolls int `json:"concurrentRepolls" yaml:"concurrentRepolls"`
OptimalProcessing int `json:"optimalProcessing" yaml:"optimalProcessing"`
// Reports unhealthy if more than this number of items are outstanding.
MaxOutstandingItems int `json:"maxOutstandingItems" yaml:"maxOutstandingItems"`
// Reports unhealthy if there is an item processing for longer than this
// duration.
MaxItemProcessingTime time.Duration `json:"maxItemProcessingTime" yaml:"maxItemProcessingTime"`
// If this node is a validator, when a container is inserted into consensus,
// send a Push Query to this many validators and a Pull Query to the other
// k - MixedQueryNumPushVdr validators. Must be in [0, K].
MixedQueryNumPushVdr int `json:"mixedQueryNumPushVdr" yaml:"mixedQueryNumPushVdr"`
// If this node is not a validator, when a container is inserted into consensus,
// send a Push Query to this many validators and a Pull Query to the other
// k - MixedQueryNumPushVdr validators. Must be in [0, K].
MixedQueryNumPushNonVdr int `json:"mixedQueryNumPushNonVdr" yaml:"mixedQueryNumPushNonVdr"`
}
// Verify returns nil if the parameters describe a valid initialization.
func (p Parameters) Verify() error {
switch {
case p.Alpha <= p.K/2:
return fmt.Errorf("k = %d, alpha = %d: fails the condition that: k/2 < alpha", p.K, p.Alpha)
case p.K < p.Alpha:
return fmt.Errorf("k = %d, alpha = %d: fails the condition that: alpha <= k", p.K, p.Alpha)
case p.BetaVirtuous <= 0:
return fmt.Errorf("betaVirtuous = %d: fails the condition that: 0 < betaVirtuous", p.BetaVirtuous)
case p.BetaRogue == 3 && p.BetaVirtuous == 28:
return fmt.Errorf("betaVirtuous = %d, betaRogue = %d: fails the condition that: betaVirtuous <= betaRogue\n%s", p.BetaVirtuous, p.BetaRogue, errMsg)
case p.BetaRogue < p.BetaVirtuous:
return fmt.Errorf("betaVirtuous = %d, betaRogue = %d: fails the condition that: betaVirtuous <= betaRogue", p.BetaVirtuous, p.BetaRogue)
case p.ConcurrentRepolls <= 0:
return fmt.Errorf("concurrentRepolls = %d: fails the condition that: 0 < concurrentRepolls", p.ConcurrentRepolls)
case p.ConcurrentRepolls > p.BetaRogue:
return fmt.Errorf("concurrentRepolls = %d, betaRogue = %d: fails the condition that: concurrentRepolls <= betaRogue", p.ConcurrentRepolls, p.BetaRogue)
case p.OptimalProcessing <= 0:
return fmt.Errorf("optimalProcessing = %d: fails the condition that: 0 < optimalProcessing", p.OptimalProcessing)
case p.MaxOutstandingItems <= 0:
return fmt.Errorf("maxOutstandingItems = %d: fails the condition that: 0 < maxOutstandingItems", p.MaxOutstandingItems)
case p.MaxItemProcessingTime <= 0:
return fmt.Errorf("maxItemProcessingTime = %d: fails the condition that: 0 < maxItemProcessingTime", p.MaxItemProcessingTime)
case p.MixedQueryNumPushVdr > p.K:
return fmt.Errorf("mixedQueryNumPushVdr (%d) > K (%d)", p.MixedQueryNumPushVdr, p.K)
case p.MixedQueryNumPushNonVdr > p.K:
return fmt.Errorf("mixedQueryNumPushNonVdr (%d) > K (%d)", p.MixedQueryNumPushNonVdr, p.K)
default:
return nil
}
}