Skip to content

Commit ccafcc7

Browse files
authored
fix: update quorum params (#626)
* refactor: update quorum params * refactor: update quorum params * fix: lint issue * fix: move back btcjson.LLMQType_50_60
1 parent 6606260 commit ccafcc7

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

dash/llmq/llmq.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@ import (
1818
var (
1919
errThresholdInvalid = errors.New("threshold must be greater than 0")
2020
errKeySharesNotGenerated = errors.New("to initialize shares you must generate the keys")
21+
22+
quorumParams = map[btcjson.LLMQType]struct {
23+
Members int
24+
Threshold int
25+
}{
26+
btcjson.LLMQType_50_60: {50, 30},
27+
btcjson.LLMQType_400_60: {400, 240},
28+
btcjson.LLMQType_400_85: {400, 340},
29+
btcjson.LLMQType_100_67: {100, 67},
30+
btcjson.LLMQType_60_75: {60, 45},
31+
btcjson.LLMQType_25_67: {25, 16},
32+
btcjson.LLMQType_DEVNET: {12, 6},
33+
btcjson.LLMQType_TEST_V17: {3, 2},
34+
btcjson.LLMQType_TEST_DIP0024: {4, 2},
35+
btcjson.LLMQType_TEST_INSTANTSEND: {3, 2},
36+
btcjson.LLMQType_DEVNET_DIP0024: {8, 4},
37+
btcjson.LLMQType_TEST_PLATFORM: {3, 2},
38+
btcjson.LLMQType_DEVNET_PLATFORM: {12, 8},
39+
40+
// temporarily commented out due to the default behavior where if llmq type is not found
41+
// then we take the length of the actual validators as members
42+
//btcjson.LLMQType_TEST: {3, 2},
43+
}
2144
)
2245

2346
type optionFunc func(c *llmqConfig)
@@ -43,24 +66,16 @@ type blsLLMQData struct {
4366
pkShares []*bls.G1Element
4467
}
4568

46-
// QuorumProps returns corresponding LLMQ parameters
69+
// QuorumParams returns corresponding LLMQ parameters
4770
// the first integer is an expected size of quorum
4871
// the second is an expected threshold
4972
// the third parameter is an error, it returns in a case if quorumType is not supported
50-
func QuorumProps(quorumType btcjson.LLMQType) (int, int, error) {
51-
switch quorumType {
52-
case btcjson.LLMQType_50_60:
53-
return 50, 30, nil
54-
case btcjson.LLMQType_400_60:
55-
return 400, 240, nil
56-
case btcjson.LLMQType_400_85:
57-
return 400, 340, nil
58-
case btcjson.LLMQType_100_67:
59-
return 100, 67, nil
60-
case 101:
61-
return 10, 6, nil
73+
func QuorumParams(quorumType btcjson.LLMQType) (int, int, error) {
74+
params, ok := quorumParams[quorumType]
75+
if !ok {
76+
return 0, 0, fmt.Errorf("quorumType '%d' doesn't match with available", quorumType)
6277
}
63-
return 0, 0, fmt.Errorf("quorumType '%d' doesn't match with available", quorumType)
78+
return params.Members, params.Threshold, nil
6479
}
6580

6681
// MustGenerate generates long-living master node quorum, but panics if a got error

types/validator_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func (vals *ValidatorSet) QuorumVotingThresholdPower() int64 {
511511

512512
// QuorumTypeMemberCount returns a number of validators for a quorum by a type
513513
func (vals *ValidatorSet) QuorumTypeMemberCount() int {
514-
size, _, err := llmq.QuorumProps(vals.QuorumType)
514+
size, _, err := llmq.QuorumParams(vals.QuorumType)
515515
if err != nil {
516516
return len(vals.Validators)
517517
}
@@ -520,7 +520,7 @@ func (vals *ValidatorSet) QuorumTypeMemberCount() int {
520520

521521
// QuorumTypeThresholdCount returns a threshold number for a quorum by a type
522522
func (vals *ValidatorSet) QuorumTypeThresholdCount() int {
523-
_, threshold, err := llmq.QuorumProps(vals.QuorumType)
523+
_, threshold, err := llmq.QuorumParams(vals.QuorumType)
524524
if err != nil {
525525
return len(vals.Validators)*2/3 + 1
526526
}

0 commit comments

Comments
 (0)